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

Skip to content

Commit d3a08a2

Browse files
committed
Implementation for an Issue #2505
1 parent ee5b5cd commit d3a08a2

8 files changed

Lines changed: 53 additions & 10 deletions

File tree

lib/controller/checks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
from lib.core.exception import SqlmapSilentQuitException
6666
from lib.core.exception import SqlmapUserQuitException
6767
from lib.core.settings import CANDIDATE_SENTENCE_MIN_LENGTH
68+
from lib.core.settings import CHECK_INTERNET_ADDRESS
69+
from lib.core.settings import CHECK_INTERNET_VALUE
6870
from lib.core.settings import DEFAULT_GET_POST_DELIMITER
6971
from lib.core.settings import DUMMY_NON_SQLI_CHECK_APPENDIX
7072
from lib.core.settings import FI_ERROR_REGEX
@@ -1501,6 +1503,10 @@ def checkConnection(suppressOutput=False):
15011503

15021504
return True
15031505

1506+
def checkInternet():
1507+
content = Request.getPage(url=CHECK_INTERNET_ADDRESS, checking=True)[0]
1508+
return CHECK_INTERNET_VALUE in (content or "")
1509+
15041510
def setVerbosity(): # Cross-linked function
15051511
raise NotImplementedError
15061512

lib/controller/controller.py

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

88
import os
99
import re
10+
import time
1011

1112
from lib.controller.action import action
1213
from lib.controller.checks import checkSqlInjection
@@ -15,6 +16,7 @@
1516
from lib.controller.checks import checkString
1617
from lib.controller.checks import checkRegexp
1718
from lib.controller.checks import checkConnection
19+
from lib.controller.checks import checkInternet
1820
from lib.controller.checks import checkNullConnection
1921
from lib.controller.checks import checkWaf
2022
from lib.controller.checks import heuristicCheckSqlInjection
@@ -276,6 +278,21 @@ def start():
276278

277279
for targetUrl, targetMethod, targetData, targetCookie, targetHeaders in kb.targets:
278280
try:
281+
282+
if conf.checkInternet:
283+
infoMsg = "[INFO] checking for Internet connection"
284+
logger.info(infoMsg)
285+
286+
if not checkInternet():
287+
warnMsg = "[%s] [WARNING] no connection detected" % time.strftime("%X")
288+
dataToStdout(warnMsg)
289+
290+
while not checkInternet():
291+
dataToStdout('.')
292+
time.sleep(5)
293+
294+
dataToStdout("\n")
295+
279296
conf.url = targetUrl
280297
conf.method = targetMethod.upper() if targetMethod else targetMethod
281298
conf.data = targetData

lib/core/optiondict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
"batch": "boolean",
197197
"binaryFields": "string",
198198
"charset": "string",
199+
"checkInternet": "boolean",
199200
"crawlDepth": "integer",
200201
"crawlExclude": "string",
201202
"csvDel": "string",

lib/core/settings.py

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

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.1.5.4"
22+
VERSION = "1.1.5.5"
2323
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2424
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2525
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
@@ -490,6 +490,12 @@
490490
# Data inside shellcodeexec to be filled with random string
491491
SHELLCODEEXEC_RANDOM_STRING_MARKER = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
492492

