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

Skip to content

Commit dda62ba

Browse files
committed
Minor adjustments and bug fixes
1 parent 7b55840 commit dda62ba

5 files changed

Lines changed: 33 additions & 10 deletions

File tree

lib/core/agent.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,15 @@ def getFields(self, query):
246246
@rtype: C{str}
247247
"""
248248

249-
fieldsSelectTop = re.search("\ASELECT\s+TOP\s+[\d]+\s+(.+?)\s+FROM", query, re.I)
250-
fieldsSelectDistinct = re.search("\ASELECT\s+DISTINCT\((.+?)\)\s+FROM", query, re.I)
251-
fieldsSelectFrom = re.search("\ASELECT\s+(.+?)\s+FROM\s+", query, re.I)
252-
fieldsSelect = re.search("\ASELECT\s+(.*)", query, re.I)
249+
if "(SELECT " in query:
250+
firstChar = "\\("
251+
else:
252+
firstChar = "\\A"
253+
254+
fieldsSelectTop = re.search("%sSELECT\s+TOP\s+[\d]+\s+(.+?)\s+FROM" % firstChar, query, re.I)
255+
fieldsSelectDistinct = re.search("%sSELECT\s+DISTINCT\((.+?)\)\s+FROM" % firstChar, query, re.I)
256+
fieldsSelectFrom = re.search("%sSELECT\s+(.+?)\s+FROM\s+" % firstChar, query, re.I)
257+
fieldsSelect = re.search("%sSELECT\s+(.*)" % firstChar, query, re.I)
253258
fieldsNoSelect = query
254259

255260
if fieldsSelectTop:
@@ -296,11 +301,11 @@ def concatQuery(self, query):
296301
"""
297302

298303
concatQuery = ""
299-
query = query.replace(", ", ",")
304+
query = query.replace(", ", ",")
300305

301306
fieldsSelectFrom, fieldsSelect, fieldsNoSelect, _, fieldsToCastStr = self.getFields(query)
302307
castedFields = self.nullCastConcatFields(fieldsToCastStr)
303-
concatQuery = query.replace(fieldsToCastStr, castedFields, 1)
308+
concatQuery = query.replace(fieldsToCastStr, castedFields, 1)
304309

305310
if kb.dbms == "MySQL":
306311
if fieldsSelectFrom:

lib/request/inject.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,15 @@ def __goInferenceProxy(expression, fromUser=False, expected=None):
228228

229229
return None
230230

231+
elif count and not count.isdigit():
232+
warnMsg = "it was not possible to count the number "
233+
warnMsg += "of entries for the SQL query provided. "
234+
warnMsg += "sqlmap will assume that it returns only "
235+
warnMsg += "one entry"
236+
logger.warn(warnMsg)
237+
238+
stopLimit = 1
239+
231240
elif ( not count or int(count) == 0 ):
232241
warnMsg = "the SQL query provided does not "
233242
warnMsg += "return any output"

lib/techniques/inband/union/use.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@ def unionUse(expression, direct=False, unescape=True, resetCounter=False):
237237
infoMsg += "%d entries" % stopLimit
238238
logger.info(infoMsg)
239239

240+
elif count and not count.isdigit():
241+
warnMsg = "it was not possible to count the number "
242+
warnMsg += "of entries for the SQL query provided. "
243+
warnMsg += "sqlmap will assume that it returns only "
244+
warnMsg += "one entry"
245+
logger.warn(warnMsg)
246+
247+
stopLimit = 1
248+
240249
elif ( not count or int(count) == 0 ):
241250
warnMsg = "the SQL query provided does not "
242251
warnMsg += "return any output"

xml/banner/generic.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
<info type="Windows" distrib="2003"/>
2020
</regexp>
2121

22+
<regexp value="Microsoft.*5\.2">
23+
<info type="Windows" distrib="2003"/>
24+
</regexp>
25+
2226
<regexp value="Microsoft.*5\.1">
2327
<info type="Windows" distrib="XP"/>
2428
</regexp>

xml/queries.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@
7474
<timedelay query="BEGIN DBMS_LOCK.SLEEP(%d); END" query2="EXEC DBMS_LOCK.SLEEP(%d.00)" query3="EXEC USER_LOCK.SLEEP(%d00)"/>
7575
<substring query="SUBSTR((%s), %d, %d)"/>
7676
<inference query="AND ASCII(SUBSTR((%s), %d, 1)) > %d"/>
77-
<!--
78-
TODO: the following query does not work with inband SQL injection:
79-
SELECT banner FROM (SELECT banner, ROWNUM AS limit FROM v$version) WHERE limit=4
80-
-->
8177
<banner query="SELECT banner FROM v$version WHERE ROWNUM=1"/>
8278
<current_user query="SELECT SYS.LOGIN_USER FROM DUAL"/>
8379
<current_db query="SELECT SYS.DATABASE_NAME FROM DUAL"/>

0 commit comments

Comments
 (0)