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

Skip to content

Commit f63ceaa

Browse files
committed
Minor refactoring
1 parent 1e60378 commit f63ceaa

5 files changed

Lines changed: 30 additions & 16 deletions

File tree

lib/core/common.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4702,3 +4702,13 @@ def safeVariableNaming(value):
47024702

47034703
def unsafeVariableNaming(value):
47044704
return re.sub(r"%s([0-9a-f]{2})" % SAFE_VARIABLE_MARKER, lambda match: match.group(1).decode("hex"), value)
4705+
4706+
def firstNotNone(*args):
4707+
retVal = None
4708+
4709+
for _ in args:
4710+
if _ is not None:
4711+
retVal = _
4712+
break
4713+
4714+
return retVal

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
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.7.22"
22+
VERSION = "1.2.7.23"
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)

lib/techniques/error/use.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from lib.core.common import dataToStdout
1717
from lib.core.common import decodeHexValue
1818
from lib.core.common import extractRegexResult
19+
from lib.core.common import firstNotNone
1920
from lib.core.common import getConsoleWidth
2021
from lib.core.common import getPartRun
2122
from lib.core.common import getUnicode
@@ -102,7 +103,7 @@ def _oneShotErrorUse(expression, field=None, chunkTest=False):
102103
try:
103104
while True:
104105
check = r"(?si)%s(?P<result>.*?)%s" % (kb.chars.start, kb.chars.stop)
105-
trimcheck = r"(?si)%s(?P<result>[^<\n]*)" % kb.chars.start
106+
trimCheck = r"(?si)%s(?P<result>[^<\n]*)" % kb.chars.start
106107

107108
if field:
108109
nulledCastedField = agent.nullAndCastField(field)
@@ -133,22 +134,21 @@ def _oneShotErrorUse(expression, field=None, chunkTest=False):
133134

