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

Skip to content

Commit 9ffa928

Browse files
committed
added some user interaction when page is dynamic
1 parent b748e6e commit 9ffa928

5 files changed

Lines changed: 65 additions & 6 deletions

File tree

lib/controller/checks.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@
2626
import socket
2727
import time
2828

29+
from difflib import SequenceMatcher
30+
2931
from lib.core.agent import agent
3032
from lib.core.common import getUnicode
3133
from lib.core.common import preparePageForLineComparison
3234
from lib.core.common import randomInt
3335
from lib.core.common import randomStr
3436
from lib.core.common import readInput
37+
from lib.core.common import showStaticWords
3538
from lib.core.common import DynamicContentItem
3639
from lib.core.convert import md5hash
3740
from lib.core.data import conf
@@ -41,6 +44,7 @@
4144
from lib.core.exception import sqlmapConnectionException
4245
from lib.core.exception import sqlmapNoneDataException
4346
from lib.core.exception import sqlmapUserQuitException
47+
from lib.core.exception import sqlmapSilentQuitException
4448
from lib.core.session import setString
4549
from lib.core.session import setRegexp
4650
from lib.request.connect import Connect as Request
@@ -251,13 +255,28 @@ def checkStability():
251255
warnMsg += "manual paragraph 'Page comparison' and provide a "
252256
warnMsg += "string or regular expression to match on"
253257
logger.warn(warnMsg)
254-
255-
message = "do you still want to continue (possible BAD results)? [Y/n] "
256-
test = readInput(message, default="Y")
257-
if test and test[0] not in ("y", "Y"):
258-
raise sqlmapUserQuitException
259258

260-
checkDynamicContent(firstPage, secondPage)
259+
message = "how do you want to proceed? [C(ontinue)/s(tring)/r(egex)/q(uit)] "
260+
test = readInput(message, default="C")
261+
if test and test[0] in ("q", "Q"):
262+
raise sqlmapUserQuitException
263+
elif test and test[0] in ("s", "S"):
264+
showStaticWords(firstPage, secondPage)
265+
message = "please enter value for parameter 'string': "
266+
test = readInput(message)
267+
if test:
268+
conf.string = test
269+
else:
270+
raise sqlmapSilentQuitException
271+
elif test and test[0] in ("r", "R"):
272+
message = "please enter value for parameter 'regex': "
273+
test = readInput(message)
274+
if test:
275+
conf.regex = test
276+
else:
277+
raise sqlmapSilentQuitException
278+
else:
279+
checkDynamicContent(firstPage, secondPage)
261280

262281
return condition
263282

lib/controller/controller.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from lib.core.data import logger
4141
from lib.core.exception import exceptionsTuple
4242
from lib.core.exception import sqlmapNotVulnerableException
43+
from lib.core.exception import sqlmapSilentQuitException
4344
from lib.core.exception import sqlmapUserQuitException
4445
from lib.core.session import setInjection
4546
from lib.core.target import initTargetEnv
@@ -286,6 +287,9 @@ def start():
286287
checkForParenthesis()
287288
action()
288289

290+
except sqlmapSilentQuitException:
291+
raise
292+
289293
except sqlmapUserQuitException:
290294
raise
291295

lib/core/common.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from ConfigParser import DEFAULTSECT
4040
from ConfigParser import RawConfigParser
4141
from StringIO import StringIO
42+
from difflib import SequenceMatcher
4243
from subprocess import PIPE
4344
from subprocess import Popen as execute
4445
from tempfile import NamedTemporaryFile
@@ -1124,6 +1125,33 @@ def preparePageForLineComparison(page):
11241125
return page.replace("><", ">\n<").replace("<br>", "\n").splitlines()
11251126
return retVal
11261127

1128+
def getFilteredPageContent(page):
1129+
retVal = page
1130+
if isinstance(page, basestring):
1131+
retVal = re.sub(r"(?s)<script.+?</script>|<style.+?</style>|<[^>]+>|\t|\n|\r", "", page)
1132+
return retVal
1133+
1134+
def getPageTextWordsSet(page):
1135+
retVal = None
1136+
if isinstance(page, basestring):
1137+
page = getFilteredPageContent(page)
1138+
retVal = set(re.findall(r"\w+", page))
1139+
return retVal
1140+
1141+
def showStaticWords(firstPage, secondPage):
1142+
infoMsg = "finding static words in longest matching part of dynamic page content"
1143+
logger.info(infoMsg)
1144+
firstPage = getFilteredPageContent(firstPage)
1145+
secondPage = getFilteredPageContent(secondPage)
1146+
match = SequenceMatcher(None, firstPage, secondPage).find_longest_match(0, len(firstPage), 0, len(secondPage))
1147+
commonText = firstPage[match[0]:match[0]+match[2]]
1148+
commonWords = getPageTextWordsSet(commonText)
1149+
infoMsg = "static words: "
1150+
for word in commonWords:
1151+
if len(word) > 2:
1152+
infoMsg += "'%s', " % word
1153+
logger.info(infoMsg)
1154+
11271155
def decloakToNamedTemporaryFile(filepath, name=None):
11281156
retVal = NamedTemporaryFile()
11291157

lib/core/exception.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class sqlmapNoneDataException(Exception):
5555
class sqlmapNotVulnerableException(Exception):
5656
pass
5757

58+
class sqlmapSilentQuitException(Exception):
59+
pass
60+
5861
class sqlmapUserQuitException(Exception):
5962
pass
6063

@@ -96,6 +99,7 @@ def unhandledException():
9699
sqlmapMissingDependence,
97100
sqlmapMissingMandatoryOptionException,
98101
sqlmapNoneDataException,
102+
sqlmapSilentQuitException,
99103
sqlmapUserQuitException,
100104
sqlmapRegExprException,
101105
sqlmapSyntaxException,

sqlmap.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
from lib.core.data import logger
5252
from lib.core.data import paths
5353
from lib.core.exception import exceptionsTuple
54+
from lib.core.exception import sqlmapSilentQuitException
5455
from lib.core.exception import sqlmapUserQuitException
5556
from lib.core.exception import unhandledException
5657
from lib.core.option import init
@@ -100,6 +101,9 @@ def main():
100101
logger.error(errMsg)
101102
closeDumper(False, errMsg)
102103

104+
except sqlmapSilentQuitException:
105+
closeDumper(False)
106+
103107
except exceptionsTuple, e:
104108
e = getUnicode(e)
105109
logger.critical(e)

0 commit comments

Comments
 (0)