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

Skip to content

Commit ca3e12a

Browse files
committed
added calculateDeltaSeconds method for dealing with non-deterministic time behaviour in some cases (e.g. WAITFOR DELAY in case of MSSQL)
1 parent 762781e commit ca3e12a

6 files changed

Lines changed: 16 additions & 8 deletions

File tree

lib/core/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,3 +1107,6 @@ def parseXmlFile(xmlFile, handler):
11071107
parse(stream, handler)
11081108
stream.close()
11091109
xfile.close()
1110+
1111+
def calculateDeltaSeconds(start, epsilon=0.05):
1112+
return int(time.time() - start + epsilon)

lib/request/inject.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import time
2727

2828
from lib.core.agent import agent
29+
from lib.core.common import calculateDeltaSeconds
2930
from lib.core.common import cleanQuery
3031
from lib.core.common import dataToSessionFile
3132
from lib.core.common import expandAsteriskForColumns
@@ -55,7 +56,7 @@ def __goInference(payload, expression, charsetType=None, firstChar=None, lastCha
5556

5657
count, value = bisection(payload, expression, length, charsetType, firstChar, lastChar)
5758

58-
debugMsg = "performed %d queries in %d seconds" % (count, int(time.time() - start))
59+
debugMsg = "performed %d queries in %d seconds" % (count, calculateDeltaSeconds(start))
5960
logger.debug(debugMsg)
6061

6162
return value

lib/techniques/blind/timebased.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import time
2626

2727
from lib.core.agent import agent
28+
from lib.core.common import calculateDeltaSeconds
2829
from lib.core.common import getDelayQuery
2930
from lib.core.data import conf
3031
from lib.core.data import kb
@@ -43,7 +44,7 @@ def timeTest():
4344
payload = agent.payload(newValue=query)
4445
start = time.time()
4546
_ = Request.queryPage(payload)
46-
duration = int(time.time() - start)
47+
duration = calculateDeltaSeconds(start)
4748

4849
if duration >= conf.timeSec:
4950
infoMsg = "the parameter '%s' is affected by a time " % kb.injParameter
@@ -64,7 +65,7 @@ def timeTest():
6465
timeQuery = getDelayQuery(andCond=True)
6566
start = time.time()
6667
payload, _ = inject.goStacked(timeQuery)
67-
duration = int(time.time() - start)
68+
duration = calculateDeltaSeconds(start)
6869

6970
if duration >= conf.timeSec:
7071
infoMsg = "the parameter '%s' is affected by a time " % kb.injParameter
@@ -84,6 +85,6 @@ def timeTest():
8485
def timeUse(query):
8586
start = time.time()
8687
_, _ = inject.goStacked(query)
87-
duration = int(time.time() - start)
88+
duration = calculateDeltaSeconds(start)
8889

8990
return duration

lib/techniques/inband/union/use.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import time
2727

2828
from lib.core.agent import agent
29+
from lib.core.common import calculateDeltaSeconds
2930
from lib.core.common import parseUnionPage
3031
from lib.core.data import conf
3132
from lib.core.data import kb
@@ -228,7 +229,7 @@ def unionUse(expression, direct=False, unescape=True, resetCounter=False, nullCh
228229
endPosition = resultPage.rindex(temp.stop) + len(temp.stop)
229230
value = str(resultPage[startPosition:endPosition])
230231

231-
duration = int(time.time() - start)
232+
duration = calculateDeltaSeconds(start)
232233

233234
debugMsg = "performed %d queries in %d seconds" % (reqCount, duration)
234235
logger.debug(debugMsg)

lib/techniques/outband/stacked.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import time
2626

27+
from lib.core.common import calculateDeltaSeconds
2728
from lib.core.common import getDelayQuery
2829
from lib.core.data import conf
2930
from lib.core.data import kb
@@ -45,7 +46,7 @@ def stackedTest():
4546
query = getDelayQuery()
4647
start = time.time()
4748
payload, _ = inject.goStacked(query)
48-
duration = int(time.time() - start)
49+
duration = calculateDeltaSeconds(start)
4950

5051
if duration >= conf.timeSec:
5152
infoMsg = "the web application supports stacked queries "

lib/utils/resume.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import re
2626
import time
2727

28+
from lib.core.common import calculateDeltaSeconds
2829
from lib.core.common import dataToSessionFile
2930
from lib.core.common import safeStringFormat
3031
from lib.core.common import randomStr
@@ -89,7 +90,7 @@ def queryOutputLength(expression, payload):
8990
lengthExprUnescaped = unescaper.unescape(lengthExpr)
9091
count, length = bisection(payload, lengthExprUnescaped, charsetType=2)
9192

92-
debugMsg = "performed %d queries in %d seconds" % (count, int(time.time() - start))
93+
debugMsg = "performed %d queries in %d seconds" % (count, calculateDeltaSeconds(start))
9394
logger.debug(debugMsg)
9495

9596
if length == " ":
@@ -186,7 +187,7 @@ def resume(expression, payload):
186187
start = time.time()
187188
count, finalValue = bisection(payload, newExpr, length=missingCharsLength)
188189

189-
debugMsg = "performed %d queries in %d seconds" % (count, int(time.time() - start))
190+
debugMsg = "performed %d queries in %d seconds" % (count, calculateDeltaSeconds(start))
190191
logger.debug(debugMsg)
191192

192193
if len(finalValue) != ( int(length) - len(resumedValue) ):

0 commit comments

Comments
 (0)