mirror of
https://github.com/byt3bl33d3r/MITMf.git
synced 2025-07-06 04:52:22 -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 sys
|
||||
import re
|
||||
import chardet
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from plugins.plugin import Plugin
|
||||
|
@ -52,6 +54,7 @@ class Inject(Plugin):
|
|||
self.dtable = {}
|
||||
self.count = 0
|
||||
|
||||
|
||||
def response(self, response, request, data):
|
||||
|
||||
ip = response.getClientIP()
|
||||
|
@ -59,7 +62,22 @@ class Inject(Plugin):
|
|||
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):
|
||||
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 self.html_url:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue