1

I have a program I'd like to exploit. I have seen (through burp suite) that when it opens it does a request to a server and depending on the answer of the server it does multiple things. The thing is that I'd like to edit this request. I'd like to create a proxy (I have seen mitmproxy can fit my needs but if you have other suggestions feel free to post them), that "passtrough" all the http request except for the one I'd like. On this "special" request all it needs to do is give a custom response. I'm making you an example. The program does 10 request to google.com, I'd like to let this request pass back and forth, than it does one special request to example.org and example.org answer this request with "OK". I'd like to change this answer to "Wrong". Is there a way to do this? I have seen something similar but nothing like this. Can you help me? P.S. I know how to program in python so if you link me an article is more than fine! Have a nice day!

Edit: I wrote this simple code i copied online but it doesn't seem to work...

from mitmproxy import http


def response(self, flow: http.HTTPFlow) -> None:
    if flow.response and flow.response.content:
        flow.response.content = flow.response.content.replace(
            b"</head>",
            b"<style>body {transform: scaleX(-1);}</style></head>"
        )


I inject this with mitmproxy -s main.py Am i doing something wrong?

Rom7x
  • 56
  • 1
  • 6
  • Mitmproxy can be extended by Python based script addons. So you can write an addon that checks the path or whatever criteria you have for the request you want to intercept and then send the custom response. Check the example addon scripts as a quick start base https://docs.mitmproxy.org/stable/addons-examples/ – Robert Feb 28 '22 at 12:54
  • It looks fantastic @Robert but the problem now it that requests aren't going through because of certificate. If a surf for google.com i get a certificate error, is there a way of passing the right certificate? – Rom7x Feb 28 '22 at 13:19
  • The device is Android? Please check this answer https://stackoverflow.com/questions/62730978/some-androids-apps-wont-connect-through-fiddler/62731432#62731432 – Robert Feb 28 '22 at 13:23
  • No, it's a Windows pc. But I don't understand why with burp suite i wasn't having this problem and with mitmproxy I'm having it – Rom7x Feb 28 '22 at 13:36
  • The mitmproxy root CA certificate is installed? Does the problem occur on client or on server side? Some servers are blocking python using TLS fingerprinting. If the proxy server is running Windows I recommend to you to check out Fiddler Classic, it is .Net based and also has a scripting interface. – Robert Feb 28 '22 at 15:10
  • Ok, now it's working but i can't get it to load the script. I post the code i wrote here: `from mitmproxy import http def response(self, flow: http.HTTPFlow) -> None: if flow.response and flow.response.content: flow.response.content = flow.response.content.replace( b"", b"" ) `. I copied this online so it should work. I think it's a load issue. I loaded it with mitmproxy -s main.py – Rom7x Feb 28 '22 at 16:04
  • Please do not post code in comments (totally unreadable), edit the question instead. – Robert Feb 28 '22 at 16:22
  • Edited! Hope you can see clearly now. Thanks again! – Rom7x Mar 02 '22 at 13:02

0 Answers0