Exemplo n.º 1
0
def parse_redirect_args(arg_list=None, random=False):
    assert (type(random) == type(False)), 'Random must be a Boolean'
    assert (type(arg_list) == type([])), 'Your arg_list must be a list'
    parser = ArgumentParser()
    group_listentype = parser.add_mutually_exclusive_group(required=True)
    group_listentype.add_argument('--tcp', action='store_const', dest='protocol', const='tcp', help='Use TCP/IP as the redirection protocol')
    group_listentype.add_argument('--udp', action='store_const', dest='protocol', const='udp', help='Use UDP/IP as the redirection protocol')
    group_listenLocation = parser.add_mutually_exclusive_group(required=True)
    if random:
        group_listenLocation.add_argument('--lplisten', action='store', dest='lplisten', nargs='*', default=None, help='Listen for new connections on the LP-side (default bind=0.0.0.0).')
        group_listenLocation.add_argument('--implantlisten', action='store', dest='implantlisten', nargs='*', default=None, help='Listen for new connections on the Implant-side (default bind=0.0.0.0).')
    elif (not random):
        group_listenLocation.add_argument('--lplisten', action='store', dest='lplisten', nargs='+', default=None, help='Listen for new connections on the LP-side (default bind=0.0.0.0).')
        group_listenLocation.add_argument('--implantlisten', action='store', dest='implantlisten', nargs='+', default=None, help='Listen for new connections on the Implant-side (default bind=0.0.0.0).')
    parser.add_argument('--target', action='store', dest='target', required=True, nargs='*', help='The address / port to which data should be forwarded. NOTE: Data is always forwarded to the side opposite where the listening port is.')
    parser.add_argument('--portsharing', action='store', dest='portsharing', nargs=2, default=None, help='For use with FLAV')
    parser.add_argument('--connections', action='store', dest='connections', default=0, type=int, help='Sets the maximum number of concurrent connections allowed.(Default=0 / 0=Unlimited)')
    parser.add_argument('--limitconnections', action='store', dest='limitconnections', nargs=2, default=None, help='Limit connections to listen address to a specified IP range.')
    parser.add_argument('--sendnotify', action='store_true', dest='sendnotify', default=False, help='Send notification of target connection success / failure to connecting sockets.')
    parser.add_argument('--packetsize', action='store', dest='packetsize', default=8192, type=int, help='Sets the maximum size (in bytes) for recv/send calls.  This is of particular interest for datagram (ie, UDP) redirection (default=8192).')
    options = parser.parse_args(arg_list)
    if (options.portsharing is not None):
        assert util.ip.validate_port(options.portsharing[0]), 'clientSrcPort in portsharing must be a valid port'
        assert util.ip.validate(options.portsharing[1]), 'clientSrcAddr in portsharing must be a valid IP address'
    if (options.limitconnections is not None):
        assert util.ip.validate(options.limitconnections[0]), 'addr in limitconnections must be a valid IP address'
        assert util.ip.validate(options.limitconnections[1]), 'mask in limitconnections must be a valid IP address'
    if random:
        assert (len(options.target) in range(0, 5)), 'Target must be a list with 0-4 elements when using random.'
        for item in options.target:
            assert (util.ip.validate(item) or util.ip.validate_port(item)), 'Target items must be either a valid IP address or valid port when using random.'
    elif (not random):
        assert (len(options.target) in range(2, 5)), 'Target must be a list with 2-4 elements when not using random.'
        assert util.ip.validate(options.target[0]), 'addr in target must be a valid IP address'
        assert util.ip.validate_port(options.target[1]), 'destPort in target must be a valid IP address'
        if (len(options.target) == 3):
            assert util.ip.validate(options.target[2]), 'srcAddr in target must be a valid IP address'
        if (len(options.target) == 4):
            assert util.ip.validate_port(options.target[3]), 'srcPort in target must be a valid IP address'
    return options