134135
# Parse the returned page to get the exact error-based
135136
# SQL injection output
136-
output = reduce(lambda x, y: x if x is not None else y, (
137+
output = firstNotNone(
137138
extractRegexResult(check, page),
138139
extractRegexResult(check, threadData.lastHTTPError[2] if wasLastResponseHTTPError() else None),
139140
extractRegexResult(check, listToStrValue((headers[header] for header in headers if header.lower() != HTTP_HEADER.URI.lower()) if headers else None)),
140-
extractRegexResult(check, threadData.lastRedirectMsg[1] if threadData.lastRedirectMsg and threadData.lastRedirectMsg[0] == threadData.lastRequestUID else None)),
141-
None
141+
extractRegexResult(check, threadData.lastRedirectMsg[1] if threadData.lastRedirectMsg and threadData.lastRedirectMsg[0] == threadData.lastRequestUID else None)
142142
)
143143

144144
if output is not None:
145145
output = getUnicode(output)
146146
else:
147-
trimmed = (
148-
extractRegexResult(trimcheck, page) or
149-
extractRegexResult(trimcheck, threadData.lastHTTPError[2] if wasLastResponseHTTPError() else None) or
150-
extractRegexResult(trimcheck, listToStrValue((headers[header] for header in headers if header.lower() != HTTP_HEADER.URI.lower()) if headers else None)) or
151-
extractRegexResult(trimcheck, threadData.lastRedirectMsg[1] if threadData.lastRedirectMsg and threadData.lastRedirectMsg[0] == threadData.lastRequestUID else None)
147+
trimmed = firstNotNone(
148+
extractRegexResult(trimCheck, page),
149+
extractRegexResult(trimCheck, threadData.lastHTTPError[2] if wasLastResponseHTTPError() else None),
150+
extractRegexResult(trimCheck, listToStrValue((headers[header] for header in headers if header.lower() != HTTP_HEADER.URI.lower()) if headers else None)),
151+
extractRegexResult(trimCheck, threadData.lastRedirectMsg[1] if threadData.lastRedirectMsg and threadData.lastRedirectMsg[0] == threadData.lastRequestUID else None)
152152
)
153153

154154
if trimmed:
@@ -163,7 +163,7 @@ def _oneShotErrorUse(expression, field=None, chunkTest=False):
163163
output = extractRegexResult(check, trimmed, re.IGNORECASE)
164164

165165
if not output:
166-
check = "(?P<result>[^\s<>'\"]+)"
166+
check = r"(?P<result>[^\s<>'\"]+)"
167167
output = extractRegexResult(check, trimmed, re.IGNORECASE)
168168
else:
169169
output = output.rstrip()

lib/techniques/union/use.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from lib.core.common import clearConsoleLine
2020
from lib.core.common import dataToStdout
2121
from lib.core.common import extractRegexResult
22+
from lib.core.common import firstNotNone
2223
from lib.core.common import flattenValue
2324
from lib.core.common import getConsoleWidth
2425
from lib.core.common import getPartRun
@@ -90,7 +91,10 @@ def _oneShotUnionUse(expression, unpack=True, limited=False):
9091
# Parse the returned page to get the exact UNION-based
9192
# SQL injection output
9293
def _(regex):
93-
return reduce(lambda x, y: x if x is not None else y, (extractRegexResult(regex, removeReflectiveValues(page, payload), re.DOTALL | re.IGNORECASE), extractRegexResult(regex, removeReflectiveValues(listToStrValue((_ for _ in headers.headers if not _.startswith(HTTP_HEADER.URI)) if headers else None), payload, True), re.DOTALL | re.IGNORECASE)), None)
94+
return firstNotNone(
95+
extractRegexResult(regex, removeReflectiveValues(page, payload), re.DOTALL | re.IGNORECASE),
96+
extractRegexResult(regex, removeReflectiveValues(listToStrValue((_ for _ in headers.headers if not _.startswith(HTTP_HEADER.URI)) if headers else None), payload, True), re.DOTALL | re.IGNORECASE)
97+
)
9498

9599
# Automatically patching last char trimming cases
96100
if kb.chars.stop not in (page or "") and kb.chars.stop[:-1] in (page or ""):

txt/checksum.md5

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ c7443613a0a2505b1faec931cee2a6ef lib/controller/handler.py
2828
1e5532ede194ac9c083891c2f02bca93 lib/controller/__init__.py
2929
0adf547455a76dc71e6a599e52da1ed9 lib/core/agent.py
3030
fd8f239e259afaf5f24bcf34a0ad187f lib/core/bigarray.py
31-
de53dd81bda04541d0992852aee0f2b3 lib/core/common.py
31+
14689a69e8c4447cc117703bb89489ad lib/core/common.py
3232
0d082da16c388b3445e656e0760fb582 lib/core/convert.py
3333
9f87391b6a3395f7f50830b391264f27 lib/core/data.py
3434
72016ea5c994a711a262fd64572a0fcd lib/core/datatype.py
@@ -48,7 +48,7 @@ c8c386d644d57c659d74542f5f57f632 lib/core/patch.py
4848
0c3eef46bdbf87e29a3f95f90240d192 lib/core/replication.py
4949
a7db43859b61569b601b97f187dd31c5 lib/core/revision.py
5050
fcb74fcc9577523524659ec49e2e964b lib/core/session.py
51-
9c991557b5b0a38f14c5667d627ead76 lib/core/settings.py
51+
23138239bf2e6e9a5c2e383862a6fe59 lib/core/settings.py
5252
dd68a9d02fccb4fa1428b20e15b0db5d lib/core/shell.py
5353
a7edc9250d13af36ac0108f259859c19 lib/core/subprocessng.py
5454
12bed9603b6fba3e5ffda11d584bc449 lib/core/target.py
@@ -95,11 +95,11 @@ debc36a3ff80ba915aeeee69b21a8ddc lib/takeover/xp_cmdshell.py
9595
799faf9008527d2e9da9d923e50f685a lib/techniques/dns/test.py
9696
48a24f48da791e67309003fd5e8428cb lib/techniques/dns/use.py
9797
1e5532ede194ac9c083891c2f02bca93 lib/techniques/error/__init__.py
98-
b9f6148c8df6b9d3316ce082dc1a63dd lib/techniques/error/use.py
98+
350d39006cf94151738a95c8d92caa28 lib/techniques/error/use.py
9999
1e5532ede194ac9c083891c2f02bca93 lib/techniques/__init__.py
100100
1e5532ede194ac9c083891c2f02bca93 lib/techniques/union/__init__.py
101101
94d7a22bb6725a91e84ba2cd9973e96d lib/techniques/union/test.py
102-
8b770864bdb106ef50c70173c824395c lib/techniques/union/use.py
102+
bfa5bcc4058eeb05c07f6e50f91952b6 lib/techniques/union/use.py
103103
77ff35587af9e3dfde63b8327e230f9a lib/utils/api.py
104104
37dfb641358669f62c2acedff241348b lib/utils/brute.py
105105
31b1e7eb489eac837db6a2bc1dcb7da7 lib/utils/crawler.py

0 commit comments

Comments
 (0)