Beispiel #1
0
def run_mitmproxy(options, event):
    mode = "regular"

    upstream = None
    if options.upstream:
        upstream = options.upstream
        mode = "upstream"

    opts = mitmproxy.options.Options(
        mode=mode,
        listen_port=int(options.proxyport),
        cadir=os.path.abspath(options.cadir),
        upstream_server=upstream
    )
    config = ProxyConfig(opts)
    
    state = flow.State()
    server = ProxyServer(config)
    proxy = ReflashProxy(opts, server, state)
    proxy.options = options
    proxy.options.sid = 0
    proxy.options.instrumented = {}
    if not proxy.options.input:
        proxy.options.mode = "pass"
    else:
        proxy.options.mode = "sandbox"
    
    proxy.stopEvent = event
    proxy.run()
Beispiel #2
0
def sniff_main():
    opts = options.Options(upstream_server="http://localhost:8080",
                           cadir="~/.mitmproxy/")
    config = ProxyConfig(opts)
    state = flow.State()
    server = ProxyServer(config)
    m = Sniff(opts, server, state)
    m.run()
Beispiel #3
0
    def __init__(self,
                 listen_host="",
                 listen_port=8080,
                 socks=False,
                 auth=None,
                 insecure=False,
                 processes=2,
                 cmd='tor',
                 on_count=0,
                 on_string=None,
                 on_regex=None,
                 on_rst=False,
                 on_callback=None):
        self.logger = logging.getLogger(__name__)

        # Change IP Policy (Configuration)
        self.counter = itertools.count(1)
        self.on_count = on_count
        self.on_regex = on_regex
        self.on_rst = on_rst

        self.on_string = on_string
        if self.on_string:
            # For Python 3
            self.on_string = str.encode(on_string)

        self.on_callback = None
        if callable(on_callback):
            self.on_callback = on_callback

        # Create MultiTor (Tor Pool)
        self.multitor = MultiTor(size=processes, cmd=cmd)

        # Create Proxy Server
        self.insecure = insecure

        options_dict = {
            'listen_host': listen_host,
            'listen_port': listen_port,
            'ssl_insecure': self.insecure,
            'mode': "socks5" if socks else "regular",
            'rawtcp': False,
            'auth_singleuser': auth
        }
        # options_dict['proxyauth' if new_mitmproxy else 'auth_singleuser'] = auth

        options = ProxyOptions(**options_dict)

        setattr(options, websocket_key, False)
        config = ProxyConfig(options)
        server = ProxyServer(config)

        if new_mitmproxy:
            super(self.__class__, self).__init__(options, server)
        else:
            state = State()
            super(self.__class__, self).__init__(options, server, state)
def start_proxy(port):
    options = Options(listen_port=port, )
    config = ProxyConfig(options=options, )
    server = ProxyServer(config)
    print('Intercepting Proxy listening on {0}'.format(port))
    m = TestInterceptor(options, server)
    m.addons.add(core.Core())
    m.addons.add(Counter())
    m.run()
Beispiel #5
0
def start_proxy(port):
    options = Options(listen_port=port, )
    # options.body_size_limit='3m'
    config = ProxyConfig(options=options,
                         #    cacert = os.path.expanduser('./mitmproxy.pem'),
                         )
    server = ProxyServer(config)
    print('Intercepting Proxy listening on {0}'.format(port))
    m = TestInterceptor(options, server)
    m.run()
def proxy_start():
    #opts = options.Options(cadir="~/.mitmproxy/")
    opts = options.Options(listen_port=8088)
    config = ProxyConfig(opts)
    server = ProxyServer(config)
    # pport = int(proxy_port)
    # config = proxy.ProxyConfig(options=)
    state = flow.State()
    #server = ProxyServer(config)
    print 'Express started on http://localhost:8088; press Ctrl-C to terminate.'
    m = MyMaster(opts, server, state)
    m.run()
Beispiel #7
0
def start_mitm_proxy(log_file):
    opts = options.Options(cadir="~/.mitmproxy/")
    config = ProxyConfig(opts)
    state = flow.State()
    server = ProxyServer(config)

    log_file = open(log_file, 'w')

    m = MyMaster(opts, server, state)
    m.set_log_file(log_file)
    m.run()
    log_file.close()
