Пример #1
0
    def _make_argparser(self):

        parser = s_cmd.Parser(prog='hive', outp=self, description=self.__doc__)

        subparsers = parser.add_subparsers(title='subcommands',
                                           required=True,
                                           dest='cmd',
                                           parser_class=functools.partial(
                                               s_cmd.Parser, outp=self))

        parser_ls = subparsers.add_parser('list',
                                          aliases=['ls'],
                                          help="List entries in the hive",
                                          usage=ListHelp)
        parser_ls.add_argument('path', nargs='?', help='Hive path')

        parser_get = subparsers.add_parser('get',
                                           help="Get any entry in the hive",
                                           usage=GetHelp)
        parser_get.add_argument('path', help='Hive path')
        parser_get.add_argument('-f',
                                '--file',
                                default=False,
                                action='store',
                                help='Save the data to a file.')
        parser_get.add_argument('--json',
                                default=False,
                                action='store_true',
                                help='Emit output as json')

        parser_rm = subparsers.add_parser('del',
                                          aliases=['rm'],
                                          help='Delete a key in the hive',
                                          usage=DelHelp)
        parser_rm.add_argument('path', help='Hive path')

        parser_edit = subparsers.add_parser('edit',
                                            aliases=['mod'],
                                            help='Sets/creates a key',
                                            usage=EditHelp)
        parser_edit.add_argument('--string',
                                 action='store_true',
                                 help="Edit value as a single string")
        parser_edit.add_argument('path', help='Hive path')
        group = parser_edit.add_mutually_exclusive_group(required=True)
        group.add_argument('value', nargs='?', help='Value to set')
        group.add_argument('--editor',
                           default=False,
                           action='store_true',
                           help='Opens an editor to set the value')
        group.add_argument('--file',
                           '-f',
                           help='Copies the contents of the file to the path')

        return parser
Пример #2
0
    def _make_argparser(self):

        parser = s_cmd.Parser(prog='trigger',
                              outp=self,
                              description=self.__doc__)
        help = 'The iden of the view where the trigger is/will be applied.  Defaults to the cortex default view.'
        parser.add_argument('--view', type=str, default=None, help=help)

        subparsers = parser.add_subparsers(title='subcommands',
                                           required=True,
                                           dest='cmd',
                                           parser_class=functools.partial(
                                               s_cmd.Parser, outp=self))

        subparsers.add_parser(
            'list',
            help="List triggers you're allowed to manipulate",
            usage=ListHelp)

        parser_add = subparsers.add_parser('add',
                                           help='add a trigger',
                                           usage=AddHelp)
        parser_add.add_argument('condition',
                                choices=s_trigger.Conditions,
                                type=str.lower,
                                help='Condition on which to trigger')
        parser_add.add_argument('--disabled',
                                action='store_true',
                                help='Create the trigger in disabled state')
        parser_add.add_argument('args',
                                metavar='arguments',
                                nargs='+',
                                help='[form] [#tag] [prop] {query}')

        parser_del = subparsers.add_parser('del',
                                           help='delete a trigger',
                                           usage=DelHelp)
        parser_del.add_argument('prefix', help='Trigger iden prefix')

        parser_mod = subparsers.add_parser(
            'mod', help='change an existing trigger query', usage=ModHelp)
        parser_mod.add_argument('prefix', help='Trigger iden prefix')
        parser_mod.add_argument('query', help='Storm query in curly braces')

        parser_en = subparsers.add_parser('enable',
                                          help='enable an existing trigger',
                                          usage=EnableHelp)
        parser_en.add_argument('prefix', help='trigger iden prefix')

        parser_dis = subparsers.add_parser('disable',
                                           help='disable an existing trigger',
                                           usage=DisableHelp)
        parser_dis.add_argument('prefix', help='trigger iden prefix')

        return parser
