mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-02-03 21:24:13 +03:00
Minor refactoring
This commit is contained in:
parent
c71bdf5c9e
commit
a989e1abfe
|
@ -6,6 +6,7 @@ See the file 'LICENSE' for copying permission
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import codecs
|
import codecs
|
||||||
|
import random
|
||||||
|
|
||||||
import lib.controller.checks
|
import lib.controller.checks
|
||||||
import lib.core.common
|
import lib.core.common
|
||||||
|
@ -25,6 +26,7 @@ from lib.core.common import isListLike
|
||||||
from lib.core.common import readInput
|
from lib.core.common import readInput
|
||||||
from lib.core.common import shellExec
|
from lib.core.common import shellExec
|
||||||
from lib.core.common import singleTimeWarnMessage
|
from lib.core.common import singleTimeWarnMessage
|
||||||
|
from lib.core.compat import xrange
|
||||||
from lib.core.convert import stdoutEncode
|
from lib.core.convert import stdoutEncode
|
||||||
from lib.core.data import conf
|
from lib.core.data import conf
|
||||||
from lib.core.option import _setHTTPHandlers
|
from lib.core.option import _setHTTPHandlers
|
||||||
|
@ -46,6 +48,7 @@ def dirtyPatches():
|
||||||
if six.PY3:
|
if six.PY3:
|
||||||
if not hasattr(_http_client.HTTPConnection, "__send_output"):
|
if not hasattr(_http_client.HTTPConnection, "__send_output"):
|
||||||
_http_client.HTTPConnection.__send_output = _http_client.HTTPConnection._send_output
|
_http_client.HTTPConnection.__send_output = _http_client.HTTPConnection._send_output
|
||||||
|
|
||||||
def _send_output(self, *args, **kwargs):
|
def _send_output(self, *args, **kwargs):
|
||||||
if conf.chunked and "encode_chunked" in kwargs:
|
if conf.chunked and "encode_chunked" in kwargs:
|
||||||
kwargs["encode_chunked"] = False
|
kwargs["encode_chunked"] = False
|
||||||
|
@ -100,3 +103,35 @@ def pympTempLeakPatch(tempDir):
|
||||||
multiprocessing.util.get_temp_dir = lambda: tempDir
|
multiprocessing.util.get_temp_dir = lambda: tempDir
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def unisonRandom():
|
||||||
|
"""
|
||||||
|
Unifying random generated data across different Python versions
|
||||||
|
"""
|
||||||
|
|
||||||
|
def _lcg():
|
||||||
|
global _rand
|
||||||
|
a = 1140671485
|
||||||
|
c = 128201163
|
||||||
|
m = 2 ** 24
|
||||||
|
_rand = (a * _rand + c) % m
|
||||||
|
return _rand
|
||||||
|
|
||||||
|
def _randint(a, b):
|
||||||
|
_ = a + (_lcg() % (b - a + 1))
|
||||||
|
return _
|
||||||
|
|
||||||
|
def _choice(seq):
|
||||||
|
return seq[_randint(0, len(seq) - 1)]
|
||||||
|
|
||||||
|
def _sample(population, k):
|
||||||
|
return [_choice(population) for _ in xrange(k)]
|
||||||
|
|
||||||
|
def _seed(seed):
|
||||||
|
global _rand
|
||||||
|
_rand = seed
|
||||||
|
|
||||||
|
random.choice = _choice
|
||||||
|
random.randint = _randint
|
||||||
|
random.sample = _sample
|
||||||
|
random.seed = _seed
|
||||||
|
|
|
@ -18,7 +18,7 @@ from lib.core.enums import OS
|
||||||
from thirdparty.six import unichr as _unichr
|
from thirdparty.six import unichr as _unichr
|
||||||
|
|
||||||
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
|
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
|
||||||
VERSION = "1.4.2.16"
|
VERSION = "1.4.2.17"
|
||||||
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
|
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
|
||||||
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
|
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
|
||||||
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
|
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
|
||||||
|
|
|
@ -33,6 +33,7 @@ from lib.core.data import kb
|
||||||
from lib.core.data import logger
|
from lib.core.data import logger
|
||||||
from lib.core.data import paths
|
from lib.core.data import paths
|
||||||
from lib.core.data import queries
|
from lib.core.data import queries
|
||||||
|
from lib.core.patch import unisonRandom
|
||||||
|
|
||||||
_rand = 0
|
_rand = 0
|
||||||
|
|
||||||
|
@ -201,44 +202,12 @@ def fuzzTest():
|
||||||
|
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
def dirtyPatchRandom():
|
|
||||||
"""
|
|
||||||
Unifying random generated data across different Python versions
|
|
||||||
"""
|
|
||||||
|
|
||||||
def _lcg():
|
|
||||||
global _rand
|
|
||||||
a = 1140671485
|
|
||||||
c = 128201163
|
|
||||||
m = 2 ** 24
|
|
||||||
_rand = (a * _rand + c) % m
|
|
||||||
return _rand
|
|
||||||
|
|
||||||
def _randint(a, b):
|
|
||||||
_ = a + (_lcg() % (b - a + 1))
|
|
||||||
return _
|
|
||||||
|
|
||||||
def _choice(seq):
|
|
||||||
return seq[_randint(0, len(seq) - 1)]
|
|
||||||
|
|
||||||
def _sample(population, k):
|
|
||||||
return [_choice(population) for _ in xrange(k)]
|
|
||||||
|
|
||||||
def _seed(seed):
|
|
||||||
global _rand
|
|
||||||
_rand = seed
|
|
||||||
|
|
||||||
random.choice = _choice
|
|
||||||
random.randint = _randint
|
|
||||||
random.sample = _sample
|
|
||||||
random.seed = _seed
|
|
||||||
|
|
||||||
def smokeTest():
|
def smokeTest():
|
||||||
"""
|
"""
|
||||||
Runs the basic smoke testing of a program
|
Runs the basic smoke testing of a program
|
||||||
"""
|
"""
|
||||||
|
|
||||||
dirtyPatchRandom()
|
unisonRandom()
|
||||||
|
|
||||||
content = open(paths.ERRORS_XML, "r").read()
|
content = open(paths.ERRORS_XML, "r").read()
|
||||||
for regex in re.findall(r'<error regexp="(.+?)"/>', content):
|
for regex in re.findall(r'<error regexp="(.+?)"/>', content):
|
||||||
|
|
|
@ -49,16 +49,16 @@ class DNSQuery(object):
|
||||||
retVal = b""
|
retVal = b""
|
||||||
|
|
||||||
if self._query:
|
if self._query:
|
||||||
retVal += self._raw[:2] # Transaction ID
|
retVal += self._raw[:2] # Transaction ID
|
||||||
retVal += b"\x85\x80" # Flags (Standard query response, No error)
|
retVal += b"\x85\x80" # Flags (Standard query response, No error)
|
||||||
retVal += self._raw[4:6] + self._raw[4:6] + b"\x00\x00\x00\x00" # Questions and Answers Counts
|
retVal += self._raw[4:6] + self._raw[4:6] + b"\x00\x00\x00\x00" # Questions and Answers Counts
|
||||||
retVal += self._raw[12:(12 + self._raw[12:].find(b"\x00") + 5)] # Original Domain Name Query
|
retVal += self._raw[12:(12 + self._raw[12:].find(b"\x00") + 5)] # Original Domain Name Query
|
||||||
retVal += b"\xc0\x0c" # Pointer to domain name
|
retVal += b"\xc0\x0c" # Pointer to domain name
|
||||||
retVal += b"\x00\x01" # Type A
|
retVal += b"\x00\x01" # Type A
|
||||||
retVal += b"\x00\x01" # Class IN
|
retVal += b"\x00\x01" # Class IN
|
||||||
retVal += b"\x00\x00\x00\x20" # TTL (32 seconds)
|
retVal += b"\x00\x00\x00\x20" # TTL (32 seconds)
|
||||||
retVal += b"\x00\x04" # Data length
|
retVal += b"\x00\x04" # Data length
|
||||||
retVal += b"".join(struct.pack('B', int(_)) for _ in resolution.split('.')) # 4 bytes of IP
|
retVal += b"".join(struct.pack('B', int(_)) for _ in resolution.split('.')) # 4 bytes of IP
|
||||||
|
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ class DNSServer(object):
|
||||||
|
|
||||||
with self._lock:
|
with self._lock:
|
||||||
for _ in self._requests:
|
for _ in self._requests:
|
||||||
if prefix is None and suffix is None or re.search(b"%s\..+\.%s" % (prefix, suffix), _, re.I):
|
if prefix is None and suffix is None or re.search(b"%s\\..+\\.%s" % (prefix, suffix), _, re.I):
|
||||||
retVal = _
|
retVal = _
|
||||||
self._requests.remove(_)
|
self._requests.remove(_)
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue
Block a user