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

Skip to content

Commit d78a3e9

Browse files
committed
Update (allowing regular char * to be inside SOAP/JSON/XML)
1 parent 6314d64 commit d78a3e9

4 files changed

Lines changed: 15 additions & 8 deletions

File tree

lib/core/agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
from lib.core.enums import PLACE
3131
from lib.core.enums import POST_HINT
3232
from lib.core.exception import SqlmapNoneDataException
33-
from lib.core.settings import ASTERISK_MARKER
3433
from lib.core.settings import CUSTOM_INJECTION_MARK_CHAR
3534
from lib.core.settings import GENERIC_SQL_COMMENT
3635
from lib.core.settings import PAYLOAD_DELIMITER
36+
from lib.core.settings import REPLACEMENT_MARKER
3737
from lib.core.unescaper import unescaper
3838

3939
class Agent(object):
@@ -128,9 +128,9 @@ def payload(self, place=None, parameter=None, value=None, newValue=None, where=N
128128
_ = "%s%s" % (origValue, CUSTOM_INJECTION_MARK_CHAR)
129129
if kb.postHint == POST_HINT.JSON and not isNumber(newValue) and not '"%s"' % _ in paramString:
130130
newValue = '"%s"' % newValue
131-
newValue = newValue.replace(CUSTOM_INJECTION_MARK_CHAR, ASTERISK_MARKER)
131+
newValue = newValue.replace(CUSTOM_INJECTION_MARK_CHAR, REPLACEMENT_MARKER)
132132
retVal = paramString.replace(_, self.addPayloadDelimiters(newValue))
133-
retVal = retVal.replace(CUSTOM_INJECTION_MARK_CHAR, "").replace(ASTERISK_MARKER, CUSTOM_INJECTION_MARK_CHAR)
133+
retVal = retVal.replace(CUSTOM_INJECTION_MARK_CHAR, "").replace(REPLACEMENT_MARKER, CUSTOM_INJECTION_MARK_CHAR)
134134
elif place in (PLACE.USER_AGENT, PLACE.REFERER, PLACE.HOST):
135135
retVal = paramString.replace(origValue, self.addPayloadDelimiters(newValue))
136136
else:

lib/core/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
PARTIAL_HEX_VALUE_MARKER = "__PARTIAL_HEX_VALUE__"
4141
URI_QUESTION_MARKER = "__QUESTION_MARK__"
4242
ASTERISK_MARKER = "__ASTERISK_MARK__"
43+
REPLACEMENT_MARKER = "__REPLACEMENT_MARK__"
4344

4445
PAYLOAD_DELIMITER = "\x00"
4546
CHAR_INFERENCE_MARK = "%c"

lib/core/target.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from lib.core.option import _setDBMS
4040
from lib.core.option import _setKnowledgeBaseAttributes
4141
from lib.core.option import _setAuthCred
42+
from lib.core.settings import ASTERISK_MARKER
4243
from lib.core.settings import CUSTOM_INJECTION_MARK_CHAR
4344
from lib.core.settings import HOST_ALIASES
4445
from lib.core.settings import JSON_RECOGNITION_REGEX
@@ -85,16 +86,14 @@ def _setRequestParams():
8586
if conf.data is not None:
8687
conf.method = HTTPMETHOD.POST
8788

88-
if CUSTOM_INJECTION_MARK_CHAR in conf.data: # later processed
89-
pass
90-
91-
elif re.search(JSON_RECOGNITION_REGEX, conf.data):
89+
if re.search(JSON_RECOGNITION_REGEX, conf.data):
9290
message = "JSON like data found in POST data. "
9391
message += "Do you want to process it? [Y/n/q] "
9492
test = readInput(message, default="Y")
9593
if test and test[0] in ("q", "Q"):
9694
raise SqlmapUserQuitException
9795
elif test[0] not in ("n", "N"):
96+
conf.data = conf.data.replace(CUSTOM_INJECTION_MARK_CHAR, ASTERISK_MARKER)
9897
conf.data = re.sub(r'("[^"]+"\s*:\s*"[^"]+)"', r'\g<1>%s"' % CUSTOM_INJECTION_MARK_CHAR, conf.data)
9998
conf.data = re.sub(r'("[^"]+"\s*:\s*)(-?\d[\d\.]*\b)', r'\g<0>%s' % CUSTOM_INJECTION_MARK_CHAR, conf.data)
10099
kb.postHint = POST_HINT.JSON
@@ -106,6 +105,7 @@ def _setRequestParams():
106105
if test and test[0] in ("q", "Q"):
107106
raise SqlmapUserQuitException
108107
elif test[0] not in ("n", "N"):
108+
conf.data = conf.data.replace(CUSTOM_INJECTION_MARK_CHAR, ASTERISK_MARKER)
109109
conf.data = re.sub(r"(<([^>]+)( [^<]*)?>)([^<]+)(</\2)", r"\g<1>\g<4>%s\g<5>" % CUSTOM_INJECTION_MARK_CHAR, conf.data)
110110
kb.postHint = POST_HINT.SOAP if "soap" in conf.data.lower() else POST_HINT.XML
111111

@@ -116,9 +116,13 @@ def _setRequestParams():
116116
if test and test[0] in ("q", "Q"):
117117
raise SqlmapUserQuitException
118118
elif test[0] not in ("n", "N"):
119+
conf.data = conf.data.replace(CUSTOM_INJECTION_MARK_CHAR, ASTERISK_MARKER)
119120
conf.data = re.sub(r"(?si)(Content-Disposition.+?)((\r)?\n--)", r"\g<1>%s\g<2>" % CUSTOM_INJECTION_MARK_CHAR, conf.data)
120121
kb.postHint = POST_HINT.MULTIPART
121122

123+
elif CUSTOM_INJECTION_MARK_CHAR in conf.data: # later processed
124+
pass
125+
122126
else:
123127
place = PLACE.POST
124128

@@ -149,7 +153,7 @@ def _setRequestParams():
149153
raise SqlmapUserQuitException
150154

151155
for place, value in ((PLACE.URI, conf.url), (PLACE.CUSTOM_POST, conf.data), (PLACE.CUSTOM_HEADER, str(conf.httpHeaders))):
152-
_ = re.sub(r"\bq=[^;']+", "", value or "")
156+
_ = re.sub(r"\bq=[^;']+", "", value or "") if place == PLACE.CUSTOM_HEADER else value or ""
153157
if CUSTOM_INJECTION_MARK_CHAR in _:
154158
if kb.processUserMarks is None:
155159
lut = {PLACE.URI: '-u', PLACE.CUSTOM_POST: '--data', PLACE.CUSTOM_HEADER: '--headers/--user-agent/--referer/--cookie'}

lib/request/connect.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
from lib.core.exception import SqlmapConnectionException
5757
from lib.core.exception import SqlmapSyntaxException
5858
from lib.core.exception import SqlmapValueException
59+
from lib.core.settings import ASTERISK_MARKER
5960
from lib.core.settings import CUSTOM_INJECTION_MARK_CHAR
6061
from lib.core.settings import DEFAULT_CONTENT_TYPE
6162
from lib.core.settings import DEFAULT_GET_POST_DELIMITER
@@ -666,6 +667,7 @@ def queryPage(value=None, place=None, content=False, getRatioValue=False, silent
666667

667668
if PLACE.CUSTOM_POST in conf.parameters:
668669
post = conf.parameters[PLACE.CUSTOM_POST].replace(CUSTOM_INJECTION_MARK_CHAR, "") if place != PLACE.CUSTOM_POST or not value else value
670+
post = post.replace(ASTERISK_MARKER, '*') if post else post
669671

670672
if PLACE.COOKIE in conf.parameters:
671673
cookie = conf.parameters[PLACE.COOKIE] if place != PLACE.COOKIE or not value else value

0 commit comments

Comments
 (0)