Пример #3
0
def makeargparser():
    desc = '''
    Command line tool for ingesting csv files into a cortex

    The storm file is run with the CSV rows specified in the variable "rows" so most
    storm files will use a variable based for loop to create edit nodes.  For example:

    for ($fqdn, $ipv4, $tag) in $rows {

        [ inet:dns:a=($fqdn, $ipv4) +#$tag ]

    }

    More advanced uses may include switch cases to provide different logic based on
    a column value.

    for ($type, $valu, $info) in $rows {

        switch $type {

            fqdn: {
                [ inet:fqdn=$valu ]
            }

            "person name": {
                [ ps:name=$valu ]
            }

            *: {
                // default case...
            }

        }

        switch $info {
            "known malware": { [+#cno.mal] }
        }

    }
    '''
    pars = s_cmd.Parser('synapse.tools.csvtool', description=desc)
    pars.add_argument('--logfile', help='Set a log file to get JSON lines from the server events.')
    pars.add_argument('--csv-header', default=False, action='store_true', help='Skip the first line from each CSV file.')
    pars.add_argument('--cli', default=False, action='store_true',
                      help='Drop into a cli session after loading data.')
    pars.add_argument('--debug', default=False, action='store_true', help='Enable verbose debug output.')
    muxp = pars.add_mutually_exclusive_group(required=True)
    muxp.add_argument('--cortex', '-c', type=str,
                      help='The telepath URL for the cortex ( or alias from ~/.syn/aliases ).')
    muxp.add_argument('--test', '-t', default=False, action='store_true',
                      help='Perform a local CSV ingest against a temporary cortex.')
    pars.add_argument('stormfile', help='A STORM script describing how to create nodes from rows.')
    pars.add_argument('csvfiles', nargs='+', help='CSV files to load.')
    return pars
Пример #4
0
    def _make_argparser(self):

        parser = s_cmd.Parser(prog='cron', outp=self, description=self.__doc__)

        subparsers = parser.add_subparsers(title='subcommands',
                                           required=True,
                                           dest='cmd',
                                           parser_class=functools.partial(
                                               s_cmd.Parser, outp=self))

        subparsers.add_parser(
            'list',
            help="List cron jobs you're allowed to manipulate",
            usage=ListHelp)

        parser_add = subparsers.add_parser('add',
                                           help='add a cron job',
                                           usage=AddHelp)
        parser_add.add_argument('--minute', '-M')
        parser_add.add_argument('--hour', '-H')
        parser_add.add_argument(
            '--day', '-d', help='day of week, day of month or number of days')
        parser_add.add_argument('--month', '-m')
        parser_add.add_argument('--year', '-y')
        group = parser_add.add_mutually_exclusive_group()
        group.add_argument('--hourly')
        group.add_argument('--daily')
        group.add_argument('--monthly')
        group.add_argument('--yearly')
        parser_add.add_argument('query', help='Storm query in curly braces')

        parser_del = subparsers.add_parser('del',
                                           help='delete a cron job',
                                           usage=DelHelp)
        parser_del.add_argument('prefix', help='Cron job iden prefix')

        parser_del = subparsers.add_parser('stat',
                                           help='details a cron job',
                                           usage=StatHelp)
        parser_del.add_argument('prefix', help='Cron job iden prefix')

        parser_mod = subparsers.add_parser(
            'mod', help='change an existing cron jobquery', usage=ModHelp)
        parser_mod.add_argument('prefix', help='Cron job iden prefix')
        parser_mod.add_argument('query',
                                help='New Storm query in curly braces')

        return parser
