mirror of
https://github.com/byt3bl33d3r/MITMf.git
synced 2025-07-07 13:32:18 -07:00
Inject.py now tries to detect encoding before parsing HTML with BeautifulSoup
This commit is contained in:
parent
fb41a510f6
commit
27c28e512e
3 changed files with 29 additions and 18 deletions
|
@ -11,6 +11,7 @@
|
|||
- @mmetince
|
||||
- @niallmerrigan
|
||||
- @auraltension
|
||||
- @HAMIDx9
|
||||
|
||||
#Unintentional contributors and/or projects that I stole code from
|
||||
|
||||
|
|
|
@ -57,11 +57,14 @@ class Inject(Plugin):
|
|||
|
||||
def response(self, response, request, data):
|
||||
|
||||
encoding = None
|
||||
ip = response.getClientIP()
|
||||
hn = response.getRequestHostname()
|
||||
mime = response.headers['Content-Type']
|
||||
|
||||
if self._should_inject(ip, hn) and self._ip_filter(ip) and self._host_filter(hn) and (hn not in self.ip) and ("text/html" in mime):
|
||||
try:
|
||||
mime = response.headers['Content-Type']
|
||||
except KeyError:
|
||||
return
|
||||
|
||||
if "charset" in mime:
|
||||
match = re.search('charset=(.*)', mime)
|
||||
|
@ -71,12 +74,19 @@ class Inject(Plugin):
|
|||
try:
|
||||
encoding = chardet.detect(data)["encoding"]
|
||||
except:
|
||||
encoding = None
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
encoding = chardet.detect(data)["encoding"]
|
||||
except:
|
||||
pass
|
||||
|
||||
if encoding:
|
||||
if self._should_inject(ip, hn) and self._ip_filter(ip) and self._host_filter(hn) and (hn not in self.ip) and ("text/html" in mime):
|
||||
|
||||
if encoding is not None:
|
||||
html = BeautifulSoup(data.decode(encoding, "ignore"), "lxml")
|
||||
else:
|
||||
html = BeautifulSoup(data, "lxml") # let bs find the encoding
|
||||
html = BeautifulSoup(data, "lxml")
|
||||
|
||||
if html.body:
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
git+git://github.com/kti/python-netfilterqueue
|
||||
pyinotify
|
||||
pycrypto>=2.6
|
||||
pyasn1>=0.1.7
|
||||
pycrypto
|
||||
pyasn1
|
||||
cryptography
|
||||
Pillow
|
||||
netaddr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue