def payload_except_callback(self, request, exception): host = request.args[0] errors = exception[1] exceptname = errors.__class__.__name__ errors = exceptname + ':' + str(errors) logger('fail', '{: <20}\t{}'.format(host, errors)) self.payloadResult.append(tuple([0, host, errors]))
def payload_callback(self, request, result): host = request.args[0] if not result: result = 'fail' else: result = ' '.join(result) logger('success', '{: <20}\t{}'.format(host, result)) self.payloadResult.append(tuple([1, host, result]))
def do_test(self, argv): '''test [default] host example: test default 10.0.0.1 ''' args = argv.split() if len(args) == 1: payloadName = 'default' host = args[0] elif len(args) == 2: payloadName, host = tuple(args) else: raise InputFormatError try: PayloadCls = self._load_payload_class(payloadName) result = self._payload_run(PayloadCls, host, test=True) logger('success', '{}:{}'.format(host, result)) except ModuleNotFoundError as e: logger('fail', 'Payload {} Not Fount:{}'.format(payloadName, str(e))) print(traceback.format_exc()) raise except NotImplementedError as e: logger( 'fail', 'Payload {} Not Implete Attack Function'.format(payloadName)) print(traceback.format_exc()) except Exception as e: logger( 'fail', 'Payload {} for {} fail:{}'.format(payloadName, host, str(e))) print(traceback.format_exc())
def do_flag(self, argv): '''get flag of hostList and send to platform''' flagCmd = configuration.flagCommand flagmodule = importlib.import_module('modules.flag.flag') importlib.reload(flagmodule) sendFlag = flagmodule.sendFlag self.do_exec(flagCmd) logger('info', '*' * 10 + 'SEND FALG' + '*' * 10) for host, flag in self.execResult: if not flag: logger('fail', '{}:GET NOT FLAG'.format(host)) continue try: flag = flag.strip() res = sendFlag(flag) logger('success', '{}:{}'.format(host, res)) except Exception as e: logger('fail', '{}:{}'.format(host, str(e)))
def do_exec(self, argv): '''execute command on all hosts USAGE:exec ls -l''' self.execResult.clear() armList = [{'cmd': argv, 'shell': shell} for shell in self.shellList] reqs = threadpool.makeRequests(payloadExec, armList, callback=self.exec_callback) [configuration.pool.putRequest(req) for req in reqs] configuration.pool.wait() logger('info', '*' * 10 + 'EXEC RESULT' + '*' * 10) for host, result in self.execResult: if result is not None: logger('success', '{: <20}\t{}'.format(host, result)) else: logger('fail', '{: <20}\t{}'.format(host, 'FAIL'))
#!/bin/python2.7 # -*- coding: utf-8 -*- ### pymm実行メインスクリプト ### import configparser import sys from modules import color from modules import logger from modules import menu reload(sys) sys.setdefaultencoding("utf-8") # ロガー生成 logger = logger.logger() # メインプロセス print '' print color.pycolor.YELLOW + ' Welcome to Python Mail Manager.' + color.pycolor.END print '' menu.main_menu()
(full_recon + feed_down))) print(':: Saving the predicted signal evts in {}...'.format(model_dir + outfile)) thefile = open(model_dir + outfile, 'w') for item in sig_list: thefile.write("%s\n" % item) if __name__ == "__main__": output_path = 'output/' data_path = '../data/' config_path = 'config/' om = OutputManager(output_path, keep_sessions=20) sys.stdout = logger(om.get_session_folder()) # fix random seed for reproducibility # np.random.seed(7) user_argv = None if (len(sys.argv) > 1): user_argv = sys.argv[1:] # commend line parser (right now not a own function as only 2 elements are used) parser = argparse.ArgumentParser() parser.add_argument('-inpath', '-evtdicpath', '-evtdic', help='path to the event dictionary',
from flask_sqlalchemy import SQLAlchemy from flask_restful import Api from resources.event import Event, Allevents, db from functools import wraps from modules import logger # get an application object app = Flask(__name__) app.config['DEBUG'] = True app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get( 'DATABASE_URI', 'sqlite:///database/data.db') # This is a logger used to log the code execution # just use code_logger.<level>("<your logging message>") # check modules/logger.py for more details code_logger = logger.logger("./log/app.log", name=__name__).log # The token check function SECRET = "testpass" def token_required(f): ''' This is a decorator used to force authenction when using some http methods ''' @wraps(f) def decorated(*args, **kwargs): token = request.args.get('token') if not token: