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

Skip to content

Commit 486a113

Browse files
committed
Consolidate logger messages for --*-test switches
1 parent 46be570 commit 486a113

8 files changed

Lines changed: 62 additions & 68 deletions

File tree

lib/controller/action.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ def action():
5656

5757
# Techniques options
5858
if conf.stackedTest:
59-
conf.dumper.technic("stacked queries support", stackedTest())
59+
conf.dumper.technic("stacked queries injection payload", stackedTest())
6060

6161
if conf.errorTest:
62-
conf.dumper.technic("error based injection support", errorTest())
62+
conf.dumper.technic("error-based injection payload", errorTest())
6363

6464
if conf.timeTest:
65-
conf.dumper.technic("time based blind sql injection payload", timeTest())
65+
conf.dumper.technic("time-based blind injection payload", timeTest())
6666

6767
if conf.unionTest and kb.unionPosition is None:
68-
conf.dumper.technic("valid union", unionTest())
68+
conf.dumper.technic("inband injection payload", unionTest())
6969

7070
# Enumeration options
7171
if conf.getBanner:

lib/request/inject.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def goStacked(expression, silent=False):
406406

407407
return payload, page
408408

409-
def goError(expression, suppressOutput=False):
409+
def goError(expression, suppressOutput=False, returnPayload=False):
410410
#expression = cleanQuery(expression)
411411

412412
if suppressOutput:
@@ -416,9 +416,9 @@ def goError(expression, suppressOutput=False):
416416
if conf.direct:
417417
return direct(expression), None
418418

419-
result = errorUse(expression)
419+
result, payload = errorUse(expression, returnPayload)
420420

421421
if suppressOutput:
422422
conf.verbose = popValue()
423423

424-
return result
424+
return result, payload

lib/techniques/blind/timebased.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from lib.request.connect import Connect as Request
2020

2121
def timeTest():
22-
infoMsg = "testing time based blind sql injection on parameter "
22+
infoMsg = "testing time-based blind sql injection on parameter "
2323
infoMsg += "'%s' with %s condition syntax" % (kb.injParameter, conf.logic)
2424
logger.info(infoMsg)
2525

@@ -32,19 +32,20 @@ def timeTest():
3232
duration = calculateDeltaSeconds(start)
3333

3434
if duration >= conf.timeSec:
35-
infoMsg = "the parameter '%s' is affected by a time " % kb.injParameter
36-
infoMsg += "based blind sql injection with AND condition syntax"
35+
infoMsg = "the target url is affected by a time-based blind "
36+
infoMsg += "sql injection with AND condition syntax on parameter "
37+
infoMsg += "'%s'" % kb.injParameter
3738
logger.info(infoMsg)
3839

3940
kb.timeTest = payload
40-
4141
else:
42-
warnMsg = "the parameter '%s' is not affected by a time " % kb.injParameter
43-
warnMsg += "based blind sql injection with AND condition syntax"
42+
warnMsg = "the target url is not affected by a time-based blind "
43+
warnMsg += "sql injection with AND condition syntax on parameter "
44+
warnMsg += "'%s'" % kb.injParameter
4445
logger.warn(warnMsg)
4546

46-
infoMsg = "testing time based blind sql injection on parameter "
47-
infoMsg += "'%s' with stacked query syntax" % kb.injParameter
47+
infoMsg = "testing time-based blind sql injection on parameter "
48+
infoMsg += "'%s' with stacked queries syntax" % kb.injParameter
4849
logger.info(infoMsg)
4950

5051
timeQuery = getDelayQuery(andCond=True)
@@ -53,14 +54,16 @@ def timeTest():
5354
duration = calculateDeltaSeconds(start)
5455

5556
if duration >= conf.timeSec:
56-
infoMsg = "the parameter '%s' is affected by a time " % kb.injParameter
57-
infoMsg += "based blind sql injection with stacked query syntax"
57+
infoMsg = "the target url is affected by a time-based blind sql "
58+
infoMsg += "injection with stacked queries syntax on parameter "
59+
infoMsg += "'%s'" % kb.injParameter
5860
logger.info(infoMsg)
5961

6062
kb.timeTest = payload
6163
else:
62-
warnMsg = "the parameter '%s' is not affected by a time " % kb.injParameter
63-
warnMsg += "based blind sql injection with stacked query syntax"
64+
warnMsg = "the target url is not affected by a time-based blind "
65+
warnMsg += "sql injection with stacked queries syntax on parameter "
66+
warnMsg += "'%s'" % kb.injParameter
6467
logger.warn(warnMsg)
6568

