def feed_with_plugin_options(opts, parser): logger = ProxyLogger() plugins = [] files = sorted([ f for f in os.scandir( os.path.join(os.path.dirname(os.path.realpath(__file__)), '../plugins/')) ], key=lambda f: f.name) for _, entry in enumerate(files): if entry.name.endswith(".py") and entry.is_file() and entry.name.lower( ) not in ['iproxyplugin.py', '__init__.py']: plugins.append(entry.path) options = opts.copy() options['plugins'] = plugins options['verbose'] = True options['debug'] = False plugin_own_options = {} pl = PluginsLoader(logger, options) for name, plugin in pl.get_plugins().items(): logger.dbg("Fetching plugin {} options.".format(name)) if hasattr(plugin, 'help'): plugin_options = parser.add_argument_group( "Plugin '{}' options".format(plugin.get_name())) plugin.help(plugin_options)
def init(opts, VERSION): global options global pluginsloaded global logger global sslintercept options = opts.copy() lib.optionsparser.parse_options(options, VERSION) logger = ProxyLogger(options) pluginsloaded = PluginsLoader(logger, options) sslintercept = SSLInterception(logger, options) if options['log'] and options['log'] != None and options['log'] != sys.stdout: if options['tee']: logger.info("Teeing stdout output to {} log file.".format(options['log'])) else: logger.info("Writing output to {} log file.".format(options['log'])) monkeypatching(logger) for name, plugin in pluginsloaded.get_plugins().items(): plugin.logger = logger plugin.help(None) return (options, logger)
def main(): global options global logger try: (options, logger) = init(options, VERSION) threads = [] if len(options['port']) == 0: options['port'].append('8080/http') servers = [] for port in options['port']: p = 0 scheme = 'http' bind = '' try: _port = port if type(port) == int: bind = options['bind'] if ':' in port: bind, port = _port.split(':') if '/http' in port: _port, scheme = port.split('/') p = int(_port) if p < 0 or p > 65535: raise Exception() if not bind: bind = '0.0.0.0' foosock = tornado.netutil.bind_sockets(p, address=bind) servers.append( (bind, p, scheme.lower() == 'https', foosock, options)) except Exception as e: logger.err( 'Specified port ({}) is not a valid number in range of 1-65535!' .format(port)) raise return False tornado.process.fork_processes(0) for srv in servers: serve_proxy(srv[0], srv[1], srv[2], srv[3]) tornado.ioloop.IOLoop.instance().start() except KeyboardInterrupt: logger.info('\nProxy serving interrupted by user.', noprefix=True) except Exception as e: print( ProxyLogger.with_color(ProxyLogger.colors_map['red'], 'Fatal error has occured.')) print( ProxyLogger.with_color(ProxyLogger.colors_map['red'], '\t%s\nTraceback:' % e)) print(ProxyLogger.with_color(ProxyLogger.colors_map['red'], '-' * 30)) traceback.print_exc() print(ProxyLogger.with_color(ProxyLogger.colors_map['red'], '-' * 30)) finally: cleanup()
def main(): global options global logger try: (options, logger) = init(options, VERSION) print(r''' ____ ___ __ __ / __ \___ ____/ / | / /___ __________/ /__ ____ / /_/ / _ \/ __ /| | /| / / __ `/ ___/ __ / _ \/ __ \ / _, _/ __/ /_/ / | |/ |/ / /_/ / / / /_/ / __/ / / / /_/ |_|\___/\__,_/ |__/|__/\__,_/_/ \__,_/\___/_/ /_/ :: RedWarden - Envelopes your malleable virus packets so they penetrate breached perimeters right under AVs, Proxies, EDRs noses! by Mariusz B. / mgeeky, '19-'21 <mb [at] binary-offensive.com> v{} '''.format(VERSION)) threads = [] if len(options['port']) == 0: options['port'].append('8080/http') servers = [] for port in options['port']: p = 0 scheme = 'http' bind = '' try: _port = port if type(port) == int: bind = options['bind'] if ':' in port: bind, port = _port.split(':') if '/http' in port: _port, scheme = port.split('/') p = int(_port) if p < 0 or p > 65535: raise Exception() if not bind: bind = '0.0.0.0' foosock = tornado.netutil.bind_sockets(p, address=bind) servers.append( (bind, p, scheme.lower() == 'https', foosock, options)) except Exception as e: logger.err( 'Specified port ({}) is not a valid number in range of 1-65535!' .format(port)) raise return False # https://www.tornadoweb.org/en/stable/tcpserver.html # advanced multi-process: tornado.process.fork_processes(0) for srv in servers: serve_proxy(srv[0], srv[1], srv[2], srv[3]) tornado.ioloop.IOLoop.current().start() except KeyboardInterrupt: logger.info('\nProxy serving interrupted by user.', noprefix=True) except Exception as e: print( ProxyLogger.with_color(ProxyLogger.colors_map['red'], 'Fatal error has occured.')) print( ProxyLogger.with_color(ProxyLogger.colors_map['red'], '\t%s\nTraceback:' % e)) print(ProxyLogger.with_color(ProxyLogger.colors_map['red'], '-' * 30)) traceback.print_exc() print(ProxyLogger.with_color(ProxyLogger.colors_map['red'], '-' * 30)) finally: cleanup()