Socket pre-connect compatibility patch for DREI

This commit is contained in:
Miroslav Stampar 2019-05-08 01:58:59 +02:00
parent 6faf9872bc
commit ba6cac75ac
2 changed files with 16 additions and 22 deletions

View File

@ -961,7 +961,7 @@ def _setDNSCache():
def _setSocketPreConnect(): def _setSocketPreConnect():
""" """
Makes a pre-connect version of socket.connect Makes a pre-connect version of socket.create_connection
""" """
if conf.disablePrecon: if conf.disablePrecon:
@ -972,17 +972,9 @@ def _setSocketPreConnect():
try: try:
for key in socket._ready: for key in socket._ready:
if len(socket._ready[key]) < SOCKET_PRE_CONNECT_QUEUE_SIZE: if len(socket._ready[key]) < SOCKET_PRE_CONNECT_QUEUE_SIZE:
family, type, proto, address = key s = socket.create_connection(*key[0], **dict(key[1]))
s = socket.socket(family, type, proto)
s._connect(address)
try:
if type == socket.SOCK_STREAM:
# Reference: https://www.techrepublic.com/article/tcp-ip-options-for-high-performance-data-transmission/
s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
except:
pass
with kb.locks.socket: with kb.locks.socket:
socket._ready[key].append((s._sock, time.time())) socket._ready[key].append((s, time.time()))
except KeyboardInterrupt: except KeyboardInterrupt:
break break
except: except:
@ -990,18 +982,18 @@ def _setSocketPreConnect():
finally: finally:
time.sleep(0.01) time.sleep(0.01)
def connect(self, address): def create_connection(*args, **kwargs):
found = False retVal = None
key = (self.family, self.type, self.proto, address) key = (tuple(args), frozenset(kwargs.items()))
with kb.locks.socket: with kb.locks.socket:
if key not in socket._ready: if key not in socket._ready:
socket._ready[key] = [] socket._ready[key] = []
while len(socket._ready[key]) > 0: while len(socket._ready[key]) > 0:
candidate, created = socket._ready[key].pop(0) candidate, created = socket._ready[key].pop(0)
if (time.time() - created) < PRECONNECT_CANDIDATE_TIMEOUT: if (time.time() - created) < PRECONNECT_CANDIDATE_TIMEOUT:
self._sock = candidate retVal = candidate
found = True
break break
else: else:
try: try:
@ -1010,13 +1002,15 @@ def _setSocketPreConnect():
except socket.error: except socket.error:
pass pass
if not found: if not retVal:
self._connect(address) retVal = socket._create_connection(*args, **kwargs)
if not hasattr(socket.socket, "_connect"): return retVal
if not hasattr(socket.socket, "_create_connection"):
socket._ready = {} socket._ready = {}
socket.socket._connect = socket.socket.connect socket._create_connection = socket.create_connection
socket.socket.connect = connect socket.create_connection = create_connection
thread = threading.Thread(target=_thread) thread = threading.Thread(target=_thread)
setDaemon(thread) setDaemon(thread)

View File

@ -18,7 +18,7 @@ from lib.core.enums import OS
from thirdparty import six from thirdparty import six
# sqlmap version (<major>.<minor>.<month>.<monthly commit>) # sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.3.5.44" VERSION = "1.3.5.45"
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)