mirror of
https://github.com/byt3bl33d3r/MITMf.git
synced 2025-07-08 05:51:48 -07:00
Fix encoding in Inject plugin by using manual encoding detection, BS fails in some cases
This commit is contained in:
parent
24070afbd0
commit
7a5186750f
2 changed files with 21 additions and 2 deletions
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
import re
|
||||||
|
import chardet
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from plugins.plugin import Plugin
|
from plugins.plugin import Plugin
|
||||||
|
@ -52,6 +54,7 @@ class Inject(Plugin):
|
||||||
self.dtable = {}
|
self.dtable = {}
|
||||||
self.count = 0
|
self.count = 0
|
||||||
|
|
||||||
|
|
||||||
def response(self, response, request, data):
|
def response(self, response, request, data):
|
||||||
|
|
||||||
ip = response.getClientIP()
|
ip = response.getClientIP()
|
||||||
|
@ -59,7 +62,22 @@ class Inject(Plugin):
|
||||||
mime = response.headers['Content-Type']
|
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):
|
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):
|
||||||
html = BeautifulSoup(data, "lxml")
|
|
||||||
|
if "charset" in mime:
|
||||||
|
match = re.search('charset=(.*)', mime)
|
||||||
|
if match:
|
||||||
|
encoding = match.group(1).strip().replace('"', "")
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
encoding = chardet.detect(data)["encoding"]
|
||||||
|
except:
|
||||||
|
encoding = None
|
||||||
|
|
||||||
|
if encoding:
|
||||||
|
html = BeautifulSoup(data.decode(encoding, "ignore"), "lxml")
|
||||||
|
else:
|
||||||
|
html = BeautifulSoup(data, "lxml") # let bs find the encoding
|
||||||
|
|
||||||
if html.body:
|
if html.body:
|
||||||
|
|
||||||
if self.html_url:
|
if self.html_url:
|
||||||
|
|
|
@ -22,3 +22,4 @@ python-magic
|
||||||
msgpack-python
|
msgpack-python
|
||||||
requests
|
requests
|
||||||
pypcap
|
pypcap
|
||||||
|
chardet
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue