# -*- encoding: utf-8 -*- # TODO: Fix stream/interaction from pupylib.PupyModule import PupyArgumentParser, PupyModuleUsageError from pupylib.PupyCompleter import module_name_completer, module_args_completer, path_completer from pupylib.PupyOutput import Error, Success from pupylib.PupyJob import PupyJob from argparse import REMAINDER usage = 'Run a module on one or multiple clients' parser = PupyArgumentParser(prog='run', description=usage) parser.add_argument('-1', '--once', default=False, action='store_true', help='Unload new deps after usage') parser.add_argument('-o', '--output', help='save command output to file.' '%%t - timestamp, %%h - host, %%m - mac, ' '%%c - client shortname, %%M - module name, ' '%%p - platform, %%u - user, %%a - ip address', completer=path_completer) parser.add_argument( '-f', '--filter', metavar='<client filter>', help= 'filter to a subset of all clients. All fields available in the "info" module can be used. '
# -*- encoding: utf-8 -*- from pupylib.PupyModule import PupyArgumentParser from pupylib.PupyOutput import ( Color, Error, Success, Table, TruncateToTerm, NewLine, Line, MultiPart ) from pupylib.utils.credentials import Credentials usage = 'Credentials manager' parser = PupyArgumentParser(prog='creds', description=usage) parser.add_argument('-A', '--all', action='store_true', help='Search/Show info for all machines, not only active ones') parser.add_argument('-k', '--key', help='Search in key in objects with key') parser.add_argument('-s', '--sort', action='store_true', help='Search in key in objects with key') parser.add_argument('--delete-db', action='store_true', help='Delete DB') parser.add_argument('search', default='', nargs='?', help='Keyword to search') def do(server, handler, config, modargs): try: credentials = Credentials(config=config) except Exception, e: handler.display(Error(e)) return clients = server.get_clients_list() cids = None if modargs.delete_db: credentials.remove()
# -*- encoding: utf-8 -*- from pupylib.PupyModule import PupyArgumentParser from pupylib.PupyOutput import Success, Color, Table import logging levels = [ 'DEBUG', 'INFO', 'WARNING', 'ERROR' ] levels += [ x.lower() for x in levels ] usage = "Show/set log level" parser = PupyArgumentParser(prog='logging', description='change pupysh logging level') parser.add_argument( '-L', '--logger', help='Apply log level only for specified logger', choices=logging.Logger.manager.loggerDict.keys() ) parser.add_argument('-s', '--set-level', choices=levels, help='Set log level') parser.add_argument('-g', '--get-level', action='store_true', help='Get log level') parser.add_argument('level', choices=levels, nargs='?', help='Set log level') def levelToString(level): return { logging.ERROR: 'ERROR', logging.WARNING: 'WARNING', logging.INFO: 'INFO', logging.DEBUG: 'DEBUG' }.get(level) def levelToColor(level): return { logging.ERROR: 'grey',
# -*- encoding: utf-8 -*- from pupylib.PupyModule import PupyArgumentParser from pupylib.PupyOutput import Color, Success, Error, Table usage = 'list/interact with established sessions' parser = PupyArgumentParser(prog='sessions', description=usage) parser.add_argument('-i', '--interact', metavar='<filter>', help="change the default --filter value for other commands") parser.add_argument('-g', '--global-reset', action='store_true', help="reset --interact to the default global behavior") parser.add_argument('-k', dest='kill', metavar='<id>', type=int, help='Kill the selected session') parser.add_argument('-K', dest='killall', action='store_true', help='Kill all sessions') parser.add_argument('-d', dest='drop', metavar='<id>', type=int, help='Drop the connection (abruptly close the socket)') parser.add_argument('-D', dest='dropall', action='store_true', help='Drop all connections') def do(server, handler, config, modargs): if modargs.global_reset: handler.default_filter = None handler.display(Success('Default filter reset to global')) elif modargs.interact: handler.default_filter = modargs.interact handler.display(Success('Default filter set to {}'.format( handler.default_filter))) elif modargs.kill: selected_client = server.get_clients(modargs.kill) if selected_client: try:
# -*- encoding: utf-8 -*- from pupylib.PupyModule import PupyArgumentParser from pupylib.PupyOutput import NewLine, MultiPart, Table, Color, Line, TruncateToTerm from pupylib.PupyCompleter import commands_completer usage = 'Show help' parser = PupyArgumentParser(prog='help', description=usage) parser.add_argument('module', nargs='?', help='Show information about command', completer=commands_completer) parser.add_argument('-M', '--modules', action='store_true', help='Show information about all modules') def do(server, handler, config, args): tables = [] if args.module: if handler.commands.has(args.module): command = handler.commands.get(args.module) tables.append( Line(Color('Command:', 'yellow'), Color(args.module + ':', 'green'), command.usage or 'No description')) if command.parser.add_help: tables.append(command.parser.format_help())
def init_argparse(cls): # changes from original main : # - argparse.ArgumentParser to PupyArgumentParser # - parser to cls.arg_parser # - function name to string (ex: func=get_adobject to func="get_adobject") cls.arg_parser = PupyArgumentParser( description= 'Rewriting of some PowerView\'s functionalities in Python') subparsers = cls.arg_parser.add_subparsers( title='Subcommands', description='Available subcommands') # TODO: support keberos authentication # Credentials parser credentials_parser = PupyArgumentParser(add_help=False) credentials_parser.add_argument( '-w', '--workgroup', dest='domain', default=str(), help='Name of the domain we authenticate with') credentials_parser.add_argument( '-u', '--user', required=True, help='Username used to connect to the Domain Controller') credentials_parser.add_argument( '-p', '--password', default=str(), help='Password associated to the username') credentials_parser.add_argument( '--hashes', action='store', metavar='LMHASH:NTHASH', help='NTLM hashes, format is LMHASH:NTHASH') # AD parser, used for net* functions running against a domain controller ad_parser = PupyArgumentParser(add_help=False, parents=[credentials_parser]) ad_parser.add_argument( '-t', '--dc-ip', dest='domain_controller', required=True, help='IP address of the Domain Controller to target') # Target parser, used for net* functions running against a normal computer target_parser = PupyArgumentParser(add_help=False, parents=[credentials_parser]) target_parser.add_argument('--computername', dest='target_computername', required=True, help='IP address of the computer target') # Parser for the get-adobject command get_adobject_parser= subparsers.add_parser('get-adobject', help='Takes a domain SID, '\ 'samAccountName or name, and return the associated object', parents=[ad_parser]) get_adobject_parser.add_argument( '--sid', dest='queried_sid', help='SID to query (wildcards accepted)') get_adobject_parser.add_argument( '--sam-account-name', dest='queried_sam_account_name', help='samAccountName to query (wildcards accepted)') get_adobject_parser.add_argument( '--name', dest='queried_name', help='Name to query (wildcards accepted)') get_adobject_parser.add_argument('-d', '--domain', dest='queried_domain', help='Domain to query') get_adobject_parser.add_argument('-a', '--ads-path', help='Additional ADS path') get_adobject_parser.set_defaults(func="get_adobject") # Parser for the get-netuser command get_netuser_parser= subparsers.add_parser('get-netuser', help='Queries information about '\ 'a domain user', parents=[ad_parser]) get_netuser_parser.add_argument( '--username', dest='queried_username', help='Username to query (wildcards accepted)') get_netuser_parser.add_argument('-d', '--domain', dest='queried_domain', help='Domain to query') get_netuser_parser.add_argument('-a', '--ads-path', help='Additional ADS path') get_netuser_parser.add_argument( '--unconstrained', action='store_true', help='Query only users with unconstrained delegation') get_netuser_parser.add_argument( '--admin-count', action='store_true', help='Query only users with adminCount=1') get_netuser_parser.add_argument( '--allow-delegation', action='store_true', help= 'Return user accounts that are not marked as \'sensitive and not allowed for delegation\'' ) get_netuser_parser.add_argument( '--spn', action='store_true', help='Query only users with not-null Service Principal Names') get_netuser_parser.set_defaults(func='get_netuser') # Parser for the get-netgroup command get_netgroup_parser= subparsers.add_parser('get-netgroup', help='Get a list of all current '\ 'domain groups, or a list of groups a domain user is member of', parents=[ad_parser]) get_netgroup_parser.add_argument( '--groupname', dest='queried_groupname', default='*', help='Group to query (wildcards accepted)') get_netgroup_parser.add_argument('--sid', dest='queried_sid', help='Group SID to query') get_netgroup_parser.add_argument( '--username', dest='queried_username', help= 'Username to query: will list the groups this user is a member of (wildcards accepted)' ) get_netgroup_parser.add_argument('-d', '--domain', dest='queried_domain', help='Domain to query') get_netgroup_parser.add_argument('-a', '--ads-path', dest='ads_path', help='Additional ADS path') get_netgroup_parser.add_argument( '--full-data', action='store_true', help= 'If set, returns full information on the groups, otherwise, just the samAccountName' ) get_netgroup_parser.add_argument( '--admin-count', action='store_true', help='Query only users with adminCount=1') get_netgroup_parser.set_defaults(func='get_netgroup') # Parser for the get-netcomputer command get_netcomputer_parser= subparsers.add_parser('get-netcomputer', help='Queries informations about '\ 'domain computers', parents=[ad_parser]) get_netcomputer_parser.add_argument('--computername', dest='queried_computername', default='*', help='Computer name to query') get_netcomputer_parser.add_argument( '-os', '--operating-system', dest='queried_os', help= 'Return computers with a specific operating system (wildcards accepted)' ) get_netcomputer_parser.add_argument( '-sp', '--service-pack', dest='queried_sp', help= 'Return computers with a specific service pack (wildcards accepted)' ) get_netcomputer_parser.add_argument( '-spn', '--service-principal-name', dest='queried_spn', help= 'Return computers with a specific service principal name (wildcards accepted)' ) get_netcomputer_parser.add_argument('-d', '--domain', dest='queried_domain', help='Domain to query') get_netcomputer_parser.add_argument('-a', '--ads-path', dest='ads_path', help='Additional ADS path') get_netcomputer_parser.add_argument('--printers', action='store_true', help='Query only printers') get_netcomputer_parser.add_argument( '--unconstrained', action='store_true', help='Query only computers with unconstrained delegation') get_netcomputer_parser.add_argument( '--ping', action='store_true', help='Ping computers (will only return up computers)') get_netcomputer_parser.add_argument( '--full-data', action='store_true', help= 'If set, returns full information on the groups, otherwise, just the dnsHostName' ) get_netcomputer_parser.set_defaults(func='get_netcomputer') # Parser for the get-netdomaincontroller command get_netdomaincontroller_parser= subparsers.add_parser('get-netdomaincontroller', help='Get a list of '\ 'domain controllers for the given domain', parents=[ad_parser]) get_netdomaincontroller_parser.add_argument('-d', '--domain', dest='queried_domain', help='Domain to query') get_netdomaincontroller_parser.set_defaults( func='get_netdomaincontroller') # Parser for the get-netfileserver command get_netfileserver_parser= subparsers.add_parser('get-netfileserver', help='Return a list of '\ 'file servers, extracted from the domain users\' homeDirectory, scriptPath, and profilePath fields', parents=[ad_parser]) get_netfileserver_parser.add_argument( '--target-users', nargs='+', metavar='TARGET_USER', help= 'A list of users to target to find file servers (wildcards accepted)' ) get_netfileserver_parser.add_argument('-d', '--domain', dest='queried_domain', help='Domain to query') get_netfileserver_parser.set_defaults(func='get_netfileserver') # Parser for the get-dfsshare command get_dfsshare_parser= subparsers.add_parser('get-dfsshare', help='Return a list of '\ 'all fault tolerant distributed file systems for a given domain', parents=[ad_parser]) get_dfsshare_parser.add_argument('-d', '--domain', dest='queried_domain', help='Domain to query') get_dfsshare_parser.add_argument( '-v', '--version', nargs='+', choices=['v1', 'v2'], default=['v1', 'v2'], help= 'The version of DFS to query for servers: v1, v2 or all (default: all)' ) get_dfsshare_parser.add_argument('-a', '--ads-path', dest='ads_path', help='Additional ADS path') get_dfsshare_parser.set_defaults(func='get_dfsshare') # Parser for the get-netou command get_netou_parser= subparsers.add_parser('get-netou', help='Get a list of all current '\ 'OUs in the domain', parents=[ad_parser]) get_netou_parser.add_argument( '--ouname', dest='queried_ouname', default='*', help='OU name to query (wildcards accepted)') get_netou_parser.add_argument( '--guid', dest='queried_guid', help= 'Only return OUs with the specified GUID in their gplink property.' ) get_netou_parser.add_argument('-d', '--domain', dest='queried_domain', help='Domain to query') get_netou_parser.add_argument('-a', '--ads-path', help='Additional ADS path') get_netou_parser.add_argument( '--full-data', action='store_true', help= 'If set, returns full information on the OUs, otherwise, just the adspath' ) get_netou_parser.set_defaults(func='get_netou') # Parser for the get-netsite command get_netsite_parser= subparsers.add_parser('get-netsite', help='Get a list of all current '\ 'sites in the domain', parents=[ad_parser]) get_netsite_parser.add_argument( '--sitename', dest='queried_sitename', help='Site name to query (wildcards accepted)') get_netsite_parser.add_argument( '--guid', dest='queried_guid', help= 'Only return sites with the specified GUID in their gplink property.' ) get_netsite_parser.add_argument('-d', '--domain', dest='queried_domain', help='Domain to query') get_netsite_parser.add_argument('-a', '--ads-path', help='Additional ADS path') get_netsite_parser.add_argument( '--full-data', action='store_true', help= 'If set, returns full information on the sites, otherwise, just the name' ) get_netsite_parser.set_defaults(func='get_netsite') # Parser for the get-netsubnet command get_netsubnet_parser= subparsers.add_parser('get-netsubnet', help='Get a list of all current '\ 'subnets in the domain', parents=[ad_parser]) get_netsubnet_parser.add_argument( '--sitename', dest='queried_sitename', help= 'Only return subnets for the specified site name (wildcards accepted)' ) get_netsubnet_parser.add_argument('-d', '--domain', dest='queried_domain', help='Domain to query') get_netsubnet_parser.add_argument('-a', '--ads-path', help='Additional ADS path') get_netsubnet_parser.add_argument( '--full-data', action='store_true', help= 'If set, returns full information on the subnets, otherwise, just the name' ) get_netsubnet_parser.set_defaults(func='get_netsubnet') # Parser for the get-netgpo command get_netgpo_parser= subparsers.add_parser('get-netgpo', help='Get a list of all current '\ 'GPOs in the domain', parents=[ad_parser]) get_netgpo_parser.add_argument( '--gponame', dest='queried_gponame', default='*', help='GPO name to query for (wildcards accepted)') get_netgpo_parser.add_argument( '--displayname', dest='queried_displayname', help='Display name to query for (wildcards accepted)') get_netgpo_parser.add_argument('-d', '--domain', dest='queried_domain', help='Domain to query') get_netgpo_parser.add_argument('-a', '--ads-path', help='Additional ADS path') get_netgpo_parser.set_defaults(func='get_netgpo') # Parser for the get-netgroup command get_netgroupmember_parser = subparsers.add_parser( 'get-netgroupmember', help='Return a list of members of a domain groups', parents=[ad_parser]) get_netgroupmember_parser.add_argument( '--groupname', dest='queried_groupname', help= 'Group to query, defaults to the \'Domain Admins\' group (wildcards accepted)' ) get_netgroupmember_parser.add_argument('--sid', dest='queried_sid', help='SID to query') get_netgroupmember_parser.add_argument('-d', '--domain', dest='queried_domain', help='Domain to query') get_netgroupmember_parser.add_argument('-a', '--ads-path', dest='ads_path', help='Additional ADS path') get_netgroupmember_parser.add_argument( '-r', '--recurse', action='store_true', help= 'If the group member is a group, try to resolve its members as well' ) get_netgroupmember_parser.add_argument('--use-matching-rule', action='store_true', help='Use LDAP_MATCHING_RULE_IN_CHAIN in the LDAP search query when -Recurse is specified.\n' \ 'Much faster than manual recursion, but doesn\'t reveal cross-domain groups') get_netgroupmember_parser.add_argument( '--full-data', action='store_true', help='If set, returns full information on the members') get_netgroupmember_parser.set_defaults(func='get_netgroupmember') # Parser for the get-netsession command get_netsession_parser= subparsers.add_parser('get-netsession', help='Queries a host to return a '\ 'list of active sessions on the host (you can use local credentials instead of domain credentials)', parents=[target_parser]) get_netsession_parser.set_defaults(func='get_netsession') #Parser for the get-localdisks command get_localdisks_parser = subparsers.add_parser('get-localdisks', help='Queries a host to return a '\ 'list of active disks on the host (you can use local credentials instead of domain credentials)', parents=[target_parser]) get_localdisks_parser.set_defaults(func='get_localdisks') #Parser for the get-netdomain command get_netdomain_parser = subparsers.add_parser( 'get-netdomain', help='Queries a host for available domains', parents=[ad_parser]) get_netdomain_parser.set_defaults(func='get_netdomain') # Parser for the get-netshare command get_netshare_parser= subparsers.add_parser('get-netshare', help='Queries a host to return a '\ 'list of available shares on the host (you can use local credentials instead of domain credentials)', parents=[target_parser]) get_netshare_parser.set_defaults(func='get_netshare') # Parser for the get-netloggedon command get_netloggedon_parser= subparsers.add_parser('get-netloggedon', help='This function will '\ 'execute the NetWkstaUserEnum RPC call ti query a given host for actively logged on '\ 'users', parents=[target_parser]) get_netloggedon_parser.set_defaults(func='get_netloggedon') # Parser for the get-netlocalgroup command get_netlocalgroup_parser= subparsers.add_parser('get-netlocalgroup', help='Gets a list of '\ 'members of a local group on a machine, or returns every local group. You can use local '\ 'credentials instead of domain credentials, however, domain credentials are needed to '\ 'resolve domain SIDs.', parents=[target_parser]) get_netlocalgroup_parser.add_argument( '--groupname', dest='queried_groupname', help= 'Group to list the members of (defaults to the local \'Administrators\' group' ) get_netlocalgroup_parser.add_argument( '--list-groups', action='store_true', help='If set, returns a list of the local groups on the targets') get_netlocalgroup_parser.add_argument( '-t', '--dc-ip', dest='domain_controller', default=str(), help= 'IP address of the Domain Controller (used to resolve domain SIDs)' ) get_netlocalgroup_parser.add_argument( '-r', '--recurse', action='store_true', help= 'If the group member is a domain group, try to resolve its members as well' ) get_netlocalgroup_parser.set_defaults(func='get_netlocalgroup') # Parser for the invoke-checklocaladminaccess command invoke_checklocaladminaccess_parser = subparsers.add_parser('invoke-checklocaladminaccess', help='Checks '\ 'if the given user has local admin access on the given host', parents=[target_parser]) invoke_checklocaladminaccess_parser.set_defaults( func='invoke_checklocaladminaccess') # Parser for the invoke-userhunter command invoke_userhunter_parser = subparsers.add_parser('invoke-userhunter', help='Finds '\ 'which machines domain users are logged into', parents=[ad_parser]) invoke_userhunter_parser.add_argument('--computername', dest='queried_computername', nargs='+', default=list(), help='Host to enumerate against') invoke_userhunter_parser.add_argument( '--computerfile', dest='queried_computerfile', type=FileType('r'), help='File of hostnames/IPs to search') invoke_userhunter_parser.add_argument( '--computer-adspath', dest='queried_computeradspath', type=str, help='ADS path used to search computers against the DC') invoke_userhunter_parser.add_argument( '--unconstrained', action='store_true', help='Query only computers with unconstrained delegation') invoke_userhunter_parser.add_argument( '--groupname', dest='queried_groupname', help='Group name to query for target users') invoke_userhunter_parser.add_argument( '--targetserver', dest='target_server', help= 'Hunt for users who are effective local admins on this target server' ) invoke_userhunter_parser.add_argument( '--username', dest='queried_username', help='Hunt for a specific user name') invoke_userhunter_parser.add_argument( '--user-adspath', dest='queried_useradspath', type=str, help='ADS path used to search users against the DC') invoke_userhunter_parser.add_argument( '--userfile', dest='queried_userfile', type=FileType('r'), help='File of user names to target') invoke_userhunter_parser.add_argument( '--threads', type=int, default=1, help='Number of threads to use (default: %(default)s)') invoke_userhunter_parser.add_argument( '-v', '--verbose', action='store_true', help='Displays results as they are found') invoke_userhunter_parser.add_argument( '--admin-count', action='store_true', help='Query only users with adminCount=1') invoke_userhunter_parser.add_argument('--allow-delegation', action='store_true', help='Return user accounts that are not marked as \'sensitive and '\ 'not allowed for delegation\'') invoke_userhunter_parser.add_argument( '--stop-on-success', action='store_true', help='Stop hunting after finding target user') invoke_userhunter_parser.add_argument( '--check-access', action='store_true', help= 'Check if the current user has local admin access to the target servers' ) invoke_userhunter_parser.add_argument( '-d', '--domain', dest='queried_domain', help='Domain to query for machines') invoke_userhunter_parser.add_argument( '--stealth', action='store_true', help='Only enumerate sessions from commonly used target servers') invoke_userhunter_parser.add_argument('--stealth-source', nargs='+', choices=['dfs', 'dc', 'file'], default=['dfs', 'dc', 'file'], help='The source of target servers to use, '\ '\'dfs\' (distributed file server), \'dc\' (domain controller), '\ 'or \'file\' (file server) (default: all)') invoke_userhunter_parser.add_argument( '--show-all', action='store_true', help='Return all user location results') invoke_userhunter_parser.add_argument( '--foreign-users', action='store_true', help='Only return users that are not part of the searched domain') invoke_userhunter_parser.set_defaults(func='invoke_userhunter')
# -*- encoding: utf-8 -*- from pupylib.PupyModule import PupyArgumentParser from pupylib.PupyOutput import Success, Error, Table, Color import time usage = 'DNSCNC control' parser = PupyArgumentParser(prog='dnscnc', description=usage) parser.add_argument('-n', '--node', help='Send command only to this node (or session)') parser.add_argument('-d', '--default', action='store_true', default=False, help='Set command as default for new connections') commands = parser.add_subparsers(title='commands', dest='command') status = commands.add_parser('status', help='DNSCNC status') sessions = commands.add_parser('sessions', help='List known DNSCNC sessions') sessions.add_argument('-r', action='store_true', help='Reverse sorting') sorting = sessions.add_mutually_exclusive_group() sorting.add_argument('-b', action='store_true', help='Sort by boot time') sorting.add_argument('-o', action='store_true', help='Sort by OS') sorting.add_argument('-i', action='store_true', help='Sort by IP') sorting.add_argument('-n', action='store_true', help='Sort by node') sorting.add_argument('-d', action='store_true', help='Sort by duration') sorting.add_argument('-c', action='store_true',
def init_argparse(cls): cli = IGDCMDClient() parser = PupyArgumentParser(prog='igdc', description=cls.__doc__) parser.add_argument('-d', '--DEBUG', action='store_true', help='enable DEBUG output') parser.add_argument( '-pp', '--pretty_print', action='store_true', help='enable xml pretty output for debug and custom action') parser.add_argument('-s', '--source', default='0.0.0.0', help='source address of requests') parser.add_argument('-u', '--url', help='control URL') subparsers = parser.add_subparsers() parser_start = subparsers.add_parser('add', help='add port mapping') parser_start.add_argument('intPort', type=int, help='Internal Port') parser_start.add_argument('extPort', type=int, help='External Port') parser_start.add_argument('proto', choices=['UDP', 'TCP'], help='Protocol') parser_start.add_argument('intIP', nargs='?', default=None, help='Internal IP') parser_start.add_argument('-r', '--remote', default='', help='remote host') parser_start.add_argument('-d', '--desc', default='', help='Description of port mapping') parser_start.add_argument('-e', '--enabled', type=int, choices=[1, 0], default=1, help='enable or disable port mapping') parser_start.add_argument('-du', '--duration', type=int, default=0, help='Duration of the mapping') parser_start.set_defaults(func=cli.addPM) parser_del = subparsers.add_parser('del', help='del port mapping') parser_del.add_argument('extPort', type=int, help='External Port') parser_del.add_argument('proto', choices=['UDP', 'TCP'], help='Protocol') parser_del.add_argument('-r', '--remote', default='', help='remote host') parser_del.set_defaults(func=cli.delPM) parser_geip = subparsers.add_parser('getextip', help='get external IP') parser_geip.set_defaults(func=cli.getExtIP) parser_gpm = subparsers.add_parser('getgpm', help='get generic pm entry') parser_gpm.add_argument('-i', '--index', type=int, help='index of PM entry') parser_gpm.set_defaults(func=cli.getGPM) parser_spm = subparsers.add_parser('getspm', help='get specific port mapping') parser_spm.add_argument('extPort', type=int, help='External Port') parser_spm.add_argument('proto', choices=['UDP', 'TCP'], help='Protocol') parser_spm.add_argument('-r', '--remote', default='', help='remote host') parser_spm.set_defaults(func=cli.getSPM) parser_nrss = subparsers.add_parser('getnrss', help='get NAT and RSIP status') parser_nrss.set_defaults(func=cli.getNRSS) parser_gwdd = subparsers.add_parser('getwdd', help='get warn disconnect delay') parser_gwdd.set_defaults(func=cli.getWDD) parser_swdd = subparsers.add_parser('setwdd', help='set warn disconnect delay') parser_swdd.add_argument('delay', type=int, help='warn disconnect delay') parser_swdd.set_defaults(func=cli.setWDD) parser_gidt = subparsers.add_parser('getidt', help='get idle disconnect time') parser_gidt.set_defaults(func=cli.getIDT) parser_sidt = subparsers.add_parser('setidt', help='set idle disconnect time') parser_sidt.add_argument('time', type=int, help='idle disconnect time') parser_sidt.set_defaults(func=cli.setIDT) parser_gadt = subparsers.add_parser('getadt', help='get auto disconnect time') parser_gadt.set_defaults(func=cli.getADT) parser_sadt = subparsers.add_parser('setadt', help='set auto disconnect time') parser_sadt.add_argument('time', type=int, help='auto disconnect time') parser_sadt.set_defaults(func=cli.setADT) parser_gsi = subparsers.add_parser('getsi', help='get status info') parser_gsi.set_defaults(func=cli.getSI) parser_rt = subparsers.add_parser('rt', help='request termination') parser_rt.set_defaults(func=cli.requestTerm) parser_ft = subparsers.add_parser('ft', help='force termination') parser_ft.set_defaults(func=cli.forceTerm) parser_rc = subparsers.add_parser('rc', help='request connection') parser_rc.set_defaults(func=cli.requestConn) parser_gct = subparsers.add_parser('getct', help='get connection type info') parser_gct.set_defaults(func=cli.getCT) parser_sct = subparsers.add_parser('setct', help='set connection type') parser_sct.add_argument('ct_type', help='connection type') parser_sct.set_defaults(func=cli.setCT) parser_cust = subparsers.add_parser('custom', help='use custom action') parser_cust.add_argument('method_name', help='name of custom action') parser_cust.add_argument( '-svc', type=str, choices=['WANIPConnection', 'WANIPv6FirewallControl'], default='WANIPConnection', help='IGD service, default is WANIPConnection') parser_cust.add_argument( '-iargs', '--input_args', default='{}', help='input args, the format is same as python dict,' 'e.g. "{\'NewPortMappingIndex\': [0, \'ui4\']}"') parser_cust.set_defaults(func=cli.custom) # following for IPv6FWControl parser_gfwstatus = subparsers.add_parser('getfwstatus', help='get IPv6 FW status') parser_gfwstatus.set_defaults(func=cli.getFWStatus) parser_addph = subparsers.add_parser('addph', help='add IPv6 FW Pinhole') parser_addph.add_argument('intIP', help='Internal IP') parser_addph.add_argument('-intPort', type=int, default=0, help='Internal Port') parser_addph.add_argument('proto', choices=['UDP', 'TCP', 'ALL'], help='Protocol') parser_addph.add_argument('-rIP', default='', help='Remote IP') parser_addph.add_argument('-rPort', type=int, default=0, help='Remote Port') parser_addph.add_argument('-lease', type=int, default=3600, help='leasetime of the pinhole') parser_addph.set_defaults(func=cli.addPH) parser_gopht = subparsers.add_parser( 'getopht', help='get IPv6 FW OutboundPinholeTimeout') parser_gopht.add_argument('-intIP', type=str, default='', help='Internal IP') parser_gopht.add_argument('-intPort', type=int, default=0, help='Internal Port') parser_gopht.add_argument('-proto', choices=['UDP', 'TCP', 'ALL'], default='ALL', help='Protocol') parser_gopht.add_argument('-rIP', default='', help='Remote IP') parser_gopht.add_argument('-rPort', type=int, default=0, help='Remote Port') parser_gopht.set_defaults(func=cli.getOPHT) parser_uph = subparsers.add_parser('updateph', help='update IPv6 FW pinhole') parser_uph.add_argument('uid', type=int, help='UniqueID of the pinhole') parser_uph.add_argument('lease', type=int, help='new leasetime of the pinhole') parser_uph.set_defaults(func=cli.updatePH) parser_dph = subparsers.add_parser('delph', help='delete IPv6 FW pinhole') parser_dph.add_argument('uid', type=int, help='UniqueID of the pinhole') parser_dph.set_defaults(func=cli.delPH) parser_gphpkts = subparsers.add_parser( 'getphpkts', help='get number of packets go through specified IPv6FW pinhole') parser_gphpkts.add_argument('uid', type=int, help='UniqueID of the pinhole') parser_gphpkts.set_defaults(func=cli.getPHPkts) parser_chkph = subparsers.add_parser( 'chkph', help='check if the specified pinhole is working') parser_chkph.add_argument('uid', type=int, help='UniqueID of the pinhole') parser_chkph.set_defaults(func=cli.chkPH) cls.arg_parser = parser cls.cli = cli
from pupylib.PupyModule import PupyArgumentParser from pupylib.PupyOutput import Error, Success, Table usage = "Manage Jobs" parser = PupyArgumentParser(prog='jobs', description=usage) killjob = parser.add_mutually_exclusive_group() killjob.add_argument('-k', '--kill', metavar='<job_id>', help="print the job current output before killing it") killjob.add_argument('-K', '--kill-no-output', metavar='<job_id>', help="kill job without printing output") parser.add_argument('-l', '--list', action='store_true', help="list jobs") parser.add_argument('-p', '--print-output', metavar='<job_id>', help="print a job output") def do(server, handler, config, modargs): if modargs.kill: j = server.get_job(modargs.kill) handler.summary(j) finished = j.is_finished() if finished: server.del_job(j.jid) handler.display(Success('Job closed'))
# -*- encoding: utf-8 -*- from pupylib.PupyModule import PupyArgumentParser from pupylib.PupyOutput import Table usage = "Assign tag to current session" parser = PupyArgumentParser(prog='tag', description=usage) parser.add_argument('-a', '--add', metavar='tag', nargs='+', help='Add tags') parser.add_argument('-r', '--remove', metavar='tag', nargs='+', help='Remove tags') parser.add_argument('-w', '--write-project', action='store_true', default=False, help='save config to project folder') parser.add_argument('-W', '--write-user', action='store_true', default=False, help='save config to user folder') def do(server, handler, config, modargs): data = [] clients = server.get_clients(handler.default_filter) if not clients: return for client in clients: tags = config.tags(client.node()) if modargs.remove: tags.remove(*modargs.remove) if modargs.add: tags.add(*modargs.add)