2008-12-05 18:34:13 +03:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
This file is part of the sqlmap project, http://sqlmap.sourceforge.net.
|
|
|
|
|
2010-03-03 18:26:27 +03:00
|
|
|
Copyright (c) 2007-2010 Bernardo Damele A. G. <bernardo.damele@gmail.com>
|
2009-04-22 15:48:07 +04:00
|
|
|
Copyright (c) 2006 Daniele Bellucci <daniele.bellucci@gmail.com>
|
2008-12-05 18:34:13 +03:00
|
|
|
|
|
|
|
sqlmap is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free
|
|
|
|
Software Foundation version 2 of the License.
|
|
|
|
|
|
|
|
sqlmap is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with sqlmap; if not, write to the Free Software Foundation, Inc., 51
|
|
|
|
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
from lib.core.data import conf
|
2009-02-09 13:28:03 +03:00
|
|
|
from lib.core.data import logger
|
2009-04-22 15:48:07 +04:00
|
|
|
from lib.core.session import setMatchRatio
|
2008-12-05 18:34:13 +03:00
|
|
|
|
2008-12-20 04:54:08 +03:00
|
|
|
def comparison(page, headers=None, getSeqMatcher=False):
|
2008-12-05 18:34:13 +03:00
|
|
|
regExpResults = None
|
|
|
|
|
2008-12-09 00:24:24 +03:00
|
|
|
# String to be excluded before calculating page hash
|
2008-12-05 18:34:13 +03:00
|
|
|
if conf.eString and conf.eString in page:
|
|
|
|
index = page.index(conf.eString)
|
|
|
|
length = len(conf.eString)
|
|
|
|
pageWithoutString = page[:index]
|
|
|
|
pageWithoutString += page[index+length:]
|
|
|
|
page = pageWithoutString
|
|
|
|
|
2008-12-09 00:24:24 +03:00
|
|
|
# Regular expression matches to be excluded before calculating page hash
|
2008-12-05 18:34:13 +03:00
|
|
|
if conf.eRegexp:
|
|
|
|
regExpResults = re.findall(conf.eRegexp, page, re.I | re.M)
|
|
|
|
|
2008-12-09 00:24:24 +03:00
|
|
|
if regExpResults:
|
|
|
|
for regExpResult in regExpResults:
|
|
|
|
index = page.index(regExpResult)
|
|
|
|
length = len(regExpResult)
|
|
|
|
pageWithoutRegExp = page[:index]
|
|
|
|
pageWithoutRegExp += page[index+length:]
|
|
|
|
page = pageWithoutRegExp
|
2008-12-05 18:34:13 +03:00
|
|
|
|
2008-12-09 00:24:24 +03:00
|
|
|
# String to match in page when the query is valid
|
2008-12-05 18:34:13 +03:00
|
|
|
if conf.string:
|
2010-05-14 18:21:13 +04:00
|
|
|
return conf.string in page
|
2008-12-05 18:34:13 +03:00
|
|
|
|
2008-12-09 00:24:24 +03:00
|
|
|
# Regular expression to match in page when the query is valid
|
|
|
|
if conf.regexp:
|
2010-05-14 18:21:13 +04:00
|
|
|
return re.search(conf.regexp, page, re.I | re.M) is not None
|
2008-12-05 18:34:13 +03:00
|
|
|
|
2010-03-10 17:14:27 +03:00
|
|
|
if conf.seqLock:
|
|
|
|
conf.seqLock.acquire()
|
|
|
|
|
2008-12-20 04:54:08 +03:00
|
|
|
conf.seqMatcher.set_seq2(page)
|
2009-02-09 13:28:03 +03:00
|
|
|
ratio = round(conf.seqMatcher.ratio(), 3)
|
|
|
|
|
2010-03-10 17:14:27 +03:00
|
|
|
if conf.seqLock:
|
|
|
|
conf.seqLock.release()
|
|
|
|
|
2009-02-09 13:28:03 +03:00
|
|
|
# If the url is stable and we did not set yet the match ratio and the
|
|
|
|
# current injected value changes the url page content
|
2010-01-02 05:02:12 +03:00
|
|
|
if conf.matchRatio is None:
|
|
|
|
if conf.md5hash is not None and ratio > 0.6 and ratio < 1:
|
2009-02-12 03:17:44 +03:00
|
|
|
logger.debug("setting match ratio to %.3f" % ratio)
|
2009-04-22 15:48:07 +04:00
|
|
|
conf.matchRatio = ratio
|
2010-01-02 05:02:12 +03:00
|
|
|
|
|
|
|
elif conf.md5hash is None or ( conf.md5hash is not None and ratio < 0.6 ):
|
2009-02-12 03:17:44 +03:00
|
|
|
logger.debug("setting match ratio to default value 0.900")
|
2009-04-22 15:48:07 +04:00
|
|
|
conf.matchRatio = 0.900
|
|
|
|
|
2010-01-02 05:02:12 +03:00
|
|
|
if conf.matchRatio is not None:
|
2009-04-22 15:48:07 +04:00
|
|
|
setMatchRatio()
|
2009-02-09 13:28:03 +03:00
|
|
|
|
|
|
|
# If it has been requested to return the ratio and not a comparison
|
|
|
|
# response
|
2008-12-20 04:54:08 +03:00
|
|
|
if getSeqMatcher:
|
2009-02-09 13:28:03 +03:00
|
|
|
return ratio
|
|
|
|
|
|
|
|
# If the url is stable it returns True if the page has the same MD5
|
|
|
|
# hash of the original one
|
|
|
|
# NOTE: old implementation, it did not handle automatically the fact
|
|
|
|
# that the url could be not stable (due to VIEWSTATE, counter, etc.)
|
2010-01-02 05:02:12 +03:00
|
|
|
#elif conf.md5hash is not None:
|
2009-02-09 13:28:03 +03:00
|
|
|
# return conf.md5hash == md5hash(page)
|
|
|
|
|
|
|
|
# If the url is not stable it returns sequence matcher between the
|
|
|
|
# first untouched HTTP response page content and this content
|
2008-12-20 04:54:08 +03:00
|
|
|
else:
|
2010-05-14 18:21:13 +04:00
|
|
|
return ratio > conf.matchRatio
|