From 1b961fc4adb2ef623747102b1539aa4d46c6e743 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Fri, 22 Jul 2011 17:48:42 +1200 Subject: 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 --- libmproxy/flow.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libmproxy/flow.py') 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): -- cgit v1.2.3