0
votes

I tried using below script but getting error.

#!/usr/bin/env python3

def request(flow: http.HTTPFlow) -> None:
    if flow.request.method == "POST" or flow.request.method == "PUT":
        logger.info("Sensitive pattern found")
        flow.kill()
        logger.info("Am I killed part 1")
1
What is the error you are getting? What is it you're trying to do? - Marit
What error? Show error text. - mentallurg

1 Answers

4
votes

It needs to import http module for using HTTPFlow. For logging, ctx.log is available, ex:

ctx.log.info("This is some informative text.")
ctx.log.warn("This is a warning.")
ctx.log.error("This is an error.")

So, the script looks like:

#!/usr/bin/env python3
from mitmproxy import http
from mitmproxy import ctx

def request(flow: http.HTTPFlow) -> None:
    if flow.request.method == "POST" or flow.request.method == "PUT":
        ctx.log.info("Sensitive pattern found")
        flow.kill()
        ctx.log.info("Am I killed part 1")