Skip to content

Commit acd5ef0

Browse files
committed
Minot improvement of JSON/eval (#5013)
1 parent a2fcab4 commit acd5ef0

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

lib/core/common.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
from lib.core.optiondict import optDict
105105
from lib.core.settings import BANNER
106106
from lib.core.settings import BOLD_PATTERNS
107+
from lib.core.settings import BOUNDARY_BACKSLASH_MARKER
107108
from lib.core.settings import BOUNDED_INJECTION_MARKER
108109
from lib.core.settings import BRUTE_DOC_ROOT_PREFIXES
109110
from lib.core.settings import BRUTE_DOC_ROOT_SUFFIXES
@@ -1384,6 +1385,38 @@ def banner():
13841385

13851386
dataToStdout(result, forceOutput=True)
13861387

1388+
def parseJson(content):
1389+
"""
1390+
This function parses POST_HINT.JSON and POST_HINT.JSON_LIKE content
1391+
1392+
>>> parseJson("{'id':1}")["id"] == 1
1393+
True
1394+
>>> parseJson('{"id":1}')["id"] == 1
1395+
True
1396+
"""
1397+
1398+
quote = None
1399+
retVal = None
1400+
1401+
for regex in (r"'[^']+'\s*:", r'"[^"]+"\s*:'):
1402+
match = re.search(regex, content)
1403+
if match:
1404+
quote = match.group(0)[0]
1405+
1406+
try:
1407+
if quote == '"':
1408+
retVal = json.loads(content)
1409+
elif quote == "'":
1410+
content = content.replace('"', '\\"')
1411+
content = content.replace("\\'", BOUNDARY_BACKSLASH_MARKER)
1412+
content = content.replace("'", '"')
1413+
content = content.replace(BOUNDARY_BACKSLASH_MARKER, "'")
1414+
retVal = json.loads(content)
1415+
except:
1416+
pass
1417+
1418+
return retVal
1419+
13871420
def parsePasswordHash(password):
13881421
"""
13891422
In case of Microsoft SQL Server password hash value is expanded to its components

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from thirdparty.six import unichr as _unichr
2121

2222
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
23-
VERSION = "1.6.3.6"
23+
VERSION = "1.6.3.7"
2424
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2525
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2626
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

lib/request/connect.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class WebSocketException(Exception):
4646
from lib.core.common import logHTTPTraffic
4747
from lib.core.common import openFile
4848
from lib.core.common import popValue
49+
from lib.core.common import parseJson
4950
from lib.core.common import pushValue
5051
from lib.core.common import randomizeParameterValue
5152
from lib.core.common import randomInt
@@ -1291,6 +1292,13 @@ def _randomizeParameter(paramString, randomParameter):
12911292
value = urldecode(value, convall=True, spaceplus=(item == post and kb.postSpaceToPlus))
12921293
variables[name] = value
12931294

1295+
if post and kb.postHint in (POST_HINT.JSON, POST_HINT.JSON_LIKE):
1296+
for name, value in (parseJson(post) or {}).items():
1297+
if safeVariableNaming(name) != name:
1298+
conf.evalCode = re.sub(r"\b%s\b" % re.escape(name), safeVariableNaming(name), conf.evalCode)
1299+
name = safeVariableNaming(name)
1300+
variables[name] = value
1301+
12941302
if cookie:
12951303
for part in cookie.split(conf.cookieDel or DEFAULT_COOKIE_DELIMITER):
12961304
if '=' in part:
@@ -1393,7 +1401,13 @@ def _randomizeParameter(paramString, randomParameter):
13931401

13941402
if not found:
13951403
if post is not None:
1396-
post += "%s%s=%s" % (delimiter, name, value)
1404+
if kb.postHint in (POST_HINT.JSON, POST_HINT.JSON_LIKE):
1405+
match = re.search(r"['\"]", post)
1406+
if match:
1407+
quote = match.group(0)
1408+
post = re.sub(r"\}\Z", "%s%s}" % (',' if re.search(r"\w", post) else "", "%s%s%s:%s" % (quote, name, quote, value if value.isdigit() else "%s%s%s" % (quote, value, quote))), post)
1409+
else:
1410+
post += "%s%s=%s" % (delimiter, name, value)
13971411
elif get is not None:
13981412
get += "%s%s=%s" % (delimiter, name, value)
13991413
elif cookie is not None:

0 commit comments

Comments
 (0)