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

Skip to content

Commit 8fda828

Browse files
committed
Minor refactoring
1 parent 453a6fb commit 8fda828

7 files changed

Lines changed: 21 additions & 17 deletions

File tree

lib/core/agent.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from lib.core.common import filterNone
1414
from lib.core.common import getSQLSnippet
1515
from lib.core.common import getTechnique
16+
from lib.core.common import getTechniqueData
1617
from lib.core.common import isDBMSVersionAtLeast
1718
from lib.core.common import isNumber
1819
from lib.core.common import isTechniqueAvailable
@@ -91,7 +92,7 @@ def payload(self, place=None, parameter=None, value=None, newValue=None, where=N
9192
if kb.forceWhere:
9293
where = kb.forceWhere
9394
elif where is None and isTechniqueAvailable(getTechnique()):
94-
where = kb.injection.data[getTechnique()].where
95+
where = getTechniqueData().where
9596

9697
if kb.injection.place is not None:
9798
place = kb.injection.place
@@ -236,7 +237,7 @@ def prefixQuery(self, expression, prefix=None, where=None, clause=None):
236237
query = None
237238

238239
if where is None and getTechnique() is not None and getTechnique() in kb.injection.data:
239-
where = kb.injection.data[getTechnique()].where
240+
where = getTechniqueData().where
240241

241242
# If we are replacing (<where>) the parameter original value with
242243
# our payload do not prepend with the prefix
@@ -284,8 +285,8 @@ def suffixQuery(self, expression, comment=None, suffix=None, where=None, trimEmp
284285
suffix = kb.injection.suffix if kb.injection and suffix is None else suffix
285286

286287
if getTechnique() is not None and getTechnique() in kb.injection.data:
287-
where = kb.injection.data[getTechnique()].where if where is None else where
288-
comment = kb.injection.data[getTechnique()].comment if comment is None else comment
288+
where = getTechniqueData().where if where is None else where
289+
comment = getTechniqueData().comment if comment is None else comment
289290

290291
if Backend.getIdentifiedDbms() == DBMS.ACCESS and any((comment or "").startswith(_) for _ in ("--", "[GENERIC_SQL_COMMENT]")):
291292
comment = queries[DBMS.ACCESS].comment.query

lib/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3222,7 +3222,7 @@ def getTechniqueData(technique=None):
32223222
Returns injection data for technique specified
32233223
"""
32243224

3225-
return kb.injection.data.get(technique)
3225+
return kb.injection.data.get(technique if technique is not None else getTechnique())
32263226

32273227
def isTechniqueAvailable(technique):
32283228
"""

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.3.7.30"
21+
VERSION = "1.3.7.31"
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/inject.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def _goInferenceProxy(expression, fromUser=False, batch=False, unpack=True, char
164164

165165
initTechnique(getTechnique())
166166

167-
query = agent.prefixQuery(kb.injection.data[getTechnique()].vector)
167+
query = agent.prefixQuery(getTechniqueData().vector)
168168
query = agent.suffixQuery(query)
169169
payload = agent.payload(newValue=query)
170170
count = None
@@ -312,15 +312,15 @@ def _goBooleanProxy(expression):
312312
initTechnique(getTechnique())
313313

314314
if conf.dnsDomain:
315-
query = agent.prefixQuery(kb.injection.data[getTechnique()].vector)
315+
query = agent.prefixQuery(getTechniqueData().vector)
316316
query = agent.suffixQuery(query)
317317
payload = agent.payload(newValue=query)
318318
output = _goDns(payload, expression)
319319

320320
if output is not None:
321321
return output
322322

323-
vector = kb.injection.data[getTechnique()].vector
323+
vector = getTechniqueData().vector
324324
vector = vector.replace(INFERENCE_MARKER, expression)
325325
query = agent.prefixQuery(vector)
326326
query = agent.suffixQuery(query)

lib/takeover/web.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from lib.core.common import getPublicTypeMembers
2222
from lib.core.common import getSQLSnippet
2323
from lib.core.common import getTechnique
24+
from lib.core.common import getTechniqueData
2425
from lib.core.common import isTechniqueAvailable
2526
from lib.core.common import isWindowsDriveLetterPath
2627
from lib.core.common import normalizePath
@@ -149,7 +150,7 @@ def _webFileInject(self, fileContent, fileName, directory):
149150
query = ""
150151

151152
if isTechniqueAvailable(getTechnique()):
152-
where = kb.injection.data[getTechnique()].where
153+
where = getTechniqueData().where
153154

154155
if where == PAYLOAD.WHERE.NEGATIVE:
155156
randInt = randomInt()

lib/techniques/blind/inference.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from lib.core.common import getCounter
2424
from lib.core.common import getPartRun
2525
from lib.core.common import getTechnique
26+
from lib.core.common import getTechniqueData
2627
from lib.core.common import goGoodSamaritan
2728
from lib.core.common import hashDBRetrieve
2829
from lib.core.common import hashDBWrite
@@ -229,10 +230,10 @@ def validateChar(idx, value):
229230

230231
result = not Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False)
231232

232-
if result and timeBasedCompare and kb.injection.data[getTechnique()].trueCode:
233-
result = threadData.lastCode == kb.injection.data[getTechnique()].trueCode
233+
if result and timeBasedCompare and getTechniqueData().trueCode:
234+
result = threadData.lastCode == getTechniqueData().trueCode
234235
if not result:
235-
warnMsg = "detected HTTP code '%s' in validation phase is differing from expected '%s'" % (threadData.lastCode, kb.injection.data[getTechnique()].trueCode)
236+
warnMsg = "detected HTTP code '%s' in validation phase is differing from expected '%s'" % (threadData.lastCode, getTechniqueData().trueCode)
236237
singleTimeWarnMessage(warnMsg)
237238

238239
incrementCounter(getTechnique())
@@ -342,7 +343,7 @@ def getChar(idx, charTbl=None, continuousOrder=True, expand=charsetType is None,
342343
incrementCounter(getTechnique())
343344

344345
if not timeBasedCompare:
345-
unexpectedCode |= threadData.lastCode not in (kb.injection.data[getTechnique()].falseCode, kb.injection.data[getTechnique()].trueCode)
346+
unexpectedCode |= threadData.lastCode not in (getTechniqueData().falseCode, getTechniqueData().trueCode)
346347
if unexpectedCode:
347348
warnMsg = "unexpected HTTP code '%s' detected. Will use (extra) validation step in similar cases" % threadData.lastCode
348349
singleTimeWarnMessage(warnMsg)
@@ -570,7 +571,7 @@ def blindThread():
570571
# One-shot query containing equals commonValue
571572
testValue = unescaper.escape("'%s'" % commonValue) if "'" not in commonValue else unescaper.escape("%s" % commonValue, quote=False)
572573

573-
query = kb.injection.data[getTechnique()].vector
574+
query = getTechniqueData().vector
574575
query = agent.prefixQuery(query.replace(INFERENCE_MARKER, "(%s)%s%s" % (expressionUnescaped, INFERENCE_EQUALS_CHAR, testValue)))
575576
query = agent.suffixQuery(query)
576577

@@ -594,7 +595,7 @@ def blindThread():
594595
subquery = queries[Backend.getIdentifiedDbms()].substring.query % (expressionUnescaped, 1, len(commonPattern))
595596
testValue = unescaper.escape("'%s'" % commonPattern) if "'" not in commonPattern else unescaper.escape("%s" % commonPattern, quote=False)
596597

597-
query = kb.injection.data[getTechnique()].vector
598+
query = getTechniqueData().vector
598599
query = agent.prefixQuery(query.replace(INFERENCE_MARKER, "(%s)=%s" % (subquery, testValue)))
599600
query = agent.suffixQuery(query)
600601

lib/techniques/error/use.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from lib.core.common import getConsoleWidth
2323
from lib.core.common import getPartRun
2424
from lib.core.common import getTechnique
25+
from lib.core.common import getTechniqueData
2526
from lib.core.common import hashDBRetrieve
2627
from lib.core.common import hashDBWrite
2728
from lib.core.common import incrementCounter
@@ -124,7 +125,7 @@ def _oneShotErrorUse(expression, field=None, chunkTest=False):
124125
nulledCastedField = queries[Backend.getIdentifiedDbms()].substring.query % (nulledCastedField, offset, kb.errorChunkLength)
125126

126127
# Forge the error-based SQL injection request
127-
vector = kb.injection.data[getTechnique()].vector
128+
vector = getTechniqueData().vector
128129
query = agent.prefixQuery(vector)
129130
query = agent.suffixQuery(query)
130131
injExpression = expression.replace(field, nulledCastedField, 1) if field else expression

0 commit comments

Comments
 (0)