def deal_onetask(self, conffile): try: arg = json.load(open(conffile, 'r')) globalTaskVar.logger.debug('prepare to run a task: %s' % arg['targetname']) sn = Scanner(conffile) sn.run() # sl = ScannerLoader(self.server, self.token, arg) # sl.run() globalTaskVar.logger.info('[*] done: %s' % arg['targetname']) # notice server this task done serverurl = 'http://' + self.server + '/dist_hi.php' postdata = { 'token': self.token, 'os': self.os, 'mac': self.mac, 'type': 'end', 'taskid': arg['taskid'] } r = requests.post(serverurl, data=postdata) # print r.status_code if r.status_code == 200: globalTaskVar.logger.debug( 'worker: hello server, one task done, taskid: %s' % arg['taskid']) globalTaskVar.logger.debug('server: %s' % r.text) # globalTaskVar.logger.info('[*] done: %s' % arg['global']['target']) # target = arg['global']['target'] # conffile = genFileName_v2(target) + '.json' # cmd = 'python hammer.py --conf-file cache/conf/'+conffile # os.system(cmd) except Exception, e: globalTaskVar.logger.error('Exception: %s' % e)
def run(self): try: # basic mode scanner if self.arg['mode'] == '1': sn = Scanner(server=self.server,token=self.token,\ target=self.arg['target'],\ threads=int(self.arg['global']['threads']) if self.arg['global']['threads']!= '' else None,\ loglevel=self.arg['global']['loglevel'] if self.arg['global']['loglevel']!= '' else 'INFO',\ gatherdepth=int(self.arg['global']['gatherdepth']) if self.arg['global']['gatherdepth']!= '' else 1) sn.initInfo() sn.infoGather() sn.scan() # plugin mode scanner elif self.arg['mode'] == '2': sn = PluginMultiRunner(server=self.server,token=self.token,\ target=self.arg['target'],\ threads=int(self.arg['global']['threads']) if self.arg['global']['threads']!= '' else None,\ pluginfilepath=self.arg['pluginfilepath'],\ pluginargs=self.arg['pluginargs']) sn.initInfo() sn.scan() except IndexError, e: # except Exception,e: print 'Exception', e
elif '_target' in dir(): # plugin type scan if '_plugin' in dir(): sn = PluginMultiRunner(server=_server, token=_token, target=_target, loglevel=_vv, threads=_threads, pluginfilepath=_plugin, pluginargs=_plugin_arg) sn.initInfo() sn.scan() else: sn = Scanner(server=_server, token=_token, target=_target, threads=_threads, loglevel=_vv, gatherdepth=_gather_depth) sn.initInfo() sn.infoGather(depth=_gather_depth) sn.scan() elif _listen: li = Listener(server=_server, token=_token, loglevel=_vv) li.run() else: usage() # ----------------------------------------------------------------------------------------------------
json.dump(globalVar.config, open(conffile, 'w')) if '_plugin' in dir() and _plugin: # 单插件模式 # plugin type scan sn = PluginMultiRunner(server=_server, token=_token, target=_target, loglevel=_vv, threads=_threads, pluginfilepath=_plugin, pluginargs=_plugin_arg) sn.initInfo() sn.scan() else: # 自收集模式 sn = Scanner(conffile=conffile) sn.safeRun() # sn.initInfo() # sn.infoGather() # sn.scan() else: usage() # ---------------------------------------------------------------------------------------------------- # # ---------------------------------------------------------------------------------------------------- if __name__ == '__main__': main()
if arg: _pluginpath = arg else: _pluginpath = 'plugins/' else: pass if _server and _token: if '_pluginpath' in dir(): # print '_pluginpath=',_pluginpath # print '_server=',_server # print '_token=',_token loadPlugins(_pluginpath, _server, _token) elif '_target' in dir(): sn = Scanner(_server, _token, _target) sn.initInfo() sn.infoGather() sn.scan() else: usage() else: usage() # ---------------------------------------------------------------------------------------------------- # # ---------------------------------------------------------------------------------------------------- if __name__ == '__main__': main()