MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / checkConnection

Function checkConnection

lib/controller/checks.py:1472–1591  ·  view source on GitHub ↗
(suppressOutput=False)

Source from the content-addressed store, hash-verified

1470 return kb.nullConnection in getPublicTypeMembers(NULLCONNECTION, True)
1471
1472def checkConnection(suppressOutput=False):
1473 threadData = getCurrentThreadData()
1474
1475 if not re.search(r"\A\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\Z", conf.hostname):
1476 if not any((conf.proxy, conf.tor, conf.dummy, conf.offline)):
1477 try:
1478 debugMsg = "resolving hostname '%s'" % conf.hostname
1479 logger.debug(debugMsg)
1480 socket.getaddrinfo(conf.hostname, None)
1481 except socket.gaierror:
1482 errMsg = "host '%s' does not exist" % conf.hostname
1483 raise SqlmapConnectionException(errMsg)
1484 except socket.error as ex:
1485 errMsg = "problem occurred while "
1486 errMsg += "resolving a host name '%s' ('%s')" % (conf.hostname, getSafeExString(ex))
1487 raise SqlmapConnectionException(errMsg)
1488 except UnicodeError as ex:
1489 errMsg = "problem occurred while "
1490 errMsg += "handling a host name '%s' ('%s')" % (conf.hostname, getSafeExString(ex))
1491 raise SqlmapDataException(errMsg)
1492
1493 if not suppressOutput and not conf.dummy and not conf.offline:
1494 infoMsg = "testing connection to the target URL"
1495 logger.info(infoMsg)
1496
1497 try:
1498 kb.originalPageTime = time.time()
1499 page, headers, _ = Request.queryPage(content=True, noteResponseTime=False)
1500
1501 rawResponse = "%s%s" % (listToStrValue(headers.headers if headers else ""), page)
1502
1503 if conf.string:
1504 infoMsg = "testing if the provided string is within the "
1505 infoMsg += "target URL page content"
1506 logger.info(infoMsg)
1507
1508 if conf.string not in rawResponse:
1509 warnMsg = "you provided '%s' as the string to " % conf.string
1510 warnMsg += "match, but such a string is not within the target "
1511 warnMsg += "URL raw response, sqlmap will carry on anyway"
1512 logger.warning(warnMsg)
1513
1514 if conf.regexp:
1515 infoMsg = "testing if the provided regular expression matches within "
1516 infoMsg += "the target URL page content"
1517 logger.info(infoMsg)
1518
1519 if not re.search(conf.regexp, rawResponse, re.I | re.M):
1520 warnMsg = "you provided '%s' as the regular expression " % conf.regexp
1521 warnMsg += "which does not have any match within the target URL raw response. sqlmap "
1522 warnMsg += "will carry on anyway"
1523 logger.warning(warnMsg)
1524
1525 kb.errorIsNone = False
1526
1527 if any(_ in (kb.serverHeader or "") for _ in PRECONNECT_INCOMPATIBLE_SERVERS):
1528 singleTimeWarnMessage("turning off pre-connect mechanism because of incompatible server ('%s')" % kb.serverHeader)
1529 conf.disablePrecon = True

Callers 2

startFunction · 0.90
_findPageFormsFunction · 0.90

Calls 15

getCurrentThreadDataFunction · 0.90
getSafeExStringFunction · 0.90
SqlmapDataExceptionClass · 0.90
listToStrValueFunction · 0.90
singleTimeWarnMessageFunction · 0.90
wasLastResponseHTTPErrorFunction · 0.90
getLastRequestHTTPErrorFunction · 0.90
wasLastResponseDBMSErrorFunction · 0.90
getUnicodeFunction · 0.90
readInputFunction · 0.90
debugMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…