Пример #1
0
def main():
    global logdir, status, test_id

    # PARSING

    parser = argparse.ArgumentParser(description='AVMonitor master.')

    parser.add_argument('action', choices=['update', 'revert', 'dispatch',
                                           'test', 'command', 'test_internet', 'push'],
                        help="The operation to perform")
    parser.add_argument('-m', '--vm', required=False,
                        help="Virtual Machine where execute the operation")
    parser.add_argument('-p', '--pool', type=int, required=False,
                        help="This is the number of parallel process (default 2)")
    parser.add_argument('-l', '--logdir', default="/var/log/avmonitor/report",
                        help="Log folder")
    parser.add_argument('-v', '--verbose', action='store_true', default=False,
                        help="Verbose")
    parser.add_argument('-k', '--kind', default="all", type=str,
                        choices=[
                            'silent', 'melt', 'exploit', 'exploit_docx', 'exploit_ppsx', 'exploit_web',
                            'mobile', 'agents', 'exploits', 'silentmelt', 'release', 'all'],
                        help="Kind of test (or test case)", )
    parser.add_argument('-c', '--cmd', required=False,
                        help="Run VMRUN command")
    parser.add_argument('-u', '--updatetime', default=50, type=int,
                        help="Update time in minutes")
    parser.add_argument(
        '-s', '--server', default='minotauro', choices=['minotauro', 'zeus', 'castore', 'polluce'],
        help="Server name")
    args = parser.parse_args()

    # LOGGER
    print "updatetime: ", args.updatetime
    logdir = "%s/%s_%s" % (args.logdir, args.action, timestamp())
    if not os.path.exists(logdir):
        print "DBG mkdir %s" % logdir
        os.mkdir(logdir)
    sym = "%s/%s" % (args.logdir, args.action)
    if os.path.exists(sym):
        os.unlink(sym)
    os.symlink(logdir, sym)
    setLogger(debug=args.verbose, filelog="%s/master.logger.txt" %
                                          (logdir.rstrip('/')))

    # GET CONFIGURATION FOR AV UPDATE PROCESS (exe, vms, etc)

    c = ConfigParser()
    c.read(vm_conf_file)

    vSphere.hostname = c.get("vsphere", "host")
    vSphere.username = "******" % (
        c.get("vsphere", "domain"), c.get("vsphere", "user"))
    vSphere.password = c.get("vsphere", "passwd")

    if args.vm:
        if args.vm == "all":
            vm_names = c.get("pool", "all").split(",")
        else:
            vm_names = args.vm.split(',')
    else:
        # get vm names
        vm_names = c.get("pool", "machines").split(",")
    args.vms = vm_names

    [job_log(v, "INIT") for v in vm_names]

    global updatetime
    updatetime = args.updatetime

    # TEST

    if args.action == "test":
        # get_results("eset")
        do_test(args)
        exit(0)

    # SHUT DOWN NETWORK

    if args.action == "update":
        os.system('sudo ./net_enable.sh')
        print "[!] Enabling NETWORKING!"
    else:
        os.system('sudo ./net_disable.sh')
        print "[!] Disabling NETWORKING!"

    if args.action == "dispatch":
        print "DBG add record to db"
        test = start_test()
        if test.id is not None:
            test_id = test.id
        else:
            print "[!] Problems with DB insert. QUITTING!"
            return

    # POOL EXECUTION

    if args.pool:
        pool_size = args.pool
    else:
        pool_size = int(c.get("pool", "size"))
        args.pool = pool_size

    pool = Pool(pool_size)

    print "[*] selected operation %s" % args.action

    actions = {"update": update, "revert": revert,
               "dispatch": dispatch, "test_internet": test_internet,
               "command": run_command, "push": push}

    print "MASTER on %s, action %s" % (vm_names, args.action)
    r = pool.map_async(actions[args.action], [(n, args) for n in vm_names])
    results = r.get()

    #    print "Finalizing test."
    #    if end_test(test) is False:
    #        print "[!] problem updating test status!"

    # REPORT

    rep = Report(test_id, results)
    if args.action == "dispatch":
        if rep.send_report_color_mail(logdir.split('/')[-1]) is False:
            print "[!] Problem sending HTML email Report!"
    else:
        if args.action == "update":  # or args.action == "revert":
            if rep.send_mail() is False:
                print "[!] Problem sending mail!"

    os.system('sudo ./net_disable.sh')
    print "[!] Disabling NETWORKING!"
    os.system('sudo rm -fr /tmp/screenshot_*')
    print "[!] Deleting Screenshots!"
