Skip to content

Commit 9564c8e

Browse files
committed
Refactoring regarding casting warnings
1 parent 5e09914 commit 9564c8e

File tree

6 files changed

+41
-30
lines changed

6 files changed

+41
-30
lines changed

lib/controller/checks.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
from lib.core.enums import PAYLOAD
7070
from lib.core.enums import PLACE
7171
from lib.core.enums import REDIRECTION
72+
from lib.core.enums import WEB_PLATFORM
7273
from lib.core.exception import SqlmapConnectionException
7374
from lib.core.exception import SqlmapDataException
7475
from lib.core.exception import SqlmapNoneDataException
@@ -1052,9 +1053,19 @@ def _(page):
10521053
kb.heuristicTest = HEURISTIC_TEST.CASTED if casting else HEURISTIC_TEST.NEGATIVE if not result else HEURISTIC_TEST.POSITIVE
10531054

10541055
if casting:
1055-
errMsg = "possible %s casting " % ("integer" if origValue.isdigit() else "type")
1056-
errMsg += "detected (e.g. \"$%s=intval($_REQUEST['%s'])\") " % (parameter, parameter)
1057-
errMsg += "at the back-end web application"
1056+
errMsg = "possible %s casting detected (e.g. '" % ("integer" if origValue.isdigit() else "type")
1057+
1058+
platform = conf.url.split('.')[-1].lower()
1059+
if platform == WEB_PLATFORM.ASP:
1060+
errMsg += "%s=CInt(request.querystring(\"%s\"))" % (parameter, parameter)
1061+
elif platform == WEB_PLATFORM.ASPX:
1062+
errMsg += "int.TryParse(Request.QueryString[\"%s\"], out %s)" % (parameter, parameter)
1063+
elif platform == WEB_PLATFORM.JSP:
1064+
errMsg += "%s=Integer.parseInt(request.getParameter(\"%s\"))" % (parameter, parameter)
1065+
else:
1066+
errMsg += "$%s=intval($_REQUEST[\"%s\"])" % (parameter, parameter)
1067+
1068+
errMsg += "') at the back-end web application"
10581069
logger.error(errMsg)
10591070

10601071
if kb.ignoreCasted is None:

lib/core/enums.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class ADJUST_TIME_DELAY:
310310
NO = 0
311311
YES = 1
312312

313-
class WEB_API:
313+
class WEB_PLATFORM:
314314
PHP = "php"
315315
ASP = "asp"
316316
ASPX = "aspx"

lib/core/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from lib.core.enums import OS
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.2.12.35"
22+
VERSION = "1.2.12.36"
2323
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2424
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2525
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
@@ -687,7 +687,7 @@
687687
MAX_CONNECT_RETRIES = 100
688688

689689
# Strings for detecting formatting errors
690-
FORMAT_EXCEPTION_STRINGS = ("Type mismatch", "Error converting", "Conversion failed", "String or binary data would be truncated", "Failed to convert", "unable to interpret text value", "Input string was not in a correct format", "System.FormatException", "java.lang.NumberFormatException", "ValueError: invalid literal", "TypeMismatchException", "CF_SQL_INTEGER", " for CFSQLTYPE ", "cfqueryparam cfsqltype", "InvalidParamTypeException", "Invalid parameter type", "is not of type numeric", "<cfif Not IsNumeric(", "invalid input syntax for integer", "invalid input syntax for type", "invalid number", "character to number conversion error", "unable to interpret text value", "String was not recognized as a valid", "Convert.ToInt", "cannot be converted to a ", "InvalidDataException")
690+
FORMAT_EXCEPTION_STRINGS = ("Type mismatch", "Error converting", "Please enter a", "Conversion failed", "String or binary data would be truncated", "Failed to convert", "unable to interpret text value", "Input string was not in a correct format", "System.FormatException", "java.lang.NumberFormatException", "ValueError: invalid literal", "TypeMismatchException", "CF_SQL_INTEGER", " for CFSQLTYPE ", "cfqueryparam cfsqltype", "InvalidParamTypeException", "Invalid parameter type", "is not of type numeric", "<cfif Not IsNumeric(", "invalid input syntax for integer", "invalid input syntax for type", "invalid number", "character to number conversion error", "unable to interpret text value", "String was not recognized as a valid", "Convert.ToInt", "cannot be converted to a ", "InvalidDataException")
691691