6669
kb.timeTest = False

lib/techniques/error/test.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,30 @@ def errorTest():
2525
if kb.errorTest is not None:
2626
return kb.errorTest
2727

28-
infoMsg = "testing error based sql injection on parameter "
28+
infoMsg = "testing error-based sql injection on parameter "
2929
infoMsg += "'%s' with %s condition syntax" % (kb.injParameter, conf.logic)
3030
logger.info(infoMsg)
3131

3232
randInt = getUnicode(randomInt(1))
3333
query = queries[kb.dbms].case.query % ("%s=%s" % (randInt, randInt))
34-
result = inject.goError(query, True)
34+
result, usedPayload = inject.goError(query, suppressOutput=True, returnPayload=True)
3535

3636
if result:
37-
infoMsg = "the web application supports error based injection "
38-
infoMsg += "on parameter '%s'" % kb.injParameter
37+
infoMsg = "the target url is affected by an error-based sql "
38+
infoMsg += "injection on parameter '%s'" % kb.injParameter
3939
logger.info(infoMsg)
4040

4141
kb.errorTest = True
4242
else:
43-
warnMsg = "the web application does not support error based injection "
44-
warnMsg += "on parameter '%s'" % kb.injParameter
43+
warnMsg = "the target url is not affected by an error-based sql "
44+
warnMsg += "injection on parameter '%s'" % kb.injParameter
4545
logger.warn(warnMsg)
4646

4747
kb.errorTest = False
4848

4949
setError()
5050

51-
return kb.errorTest
51+
if kb.errorTest:
52+
return usedPayload
53+
else:
54+
return False

lib/techniques/error/use.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from lib.core.settings import ERROR_START_CHAR
3030
from lib.core.settings import ERROR_END_CHAR
3131

32-
def errorUse(expression):
32+
def errorUse(expression, returnPayload=False):
3333
"""
3434
Retrieve the output of a SQL query taking advantage of an error SQL
3535
injection vulnerability on the affected parameter.
@@ -79,4 +79,7 @@ def errorUse(expression):
7979
infoMsg = "retrieved: %s" % replaceNewlineTabs(output, stdout=True)
8080
logger.info(infoMsg)
8181

82-
return output
82+
if returnPayload:
83+
return output, payload
84+
else:
85+
return output

lib/techniques/inband/union/test.py

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,8 @@
1818
from lib.parse.html import htmlParser
1919
from lib.request.connect import Connect as Request
2020

21-
def __forgeUserFriendlyValue(payload):
22-
value = ""
23-
24-
if kb.injPlace == "GET":
25-
value = "%s?%s" % (conf.url, payload)
26-
elif kb.injPlace == "POST":
27-
value = "URL:\t'%s'" % conf.url
28-
value += "\nPOST:\t'%s'\n" % payload
29-
elif kb.injPlace == "Cookie":
30-
value = "URL:\t'%s'" % conf.url
31-
value += "\nCookie:\t'%s'\n" % payload
32-
elif kb.injPlace == "User-Agent":
33-
value = "URL:\t\t'%s'" % conf.url
34-
value += "\nUser-Agent:\t'%s'\n" % payload
35-
36-
return value
37-
3821
def __unionPosition(negative=False, falseCond=False):
39-
value = None
22+
validPayload = None
4023

4124
if negative or falseCond:
4225
negLogMsg = "partial (single entry)"
@@ -77,56 +60,58 @@ def __unionPosition(negative=False, falseCond=False):
7760

7861
if resultPage and randQuery in resultPage and not htmlParsed:
7962
setUnion(position=exprPosition)
80-
value = __forgeUserFriendlyValue(payload)
63+
validPayload = payload
8164

8265
break
8366

8467
if isinstance(kb.unionPosition, int):
8568
infoMsg = "the target url is affected by an exploitable "
86-
infoMsg += "%s inband sql injection vulnerability" % negLogMsg
69+
infoMsg += "%s inband sql injection vulnerability " % negLogMsg
70+
infoMsg += "on parameter '%s'" % kb.injParameter
8771
logger.info(infoMsg)
8872
else:
8973
warnMsg = "the target url is not affected by an exploitable "
90-
warnMsg += "%s inband sql injection vulnerability" % negLogMsg
74+
warnMsg += "%s inband sql injection vulnerability " % negLogMsg
75+
warnMsg += "on parameter '%s'" % kb.injParameter
9176

9277
if negLogMsg == "partial":
9378
warnMsg += ", sqlmap will retrieve the query output "
9479
warnMsg += "through blind sql injection technique"
9580

9681
logger.warn(warnMsg)
9782

98-
return value
83+
return validPayload
9984

10085
def __unionConfirm():
101-
value = None
86+
validPayload = None
10287

10388
# Confirm the inband SQL injection and get the exact column
10489
# position
10590
if not isinstance(kb.unionPosition, int):
106-
value = __unionPosition()
91+
validPayload = __unionPosition()
10792

10893
# Assure that the above function found the exploitable full inband
10994
# SQL injection position
11095
if not isinstance(kb.unionPosition, int):
111-
value = __unionPosition(negative=True)
96+
validPayload = __unionPosition(negative=True)
11297

11398
# Assure that the above function found the exploitable partial
11499
# (single entry) inband SQL injection position with negative
115-
# parameter value
100+
# parameter validPayload
116101
if not isinstance(kb.unionPosition, int):
117-
value = __unionPosition(falseCond=True)
102+
validPayload = __unionPosition(falseCond=True)
118103

119104
# Assure that the above function found the exploitable partial
120105
# (single entry) inband SQL injection position by appending
121-
# a false condition after the parameter value
106+
# a false condition after the parameter validPayload
122107
if not isinstance(kb.unionPosition, int):
123108
return
124109
else:
125110
setUnion(falseCond=True)
126111
else:
127112
setUnion(negative=True)
128113

129-
return value
114+
return validPayload
130115

131116
def __unionTestByNULLBruteforce(comment):
132117
"""
@@ -200,7 +185,7 @@ def unionTest():
200185
infoMsg += "'%s' with %s technique" % (kb.injParameter, technique)
201186
logger.info(infoMsg)
202187