493+
# Generic address for checking the Internet connection while using switch --check-internet
494+
CHECK_INTERNET_ADDRESS = "http://ipinfo.io/"
495+
496+
# Value to look for in response to CHECK_INTERNET_ADDRESS
497+
CHECK_INTERNET_VALUE = "IP Address Details"
498+
493499
# Vectors used for provoking specific WAF/IPS/IDS behavior(s)
494500
WAF_ATTACK_VECTORS = (
495501
"", # NIL

lib/parse/cmdline.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,10 @@ def cmdLineParser(argv=None):
637637
general.add_option("--charset", dest="charset",
638638
help="Force character encoding used for data retrieval")
639639

640+
general.add_option("--check-internet", dest="checkInternet",
641+
action="store_true",
642+
help="Check Internet connection before assessing the target")
643+
640644
general.add_option("--crawl", dest="crawlDepth", type="int",
641645
help="Crawl the website starting from the target URL")
642646

lib/request/connect.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ def getPage(**kwargs):
257257
refreshing = kwargs.get("refreshing", False)
258258
retrying = kwargs.get("retrying", False)
259259
crawling = kwargs.get("crawling", False)
260+
checking = kwargs.get("checking", False)
260261
skipRead = kwargs.get("skipRead", False)
261262

262263
if multipart:
@@ -284,7 +285,7 @@ def getPage(**kwargs):
284285

285286
_ = urlparse.urlsplit(url)
286287
requestMsg = u"HTTP request [#%d]:\n%s " % (threadData.lastRequestUID, method or (HTTPMETHOD.POST if post is not None else HTTPMETHOD.GET))
287-
requestMsg += ("%s%s" % (_.path or "/", ("?%s" % _.query) if _.query else "")) if not any((refreshing, crawling)) else url
288+
requestMsg += ("%s%s" % (_.path or "/", ("?%s" % _.query) if _.query else "")) if not any((refreshing, crawling, checking)) else url
288289
responseMsg = u"HTTP response "
289290
requestHeaders = u""
290291
responseHeaders = None
@@ -306,7 +307,7 @@ def getPage(**kwargs):
306307
params = urlencode(params)
307308
url = "%s?%s" % (url, params)
308309

309-
elif any((refreshing, crawling)):
310+
elif any((refreshing, crawling, checking)):
310311
pass
311312

312313
elif target:
@@ -544,6 +545,9 @@ class _(dict):
544545
page = None
545546
responseHeaders = None
546547

548+
if checking:
549+
return None, None, None
550+
547551
try:
548552
page = ex.read() if not skipRead else None
549553
responseHeaders = ex.info()
@@ -618,7 +622,9 @@ class _(dict):
618622
except (urllib2.URLError, socket.error, socket.timeout, httplib.HTTPException, struct.error, binascii.Error, ProxyError, SqlmapCompressionException, WebSocketException, TypeError):
619623
tbMsg = traceback.format_exc()
620624

621-
if "no host given" in tbMsg:
625+
if checking:
626+
return None, None, None
627+
elif "no host given" in tbMsg:
622628
warnMsg = "invalid URL address used (%s)" % repr(url)
623629
raise SqlmapSyntaxException(warnMsg)
624630
elif "forcibly closed" in tbMsg or "Connection is already closed" in tbMsg:

sqlmap.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,9 @@ binaryFields =
674674
# Force character encoding used for data retrieval.
675675
charset =
676676

677+
# Check Internet connection before assessing the target.
678+
checkInternet = False
679+
677680
# Crawl the website starting from the target URL.
678681
# Valid: integer
679682
# Default: 0

txt/checksum.md5

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ c55b400b72acc43e0e59c87dd8bb8d75 extra/shellcodeexec/windows/shellcodeexec.x32.
2121
310efc965c862cfbd7b0da5150a5ad36 extra/sqlharvest/__init__.py
2222
7713aa366c983cdf1f3dbaa7383ea9e1 extra/sqlharvest/sqlharvest.py
2323
7afe836fd97271ccba67b4c0da2482ff lib/controller/action.py
24-
95fda7f284e0a882634cf5e94cbb73e1 lib/controller/checks.py
25-
df647d57cf02cc0e4bda6b8ccc9d8138 lib/controller/controller.py
24+
4ea6e0c35aedbdce88bbdff7c8786ae5 lib/controller/checks.py
25+
130d1c16708668b8d89605b6b5b38bf5 lib/controller/controller.py
2626
52a3969f57170e935e3fc0156335bf2c lib/controller/handler.py
2727
310efc965c862cfbd7b0da5150a5ad36 lib/controller/__init__.py
2828
60599fbb43b7d5e658b84371d3ad0b42 lib/core/agent.py
@@ -39,14 +39,14 @@ b9ff4e622c416116bee6024c0f050349 lib/core/enums.py
3939
9381a0c7e8bc19986299e84f4edda1a0 lib/core/exception.py
4040
310efc965c862cfbd7b0da5150a5ad36 lib/core/__init__.py
4141
9ba39bf66e9ecd469446bdbbeda906c3 lib/core/log.py
42-
ebb778c2d26eba8b34d7d8658e4105a6 lib/core/optiondict.py
42+
edcfce0850771e6454acef244d5c5760 lib/core/optiondict.py
4343
636485a22f158bec137d63c73aeace5c lib/core/option.py
4444
5f2f56e6c5f274408df61943f1e080c0 lib/core/profiling.py
4545
40be71cd774662a7b420caeb7051e7d5 lib/core/readlineng.py
4646
d8e9250f3775119df07e9070eddccd16 lib/core/replication.py
4747
785f86e3f963fa3798f84286a4e83ff2 lib/core/revision.py
4848
40c80b28b3a5819b737a5a17d4565ae9 lib/core/session.py
49-
9724eef5ffad3ea233a9340f05210cdb lib/core/settings.py
49+
aacedcb97c903d5e754a883f1a7617aa lib/core/settings.py
5050
d91291997d2bd2f6028aaf371bf1d3b6 lib/core/shell.py
5151
2ad85c130cc5f2b3701ea85c2f6bbf20 lib/core/subprocessng.py
5252
155e2d3fda87b2e3ffa4f7a770513946 lib/core/target.py
@@ -57,7 +57,7 @@ ad74fc58fc7214802fd27067bce18dd2 lib/core/unescaper.py
5757
4d13ed693401a498b6d073a2a494bd83 lib/core/wordlist.py
5858
310efc965c862cfbd7b0da5150a5ad36 lib/__init__.py
5959
8c4b04062db2245d9e190b413985202a lib/parse/banner.py
60-
aa89ea0c7c44eb74eaaeeccaddc94d39 lib/parse/cmdline.py
60+
4185a1ed8fbec400dd297474ac89c357 lib/parse/cmdline.py
6161
3a31657bc38f277d0016ff6d50bde61f lib/parse/configfile.py
6262
14539f1be714d4f1ed042067d63bc50a lib/parse/handler.py
6363
64e5bb3ecbdd75144500588b437ba8da lib/parse/headers.py
@@ -68,7 +68,7 @@ aa89ea0c7c44eb74eaaeeccaddc94d39 lib/parse/cmdline.py
6868
403d873f1d2fd0c7f73d83f104e41850 lib/request/basicauthhandler.py
6969
aa8abda6eab79646b1759c0653925328 lib/request/basic.py
7070
ef48de622b0a6b4a71df64b0d2785ef8 lib/request/comparison.py
71-
e5d14d0b8c07e082fb819b515f5b1dfb lib/request/connect.py
71+
108ca3607d42bd4923277019a8d6db7d lib/request/connect.py
7272
fb6b788d0016ab4ec5e5f661f0f702ad lib/request/direct.py
7373
cc1163d38e9b7ee5db2adac6784c02bb lib/request/dns.py
7474
5dcdb37823a0b5eff65cd1018bcf09e4 lib/request/httpshandler.py

0 commit comments

Comments
 (0)