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

Skip to content

Commit a989e1a

Browse files
committed
Minor refactoring
1 parent c71bdf5 commit a989e1a

4 files changed

Lines changed: 49 additions & 45 deletions

File tree

lib/core/patch.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import codecs
9+
import random
910

1011
import lib.controller.checks
1112
import lib.core.common
@@ -25,6 +26,7 @@
2526
from lib.core.common import readInput
2627
from lib.core.common import shellExec
2728
from lib.core.common import singleTimeWarnMessage
29+
from lib.core.compat import xrange
2830
from lib.core.convert import stdoutEncode
2931
from lib.core.data import conf
3032
from lib.core.option import _setHTTPHandlers
@@ -46,6 +48,7 @@ def dirtyPatches():
4648
if six.PY3:
4749
if not hasattr(_http_client.HTTPConnection, "__send_output"):
4850
_http_client.HTTPConnection.__send_output = _http_client.HTTPConnection._send_output
51+
4952
def _send_output(self, *args, **kwargs):
5053
if conf.chunked and "encode_chunked" in kwargs:
5154
kwargs["encode_chunked"] = False
@@ -100,3 +103,35 @@ def pympTempLeakPatch(tempDir):
100103
multiprocessing.util.get_temp_dir = lambda: tempDir
101104
except:
102105
pass
106+
107+
def unisonRandom():
108+
"""
109+
Unifying random generated data across different Python versions
110+
"""
111+
112+
def _lcg():
113+
global _rand
114+
a = 1140671485
115+
c = 128201163
116+
m = 2 ** 24
117+
_rand = (a * _rand + c) % m
118+
return _rand
119+
120+
def _randint(a, b):
121+
_ = a + (_lcg() % (b - a + 1))
122+
return _
123+
124+
def _choice(seq):
125+
return seq[_randint(0, len(seq) - 1)]
126+
127+
def _sample(population, k):
128+
return [_choice(population) for _ in xrange(k)]
129+
130+
def _seed(seed):
131+
global _rand
132+
_rand = seed
133+
134+
random.choice = _choice
135+
random.randint = _randint
136+
random.sample = _sample
137+
random.seed = _seed

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from thirdparty.six import unichr as _unichr
1919

2020
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
21-
VERSION = "1.4.2.16"
21+
VERSION = "1.4.2.17"
2222
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2323
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2424
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

lib/core/testing.py

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from lib.core.data import logger
3434
from lib.core.data import paths
3535
from lib.core.data import queries
36+
from lib.core.patch import unisonRandom
3637

3738
_rand = 0
3839

@@ -201,44 +202,12 @@ def _thread():
201202

202203
count += 1
203204

204-
def dirtyPatchRandom():
205-
"""
206-
Unifying random generated data across different Python versions
207-
"""
208-
209-
def _lcg():
210-
global _rand
211-
a = 1140671485
212-
c = 128201163
213-
m = 2 ** 24
214-
_rand = (a * _rand + c) % m
215-
return _rand
216-
217-
def _randint(a, b):
218-
_ = a + (_lcg() % (b - a + 1))
219-
return _
220-
221-
def _choice(seq):
222-
return seq[_randint(0, len(seq) - 1)]
223-
224-
def _sample(population, k):
225-
return [_choice(population) for _ in xrange(k)]
226-
227-
def _seed(seed):
228-
global _rand
229-
_rand = seed
230-
231-
random.choice = _choice
232-
random.randint = _randint
233-
random.sample = _sample
234-
random.seed = _seed
235-
236205
def smokeTest():
237206
"""
238207
Runs the basic smoke testing of a program
239208
"""
240209

241-
dirtyPatchRandom()
210+
unisonRandom()
242211

243212
content = open(paths.ERRORS_XML, "r").read()
244213
for regex in re.findall(r'<error regexp="(.+?)"/>', content):

lib/request/dns.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ def response(self, resolution):
4949
retVal = b""
5050

5151
if self._query:
52-
retVal += self._raw[:2] # Transaction ID
53-
retVal += b"\x85\x80" # Flags (Standard query response, No error)
54-
retVal += self._raw[4:6] + self._raw[4:6] + b"\x00\x00\x00\x00" # Questions and Answers Counts
55-
retVal += self._raw[12:(12 + self._raw[12:].find(b"\x00") + 5)] # Original Domain Name Query
56-
retVal += b"\xc0\x0c" # Pointer to domain name
57-
retVal += b"\x00\x01" # Type A
58-
retVal += b"\x00\x01" # Class IN
59-
retVal += b"\x00\x00\x00\x20" # TTL (32 seconds)
60-
retVal += b"\x00\x04" # Data length
61-
retVal += b"".join(struct.pack('B', int(_)) for _ in resolution.split('.')) # 4 bytes of IP
52+
retVal += self._raw[:2] # Transaction ID
53+
retVal += b"\x85\x80" # Flags (Standard query response, No error)
54+
retVal += self._raw[4:6] + self._raw[4:6] + b"\x00\x00\x00\x00" # Questions and Answers Counts
55+
retVal += self._raw[12:(12 + self._raw[12:].find(b"\x00") + 5)] # Original Domain Name Query
56+
retVal += b"\xc0\x0c" # Pointer to domain name
57+
retVal += b"\x00\x01" # Type A
58+
retVal += b"\x00\x01" # Class IN
59+
retVal += b"\x00\x00\x00\x20" # TTL (32 seconds)
60+
retVal += b"\x00\x04" # Data length
61+
retVal += b"".join(struct.pack('B', int(_)) for _ in resolution.split('.')) # 4 bytes of IP
6262

6363
return retVal
6464

@@ -114,7 +114,7 @@ def pop(self, prefix=None, suffix=None):
114114

115115
with self._lock:
116116
for _ in self._requests:
117-
if prefix is None and suffix is None or re.search(b"%s\..+\.%s" % (prefix, suffix), _, re.I):
117+
if prefix is None and suffix is None or re.search(b"%s\\..+\\.%s" % (prefix, suffix), _, re.I):
118118
retVal = _
119119
self._requests.remove(_)
120120
break

0 commit comments

Comments
 (0)