Skip to content

Python Mangler Functions

Josh edited this page Jul 19, 2023 · 4 revisions

There are currently 3 functions you can use to modify traffic in the python Mangler.

  • def mangle(input, isC2S): - Used to modify traffic and inject payloads in either direction.
  • def preIntercept(input,isC2S): - Only called when intercept is enabled. This can be used to decode traffic into human readable/editable form before being sent to the interceptor.
  • def postIntercept(input, isC2S): - Only called when intercept is enabled. This is used to encode the traffic back to binary after it leaves the interceptor.
  • def formatOnly(input, isC2S): - If the function exits it will automatically format the data in the table only. Does not affect the actual flow of the traffic. This is useful if you want to extract parts of the packets, decode websockets or decode protobuffs.
  • def interceptRules(input, isC2S) - This function must only return True or False. You can use this function control when to intercept a request or response. If this function exists and you have the interceptor enabled, only requests that return True will actually go to the interceptor and all others will be bypassed.

isC2S

You can control the direction of you edits using the boolean value isC2S (is Client to Server). If you only want to modify data originating from Server to client you can call the mangle function as follows:

def mangle(input, isC2S):
   if isC2S == False:
      input=input.replace("junk","more junk")
   return input

The above method will modify traffic originating from the server but will let traffic flow unaltered from Client to the Server.

Using interceptRules:

You can use the following function to control which requests actually go to the manual interceptor.


def interceptRules(input, isC2S):
   return isC2S ==True and b"test data" in input

Important Note about Byte Arrays!!!!

Nope proxy always expects the return value from all functions to be a Byte Array. This is usually not a problem when modifying requests but sometimes the modification will change your input variable into something other than a Byte Array. If this happens then you can call the bytearray function to convert it back.

###Example to force a byte array

def mangle(input, isC2S):
   input=input.replace("junk","more junk")
   return bytearray(input)