MITMf/plugins/replace.py
byt3bl33d3r eea5f53be2 Initial commit for v1.0 using mitmproxy instead of twisted
Added a plugin system to Net-Creds so you can now add your own parsers,
api hook names might change between now and the offcial release
(will submit a PR to the original repo once completed)

The main MITM HTTP Proxy now uses mitmproxy which is a big deal, cuts
the code down by an insane amount, no more twisted! yay!

Basic plugin have been re-wrote for the new proxy engine

Since we are using mitmproxy we have out of the box support for SSL/TLS!
2016-02-06 13:27:08 -07:00

21 lines
918 B
Python

import re
from netlib.http import decoded
from plugins.plugin import Plugin
class Replace(Plugin):
name = 'Replace'
optname = 'replace'
desc = 'Replace arbitrary content in HTML content'
version = '0.2'
def response(self, context, flow):
if flow.response.headers.get_first("content-type", "").startswith("text/html"):
with decoded(flow.response):
for rulename, regexs in self.config['Replace'].iteritems():
for regex1,regex2 in regexs.iteritems():
if re.search(regex1, flow.response.content):
data = re.sub(regex1, regex2, flow.response.content)
context.log("[Replace] Occurances matching '{}' replaced with '{}' according to rule '{}' on {}".format(regex1, regex2, rulename, flow.request.host))
flow.response.content = data