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

Skip to content

Commit 207e96e

Browse files
committed
Major bug fix in the comparison algorithm to correctly handle also the
case that the url is stable and the False response changes the page content very little.
1 parent c405fb5 commit 207e96e

6 files changed

Lines changed: 57 additions & 16 deletions

File tree

doc/ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
sqlmap (0.6.5-1) stable; urgency=low
2+
3+
* Major bug fix in the comparison algorithm to correctly handle also the
4+
case that the url is stable and the False response changes the page
5+
content very little.
6+
7+
-- Bernardo Damele A. G. <[email protected]> Day, DD MMM 2009 HH:MM:SS +0000
8+
19
sqlmap (0.6.4-1) stable; urgency=low
210

311
* Major enhancement to make the comparison algorithm work properly also

doc/THANKS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ Luke Jahnke <[email protected]>
5858
Anant Kochhar <[email protected]>
5959
for providing me with feedback on the user's manual
6060

61+
Alexander Kornbrust <[email protected]>
62+
for reporting a bug
63+
6164
Nico Leidecker <[email protected]>
6265
for providing me with feedback on a few features
6366

lib/controller/checks.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from lib.core.agent import agent
3232
from lib.core.common import randomInt
3333
from lib.core.common import randomStr
34+
from lib.core.convert import md5hash
3435
from lib.core.data import conf
3536
from lib.core.data import kb
3637
from lib.core.data import logger
@@ -296,23 +297,24 @@ def checkStability():
296297

297298
firstPage, firstHeaders = Request.queryPage(content=True)
298299
time.sleep(1)
299-
300300
secondPage, secondHeaders = Request.queryPage(content=True)
301301

302302
condition = firstPage == secondPage
303303

304-
if condition == False:
304+
if condition == True:
305+
conf.md5hash = md5hash(firstPage)
306+
307+
logMsg = "url is stable"
308+
logger.info(logMsg)
309+
310+
elif condition == False:
305311
warnMsg = "url is not stable, sqlmap will base the page "
306312
warnMsg += "comparison on a sequence matcher, if no dynamic nor "
307313
warnMsg += "injectable parameters are detected, refer to user's "
308314
warnMsg += "manual paragraph 'Page comparison' and provide a "
309315
warnMsg += "string or regular expression to match on"
310316
logger.warn(warnMsg)
311317

312-
if condition == True:
313-
logMsg = "url is stable"
314-
logger.info(logMsg)
315-
316318
return condition
317319

318320

lib/core/option.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ def __setConfAttributes():
600600
conf.httpHeaders = []
601601
conf.hostname = None
602602
conf.loggedToOut = None
603+
conf.md5hash = None
603604
conf.multipleTargets = False
604605
conf.outputPath = None
605606
conf.paramDict = {}

lib/core/settings.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131

3232
# sqlmap version and site
33-
VERSION = "0.6.4"
33+
VERSION = "0.6.5-rc1"
3434
VERSION_STRING = "sqlmap/%s" % VERSION
3535
SITE = "http://sqlmap.sourceforge.net"
3636

@@ -64,15 +64,18 @@
6464
ORACLE_ALIASES = [ "oracle", "orcl", "ora", "or" ]
6565

6666
SUPPORTED_DBMS = MSSQL_ALIASES + MYSQL_ALIASES + PGSQL_ALIASES + ORACLE_ALIASES
67+
SUPPORTED_OS = ( "linux", "windows" )
6768

6869
# TODO: port to command line/configuration file options?
6970
SECONDS = 5
7071
RETRIES = 3
71-
MATCH_RATIO = 0.9
72+
73+
MATCH_RATIO = None
7274

7375
SQL_STATEMENTS = {
7476
"SQL SELECT statement": (
7577
"select ",
78+
"show ",
7679
" top ",
7780
" from ",
7881
" from dual",

lib/request/comparison.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@
2626

2727
import re
2828

29+
from lib.core.convert import md5hash
2930
from lib.core.data import conf
30-
from lib.core.settings import MATCH_RATIO
31+
from lib.core.data import logger
32+
#from lib.core.settings import MATCH_RATIO
3133

34+
MATCH_RATIO = None
3235

3336
def comparison(page, headers=None, getSeqMatcher=False):
37+
global MATCH_RATIO
38+
3439
regExpResults = None
3540

3641
# String to be excluded before calculating page hash
@@ -67,15 +72,34 @@ def comparison(page, headers=None, getSeqMatcher=False):
6772
else:
6873
return False
6974

70-
# By default it returns sequence matcher between the first untouched
71-
# HTTP response page content and this content
7275
conf.seqMatcher.set_seq2(page)
73-
76+
ratio = round(conf.seqMatcher.ratio(), 3)
77+
78+
# If the url is stable and we did not set yet the match ratio and the
79+
# current injected value changes the url page content
80+
if MATCH_RATIO == None:
81+
if conf.md5hash != None and ratio != 1:
82+
logger.debug("Setting match ratio to %.3f" % ratio)
83+
MATCH_RATIO = ratio
84+
elif conf.md5hash == None:
85+
logger.debug("Setting match ratio to default value 0.900")
86+
MATCH_RATIO = 0.900
87+
88+
# If it has been requested to return the ratio and not a comparison
89+
# response
7490
if getSeqMatcher:
75-
return round(conf.seqMatcher.ratio(), 3)
76-
77-
elif round(conf.seqMatcher.ratio(), 3) >= MATCH_RATIO:
91+
return ratio
92+
93+
# If the url is stable it returns True if the page has the same MD5
94+
# hash of the original one
95+
# NOTE: old implementation, it did not handle automatically the fact
96+
# that the url could be not stable (due to VIEWSTATE, counter, etc.)
97+
#elif conf.md5hash != None:
98+
# return conf.md5hash == md5hash(page)
99+
100+
# If the url is not stable it returns sequence matcher between the
101+
# first untouched HTTP response page content and this content
102+
elif ratio > MATCH_RATIO:
78103
return True
79-
80104
else:
81105
return False

0 commit comments

Comments
 (0)