Пример #5
0
def makeargparser():
    global outp
    pars = s_cmd.Parser('synapse.tools.cellauth', outp=outp, description=desc)

    pars.add_argument('--debug', action='store_true', help='Show debug traceback on error.')
    pars.add_argument('cellurl', help='The telepath URL to connect to a cell.')

    subpars = pars.add_subparsers(required=True,
                                  title='subcommands',
                                  dest='cmd',
                                  parser_class=functools.partial(s_cmd.Parser, outp=outp))

    # list
    pars_list = subpars.add_parser('list', help='List users/roles')
    pars_list.add_argument('name', nargs='*', default=None, help='The name of the user/role to list')
    pars_list.add_argument('-d', '--detail', default=False, action='store_true',
                           help='Show rule details for roles associated with a user.')
    pars_list.set_defaults(func=handleList)

    # create / modify / delete
    pars_mod = subpars.add_parser('modify', help='Create, modify, delete the names user/role')
    muxp = pars_mod.add_mutually_exclusive_group()
    muxp.add_argument('--adduser', action='store_true', help='Add the named user to the cortex.')
    muxp.add_argument('--addrole', action='store_true', help='Add the named role to the cortex.')

    muxp.add_argument('--deluser', action='store_true', help='Delete the named user to the cortex.')
    muxp.add_argument('--delrole', action='store_true', help='Delete the named role to the cortex.')

    muxp.add_argument('--admin', action='store_true', help='Grant admin powers to the user/role.')
    muxp.add_argument('--noadmin', action='store_true', help='Revoke admin powers from the user/role.')

    muxp.add_argument('--lock', action='store_true', help='Lock the user account.')
    muxp.add_argument('--unlock', action='store_true', help='Unlock the user account.')

    muxp.add_argument('--passwd', help='Set the user password.')

    muxp.add_argument('--grant', help='Grant the specified role to the user.')
    muxp.add_argument('--revoke', help='Grant the specified role to the user.')

    muxp.add_argument('--addrule', help='Add the given rule to the user/role.')
    muxp.add_argument('--delrule', type=int, help='Delete the given rule number from the user/role.')

    pars_mod.add_argument('--object', type=str, help='The iden of the object to which to apply the new rule. Only '
                                                     'supported on Cells running Synapse >= 0.1.33.')

    pars_mod.add_argument('name', help='The user/role to modify.')
    pars_mod.set_defaults(func=handleModify)
    return pars
Пример #6
0
def makeargparser():
    desc = '''
    synapse healthcheck tool
    '''
    pars = s_cmd.Parser('healthcheck', description=desc)
    pars.add_argument('--cell',
                      '-c',
                      required=True,
                      type=str,
                      help='Telepath path to the cell to check.')
    pars.add_argument('--timeout',
                      '-t',
                      default=10,
                      type=float,
                      help='Connection and call timeout')
    return pars
Пример #7
0
    def _make_argparser(self):

        parser = s_cmd.Parser(prog='log', outp=self, description=self.__doc__)
        muxp = parser.add_mutually_exclusive_group(required=True)
        muxp.add_argument('--on',
                          action='store_true',
                          default=False,
                          help='Enables logging of storm messages to a file.')
        muxp.add_argument(
            '--off',
            action='store_true',
            default=False,
            help='Disables message logging and closes the current storm file.')
        parser.add_argument(
            '--format',
            choices=('mpk', 'jsonl'),
            default='mpk',
            type=str.lower,
            help=
            'The format used to save messages to disk. Defaults to msgpack (mpk).'
        )
        parser.add_argument(
            '--path',
            type=str,
            default=None,
            help=
            'The path to the log file.  This will append messages to a existing file.'
        )
        optmux = parser.add_mutually_exclusive_group()
        optmux.add_argument(
            '--edits-only',
            action='store_true',
            default=False,
            help='Only records edits. Does not record any other messages.')
        optmux.add_argument(
            '--nodes-only',
            action='store_true',
            default=False,
            help='Only record the packed nodes returned by storm.')
        return parser