Exemplo n.º 2
0
def main():
    parser = ArgumentParser(prog='survey')
    actiongrp = parser.add_mutually_exclusive_group(required=True)
    actiongrp.add_argument(
        '--run',
        dest='run',
        const=ops.survey.DEFAULT_CONFIG,
        nargs='?',
        metavar='SURVEY',
        help='Run specified survey. Uses default if none specified. (%(const)s)'
    )
    actiongrp.add_argument('--modify',
                           dest='modify',
                           action='store_true',
                           default=False,
                           help='Manipulate the settings for default survey.')
    parser.add_argument('--sections',
                        dest='sections',
                        default=ops.survey.DEFAULT_SECTIONS,
                        metavar='SECTION',
                        nargs='+',
                        help='Sections for --run or --override.')
    modgrp = parser.add_argument_group(
        title='--modify options',
        description='These options are only used with the --modify option.')
    modgrp.add_argument('--override',
                        dest='override',
                        help='Change the default survey file for all targets.')
    modgrp.add_argument(
        '--exclude',
        dest='exclude',
        nargs='+',
        metavar='GROUP',
        help=
        'Adds the specified groups to the list of tasks to exclude when running survey configurations.'
    )
    modgrp.add_argument(
        '--include',
        dest='include',
        nargs='+',
        metavar='GROUP',
        help=
        'Removes the specified groups from the list of tasks to exclude when running survey configurations.'
    )
    modgrp.add_argument('--exclusions',
                        dest='printex',
                        action='store_true',
                        default=False,
                        help='Print out a list of excluded survey groups.')
    parser.add_argument(
        '--quiet',
        dest='quiet',
        action='store_true',
        default=False,
        help=
        'Suppress some framework messages, including the running commands list at the end.'
    )
    options = parser.parse_args()
    if ((not options.modify) and
        ((options.override is not None) or (options.exclude is not None) or
         (options.include is not None) or options.printex)):
        parser.error('-modify is required for these options')
    if options.modify:
        if options.override:
            ops.survey.override(options.override, options.sections)
        if options.exclude:
            if ops.survey.exclude(options.exclude):
                ops.info(('%s added to exclusion list.' % options.exclude))
                ops.survey.print_exclusion_list()
            else:
                ops.info(('%s already in exclusion list.' % options.exclude))
        if options.include:
            if ops.survey.include(options.include):
                ops.info(('%s removed from exclusion list.' % options.include))
                ops.survey.print_exclusion_list()
            else:
                ops.info(('%s not in exclusion list.' % options.include))
        if options.printex:
            ops.survey.print_exclusion_list()
    else:
        execute(options.run, options.sections, options.quiet)
Exemplo n.º 3
0
        diffs = _dodiff(dirres, os.path.join(os.path.join(ops.TARGET_TEMP, 'hour.txt')))
        _recordstate(dirres, os.path.join(os.path.join(ops.TARGET_TEMP, 'hour.txt')), restart)
    diffnames = []
    for modfile in diffs:
        prettyfiletime = modfile.filetimes.modified.time[0:19].replace('T', ' ')
        if modfile.attributes.directory:
            diffnames.append({'Path': modfile.dszparent.path, 'Name': modfile.name, 'Size': '<DIR>', 'Modtime': prettyfiletime})
        else:
            diffnames.append({'Path': modfile.dszparent.path, 'Name': modfile.name, 'Size': modfile.size, 'Modtime': prettyfiletime})
    if (len(diffnames) > 0):
        ops.pprint.pprint(diffnames, header=['Modtime', 'Size', 'Path', 'Name'], dictorder=['Modtime', 'Size', 'Path', 'Name'])
    else:
        ops.info('No changes detected')
if (__name__ == '__main__'):
    parser = ArgumentParser()
    path_group = parser.add_mutually_exclusive_group()
    time_group = parser.add_mutually_exclusive_group()
    age_group = parser.add_mutually_exclusive_group()
    parser.add_argument('--mask', action='store', dest='mask', default='*', help='Mask to use for the dir command, default is *')
    path_group.add_argument('--path', action='store', dest='path', default='*', help='Path to use for the dir command, default is *')
    age_group.add_argument('--age', action='store', dest='age', default='1h', help='Path to use for the dir command, default is 1h, may be ([#y][#w][#d][#h][#m][#s])')
    parser.add_argument('--recursive', action='store_true', dest='recursive', default=False, help='If present, dir will be done recursively, otherwise will not be recursive')
    parser.add_argument('--restart', action='store_true', dest='restart', default=False, help='If present, will not compare with previous results and will start a new baseline')
    parser.add_argument('--safe', action='store_true', dest='safe', default=False, help="Will run times and then craft a before/after parameter, rather then use dir's age parameter")
    path_group.add_argument('--sysdrive', action='store_true', dest='sysdrive', default=False, help='Will only run the dir against the system drive')
    parser.add_argument('--nodiff', action='store_true', dest='nodiff', default=False, help='Do not run a diffhour, only a normal hour')
    parser.add_argument('--noquiet', action='store_true', dest='noquiet', default=False, help='Display the results of the dir to screen')
    time_group.add_argument('--fromtime', action='store', dest='fromtime', metavar='"YYYY-MM-DD [hh:mm:ss]"', default=None, help='Date from which to calculate the age. Default is to calculate normally.')
    time_group.add_argument('--centeredtime', action='store', dest='centeredtime', metavar='"YYYY-MM-DD [hh:mm:ss]"', default=None, help='Date from which to calculate the age in both directions. Default is to calculate normally.')
    age_group.add_argument('--fromstart', action='store_true', dest='fromstart', default=False, help="Calculate the -after time since the first 'time' command run on this cpaddr")
    options = parser.parse_args()