0

I am working with mitmproxy, and I am still fairly new to it (been using it for a couple of days). Right now I am attempting to intercept get requests, and replace all instances of a string, for example "data: 123" with "data: 456", and then resume the flow of information with the intent of illiciting a certain response from the application . I have gotten to the point where I am successfully intercepting my desired URLs, but I do not understand how to create a script to replace all instances of "data: 123", or if it is even possible to do that while intercepting. Any help is appreciated! The get request looks something like this. The reason for replacing all instances is because the data seems to be repeatedly (unnecessarily?) several times, and manually replacing each is not feasible.

    "text": {
    "data": "123",
    "size": 36,
    "style": "bold",
    "name": "text1",
    "hOffset": 250,
    "vOffset": 100,
    "alignment": "center",
    "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
    "text": {
    "data": "123",
    "size": 36,
    "style": "bold",
    "name": "text1",
    "hOffset": 250,
    "vOffset": 100,
    "alignment": "center",
    "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}

Note that the actual data I am intercepting is larger and not nicely formatted like this, thus the need for a script. I have looked through examples on https://github.com/mitmproxy/mitmproxy but nothing seems to help with what I am trying to do.

Any help and guidance towards finding a solution for my issue is greatly appreciated!!!

user1576752
  • 29
  • 1
  • 3
  • 10

1 Answers1

0

You can get and modify GET requests path in the handle_requests method in the implementation example given in the doc.

def handle_request(self, flow):
  request = flow.request

  # ---------------------------------
  # Play with the GET path with regex
  # Add 'import re'
  newPath = re.sub(r"data:123", "data:456", request.path)
  # ---------------------------------

  flow.request.path = newPath
  flow.reply()
Dr. Jekyll
  • 386
  • 4
  • 16