Пример #2
0
def main():
    global logdir, status, test_id

    # PARSING

    parser = argparse.ArgumentParser(description='AVMonitor master.')

    parser.add_argument('action',
                        choices=[
                            'update', 'revert', 'dispatch', 'test', 'command',
                            'test_internet', 'push'
                        ],
                        help="The operation to perform")
    parser.add_argument('-m',
                        '--vm',
                        required=False,
                        help="Virtual Machine where execute the operation")
    parser.add_argument(
        '-p',
        '--pool',
        type=int,
        required=False,
        help="This is the number of parallel process (default 2)")
    parser.add_argument('-l',
                        '--logdir',
                        default="/var/log/avmonitor/report",
                        help="Log folder")
    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        default=False,
                        help="Verbose")
    parser.add_argument(
        '-k',
        '--kind',
        default="all",
        type=str,
        choices=[
            'silent', 'melt', 'exploit', 'exploit_docx', 'exploit_ppsx',
            'exploit_web', 'mobile', 'agents', 'exploits', 'silentmelt',
            'release', 'all'
        ],
        help="Kind of test (or test case)",
    )
    parser.add_argument('-c',
                        '--cmd',
                        required=False,
                        help="Run VMRUN command")
    parser.add_argument('-u',
                        '--updatetime',
                        default=50,
                        type=int,
                        help="Update time in minutes")
    parser.add_argument('-s',
                        '--server',
                        default='minotauro',
                        choices=['minotauro', 'zeus', 'castore', 'polluce'],
                        help="Server name")
    args = parser.parse_args()

    # LOGGER
    print "updatetime: ", args.updatetime
    logdir = "%s/%s_%s" % (args.logdir, args.action, timestamp())
    if not os.path.exists(logdir):
        print "DBG mkdir %s" % logdir
        os.mkdir(logdir)
    sym = "%s/%s" % (args.logdir, args.action)
    if os.path.exists(sym):
        os.unlink(sym)
    os.symlink(logdir, sym)
    setLogger(debug=args.verbose,
              filelog="%s/master.logger.txt" % (logdir.rstrip('/')))

    # GET CONFIGURATION FOR AV UPDATE PROCESS (exe, vms, etc)

    c = ConfigParser()
    c.read(vm_conf_file)

    vSphere.hostname = c.get("vsphere", "host")
    vSphere.username = "******" % (c.get("vsphere",
                                         "domain"), c.get("vsphere", "user"))
    vSphere.password = c.get("vsphere", "passwd")

    if args.vm:
        if args.vm == "all":
            vm_names = c.get("pool", "all").split(",")
        else:
            vm_names = args.vm.split(',')
    else:
        # get vm names
        vm_names = c.get("pool", "machines").split(",")
    args.vms = vm_names

    [job_log(v, "INIT") for v in vm_names]

    global updatetime
    updatetime = args.updatetime

    # TEST

    if args.action == "test":
        #get_results("eset")
        do_test(args)
        exit(0)

    # SHUT DOWN NETWORK

    if args.action == "update":
        os.system('sudo ./net_enable.sh')
        print "[!] Enabling NETWORKING!"
    else:
        os.system('sudo ./net_disable.sh')
        print "[!] Disabling NETWORKING!"

    if args.action == "dispatch":
        print "DBG add record to db"
        test = start_test()
        if test.id is not None:
            test_id = test.id
        else:
            print "[!!] Problems with DB insert. QUITTING!"
            return

    # POOL EXECUTION

    if args.pool:
        pool_size = args.pool
    else:
        pool_size = int(c.get("pool", "size"))
        args.pool = pool_size

    pool = Pool(pool_size)

    print "[*] selected operation %s" % args.action

    actions = {
        "update": update,
        "revert": revert,
        "dispatch": dispatch,
        "test_internet": test_internet,
        "command": run_command,
        "push": push
    }

    print "MASTER on %s, action %s" % (vm_names, args.action)
    r = pool.map_async(actions[args.action], [(n, args) for n in vm_names])
    results = r.get()

    print "DBG results all are: %s" % results

    #    print "Finalizing test."
    #    if end_test(test) is False:
    #        print "[!] problem updating test status!"

    # REPORT

    if args.action == "dispatch":
        end_test(test)
        rep = Report(test_id, results)
        if rep.send_report_color_mail(logdir.split('/')[-1]) is False:
            print "[!] Problem sending HTML email Report!"
    else:
        if args.action == "update":  # or args.action == "revert":
            if rep.send_mail() is False:
                print "[!] Problem sending mail!"

    os.system('sudo ./net_disable.sh')
    print "[!] Disabling NETWORKING!"
    os.system('sudo rm -fr /tmp/screenshot_*')
    print "[!] Deleting Screenshots!"