mirror of
https://github.com/byt3bl33d3r/MITMf.git
synced 2025-07-06 21:12:16 -07:00
Try except added to re.sub to prevent plugin from crashing if incorrect regexes where provided. Removed default values for search_str and replace_str
This commit is contained in:
parent
d6f3405f71
commit
5c1dbb3596
1 changed files with 13 additions and 7 deletions
|
@ -21,7 +21,7 @@ class Replace(CacheKill,Plugin):
|
|||
self.implements.remove("handleHeader")
|
||||
self.implements.remove("connectionMade")
|
||||
|
||||
if self.search_str==self.replace_str=="" and self.regex_file is None:
|
||||
if (self.search_str==self.replace_str==None or self.search_str==self.replace_str=="") and self.regex_file is None:
|
||||
print "[*] Please provide a search and replace string or a regex file"
|
||||
quit()
|
||||
|
||||
|
@ -36,15 +36,21 @@ class Replace(CacheKill,Plugin):
|
|||
|
||||
if self._should_replace(ip,hn,mime):
|
||||
|
||||
if self.search_str==self.replace_str!="":
|
||||
# Did the user provide us a search and replace str?
|
||||
if self.search_str==self.replace_str!=None and self.search_str==self.replace_str!="":
|
||||
data = data.replace(self.search_str, self.replace_str)
|
||||
logging.info("%s [%s] Replaced '%s' with '%s'" % (request.client.getClientIP(), request.headers['host'], self.search_str, self.replace_str))
|
||||
|
||||
# DI the user provide us with a regex file?
|
||||
if self.regex_file is not None:
|
||||
for line in self.regex_file:
|
||||
replaceRegex = line.split("\t")
|
||||
data = re.sub(replaceRegex[0], replaceRegex[1], data)
|
||||
logging.info("%s [%s] Replaced '%s' with '%s'" % (request.client.getClientIP(), request.headers['host'], replaceRegex[0], replaceRegex[1]))
|
||||
try:
|
||||
data = re.sub(replaceRegex[0], replaceRegex[1], data)
|
||||
|
||||
logging.info("%s [%s] Replaced '%s' with '%s'" % (request.client.getClientIP(), request.headers['host'], replaceRegex[0], replaceRegex[1]))
|
||||
except Exception, e:
|
||||
logging.error("%s [%s] Your provided regex (%s) or replace value (%s) is empyt or invalid. Please debug your provided regex(es)" % (request.client.getClientIP(), request.headers['host'], replaceRegex[0], replaceRegex[1]))
|
||||
|
||||
self.ctable[ip] = time.time()
|
||||
self.dtable[ip+hn] = True
|
||||
|
@ -54,9 +60,9 @@ class Replace(CacheKill,Plugin):
|
|||
return
|
||||
|
||||
def add_options(self,options):
|
||||
options.add_argument("--regex-file",type=file,help="Load file with regexes")
|
||||
options.add_argument("--replace-str",type=str,default="",help="String you would like to replace.")
|
||||
options.add_argument("--search-str",type=str,default="",help="String you would like to replace --replace-str with. Default: '' (empty string)")
|
||||
options.add_argument("--replace-str",type=str,help="String you would like to replace.")
|
||||
options.add_argument("--search-str",type=str,help="String you would like to replace --replace-str with. Default: '' (empty string)")
|
||||
options.add_argument("--regex-file",type=file,help="Load file with regexes. File format: <regex1>[tab]<regex2>[new-line]")
|
||||
options.add_argument("--keep-cache",action="store_true",help="Don't kill the server/client caching.")
|
||||
|
||||
def _should_replace(self,ip,hn,mime):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue