From 814d7103205f76b08c001752b3dd04ea66042150 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Fri, 8 Apr 2016 14:41:34 +0200 Subject: [PATCH] Minor speed up --- lib/core/common.py | 29 ++++++++++++++++++----------- lib/core/defaults.py | 1 - lib/core/option.py | 4 ---- lib/core/optiondict.py | 1 - lib/core/settings.py | 2 +- lib/core/threads.py | 2 ++ lib/parse/cmdline.py | 3 --- lib/request/connect.py | 3 --- 8 files changed, 21 insertions(+), 24 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index c7673ca16..21ffc015d 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -968,7 +968,12 @@ def randomRange(start=0, stop=1000, seed=None): 423 """ - randint = random.WichmannHill(seed).randint if seed is not None else random.randint + if seed is not None: + _ = getCurrentThreadData().random + _.seed(seed) + randint = _.randint + else: + randint = random.randint return int(randint(start, stop)) @@ -981,7 +986,12 @@ def randomInt(length=4, seed=None): 874254 """ - choice = random.WichmannHill(seed).choice if seed is not None else random.choice + if seed is not None: + _ = getCurrentThreadData().random + _.seed(seed) + choice = _.choice + else: + choice = random.choice return int("".join(choice(string.digits if _ != 0 else string.digits.replace('0', '')) for _ in xrange(0, length))) @@ -994,7 +1004,12 @@ def randomStr(length=4, lowercase=False, alphabet=None, seed=None): 'RNvnAv' """ - choice = random.WichmannHill(seed).choice if seed is not None else random.choice + if seed is not None: + _ = getCurrentThreadData().random + _.seed(seed) + choice = _.choice + else: + choice = random.choice if alphabet: retVal = "".join(choice(alphabet) for _ in xrange(0, length)) @@ -3147,14 +3162,6 @@ def intersect(valueA, valueB, lowerCase=False): return retVal -def cpuThrottle(value): - """ - Does a CPU throttling for lesser CPU consumption - """ - - delay = 0.00001 * (value ** 2) - time.sleep(delay) - def removeReflectiveValues(content, payload, suppressWarning=False): """ Neutralizes reflective values in a given content based on a payload diff --git a/lib/core/defaults.py b/lib/core/defaults.py index 99674aa1e..e8a78d7ac 100644 --- a/lib/core/defaults.py +++ b/lib/core/defaults.py @@ -11,7 +11,6 @@ _defaults = { "csvDel": ",", "timeSec": 5, "googlePage": 1, - "cpuThrottle": 5, "verbose": 1, "delay": 0, "timeout": 30, diff --git a/lib/core/option.py b/lib/core/option.py index 935bbee8d..00317cf48 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -2331,10 +2331,6 @@ def _basicOptionValidation(): errMsg = "value for option '--first' (firstChar) must be smaller than or equal to value for --last (lastChar) option" raise SqlmapSyntaxException(errMsg) - if isinstance(conf.cpuThrottle, int) and (conf.cpuThrottle > 100 or conf.cpuThrottle < 0): - errMsg = "value for option '--cpu-throttle' (cpuThrottle) must be in range [0,100]" - raise SqlmapSyntaxException(errMsg) - if conf.textOnly and conf.nullConnection: errMsg = "switch '--text-only' is incompatible with switch '--null-connection'" raise SqlmapSyntaxException(errMsg) diff --git a/lib/core/optiondict.py b/lib/core/optiondict.py index dd08bd744..1689f4be3 100644 --- a/lib/core/optiondict.py +++ b/lib/core/optiondict.py @@ -230,7 +230,6 @@ optDict = { "disablePrecon": "boolean", "binaryFields": "string", "profile": "boolean", - "cpuThrottle": "integer", "forceDns": "boolean", "identifyWaf": "boolean", "skipWaf": "boolean", diff --git a/lib/core/settings.py b/lib/core/settings.py index 93bb863f4..c1db4925c 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -20,7 +20,7 @@ from lib.core.enums import OS from lib.core.revision import getRevisionNumber # sqlmap version (...) -VERSION = "1.0.4.10" +VERSION = "1.0.4.11" REVISION = getRevisionNumber() STABLE = VERSION.count('.') <= 2 VERSION_STRING = "sqlmap/%s#%s" % (VERSION, "stable" if STABLE else "dev") diff --git a/lib/core/threads.py b/lib/core/threads.py index 5ddfb263c..f2dcd6b86 100644 --- a/lib/core/threads.py +++ b/lib/core/threads.py @@ -6,6 +6,7 @@ See the file 'doc/COPYING' for copying permission """ import difflib +import random import threading import time import traceback @@ -51,6 +52,7 @@ class _ThreadData(threading.local): self.lastRequestMsg = None self.lastRequestUID = 0 self.lastRedirectURL = None + self.random = random.WichmannHill() self.resumed = False self.retriesCount = 0 self.seqMatcher = difflib.SequenceMatcher(None) diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index 363fb517d..2d367e9fd 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -763,9 +763,6 @@ def cmdLineParser(argv=None): parser.add_option("--binary-fields", dest="binaryFields", help=SUPPRESS_HELP) - parser.add_option("--cpu-throttle", dest="cpuThrottle", type="int", - help=SUPPRESS_HELP) - parser.add_option("--force-dns", dest="forceDns", action="store_true", help=SUPPRESS_HELP) diff --git a/lib/request/connect.py b/lib/request/connect.py index c5d2eceb1..c310be00d 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -32,7 +32,6 @@ from lib.core.agent import agent from lib.core.common import asciifyUrl from lib.core.common import calculateDeltaSeconds from lib.core.common import clearConsoleLine -from lib.core.common import cpuThrottle from lib.core.common import dataToStdout from lib.core.common import evaluateCode from lib.core.common import extractRegexResult @@ -220,8 +219,6 @@ class Connect(object): if isinstance(conf.delay, (int, float)) and conf.delay > 0: time.sleep(conf.delay) - elif conf.cpuThrottle: - cpuThrottle(conf.cpuThrottle) if conf.offline: return None, None, None