Skip to content

Commit 2ef07c8

Browse files
committed
Some more refactoring
1 parent e3028f1 commit 2ef07c8

File tree

14 files changed

+71
-67
lines changed

14 files changed

+71
-67
lines changed

lib/controller/checks.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ def checkDynParam(place, parameter, value):
11671167
dynamicity might depend on another parameter.
11681168
"""
11691169

1170-
if kb.redirectChoice:
1170+
if kb.choices.redirect:
11711171
return None
11721172

11731173
kb.matchRatio = None
@@ -1268,7 +1268,7 @@ def checkStability():
12681268

12691269
secondPage, _, _ = Request.queryPage(content=True, noteResponseTime=False, raise404=False)
12701270

1271-
if kb.redirectChoice:
1271+
if kb.choices.redirect:
12721272
return None
12731273

12741274
kb.pageStable = (firstPage == secondPage)
@@ -1415,11 +1415,11 @@ def checkWaf():
14151415
value = "" if not conf.parameters.get(PLACE.GET) else conf.parameters[PLACE.GET] + DEFAULT_GET_POST_DELIMITER
14161416
value += "%s=%s" % (randomStr(), agent.addPayloadDelimiters(payload))
14171417

1418-
pushValue(kb.redirectChoice)
1418+
pushValue(kb.choices.redirect)
14191419
pushValue(kb.resendPostOnRedirect)
14201420
pushValue(conf.timeout)
14211421

1422-
kb.redirectChoice = REDIRECTION.YES
1422+
kb.choices.redirect = REDIRECTION.YES
14231423
kb.resendPostOnRedirect = False
14241424
conf.timeout = IPS_WAF_CHECK_TIMEOUT
14251425

@@ -1432,7 +1432,7 @@ def checkWaf():
14321432

14331433
conf.timeout = popValue()
14341434
kb.resendPostOnRedirect = popValue()
1435-
kb.redirectChoice = popValue()
1435+
kb.choices.redirect = popValue()
14361436

14371437
hashDBWrite(HASHDB_KEYS.CHECK_WAF_RESULT, retVal, True)
14381438

@@ -1565,7 +1565,7 @@ def checkConnection(suppressOutput=False):
15651565
else:
15661566
kb.errorIsNone = True
15671567

1568-
if kb.redirectChoice == REDIRECTION.YES and threadData.lastRedirectURL and threadData.lastRedirectURL[0] == threadData.lastRequestUID:
1568+
if kb.choices.redirect == REDIRECTION.YES and threadData.lastRedirectURL and threadData.lastRedirectURL[0] == threadData.lastRequestUID:
15691569
if (threadData.lastRedirectURL[1] or "").startswith("https://") and conf.hostname in getUnicode(threadData.lastRedirectURL[1]):
15701570
conf.url = re.sub(r"https?://", "https://", conf.url)
15711571
match = re.search(r":(\d+)", threadData.lastRedirectURL[1])

lib/core/datatype.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ class AttribDict(dict):
2121
1
2222
"""
2323

24-
def __init__(self, indict=None, attribute=None):
24+
def __init__(self, indict=None, attribute=None, keycheck=True):
2525
if indict is None:
2626
indict = {}
2727

2828
# Set any attributes here - before initialisation
2929
# these remain as normal attributes
3030
self.attribute = attribute
31+
self.keycheck = keycheck
3132
dict.__init__(self, indict)
3233
self.__initialised = True
3334

@@ -43,7 +44,10 @@ def __getattr__(self, item):
4344
try:
4445
return self.__getitem__(item)
4546
except KeyError:
46-
raise AttributeError("unable to access item '%s'" % item)
47+
if self.keycheck:
48+
raise AttributeError("unable to access item '%s'" % item)
49+
else:
50+
return None
4751

