0

I am a newbie on python web programming, still don't know how to integrate mitmproxy with web framework such as flask. I mean is it possible to send a request to start mitmproxy service, another request to stop it, as example below:

 app = Flask(__name__)

class MyMaster(flow.FlowMaster):
    def run(self):
        try:
            flow.FlowMaster.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/", listen_port=9000)
config = ProxyConfig(opts)
state = flow.State()
server = ProxyServer(config)
m = MyMaster(opts, server, state)

@app.route("/")
def index():
    return "hello"

@app.route("/start")
def start():
    global m
    m.run()
    return 'Start!'

def stop():
    global m
    m.shutdown()

app.run(debug=True)

now I have to divide my application into two parts, the mitmproxy as service be controlled by supervisor, store the data into database, another flask app to display the data from database. actually I want to control the service from the client side.

Xun Lee
  • 313
  • 1
  • 3
  • 12
  • It's not clear what you're asking but typically, you want to run mitmproxy separate from your app. You can conditionally activate or deactivate mitmproxy collection based on what's in the request. – pvg Dec 23 '16 at 03:48
  • Ok, take a look at [ask] and [mcve]. You need to write your questions specifically, with your goals, results, errors and verifiable code described. 'i tried mitmproxy but it doesn't work' is just not enough information for anyone to really help you with. – pvg Dec 23 '16 at 03:51
  • yes, I want to activate mitmproxy in my app, but don't know how to, always block on def start. – Xun Lee Dec 23 '16 at 03:52
  • That doesn't really mean anything to anyone else. Please take a look at the SO docs linked to make your question clearer. – pvg Dec 23 '16 at 03:53
  • I once tried the example on mitmproxy example demo, I execute it with mitmdump command, but I cannot visit the domain of app I set. https://github.com/mitmproxy/mitmproxy/blob/v0.18.1/examples/proxapp.py – Xun Lee Dec 23 '16 at 03:58
  • These details need to go in your questions along with the specific problems you encountered. – pvg Dec 23 '16 at 03:58
  • sorry, for my poor English and expression, can you help me, SOS – Xun Lee Dec 23 '16 at 04:10
  • @XunLee Take a look of https://github.com/mitmproxy/mitmproxy/blob/master/examples/simple/wsgi_flask_app.py, and if possible, ask the creator for those complex questions. I also though about Flask (web GUI) or other things related to mtmproxy. I don't really need if you need to use Flask, or maybe is good enough for you to use a Java GUI like Paros. Good luck. – m3nda Jan 27 '17 at 20:24
  • And for the sake of your question, starting/stopping a process from a Flask web/api is not so much related with mtmproxy, it is more related to system calls and process management. – m3nda Jan 27 '17 at 20:27

0 Answers0