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

Skip to content

Commit 01cf139

Browse files
committed
code refactoring
1 parent af22679 commit 01cf139

4 files changed

Lines changed: 18 additions & 38 deletions

File tree

lib/core/common.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,17 @@ def wasLastRequestDBMSError():
15321532
Returns True if the last web request resulted in a (recognized) DBMS error page
15331533
"""
15341534

1535-
return kb.lastErrorPage and kb.lastErrorPage[0]==kb.lastRequestUID
1535+
return kb.lastErrorPage and kb.lastErrorPage[0] == kb.lastRequestUID
1536+
1537+
def wasLastRequestDelayed():
1538+
"""
1539+
Returns True if the last web request resulted in a time-delay
1540+
"""
1541+
1542+
# 99.9999999997440% of all non time-based sql injection
1543+
# affected durations should be inside +-7*stdev(durations)
1544+
# (Math reference: http://www.answers.com/topic/standard-deviation)
1545+
return (kb.lastQueryDuration >= average(kb.responseTimes) + 7 * stdev(kb.responseTimes))
15361546

15371547
def extractErrorMessage(page):
15381548
"""

lib/request/connect.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from lib.core.common import logHTTPTraffic
2626
from lib.core.common import readInput
2727
from lib.core.common import stdev
28+
from lib.core.common import wasLastRequestDelayed
2829
from lib.core.convert import urlencode
2930
from lib.core.common import urlEncodeCookieValues
3031
from lib.core.data import conf
@@ -420,10 +421,7 @@ def queryPage(value=None, place=None, content=False, getSeqMatcher=False, silent
420421
conf.cj.clear()
421422

422423
if timeBasedCompare:
423-
# 99.9999999997440% of all non time-based sql injection
424-
# affected durations should be inside +-7*stdev(durations)
425-
# (Reference: http://www.answers.com/topic/standard-deviation)
426-
return (kb.lastQueryDuration >= average(kb.responseTimes) + 7 * stdev(kb.responseTimes))
424+
return wasLastRequestDelayed()
427425
else:
428426
kb.responseTimes.append(kb.lastQueryDuration)
429427

lib/takeover/xp_cmdshell.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
from lib.core.common import randomStr
1111
from lib.core.common import readInput
12+
from lib.core.common import wasLastRequestDelayed
1213
from lib.core.data import conf
1314
from lib.core.data import kb
1415
from lib.core.data import logger
1516
from lib.core.exception import sqlmapUnsupportedFeatureException
1617
from lib.core.unescaper import unescaper
1718
from lib.request import inject
18-
from lib.techniques.blind.timebased import timeUse
1919

2020
class xp_cmdshell:
2121
"""
@@ -88,13 +88,11 @@ def __xpCmdshellConfigure(self, mode):
8888
inject.goStacked(cmd)
8989

9090
def __xpCmdshellCheck(self):
91-
query = self.xpCmdshellForgeCmd("ping -n %d 127.0.0.1" % (conf.timeSec * 2))
92-
duration = timeUse(query)
91+
cmd = self.xpCmdshellForgeCmd("ping -n %d 127.0.0.1" % (conf.timeSec * 2))
9392

94-
if duration >= conf.timeSec:
95-
return True
96-
else:
97-
return False
93+
inject.goStacked(cmd)
94+
95+
return wasLastRequestDelayed()
9896

9997
def xpCmdshellForgeCmd(self, cmd):
10098
self.__randStr = randomStr(lowercase=True)

lib/techniques/blind/timebased.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)