mirror of
https://github.com/byt3bl33d3r/MITMf.git
synced 2025-07-06 21:12:16 -07:00
Add refactoring of file reading
This commit is contained in:
parent
906c7951df
commit
2f802e71c7
3 changed files with 11 additions and 19 deletions
|
@ -73,29 +73,25 @@ class AppCachePlugin(Plugin):
|
||||||
p = self.getTemplatePrefix(section)
|
p = self.getTemplatePrefix(section)
|
||||||
self.clientlog.info("Poisoning raw URL", extra=request.clientInfo)
|
self.clientlog.info("Poisoning raw URL", extra=request.clientInfo)
|
||||||
if os.path.exists(p + '.replace'): # replace whole content
|
if os.path.exists(p + '.replace'): # replace whole content
|
||||||
f = open(p + '.replace', 'r')
|
with open(p + '.replace', 'r') as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
f.close()
|
|
||||||
|
|
||||||
elif os.path.exists(p + '.append'): # append file to body
|
elif os.path.exists(p + '.append'): # append file to body
|
||||||
f = open(p + '.append', 'r')
|
with open(p + '.append', 'r') as f:
|
||||||
data += f.read()
|
data += f.read()
|
||||||
f.close()
|
|
||||||
|
|
||||||
elif (section.get('tamper_url',False) == url) or (section.has_key('tamper_url_match') and re.search(section['tamper_url_match'], url)):
|
elif (section.get('tamper_url',False) == url) or (section.has_key('tamper_url_match') and re.search(section['tamper_url_match'], url)):
|
||||||
self.clientlog.info("Found URL in section '{}'!".format(name), extra=request.clientInfo)
|
self.clientlog.info("Found URL in section '{}'!".format(name), extra=request.clientInfo)
|
||||||
p = self.getTemplatePrefix(section)
|
p = self.getTemplatePrefix(section)
|
||||||
self.clientlog.info("Poisoning URL with tamper template: {}".format(p), extra=request.clientInfo)
|
self.clientlog.info("Poisoning URL with tamper template: {}".format(p), extra=request.clientInfo)
|
||||||
if os.path.exists(p + '.replace'): # replace whole content
|
if os.path.exists(p + '.replace'): # replace whole content
|
||||||
f = open(p + '.replace', 'r')
|
with open(p + '.replace', 'r') as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
f.close()
|
|
||||||
|
|
||||||
elif os.path.exists(p + '.append'): # append file to body
|
elif os.path.exists(p + '.append'): # append file to body
|
||||||
f = open(p + '.append', 'r')
|
with open(p + '.append', 'r') as f:
|
||||||
appendix = f.read()
|
appendix = f.read()
|
||||||
data = re.sub(re.compile("</body>", re.IGNORECASE), appendix + "</body>", data) #append to body
|
data = re.sub(re.compile("</body>", re.IGNORECASE), appendix + "</body>", data) #append to body
|
||||||
f.close()
|
|
||||||
|
|
||||||
# add manifest reference
|
# add manifest reference
|
||||||
data = re.sub(re.compile("<html",re.IGNORECASE),"<html manifest=\"" + self.getManifestUrl(section)+"\"", data)
|
data = re.sub(re.compile("<html",re.IGNORECASE),"<html manifest=\"" + self.getManifestUrl(section)+"\"", data)
|
||||||
|
@ -155,9 +151,8 @@ class AppCachePlugin(Plugin):
|
||||||
if not os.path.exists(p+'.manifest'):
|
if not os.path.exists(p+'.manifest'):
|
||||||
p = self.getDefaultTemplatePrefix()
|
p = self.getDefaultTemplatePrefix()
|
||||||
|
|
||||||
f = open(p + '.manifest', 'r')
|
with open(p + '.manifest', 'r') as f:
|
||||||
manifest = f.read()
|
manifest = f.read()
|
||||||
f.close()
|
|
||||||
return self.decorate(manifest, section)
|
return self.decorate(manifest, section)
|
||||||
|
|
||||||
def decorate(self, content, section):
|
def decorate(self, content, section):
|
||||||
|
|
|
@ -45,7 +45,6 @@ class FerretNG(Plugin):
|
||||||
with open(options.cookie_file, 'r') as cookie_file:
|
with open(options.cookie_file, 'r') as cookie_file:
|
||||||
self.cookie_file = json.dumps(cookie_file.read())
|
self.cookie_file = json.dumps(cookie_file.read())
|
||||||
URLMonitor.getInstance().cookies = self.cookie_file
|
URLMonitor.getInstance().cookies = self.cookie_file
|
||||||
cookie_file.close()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
shutdown("[-] Error loading cookie log file: {}".format(e))
|
shutdown("[-] Error loading cookie log file: {}".format(e))
|
||||||
|
|
||||||
|
@ -94,4 +93,3 @@ class FerretNG(Plugin):
|
||||||
self.log.info("Writing cookies to log file")
|
self.log.info("Writing cookies to log file")
|
||||||
with open('./logs/ferret-ng/cookies-{}.log'.format(datetime.now().strftime("%Y-%m-%d_%H:%M:%S:%s")), 'w') as cookie_file:
|
with open('./logs/ferret-ng/cookies-{}.log'.format(datetime.now().strftime("%Y-%m-%d_%H:%M:%S:%s")), 'w') as cookie_file:
|
||||||
cookie_file.write(str(URLMonitor.getInstance().cookies))
|
cookie_file.write(str(URLMonitor.getInstance().cookies))
|
||||||
cookie_file.close()
|
|
||||||
|
|
|
@ -46,7 +46,6 @@ class ScreenShotter(Inject, Plugin):
|
||||||
try:
|
try:
|
||||||
with open('./logs/' + img_file, 'wb') as img:
|
with open('./logs/' + img_file, 'wb') as img:
|
||||||
img.write(base64.b64decode(urllib.unquote(request.postData).decode('utf8').split(',')[1]))
|
img.write(base64.b64decode(urllib.unquote(request.postData).decode('utf8').split(',')[1]))
|
||||||
img.close()
|
|
||||||
|
|
||||||
self.clientlog.info('Saved screenshot to {}'.format(img_file), extra=request.clientInfo)
|
self.clientlog.info('Saved screenshot to {}'.format(img_file), extra=request.clientInfo)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue