diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2011-07-22 17:48:42 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2011-07-22 17:48:42 +1200 |
commit | 1b961fc4adb2ef623747102b1539aa4d46c6e743 (patch) | |
tree | 941bda1de0d524508a2bc9bfea711ecee15e84f3 /libmproxy/flow.py | |
parent | 9c24401b187fa2915d8b6cc424fc25f5e51369c8 (diff) | |
download | mitmproxy-1b961fc4adb2ef623747102b1539aa4d46c6e743.tar.gz mitmproxy-1b961fc4adb2ef623747102b1539aa4d46c6e743.tar.bz2 mitmproxy-1b961fc4adb2ef623747102b1539aa4d46c6e743.zip |
Add utility functions to search and replace strings in flows
This is a common task in pentesting scenarios. This commit adds the following
functions:
utils.Headers.replace
proxy.Request.replace
proxy.Response.replace
flow.Flow.replace
Diffstat (limited to 'libmproxy/flow.py')
-rw-r--r-- | libmproxy/flow.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libmproxy/flow.py b/libmproxy/flow.py index 13b5acbc..d174b41f 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -323,6 +323,18 @@ class Flow: self.response.ack() self.intercepting = False + def replace(self, pattern, repl, count=0, flags=0): + """ + Replaces a regular expression pattern with repl in all parts of the + flow . Returns the number of replacements made. + """ + c = self.request.replace(pattern, repl, count, flags) + if self.response: + c += self.response.replace(pattern, repl, count, flags) + if self.error: + c += self.error.replace(pattern, repl, count, flags) + return c + class State: def __init__(self): |