692692
# Regular expression used for extracting ASP.NET view state values
693693
VIEWSTATE_REGEX = r'(?i)(?P<name>__VIEWSTATE[^"]*)[^>]+value="(?P<result>[^"]+)'

lib/request/connect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class WebSocketException(Exception):
7878
from lib.core.enums import PLACE
7979
from lib.core.enums import POST_HINT
8080
from lib.core.enums import REDIRECTION
81-
from lib.core.enums import WEB_API
81+
from lib.core.enums import WEB_PLATFORM
8282
from lib.core.exception import SqlmapCompressionException
8383
from lib.core.exception import SqlmapConnectionException
8484
from lib.core.exception import SqlmapGenericException
@@ -889,7 +889,7 @@ def queryPage(value=None, place=None, content=False, getRatioValue=False, silent
889889
postUrlEncode = False
890890

891891
if conf.hpp:
892-
if not any(conf.url.lower().endswith(_.lower()) for _ in (WEB_API.ASP, WEB_API.ASPX)):
892+
if not any(conf.url.lower().endswith(_.lower()) for _ in (WEB_PLATFORM.ASP, WEB_PLATFORM.ASPX)):
893893
warnMsg = "HTTP parameter pollution should work only against "
894894
warnMsg += "ASP(.NET) targets"
895895
singleTimeWarnMessage(warnMsg)

lib/takeover/web.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from lib.core.enums import OS
4444
from lib.core.enums import PAYLOAD
4545
from lib.core.enums import PLACE
46-
from lib.core.enums import WEB_API
46+
from lib.core.enums import WEB_PLATFORM
4747
from lib.core.exception import SqlmapNoneDataException
4848
from lib.core.settings import BACKDOOR_RUN_CMD_TIMEOUT
4949
from lib.core.settings import EVENTVALIDATION_REGEX
@@ -60,7 +60,7 @@ class Web:
6060
"""
6161

6262
def __init__(self):
63-
self.webApi = None
63+
self.webPlatform = None
6464
self.webBaseUrl = None
6565
self.webBackdoorUrl = None
6666
self.webBackdoorFilePath = None
@@ -109,14 +109,14 @@ def _webFileStreamUpload(self, stream, destFileName, directory):
109109
except TypeError:
110110
pass
111111

112-
if self.webApi in getPublicTypeMembers(WEB_API, True):
112+
if self.webPlatform in getPublicTypeMembers(WEB_PLATFORM, True):
113113
multipartParams = {
114114
"upload": "1",
115115
"file": stream,
116116
"uploadDir": directory,
117117
}
118118

119-
if self.webApi == WEB_API.ASPX:
119+
if self.webPlatform == WEB_PLATFORM.ASPX:
120120
multipartParams['__EVENTVALIDATION'] = kb.data.__EVENTVALIDATION
121121
multipartParams['__VIEWSTATE'] = kb.data.__VIEWSTATE
122122

@@ -130,7 +130,7 @@ def _webFileStreamUpload(self, stream, destFileName, directory):
130130
else:
131131
return True
132132
else:
133-
logger.error("sqlmap hasn't got a web backdoor nor a web file stager for %s" % self.webApi)
133+
logger.error("sqlmap hasn't got a web backdoor nor a web file stager for %s" % self.webPlatform)
134134
return False
135135

136136
def _webFileInject(self, fileContent, fileName, directory):
@@ -158,21 +158,21 @@ def webInit(self):
158158
remote directory within the web server document root.
159159
"""
160160

161-
if self.webBackdoorUrl is not None and self.webStagerUrl is not None and self.webApi is not None:
161+
if self.webBackdoorUrl is not None and self.webStagerUrl is not None and self.webPlatform is not None:
162162
return
163163

164164
self.checkDbmsOs()
165165

166166
default = None
167-
choices = list(getPublicTypeMembers(WEB_API, True))
167+
choices = list(getPublicTypeMembers(WEB_PLATFORM, True))
168168

169169
for ext in choices:
170170
if conf.url.endswith(ext):
171171
default = ext
172172
break
173173

174174
if not default:
175-
default = WEB_API.ASP if Backend.isOs(OS.WINDOWS) else WEB_API.PHP
175+
default = WEB_PLATFORM.ASP if Backend.isOs(OS.WINDOWS) else WEB_PLATFORM.PHP
176176

177177
message = "which web application language does the web server "
178178
message += "support?\n"
@@ -196,7 +196,7 @@ def webInit(self):
196196
logger.warn("invalid value, it must be between 1 and %d" % len(choices))
197197

198198
else:
199-
self.webApi = choices[int(choice) - 1]
199+
self.webPlatform = choices[int(choice) - 1]
200200
break
201201

202202
if not kb.absFilePaths:
@@ -266,16 +266,16 @@ def webInit(self):
266266
_.append("%s/%s" % (directory.rstrip('/'), path.strip('/')))
267267
directories = _
268268

269-
backdoorName = "tmpb%s.%s" % (randomStr(lowercase=True), self.webApi)
270-
backdoorContent = decloak(os.path.join(paths.SQLMAP_SHELL_PATH, "backdoors", "backdoor.%s_" % self.webApi))
269+
backdoorName = "tmpb%s.%s" % (randomStr(lowercase=True), self.webPlatform)
270+
backdoorContent = decloak(os.path.join(paths.SQLMAP_SHELL_PATH, "backdoors", "backdoor.%s_" % self.webPlatform))
271271

272-
stagerContent = decloak(os.path.join(paths.SQLMAP_SHELL_PATH, "stagers", "stager.%s_" % self.webApi))
272+
stagerContent = decloak(os.path.join(paths.SQLMAP_SHELL_PATH, "stagers", "stager.%s_" % self.webPlatform))
273273

274274
for directory in directories:
275275
if not directory:
276276
continue
277277

278-
stagerName = "tmpu%s.%s" % (randomStr(lowercase=True), self.webApi)
278+
stagerName = "tmpu%s.%s" % (randomStr(lowercase=True), self.webPlatform)
279279
self.webStagerFilePath = posixpath.join(ntToPosixSlashes(directory), stagerName)
280280

281281
uploaded = False
@@ -317,14 +317,14 @@ def webInit(self):
317317
infoMsg += "via UNION method"
318318
logger.info(infoMsg)
319319

320-
stagerName = "tmpu%s.%s" % (randomStr(lowercase=True), self.webApi)
320+
stagerName = "tmpu%s.%s" % (randomStr(lowercase=True), self.webPlatform)
321321
self.webStagerFilePath = posixpath.join(ntToPosixSlashes(directory), stagerName)
322322

323323
handle, filename = tempfile.mkstemp()
324324
os.close(handle)
325325

326326
with open(filename, "w+b") as f:
327-
_ = decloak(os.path.join(paths.SQLMAP_SHELL_PATH, "stagers", "stager.%s_" % self.webApi))
327+
_ = decloak(os.path.join(paths.SQLMAP_SHELL_PATH, "stagers", "stager.%s_" % self.webPlatform))
328328
_ = _.replace(SHELL_WRITABLE_DIR_TAG, utf8encode(directory.replace('/', '\\\\') if Backend.isOs(OS.WINDOWS) else directory))
329329
f.write(_)
330330

@@ -353,15 +353,15 @@ def webInit(self):
353353
logger.warn(warnMsg)
354354
continue
355355

356-
elif self.webApi == WEB_API.ASPX:
356+
elif self.webPlatform == WEB_PLATFORM.ASPX:
357357
kb.data.__EVENTVALIDATION = extractRegexResult(EVENTVALIDATION_REGEX, uplPage)
358358
kb.data.__VIEWSTATE = extractRegexResult(VIEWSTATE_REGEX, uplPage)
359359

360360
infoMsg = "the file stager has been successfully uploaded "
361361
infoMsg += "on '%s' - %s" % (directory, self.webStagerUrl)
362362
logger.info(infoMsg)
363363

364-
if self.webApi == WEB_API.ASP:
364+
if self.webPlatform == WEB_PLATFORM.ASP:
365365
match = re.search(r'input type=hidden name=scriptsdir value="([^"]+)"', uplPage)
366366

367367
if match:

txt/checksum.md5

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ b3e60ea4e18a65c48515d04aab28ff68 extra/sqlharvest/sqlharvest.py
2323
1e5532ede194ac9c083891c2f02bca93 extra/wafdetectify/__init__.py
2424
c1bccc94522d3425a372dcd57f78418e extra/wafdetectify/wafdetectify.py
2525
3459c562a6abb9b4bdcc36925f751f3e lib/controller/action.py
26-
0f0feede9750be810d2b8a7ab159b7b0 lib/controller/checks.py
26+
d4582467b0735525d8d8bdc0396ec87f lib/controller/checks.py
2727
197bdf07f8ea15ecc7e0dafea4f9ae2f lib/controller/controller.py
2828
988b548f6578adf9cec17afdeee8291c lib/controller/handler.py
2929
1e5532ede194ac9c083891c2f02bca93 lib/controller/__init__.py
@@ -37,7 +37,7 @@ c347f085bd561adfa26d3a9512e5f3b9 lib/core/bigarray.py
3737
fbb55cc6100318ff922957b6577dc58f lib/core/defaults.py
3838
ac7c070b2726d39fbac1916b1a5f92b2 lib/core/dicts.py
3939
760de985e09f5d11aacd3a8f2d8e9ff2 lib/core/dump.py
40-
0cf974cf4ff3b96e1a349a12e39f4693 lib/core/enums.py
40+
5b6999c4b78180961e9f33e172d4dd66 lib/core/enums.py
4141
cada93357a7321655927fc9625b3bfec lib/core/exception.py
4242
1e5532ede194ac9c083891c2f02bca93 lib/core/__init__.py
4343
458a194764805cd8312c14ecd4be4d1e lib/core/log.py
@@ -49,7 +49,7 @@ c8c386d644d57c659d74542f5f57f632 lib/core/patch.py
4949
0c3eef46bdbf87e29a3f95f90240d192 lib/core/replication.py
5050
a7db43859b61569b601b97f187dd31c5 lib/core/revision.py
5151
fcb74fcc9577523524659ec49e2e964b lib/core/session.py
52-
08295f121daafa4c20282201861422cb lib/core/settings.py
52+
3afa2b42741332ce14a8c98befcfdff7 lib/core/settings.py
5353
a971ce157d04de96ba6e710d3d38a9a8 lib/core/shell.py
5454
a7edc9250d13af36ac0108f259859c19 lib/core/subprocessng.py
5555
1581be48127a3a7a9fd703359b6e7567 lib/core/target.py
@@ -71,7 +71,7 @@ f6b5957bf2103c3999891e4f45180bce lib/parse/payloads.py
7171
30eed3a92a04ed2c29770e1b10d39dc0 lib/request/basicauthhandler.py
7272
2b81435f5a7519298c15c724e3194a0d lib/request/basic.py
7373
859b6ad583e0ffba154f17ee179b5b89 lib/request/comparison.py
74-
40c4cc791ec657b612ccecf5b3241651 lib/request/connect.py
74+
7ec820ec27161208a8411d81ec48161a lib/request/connect.py
7575
dd4598675027fae99f2e2475b05986da lib/request/direct.py
7676
2044fce3f4ffa268fcfaaf63241b1e64 lib/request/dns.py
7777
98535d0efca5551e712fcc4b34a3f772 lib/request/httpshandler.py
@@ -88,7 +88,7 @@ acc1db3667bf910b809eb279b60595eb lib/takeover/icmpsh.py
8888
4bf186a747e1a0c4ed5127ef064c3920 lib/takeover/metasploit.py
8989
fb9e34d558293b5d6b9727f440712886 lib/takeover/registry.py
9090
6a49f359b922df0247eb236126596336 lib/takeover/udf.py
91-
a3d07df8a780c668a11f06be42014cdc lib/takeover/web.py
91+
ce8524022df29602f3d6c3c41f938ad4 lib/takeover/web.py
9292
debc36a3ff80ba915aeeee69b21a8ddc lib/takeover/xp_cmdshell.py
9393
db208ab47de010836c6bf044e2357861 lib/techniques/blind/inference.py
9494
1e5532ede194ac9c083891c2f02bca93 lib/techniques/blind/__init__.py

0 commit comments

Comments
 (0)