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

Skip to content

Commit 5097a2c

Browse files
committed
Less timeout error messages (because of server dropping of non-active connections)
1 parent bce9db1 commit 5097a2c

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

lib/core/option.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
from lib.core.settings import MAX_NUMBER_OF_THREADS
121121
from lib.core.settings import NULL
122122
from lib.core.settings import PARAMETER_SPLITTING_REGEX
123+
from lib.core.settings import PRECONNECT_CANDIDATE_TIMEOUT
123124
from lib.core.settings import PROBLEMATIC_CUSTOM_INJECTION_PATTERNS
124125
from lib.core.settings import SITE
125126
from lib.core.settings import SOCKET_PRE_CONNECT_QUEUE_SIZE
@@ -1039,7 +1040,7 @@ def _():
10391040
s = socket.socket(family, type, proto)
10401041
s._connect(address)
10411042
with kb.locks.socket:
1042-
socket._ready[key].append(s._sock)
1043+
socket._ready[key].append((s._sock, time.time()))
10431044
except KeyboardInterrupt:
10441045
break
10451046
except:
@@ -1054,9 +1055,17 @@ def connect(self, address):
10541055
with kb.locks.socket:
10551056
if key not in socket._ready:
10561057
socket._ready[key] = []
1057-
if len(socket._ready[key]) > 0:
1058-
self._sock = socket._ready[key].pop(0)
1059-
found = True
1058+
while len(socket._ready[key]) > 0:
1059+
candidate, created = socket._ready[key].pop(0)
1060+
if (time.time() - created) < PRECONNECT_CANDIDATE_TIMEOUT:
1061+
self._sock = candidate
1062+
found = True
1063+
break
1064+
else:
1065+
try:
1066+
candidate.close()
1067+
except socket.error:
1068+
pass
10601069

10611070
if not found:
10621071
self._connect(address)
@@ -2282,6 +2291,7 @@ def _setTorHttpProxySettings():
22822291
infoMsg = "setting Tor HTTP proxy settings"
22832292
logger.info(infoMsg)
22842293

2294+
s = None
22852295
found = None
22862296

22872297
for port in (DEFAULT_TOR_HTTP_PORTS if not conf.torPort else (conf.torPort,)):
@@ -2293,7 +2303,8 @@ def _setTorHttpProxySettings():
22932303
except socket.error:
22942304
pass
22952305

2296-
s.close()
2306+
if s:
2307+
s.close()
22972308

22982309
if found:
22992310
conf.proxy = "http://%s:%d" % (LOCALHOST, found)

lib/core/settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from lib.core.revision import getRevisionNumber
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.0.7.21"
22+
VERSION = "1.0.7.22"
2323
REVISION = getRevisionNumber()
2424
STABLE = VERSION.count('.') <= 2
2525
VERSION_STRING = "sqlmap/%s#%s" % (VERSION, "stable" if STABLE else "dev")
@@ -81,6 +81,9 @@
8181
# Regular expression used for recognition of generic maximum connection messages
8282
MAX_CONNECTIONS_REGEX = r"max.+connections"
8383

84+
# Timeout before the pre-connection candidate is being disposed (because of high probability that the web server will reset it)
85+
PRECONNECT_CANDIDATE_TIMEOUT = 10
86+
8487
# Regular expression used for extracting results from Google search
8588
GOOGLE_REGEX = r"webcache\.googleusercontent\.com/search\?q=cache:[^:]+:([^+]+)\+&amp;cd=|url\?\w+=((?![^>]+webcache\.googleusercontent\.com)http[^>]+)&(sa=U|rct=j)"
8689

0 commit comments

Comments
 (0)