How run commands within mitmdump?

I’m using mitmdump and I need make new requests from a web page (test.html). By example, in my inline script (test.py) I have a python function like this:

def makeNewRequest(data):
context, flow = savedFlow, savedContext #saved from prior request - global variables
flow.request.content = data
context.replay_request(flow)

I need run this “makeNewRequest” function from a button in test.html.

I plan to do using websockets from javascript in test.html to a python websocket server in my inline script test.py. This websocket server would be a new Thread inside test.py.

In this thread (How to view the proxy server’s URL) I read about create new script with Flask, and run commands from this script, but it seems both scripts (main script and Flask script) are not sharing global variables, so I don’t know how run “makeNewRequest” function from Flask script.

I know it is a little confusing my idea, but I hope you understand it.

Your main problem would not be sharing state, your main problem would be concurrency. You should not call stuff from the context in an external thread, so I would strongly recommend not spawning an external server. What part about the Flask approach would not work for you?

In my response I save some values in a global variable ‘allData’.

def response(context, flow):
allData = readValues(flow.response.content)

Now, I want Flask reads this values from ‘allData’ to create a webpage with form filled with these values, but Flask can’t read this variable because is not defined.

I execute mitmdump with the following params:

mitmdump -s main.py -s flask.py

Maybe my error could be running it with two different scripts. Would I put flask code into main.py script to access allData variable?

Yes, each inline script has its own scope.