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

Skip to content

Commit 8b97066

Browse files
committed
Got rid of unreliable 'ORDER BY' technique to detect UNION query SQL injection, consequently switch --union-tech has gone now.
Minor code refactoring too.
1 parent e929193 commit 8b97066

6 files changed

Lines changed: 25 additions & 79 deletions

File tree

lib/controller/controller.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,6 @@
4545
from lib.core.target import initTargetEnv
4646
from lib.core.target import setupTargetEnv
4747

48-
def __saveToSessionFile():
49-
for inj in kb.injections:
50-
setInjection(inj)
51-
52-
place = inj.place
53-
parameter = inj.parameter
54-
55-
for stype, sdata in inj.data.items():
56-
payload = sdata[0]
57-
58-
if stype == 1:
59-
kb.booleanTest = payload
60-
setBooleanBased(place, parameter, payload)
61-
elif stype == 2:
62-
kb.errorTest = payload
63-
setError(place, parameter, payload)
64-
elif stype == 4:
65-
kb.stackedTest = payload
66-
setStacked(place, parameter, payload)
67-
elif stype == 5:
68-
kb.timeTest = payload
69-
setTimeBased(place, parameter, payload)
70-
7148
def __selectInjection():
7249
"""
7350
Selection function for injection place, parameters and type.
@@ -144,6 +121,29 @@ def __showInjections():
144121

145122
dumper.technic(header, data)
146123

124+
def __saveToSessionFile():
125+
for inj in kb.injections:
126+
setInjection(inj)
127+
128+
place = inj.place
129+
parameter = inj.parameter
130+
131+
for stype, sdata in inj.data.items():
132+
payload = sdata[0]
133+
134+
if stype == 1:
135+
kb.booleanTest = payload
136+
setBooleanBased(place, parameter, payload)
137+
elif stype == 2:
138+
kb.errorTest = payload
139+
setError(place, parameter, payload)
140+
elif stype == 4:
141+
kb.stackedTest = payload
142+
setStacked(place, parameter, payload)
143+
elif stype == 5:
144+
kb.timeTest = payload
145+
setTimeBased(place, parameter, payload)
146+
147147
def start():
148148
"""
149149
This function calls a function that performs checks on both URL

lib/core/option.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -499,24 +499,6 @@ def __setWriteFile():
499499
conf.wFileType = getFileType(conf.wFile)
500500

501501
def __setUnion():
502-
if isinstance(conf.uTech, basestring):
503-
debugMsg = "setting the UNION query SQL injection detection technique"
504-
logger.debug(debugMsg)
505-
506-
uTechOriginal = conf.uTech
507-
conf.uTech = conf.uTech.lower()
508-
509-
if conf.uTech and conf.uTech not in ( "char", "orderby" ):
510-
infoMsg = "resetting the UNION query detection technique to "
511-
infoMsg += "'char', '%s' is not a valid technique" % uTechOriginal
512-
logger.info(infoMsg)
513-
514-
conf.uTech = "char"
515-
else:
516-
debugMsg = "setting UNION query detection technique to "
517-
debugMsg += "'%s'" % uTechOriginal
518-
logger.debug(debugMsg)
519-
520502
if isinstance(conf.uCols, basestring) and conf.uChar != "1-20":
521503
debugMsg = "setting the UNION query SQL injection range of columns"
522504
logger.debug(debugMsg)

lib/core/optiondict.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
"Techniques": {
7878
"timeSec": "integer",
7979
"unionTest": "boolean",
80-
"uTech": "string",
8180
"uCols": "integer",
8281
"uChar": "string"
8382
},

lib/parse/cmdline.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,6 @@ def cmdLineParser():
235235
action="store_true", default=False,
236236
help="Test for and use UNION query (inband) SQL injection")
237237

238-
techniques.add_option("--union-tech", dest="uTech", default="char",
239-
help="Technique to test for UNION query SQL injection")
240-
241238
techniques.add_option("--union-cols", dest="uCols", default="1-20",
242239
help="Range of columns to test for UNION query SQL injection")
243240

lib/techniques/inband/union/test.py

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,6 @@ def __unionTestByCharBruteforce(comment):
117117

118118
return validPayload
119119

120-
def __unionTestByOrderBy(comment):
121-
columns = None
122-
prevPayload = ""
123-
124-
for count in range(conf.uColsStart, conf.uColsStop+1):
125-
query = agent.prefixQuery("ORDER BY %d" % count)
126-
orderByQuery = agent.suffixQuery(query, comment)
127-
payload = agent.payload(newValue=orderByQuery, negative=negative, falseCond=falseCond)
128-
_, seqMatcher = Request.queryPage(payload, getSeqMatcher=True)
129-
130-
if seqMatcher >= 0.6:
131-
columns = count
132-
setUnion(count=count)
133-
elif columns:
134-
break
135-
136-
prevPayload = payload
137-
138-
return columns
139-
140120
def unionTest():
141121
"""
142122
This method tests if the target url is affected by an inband
@@ -149,9 +129,7 @@ def unionTest():
149129
if kb.unionTest is not None:
150130
return kb.unionTest
151131

152-
if conf.uTech == "orderby":
153-
technique = "ORDER BY clause bruteforcing"
154-
elif conf.uChar == "NULL":
132+
if conf.uChar == "NULL":
155133
technique = "NULL bruteforcing"
156134
else:
157135
technique = "char (%s) bruteforcing" % conf.uChar
@@ -163,10 +141,7 @@ def unionTest():
163141
validPayload = None
164142
comment = queries[kb.dbms].comment.query
165143

166-
if conf.uTech == "orderby":
167-
validPayload = __unionTestByOrderBy(comment)
168-
else:
169-
validPayload = __unionTestByCharBruteforce(comment)
144+
validPayload = __unionTestByCharBruteforce(comment)
170145

171146
if validPayload:
172147
setUnion(comment=comment)

sqlmap.conf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,6 @@ timeSec = 5
255255
# Valid: True or False
256256
unionTest = False
257257

258-
# Technique to test for UNION query SQL injection
259-
# The possible techniques are by NULL bruteforcing (bf) or by ORDER BY
260-
# clause (ob)
261-
# Valid: char, OrderBy
262-
# Default: char
263-
uTech = char
264-
265258
# Range of columns to test for
266259
# Valid: range of integers
267260
# Default: 1-20

0 commit comments

Comments
 (0)