Пример #8
0
    def _make_argparser(self):

        parser = s_cmd.Parser(prog='trigger',
                              outp=self,
                              description=self.__doc__)

        subparsers = parser.add_subparsers(title='subcommands',
                                           required=True,
                                           dest='cmd',
                                           parser_class=functools.partial(
                                               s_cmd.Parser, outp=self))

        subparsers.add_parser(
            'list',
            help="List triggers you're allowed to manipulate",
            usage=ListHelp)

        parser_add = subparsers.add_parser('add',
                                           help='add a trigger',
                                           usage=AddHelp)
        parser_add.add_argument('condition',
                                choices=s_trigger.Conditions,
                                type=str.lower,
                                help='Condition on which to trigger')
        parser_add.add_argument('args',
                                metavar='arguments',
                                nargs='+',
                                help='[form] [#tag] [prop] {query}')

        parser_del = subparsers.add_parser('del',
                                           help='delete a trigger',
                                           usage=DelHelp)
        parser_del.add_argument('prefix', help='Trigger iden prefix')

        parser_mod = subparsers.add_parser(
            'mod', help='change an existing trigger query', usage=ModHelp)
        parser_mod.add_argument('prefix', help='Trigger iden prefix')
        parser_mod.add_argument('query', help='Storm query in curly braces')
        return parser
Пример #9
0
 def _make_argparser(self):
     parser = s_cmd.Parser(prog='at', outp=self, description=self.__doc__)
     parser.add_argument('args', nargs='+', help='date | delta| {query})')
     return parser
Пример #10
0
 def _make_argparser(self):
     parser = s_cmd.Parser(prog='kill', outp=self, description=self.__doc__)
     parser.add_argument('iden', help='Task iden to kill.', type=str)
     return parser
Пример #11
0
 def getArgParser(self):
     desc = self.getCmdDoc()
     pars = s_cmd.Parser(prog=self._cmd_name,
                         description=desc,
                         outp=self._cmd_cli.outp)
     return pars
Пример #12
0
def makeargparser():
    global outp
    pars = s_cmd.Parser('synapse.tools.cellauth', outp=outp, description=desc)

    pars.add_argument('--debug',
                      action='store_true',
                      help='Show debug traceback on error.')
    pars.add_argument('cellurl', help='The telepath URL to connect to a cell.')

    subpars = pars.add_subparsers(required=True,
                                  title='subcommands',
                                  dest='cmd',
                                  parser_class=functools.partial(s_cmd.Parser,
                                                                 outp=outp))

    # list
    pars_list = subpars.add_parser('list', help='List users/roles')
    pars_list.add_argument('name',
                           nargs='*',
                           default=None,
                           help='The name of the user/role to list')
    pars_list.set_defaults(func=handleList)

    # create / modify / delete
    pars_mod = subpars.add_parser(
        'modify', help='Create, modify, delete the names user/role')
    pars_mod.add_argument('--adduser',
                          action='store_true',
                          help='Add the named user to the cortex.')
    pars_mod.add_argument('--addrole',
                          action='store_true',
                          help='Add the named role to the cortex.')

    pars_mod.add_argument('--admin',
                          action='store_true',
                          help='Grant admin powers to the user/role.')
    pars_mod.add_argument('--noadmin',
                          action='store_true',
                          help='Revoke admin powers from the user/role.')

    pars_mod.add_argument('--lock',
                          action='store_true',
                          help='Lock the user account.')
    pars_mod.add_argument('--unlock',
                          action='store_true',
                          help='Unlock the user account.')

    # pars_mod.add_argument('--deluser', action='store_true', help='Add the named user to the cortex.')
    # pars_mod.add_argument('--delrole', action='store_true', help='Add the named role to the cortex.')

    pars_mod.add_argument('--passwd', help='Set the user password.')

    pars_mod.add_argument('--grant',
                          help='Grant the specified role to the user.')
    pars_mod.add_argument('--revoke',
                          help='Grant the specified role to the user.')

    pars_mod.add_argument('--addrule',
                          help='Add the given rule to the user/role.')
    pars_mod.add_argument(
        '--delrule',
        type=int,
        help='Delete the given rule number from the user/role.')

    pars_mod.add_argument('name', help='The user/role to modify.')
    pars_mod.set_defaults(func=handleModify)
    return pars