4852
def __setattr__(self, item, value):
4953
"""

lib/core/option.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,12 +2013,10 @@ def _setKnowledgeBaseAttributes(flushAll=True):
20132013
kb.chars.stop = "%s%s%s" % (KB_CHARS_BOUNDARY_CHAR, randomStr(length=3, alphabet=KB_CHARS_LOW_FREQUENCY_ALPHABET), KB_CHARS_BOUNDARY_CHAR)
20142014
kb.chars.at, kb.chars.space, kb.chars.dollar, kb.chars.hash_ = ("%s%s%s" % (KB_CHARS_BOUNDARY_CHAR, _, KB_CHARS_BOUNDARY_CHAR) for _ in randomStr(length=4, lowercase=True))
20152015

2016+
kb.choices = AttribDict(keycheck=False)
20162017
kb.codePage = None
2017-
kb.columnExistsChoice = None
20182018
kb.commonOutputs = None
2019-
kb.connErrorChoice = None
20202019
kb.connErrorCounter = 0
2021-
kb.cookieEncodeChoice = None
20222020
kb.copyExecTest = None
20232021
kb.counters = {}
20242022
kb.customInjectionMark = CUSTOM_INJECTION_MARK_CHAR
@@ -2122,7 +2120,6 @@ def _setKnowledgeBaseAttributes(flushAll=True):
21222120
kb.proxyAuthHeader = None
21232121
kb.queryCounter = 0
21242122
kb.randomPool = {}
2125-
kb.redirectChoice = None
21262123
kb.reflectiveMechanism = True
21272124
kb.reflectiveCounters = {REFLECTIVE_COUNTER.MISS: 0, REFLECTIVE_COUNTER.HIT: 0}
21282125
kb.requestCounter = 0
@@ -2142,9 +2139,7 @@ def _setKnowledgeBaseAttributes(flushAll=True):
21422139
kb.reduceTests = None
21432140
kb.sslSuccess = False
21442141
kb.stickyDBMS = False
2145-
kb.storeHashesChoice = None
21462142
kb.suppressResumeInfo = False
2147-
kb.tableExistsChoice = None
21482143
kb.tableFrom = None
21492144
kb.technique = None
21502145
kb.tempDir = None

lib/core/settings.py

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

2020
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
21-
VERSION = "1.5.1.18"
21+
VERSION = "1.5.1.19"
2222
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2323
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2424
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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,8 @@ class _(dict):
610610

611611
# Get HTTP response
612612
if hasattr(conn, "redurl"):
613-
page = (threadData.lastRedirectMsg[1] if kb.redirectChoice == REDIRECTION.NO else Connect._connReadProxy(conn)) if not skipRead else None
614-
skipLogTraffic = kb.redirectChoice == REDIRECTION.NO
613+
page = (threadData.lastRedirectMsg[1] if kb.choices.redirect == REDIRECTION.NO else Connect._connReadProxy(conn)) if not skipRead else None
614+
skipLogTraffic = kb.choices.redirect == REDIRECTION.NO
615615
code = conn.redcode if not finalCode else code
616616
else:
617617
page = Connect._connReadProxy(conn) if not skipRead else None
@@ -844,13 +844,13 @@ class _(dict):
844844
with kb.locks.connError:
845845
kb.connErrorCounter += 1
846846

847-
if kb.connErrorCounter >= MAX_CONSECUTIVE_CONNECTION_ERRORS and kb.connErrorChoice is None:
847+
if kb.connErrorCounter >= MAX_CONSECUTIVE_CONNECTION_ERRORS and kb.choices.connError is None:
848848
message = "there seems to be a continuous problem with connection to the target. "
849849
message += "Are you sure that you want to continue? [y/N] "
850850

851-
kb.connErrorChoice = readInput(message, default='N', boolean=True)
851+
kb.choices.connError = readInput(message, default='N', boolean=True)
852852

853-
if kb.connErrorChoice is False:
853+
if kb.choices.connError is False:
854854
raise SqlmapSkipTargetException
855855

856856
if "forcibly closed" in tbMsg:
@@ -1025,10 +1025,10 @@ def queryPage(value=None, place=None, content=False, getRatioValue=False, silent
10251025
skip = False
10261026

10271027
if place == PLACE.COOKIE or place == PLACE.CUSTOM_HEADER and value.split(',')[0].upper() == HTTP_HEADER.COOKIE.upper():
1028-
if kb.cookieEncodeChoice is None:
1028+
if kb.choices.cookieEncode is None:
10291029
msg = "do you want to URL encode cookie values (implementation specific)? %s" % ("[Y/n]" if not conf.url.endswith(".aspx") else "[y/N]") # Reference: https://support.microsoft.com/en-us/kb/313282
1030-
kb.cookieEncodeChoice = readInput(msg, default='Y' if not conf.url.endswith(".aspx") else 'N', boolean=True)
1031-
if not kb.cookieEncodeChoice:
1030+
kb.choices.cookieEncode = readInput(msg, default='Y' if not conf.url.endswith(".aspx") else 'N', boolean=True)
1031+
if not kb.choices.cookieEncode:
10321032
skip = True
10331033

10341034
if not skip:

lib/request/redirecthandler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ def _get_header_redirect(self, headers):
4848

4949
def _ask_redirect_choice(self, redcode, redurl, method):
5050
with kb.locks.redirect:
51-
if kb.redirectChoice is None:
51+
if kb.choices.redirect is None:
5252
msg = "got a %d redirect to " % redcode
5353
msg += "'%s'. Do you want to follow? [Y/n] " % redurl
5454

55-
kb.redirectChoice = REDIRECTION.YES if readInput(msg, default='Y', boolean=True) else REDIRECTION.NO
55+
kb.choices.redirect = REDIRECTION.YES if readInput(msg, default='Y', boolean=True) else REDIRECTION.NO
5656

57-
if kb.redirectChoice == REDIRECTION.YES and method == HTTPMETHOD.POST and kb.resendPostOnRedirect is None:
57+
if kb.choices.redirect == REDIRECTION.YES and method == HTTPMETHOD.POST and kb.resendPostOnRedirect is None:
5858
msg = "redirect is a result of a "
5959
msg += "POST request. Do you want to "
6060
msg += "resend original POST data to a new "
@@ -116,7 +116,7 @@ def http_error_302(self, req, fp, code, msg, headers):
116116
redurl = None
117117
result = fp
118118

119-
if redurl and kb.redirectChoice == REDIRECTION.YES:
119+
if redurl and kb.choices.redirect == REDIRECTION.YES:
120120
parseResponse(content, headers)
121121

122122
req.headers[HTTP_HEADER.HOST] = getHostHeader(redurl)

lib/utils/brute.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ def _addPageTextWords():
6363

6464
@stackedmethod
6565
def tableExists(tableFile, regex=None):
66-
if kb.tableExistsChoice is None and not any(_ for _ in kb.injection.data if _ not in (PAYLOAD.TECHNIQUE.TIME, PAYLOAD.TECHNIQUE.STACKED)) and not conf.direct:
66+
if kb.choices.tableExists is None and not any(_ for _ in kb.injection.data if _ not in (PAYLOAD.TECHNIQUE.TIME, PAYLOAD.TECHNIQUE.STACKED)) and not conf.direct:
6767
warnMsg = "it's not recommended to use '%s' and/or '%s' " % (PAYLOAD.SQLINJECTION[PAYLOAD.TECHNIQUE.TIME], PAYLOAD.SQLINJECTION[PAYLOAD.TECHNIQUE.STACKED])
6868
warnMsg += "for common table existence check"
6969
logger.warn(warnMsg)
7070

7171
message = "are you sure you want to continue? [y/N] "
72-
kb.tableExistsChoice = readInput(message, default='N', boolean=True)
72+
kb.choices.tableExists = readInput(message, default='N', boolean=True)
7373

74-
if not kb.tableExistsChoice:
74+
if not kb.choices.tableExists:
7575
return None
7676

7777
result = inject.checkBooleanExpression("%s" % safeStringFormat(BRUTE_TABLE_EXISTS_TEMPLATE, (randomInt(1), randomStr())))
@@ -187,15 +187,15 @@ def tableExistsThread():
187187
return kb.data.cachedTables
188188

189189
def columnExists(columnFile, regex=None):
190-
if kb.columnExistsChoice is None and not any(_ for _ in kb.injection.data if _ not in (PAYLOAD.TECHNIQUE.TIME, PAYLOAD.TECHNIQUE.STACKED)) and not conf.direct:
190+
if kb.choices.columnExists is None and not any(_ for _ in kb.injection.data if _ not in (PAYLOAD.TECHNIQUE.TIME, PAYLOAD.TECHNIQUE.STACKED)) and not conf.direct:
191191
warnMsg = "it's not recommended to use '%s' and/or '%s' " % (PAYLOAD.SQLINJECTION[PAYLOAD.TECHNIQUE.TIME], PAYLOAD.SQLINJECTION[PAYLOAD.TECHNIQUE.STACKED])
192192
warnMsg += "for common column existence check"
193193
logger.warn(warnMsg)
194194

195195
message = "are you sure you want to continue? [y/N] "
196-
kb.columnExistsChoice = readInput(message, default='N', boolean=True)
196+
kb.choices.columnExists = readInput(message, default='N', boolean=True)
197197

198-
if not kb.columnExistsChoice:
198+
if not kb.choices.columnExists:
199199
return None
200200

201201
if not conf.tbl:

lib/utils/hash.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,13 +637,13 @@ def storeHashesToFile(attack_dict):
637637
if item and item not in items:
638638
items.add(item)
639639

640-
if kb.storeHashesChoice is None:
640+
if kb.choices.storeHashes is None:
641641
message = "do you want to store hashes to a temporary file "
642642
message += "for eventual further processing with other tools [y/N] "
643643

644-
kb.storeHashesChoice = readInput(message, default='N', boolean=True)
644+
kb.choices.storeHashes = readInput(message, default='N', boolean=True)
645645

646-
if items and kb.storeHashesChoice:
646+
if items and kb.choices.storeHashes:
647647
handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.HASHES, suffix=".txt")
648648
os.close(handle)
649649

lib/utils/search.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ def _search(dork):
184184

185185
@stackedmethod
186186
def search(dork):
187-
pushValue(kb.redirectChoice)
188-
kb.redirectChoice = REDIRECTION.YES
187+
pushValue(kb.choices.redirect)
188+
kb.choices.redirect = REDIRECTION.YES
189189

190190
try:
191191
return _search(dork)
@@ -203,7 +203,7 @@ def search(dork):
203203
else:
204204
raise
205205
finally:
206-
kb.redirectChoice = popValue()
206+
kb.choices.redirect = popValue()
207207

208208
def setHTTPHandlers(): # Cross-referenced function
209209
raise NotImplementedError

plugins/dbms/raima/connector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010

1111
class Connector(GenericConnector):
1212
def connect(self):
13-
errMsg = "on Raima it is not (currently) possible to establish a "
13+
errMsg = "on Raima Database Manager it is not (currently) possible to establish a "
1414
errMsg += "direct connection"
1515
raise SqlmapUnsupportedFeatureException(errMsg)

0 commit comments

Comments
 (0)