Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 13e93f5

Browse files
committed
one bug fix in dynamic content engine and some code refactoring
1 parent 73b33ed commit 13e93f5

5 files changed

Lines changed: 27 additions & 23 deletions

File tree

lib/controller/checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def checkDynamicContent(firstPage, secondPage):
185185
if postfix is None and (blocks[i][0] + blocks[i][2] >= len(firstPage)):
186186
continue
187187

188-
kb.dynamicMarkings.append((prefix[-conf.dynMarkLength:] if prefix else None, postfix[:conf.dynMarkLength] if postfix else None))
188+
kb.dynamicMarkings.append((re.escape(prefix[-conf.dynMarkLength:]) if prefix else None, re.escape(postfix[:conf.dynMarkLength]) if postfix else None))
189189

190190
if len(kb.dynamicMarkings) > 0:
191191
infoMsg = "dynamic content marked for removal (%d region%s)" % (len(kb.dynamicMarkings), 's' if len(kb.dynamicMarkings) > 1 else '')

lib/core/common.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,21 +1239,25 @@ def getConsoleWidth(default=80):
12391239
return width if width else default
12401240

12411241
def parseXmlFile(xmlFile, handler):
1242-
if xmlFile not in kb.cache.content:
1243-
if conf.parseLock:
1244-
conf.parseLock.acquire()
1245-
if xmlFile not in kb.cache.content:
1246-
checkFile(xmlFile)
1247-
xfile = codecs.open(xmlFile, 'rb', conf.dataEncoding)
1248-
content = xfile.read()
1249-
kb.cache.content[xmlFile] = content
1250-
xfile.close()
1251-
if conf.parseLock:
1252-
conf.parseLock.release()
1253-
stream = StringIO(kb.cache.content[xmlFile])
1242+
stream = StringIO(readCachedFileContent(xmlFile))
12541243
parse(stream, handler)
12551244
stream.close()
12561245

1246+
def readCachedFileContent(filename, mode='rb'):
1247+
if filename not in kb.cache.content:
1248+
kb.data.cacheLock.acquire()
1249+
1250+
if filename not in kb.cache.content:
1251+
checkFile(filename)
1252+
xfile = codecs.open(filename, mode, conf.dataEncoding)
1253+
content = xfile.read()
1254+
kb.cache.content[filename] = content
1255+
xfile.close()
1256+
1257+
kb.data.cacheLock.release()
1258+
1259+
return kb.cache.content[filename]
1260+
12571261
def readXmlFile(xmlFile):
12581262
checkFile(xmlFile)
12591263
xfile = codecs.open(xmlFile, 'r', conf.dataEncoding)

lib/core/option.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import re
1717
import socket
1818
import sys
19+
import threading
1920
import urllib2
2021
import urlparse
2122

@@ -993,15 +994,13 @@ def __setConfAttributes():
993994
conf.outputPath = None
994995
conf.paramDict = {}
995996
conf.parameters = {}
996-
conf.parseLock = None
997997
conf.path = None
998998
conf.port = None
999999
conf.redirectHandled = False
10001000
conf.retriesCount = 0
10011001
conf.scheme = None
10021002
#conf.seqMatcher = difflib.SequenceMatcher(lambda x: x in " \t")
10031003
conf.seqMatcher = difflib.SequenceMatcher(None)
1004-
conf.seqLock = None
10051004
conf.sessionFP = None
10061005
conf.start = True
10071006
conf.threadContinue = True
@@ -1027,7 +1026,10 @@ def __setKnowledgeBaseAttributes():
10271026
kb.cache.regex = {}
10281027

10291028
kb.commonOutputs = None
1029+
10301030
kb.data = advancedDict()
1031+
kb.data.cacheLock = threading.Lock()
1032+
kb.data.seqLock = None
10311033

10321034
# Basic back-end DBMS fingerprint
10331035
kb.dbms = None

lib/request/comparison.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def comparison(page, headers=None, getSeqMatcher=False, pageLength=None):
5858
else:
5959
page = re.sub('(?s)%s.+%s' % (prefix, postfix), '%s%s' % (prefix, postfix), page)
6060

61-
if conf.seqLock:
62-
conf.seqLock.acquire()
61+
if kb.data.seqLock:
62+
kb.data.seqLock.acquire()
6363

6464
if not conf.eRegexp and not conf.eString and kb.nullConnection:
6565
ratio = 1. * pageLength / len(conf.seqMatcher.a)
@@ -69,8 +69,8 @@ def comparison(page, headers=None, getSeqMatcher=False, pageLength=None):
6969
conf.seqMatcher.set_seq2(page if not conf.textOnly else getFilteredPageContent(page))
7070
ratio = round(conf.seqMatcher.ratio(), 3)
7171

72-
if conf.seqLock:
73-
conf.seqLock.release()
72+
if kb.data.seqLock:
73+
kb.data.seqLock.release()
7474

7575
# If the url is stable and we did not set yet the match ratio and the
7676
# current injected value changes the url page content

lib/techniques/blind/inference.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,7 @@ def etaProgressUpdate(charTime, index):
251251
idxlock = threading.Lock()
252252
iolock = threading.Lock()
253253
valuelock = threading.Lock()
254-
conf.seqLock = threading.Lock()
255-
conf.parseLock = threading.Lock()
254+
kb.data.seqLock = threading.Lock()
256255
conf.threadContinue = True
257256

258257
def downloadThread():
@@ -416,8 +415,7 @@ def downloadThread():
416415
if conf.verbose >= 1 and not showEta and infoMsg:
417416
dataToStdout(infoMsg)
418417

419-
conf.seqLock = None
420-
conf.parseLock = None
418+
kb.data.seqLock = None
421419

422420
# No multi-threading (--threads = 1)
423421
else:

0 commit comments

Comments
 (0)