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

Skip to content

Commit bb987ec

Browse files
committed
fix for DNS leakage
1 parent 9498a3f commit bb987ec

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

lib/core/option.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
from lib.core.settings import CODECS_LIST_PAGE
8181
from lib.core.settings import DEFAULT_PAGE_ENCODING
8282
from lib.core.settings import DEFAULT_TOR_PORTS
83+
from lib.core.settings import GENERAL_IP_ADDRESS_REGEX
8384
from lib.core.settings import IS_WIN
8485
from lib.core.settings import PLATFORM
8586
from lib.core.settings import PYVERSION
@@ -829,8 +830,12 @@ def __setDNSCache():
829830
"""
830831

831832
def _getaddrinfo(*args, **kwargs):
832-
if args in kb.cache:
833+
if conf.proxyDNSResponse:
834+
return conf.proxyDNSResponse
835+
836+
elif args in kb.cache:
833837
return kb.cache[args]
838+
834839
else:
835840
kb.cache[args] = socket._getaddrinfo(*args, **kwargs)
836841
return kb.cache[args]
@@ -897,6 +902,17 @@ def __setHTTPProxy():
897902
else:
898903
proxyHandler = urllib2.ProxyHandler({"http": __proxyString})
899904

905+
# Patch for DNS leakage
906+
if conf.proxy:
907+
if not re.match(GENERAL_IP_ADDRESS_REGEX, __hostname):
908+
try:
909+
addrinfo = socket.getaddrinfo(__hostname, __port)
910+
except:
911+
errMsg = "proxy host '%s' does not exist" % __hostname
912+
raise sqlmapConnectionException, errMsg
913+
__hostname = addrinfo[0][4][0]
914+
conf.proxyDNSResponse = [(2, 1, 0, '', (__hostname, int(__port)))]
915+
900916
def __setSafeUrl():
901917
"""
902918
Check and set the safe URL options.
@@ -1323,6 +1339,7 @@ def __setConfAttributes():
13231339
conf.parameters = {}
13241340
conf.path = None
13251341
conf.port = None
1342+
conf.proxyDNSResponse = None
13261343
conf.resultsFilename = None
13271344
conf.resultsFP = None
13281345
conf.scheme = None

0 commit comments

Comments
 (0)