203-
value = None
188+
validPayload = None
204189
columns = None
205190

206191
for comment in (queries[kb.dbms].comment.query, ""):
@@ -215,13 +200,13 @@ def unionTest():
215200
break
216201

217202
if kb.unionCount:
218-
value = __unionConfirm()
203+
validPayload = __unionConfirm()
219204
else:
220205
warnMsg = "the target url is not affected by an "
221206
warnMsg += "inband sql injection vulnerability"
222207
logger.warn(warnMsg)
223208

224-
if value is None:
225-
value = ""
209+
if validPayload is None:
210+
validPayload = ""
226211

227-
return value
212+
return validPayload

lib/techniques/outband/stacked.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def stackedTest():
2424
if kb.stackedTest is not None:
2525
return kb.stackedTest
2626

27-
infoMsg = "testing stacked queries support on parameter "
27+
infoMsg = "testing stacked queries sql injection on parameter "
2828
infoMsg += "'%s'" % kb.injParameter
2929
logger.info(infoMsg)
3030

@@ -34,14 +34,14 @@ def stackedTest():
3434
duration = calculateDeltaSeconds(start)
3535

3636
if duration >= conf.timeSec:
37-
infoMsg = "the web application supports stacked queries "
38-
infoMsg += "on parameter '%s'" % kb.injParameter
37+
infoMsg = "the target url is affected by a stacked queries "
38+
infoMsg += "sql injection on parameter '%s'" % kb.injParameter
3939
logger.info(infoMsg)
4040

4141
kb.stackedTest = payload
4242
else:
43-
warnMsg = "the web application does not support stacked queries "
44-
warnMsg += "on parameter '%s'" % kb.injParameter
43+
warnMsg = "the target url is not affected by a stacked queries "
44+
warnMsg += "sql injection on parameter '%s'" % kb.injParameter
4545
logger.warn(warnMsg)
4646

4747
kb.stackedTest = False

plugins/generic/enumeration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def getBanner(self):
7575

7676
if not kb.data.banner:
7777
if conf.unionTest:
78-
conf.dumper.technic("valid union", unionTest())
78+
conf.dumper.technic("inband injection payload", unionTest())
7979

8080
query = queries[kb.dbms].banner.query
8181
kb.data.banner = inject.getValue(query)

0 commit comments

Comments
 (0)