Beispiel #8
0
def start_server(port, mode, domain):
    if mode == "http":
        mode = "regular"
    opts = options.Options(cadir="~/.mitmproxy/",
                           listen_port=int(port) or 8080,
                           mode=mode)
    if domain:
        global _domain
        _domain = domain
    config = ProxyConfig(opts)
    server = ProxyServer(config)
    m = MyMaster(opts, server)
    m.run()
Beispiel #9
0
    def __init__(self, mode, cache_path, rewarders=[]):
        opts = options.Options(cadir="~/.mitmproxy/")
        opts.listen_port = 8888
        config = ProxyConfig(opts)
        server = ProxyServer(config)
        super(ProxyController, self).__init__(opts, server)

        self.mode = mode

        self.cache = ProxyCache(cache_path)
        self.cache.configure(opts, {})

        self.WOB_LOCK = threading.Lock()
        self.WOB_REWARD_GLOBAL = 0
        self.WOB_DONE_GLOBAL = False
        self.rewarders = rewarders
Beispiel #10
0
 def do_start(self, arg):
     if not self.start_status:
         logger.info("OK")
         self.prompt = "\033[1;35m [*]探测装置-> \033[0m"
         self.start_status = True
         opts = options.Options(upstream_server="http://localhost:8080",
                                cadir="~/.mitmproxy/")
         config = ProxyConfig(opts)
         state = flow.State()
         server = ProxyServer(config)
         self.m = Sniff(opts, server, state)
         self.th_sniff = threading.Thread(target=self.m.run, name='sniff')
         self.th_sniff.setDaemon(True)
         self.th_sniff.start()
     else:
         logger.error("Sniff已开启")
Beispiel #11
0
def MainProxy():
    """
    The Proxy called by waunitproxy
    """
    # Configuration file
    if (os.path.isfile(args.config_file)):
        #use ~/.mitmproxy/mitmproxy-ca.pem as default CA file.
        proxyconfig = ProxyConfig(port=config.getint('Proxy', 'port'),
                                  cadir="~/.mitmproxy/")
        state = flow.State()
        server = ProxyServer(proxyconfig)
        try:
            m = GoogleAnalyticsUniversal(server, state)
            m.run()
        except (KeyboardInterrupt):
            pass
    else:
        print "Invalid config file. Use --config to specify the configuration file (e.g. --config waunit.cfg)"
    def __init__(self):
        options = Options(
            listen_port=config.port,
            ignore_hosts=[
                ''.join([
                    r'^(?![0-9.]+:)',  # https://docs.mitmproxy.org/stable/howto-ignoredomains/
                    EpicAddon.hosts,  # Allow epic hosts
                    OriginAddon.hosts,  # Allow origin hosts
                ])
            ])
        options.add_option("body_size_limit", int, 0,
                           "")  # Fix for weird bug that crashes mitmproxy

        super().__init__(options)

        self.server = ProxyServer(ProxyConfig(options))
        self.addons.add(EpicAddon())
        self.addons.add(OriginAddon())

        log.info(f'Successfully initialized mitmproxy on port {config.port}')
Beispiel #13
0
    def __init__(self, port=12345, mode="regular", cadir="ssl/"):
        super(ProxyDaemon, self).__init__()

        if not os.path.exists(cadir):
            logger.error("%s does not exist" % cadir)
            raise ValueError("%s does not exist" % cadir)

        global HINT
        while True:
            try:
                opts = options.Options(listen_port=port + HINT,
                                       mode=mode,
                                       cadir=cadir)

                config = ProxyConfig(opts)
                server = ProxyServer(config)
                self.port = port + HINT
                self.mproxy = Proxy(opts, server)
                break
            except ServerException:
                pass
            finally:
                HINT += 1
Beispiel #14
0
class MyMaster(master.Master):
    def run(self):
        try:
            master.Master.run(self)
        except KeyboardInterrupt:
            self.shutdown()

    @controller.handler
    def request(self, f):
        print("request", f)

    @controller.handler
    def response(self, f):
        print("response", f)

    @controller.handler
    def error(self, f):
        print("error", f)

    @controller.handler
    def log(self, l):
        print("log", l.msg)


opts = options.Options(cadir="~/.mitmproxy/")
config = ProxyConfig(opts)
server = ProxyServer(config)
m = MyMaster(opts, server)
m.run()
Beispiel #15
0
 def __init__(self, **options):
     opts = Options(**options)
     server = ProxyServer(ProxyConfig(opts))
     super().__init__(opts, server)