def TaskStarter(version): # Get all the options passed and pass it to the TaskConducter, this will # keep all the processing on the side. # need to pass the store true somehow to tell printer to restrict output log = helpers.log() log.start() cli_all, cli_domain, cli_list, cli_test, cli_scope, cli_names, cli_verify, cli_verbose = cli_parser() cli_domain = cli_domain.lower() Task = TaskController.Conducter() Task.load_modules() if cli_list: log.infomsg("Tasked to List Modules", "Main") Task.ListModules() V = VersionCheck.VersionCheck(version) V.VersionRequest() sys.exit(0) if not len(cli_domain) > 1: log.warningmsg("Domain not supplied", "Main") print helpers.color("[*] No Domain Supplied to start up!\n", warning=True) sys.exit(0) if cli_test: # setup a small easy test to activate certain modules log.infomsg("Tasked to Test Module: " + cli_test, "Main") V = VersionCheck.VersionCheck(version) V.VersionRequest() Task.TestModule(cli_domain, cli_test, verbose=cli_verbose, scope=cli_scope, Names=cli_names, Verify=cli_verify) if cli_all: log.infomsg("Tasked to run all Modules on domain: " + cli_domain, "Main") V = VersionCheck.VersionCheck(version) V.VersionRequest() Task.TaskSelector(cli_domain, verbose=cli_verbose, scope=cli_scope, Names=cli_names, Verify=cli_verify)
def TaskControler(version): # Get all the options passed and pass it to the TaskConducter, this will # keep all the prcessing on the side. # need to pass the store true somehow to tell printer to restrict output cli_all, cli_domain, cli_list, cli_test, cli_verbose = cli_parser() cli_domain = cli_domain.lower() Task = TaskController.Conducter() Task.load_modules() if cli_list: Task.ListModules() V = VersionCheck.VersionCheck(version) V.VersionRequest() sys.exit(0) if not len(cli_domain) > 1: print helpers.color("[*] No Domain Supplied to start up!\n", warning=True) sys.exit(0) if cli_test: # setup a small easy test to activate certain modules V = VersionCheck.VersionCheck(version) V.VersionRequest() Task.TestModule(cli_domain, cli_test, verbose=cli_verbose) if cli_all: V = VersionCheck.VersionCheck(version) V.VersionRequest() Task.TaskSelector(cli_domain, verbose=cli_verbose)
def test_taskcontrollers(): Task = TaskController.Conducter() Task.load_modules() # check inits for x in Task.modules: l = Task.modules[x] mod = l.ClassName('test.com', verbose=True) Task.ListModules() Task.title() Task.title_screen() V = VersionCheck.VersionCheck("1.3") V.VersionRequest() # test the cleaning function of the TC # create fake email items Task.ConsumerList = [ '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**' ] Task.HtmlList = [ '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**' ] finallist, htmllist = Task.CleanResults('test.com') # now make sure we have correct data i = finallist.count("*****@*****.**") b = htmllist.count("*****@*****.**") assert '*****@*****.**' in finallist assert '*****@*****.**' in finallist assert '*****@*****.**' not in finallist assert i < 2 assert '*****@*****.**' in htmllist assert '*****@*****.**' in htmllist assert '*****@*****.**' not in htmllist assert b < 2
def main(): parser = argparse.ArgumentParser(description='Minion Data Collector.') parser.add_argument("-i", "--input", dest='argFilename', help='specifies input file', type=extant_file, metavar="FILE") parser.add_argument("-v", "--verbose", help="prints information, values 0-3", type=int) parser.add_argument("-r", "--runonce", help="calls all collectors once and exits", action="store_true") parser.add_argument( "-a", "--aliasfile", help="specify an external file that has alias defintions", type=str) try: args = parser.parse_args() if None == args.verbose: _VerboseLevel = 0 else: _VerboseLevel = args.verbose _RunOnce = args.runonce except: return ShowVersion() if not VersionCheck.CheckVersion(): Log.getLogger().error("Invalid version of Python") return if 3 <= _VerboseLevel: Log.setLevel(logging.DEBUG) elif 2 == _VerboseLevel: Log.setLevel(logging.WARNING) elif 1 == _VerboseLevel: Log.setLevel(logging.INFO) else: Log.setLevel(logging.ERROR) curr_dir_path = os.path.dirname(os.path.realpath(__file__)) Alias.AliasMgr.AddAlias("WORKING_DIR", curr_dir_path) Alias.AliasMgr.AddEnvironmentVariables() if None != args.aliasfile: if not Alias.AliasMgr.LoadExternalAliasFile(args.aliasfile): return signal.signal( signal.SIGINT, signal.SIG_IGN ) # turn of Ctrl+C signal handler (will get inherted by sub processes if not os.path.exists(_ConfigFilename): Log.getLogger().error("Config file [" + _ConfigFilename + "] not found!") return config = Configuration.Configuration(_ConfigFilename, True) if None == config or not config.IsValid(): pass else: print("Starting Collectors...") totalCollectors = 0 for namespace in config.GetNamespaces(): totalCollectors += namespace.Begin(_RunOnce) signal.signal(signal.SIGINT, signal_handler) # make my own Ctrl+C handler now print(str(totalCollectors) + " Collectors started.") if False == _RunOnce: print("Press CTRL+C to Exit") else: print("Running Once") if False == _RunOnce: while _ThreadActive: if 0 == _VerboseLevel: for c in spinning_cursor(): countStr = '[' + str(config.GetCollectorCount()) + '] ' sys.stdout.write(countStr) sys.stdout.write(c) Sleep.SleepMs(100) sys.stdout.flush() sys.stdout.write('\b') for c in countStr: sys.stdout.write('\b') else: Sleep.SleepMs(100) print("Shutting down...") try: ThreadManager.GetThreadManager().StopAllThreads() except: pass