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

Skip to content

Commit 119eec3

Browse files
committed
improving "boolean detection" by automatic recognition of convenient --string candidate
1 parent 698b7a1 commit 119eec3

5 files changed

Lines changed: 32 additions & 3 deletions

File tree

lib/controller/checks.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from lib.core.common import Backend
1818
from lib.core.common import beep
1919
from lib.core.common import extractRegexResult
20+
from lib.core.common import extractTextTagContent
2021
from lib.core.common import findDynamicContent
2122
from lib.core.common import Format
2223
from lib.core.common import getComparePageRatio
@@ -329,9 +330,11 @@ def genCmpPayload():
329330
kb.matchRatio = None
330331
kb.negativeLogic = (where == PAYLOAD.WHERE.NEGATIVE)
331332
Request.queryPage(genCmpPayload(), place, raise404=False)
333+
falsePage = threadData.lastComparisonPage
332334

333335
# Perform the test's True request
334336
trueResult = Request.queryPage(reqPayload, place, raise404=False)
337+
truePage = threadData.lastComparisonPage
335338

336339
if trueResult:
337340
falseResult = Request.queryPage(genCmpPayload(), place, raise404=False)
@@ -342,6 +345,15 @@ def genCmpPayload():
342345
logger.info(infoMsg)
343346

344347
injectable = True
348+
else:
349+
trueSet = set(extractTextTagContent(truePage))
350+
falseSet = set(extractTextTagContent(falsePage))
351+
candidate = reduce(lambda x, y: x or (y.strip() if y.strip() in (kb.pageTemplate or "") else None), (trueSet - falseSet), None)
352+
if candidate:
353+
conf.string = candidate
354+
infoMsg = "%s parameter '%s' is '%s' injectable (with --string='%s')" % (place, parameter, title, candidate)
355+
logger.info(infoMsg)
356+
injectable = True
345357

346358
# In case of error-based SQL injection
347359
elif method == PAYLOAD.METHOD.GREP:

lib/core/common.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
from lib.core.settings import DYNAMICITY_MARK_LENGTH
125125
from lib.core.settings import REFLECTIVE_MISS_THRESHOLD
126126
from lib.core.settings import SENSITIVE_DATA_REGEX
127+
from lib.core.settings import TEXT_TAG_REGEX
127128
from lib.core.settings import UNION_UNIQUE_FIFO_LENGTH
128129
from lib.core.settings import URI_INJECTION_MARK_CHAR
129130
from lib.core.settings import URI_QUESTION_MARKER
@@ -2155,6 +2156,13 @@ def extractRegexResult(regex, content, flags=0):
21552156

21562157
return retVal
21572158

2159+
def extractTextTagContent(page):
2160+
"""
2161+
Returns list containing content from "textual" tags
2162+
"""
2163+
2164+
return [_.group('result') for _ in re.finditer(TEXT_TAG_REGEX, page or "")]
2165+
21582166
def trimAlphaNum(value):
21592167
"""
21602168
Trims alpha numeric characters from start and ending of a given value

lib/core/settings.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@
6262

6363
PAYLOAD_DELIMITER = "\x00"
6464
CHAR_INFERENCE_MARK = "%c"
65-
PRINTABLE_CHAR_REGEX = r'[^\x00-\x1f\x7e-\xff]'
65+
PRINTABLE_CHAR_REGEX = r"[^\x00-\x1f\x7e-\xff]"
6666

6767
# regular expression used for extracting results from google search
68-
GOOGLE_REGEX = r'url\?q=(http[^>]+)&sa=U&amp'
68+
GOOGLE_REGEX = r"url\?q=(http[^>]+)&sa=U&amp"
69+
70+
# regular expression used for extracting content from "textual" tags
71+
TEXT_TAG_REGEX = r"(?si)<(abbr|acronym|b|blockquote|br|center|cite|code|dt|em|font|h\d|i|li|p|pre|q|strong|sub|sup|td|th|title|tt|u)(?!\w).*?>(?P<result>[^<]+)"
6972

7073
# dumping characters used in GROUP_CONCAT MySQL technique
7174
CONCAT_ROW_DELIMITER = ','

lib/core/threads.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def reset(self):
4343
self.disableStdOut = False
4444
self.hashDBCursor = None
4545
self.inTransaction = False
46+
self.lastComparisonPage = None
4647
self.lastErrorPage = None
4748
self.lastHTTPError = None
4849
self.lastRedirectMsg = None

lib/request/comparison.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,15 @@ def _adjust(condition, getRatioValue):
4545
return retVal
4646

4747
def _comparison(page, headers, code, getRatioValue, pageLength):
48+
threadData = getCurrentThreadData()
49+
50+
if kb.testMode:
51+
threadData.lastComparisonPage = page
52+
4853
if page is None and pageLength is None:
4954
return None
5055

51-
seqMatcher = getCurrentThreadData().seqMatcher
56+
seqMatcher = threadData.seqMatcher
5257
seqMatcher.set_seq1(kb.pageTemplate)
5358

5459
if any([conf.string, conf.regexp]):

0 commit comments

Comments
 (0)