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

Skip to content

Commit ba6cac7

Browse files
committed
Socket pre-connect compatibility patch for DREI
1 parent 6faf987 commit ba6cac7

2 files changed

Lines changed: 16 additions & 22 deletions

File tree

lib/core/option.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ def _getaddrinfo(*args, **kwargs):
961961

962962
def _setSocketPreConnect():
963963
"""
964-
Makes a pre-connect version of socket.connect
964+
Makes a pre-connect version of socket.create_connection
965965
"""
966966

967967
if conf.disablePrecon:
@@ -972,36 +972,28 @@ def _thread():
972972
try:
973973
for key in socket._ready:
974974
if len(socket._ready[key]) < SOCKET_PRE_CONNECT_QUEUE_SIZE:
975-
family, type, proto, address = key
976-
s = socket.socket(family, type, proto)
977-
s._connect(address)
978-
try:
979-
if type == socket.SOCK_STREAM:
980-
# Reference: https://www.techrepublic.com/article/tcp-ip-options-for-high-performance-data-transmission/
981-
s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
982-
except:
983-
pass
975+
s = socket.create_connection(*key[0], **dict(key[1]))
984976
with kb.locks.socket:
985-
socket._ready[key].append((s._sock, time.time()))
977+
socket._ready[key].append((s, time.time()))
986978
except KeyboardInterrupt:
987979
break
988980
except:
989981
pass
990982
finally:
991983
time.sleep(0.01)
992984

993-
def connect(self, address):
994-
found = False
985+
def create_connection(*args, **kwargs):
986+
retVal = None
995987

996-
key = (self.family, self.type, self.proto, address)
988+
key = (tuple(args), frozenset(kwargs.items()))
997989
with kb.locks.socket:
998990
if key not in socket._ready:
999991
socket._ready[key] = []
992+
1000993
while len(socket._ready[key]) > 0:
1001994
candidate, created = socket._ready[key].pop(0)
1002995
if (time.time() - created) < PRECONNECT_CANDIDATE_TIMEOUT:
1003-
self._sock = candidate
1004-
found = True
996+
retVal = candidate
1005997
break
1006998
else:
1007999
try:
@@ -1010,13 +1002,15 @@ def connect(self, address):
10101002
except socket.error:
10111003
pass
10121004

1013-
if not found:
1014-
self._connect(address)
1005+
if not retVal:
1006+
retVal = socket._create_connection(*args, **kwargs)
1007+
1008+
return retVal
10151009

1016-
if not hasattr(socket.socket, "_connect"):
1010+
if not hasattr(socket.socket, "_create_connection"):
10171011
socket._ready = {}
1018-
socket.socket._connect = socket.socket.connect
1019-
socket.socket.connect = connect
1012+
socket._create_connection = socket.create_connection
1013+
socket.create_connection = create_connection
10201014

10211015
thread = threading.Thread(target=_thread)
10221016
setDaemon(thread)

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 import six
1919

2020
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
21-
VERSION = "1.3.5.44"
21+
VERSION = "1.3.5.45"
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)

0 commit comments

Comments
 (0)