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

Skip to content

Commit 4d75998

Browse files
committed
Implementation for Issue #91
1 parent c1a1425 commit 4d75998

1 file changed

Lines changed: 38 additions & 28 deletions

File tree

lib/core/option.py

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -876,50 +876,60 @@ def __setHTTPProxy():
876876

877877
return
878878

879-
debugMsg = "setting the HTTP proxy to pass by all HTTP requests"
879+
debugMsg = "setting the %s proxy to pass by all HTTP requests" % ("SOCKS" if "socks" in conf.proxy else "HTTP")
880880
logger.debug(debugMsg)
881881

882-
__proxySplit = urlparse.urlsplit(conf.proxy)
883-
__hostnamePort = __proxySplit[1].split(":")
882+
proxySplit = urlparse.urlsplit(conf.proxy)
883+
hostnamePort = proxySplit[1].split(":")
884884

885-
__scheme = __proxySplit[0]
886-
__hostname = __hostnamePort[0]
887-
__port = None
888-
__proxyString = ""
885+
scheme = proxySplit[0].lower()
886+
hostname = hostnamePort[0]
887+
port = None
888+
username = None
889+
password = None
889890

890-
if len(__hostnamePort) == 2:
891+
if len(hostnamePort) == 2:
891892
try:
892-
__port = int(__hostnamePort[1])
893+
port = int(hostnamePort[1])
893894
except:
894895
pass #drops into the next check block
895896

896-
if not __scheme or not __hostname or not __port:
897-
errMsg = "proxy value must be in format 'http://url:port'"
897+
if not all((scheme, hostname, port)):
898+
errMsg = "proxy value must be in format '(http|socks|socks4|socks5)://url:port'"
898899
raise sqlmapSyntaxException, errMsg
899900

900901
if conf.pCred:
901-
pCredRegExp = re.search("^(.*?):(.*?)$", conf.pCred)
902-
903-
if not pCredRegExp:
902+
_ = re.search("^(.*?):(.*?)$", conf.pCred)
903+
if not _:
904904
errMsg = "Proxy authentication credentials "
905905
errMsg += "value must be in format username:password"
906906
raise sqlmapSyntaxException, errMsg
907+
else:
908+
username = _.group(1)
909+
password = _.group(2)
907910

908-
# Reference: http://stackoverflow.com/questions/34079/how-to-specify-an-authenticated-proxy-for-a-python-http-connection
909-
__proxyString = "%s@" % conf.pCred
910-
911-
__proxyString += "%s:%d" % (__hostname, __port)
912-
913-
# Workaround for http://bugs.python.org/issue1424152 (urllib/urllib2:
914-
# HTTPS over (Squid) Proxy fails) as long as HTTP over SSL requests
915-
# can't be tunneled over an HTTP proxy natively by Python (<= 2.5)
916-
# urllib2 standard library
917-
if PYVERSION >= "2.6":
918-
proxyHandler = urllib2.ProxyHandler({"http": __proxyString, "https": __proxyString})
919-
elif conf.scheme == "https":
920-
proxyHandler = ProxyHTTPSHandler(__proxyString)
911+
if "socks" in scheme:
912+
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5 if "4" not in scheme else socks.PROXY_TYPE_SOCKS4, hostname, port, username=username, password=password)
913+
socks.wrapmodule(urllib2)
921914
else:
922-
proxyHandler = urllib2.ProxyHandler({"http": __proxyString})
915+
if conf.pCred:
916+
# Reference: http://stackoverflow.com/questions/34079/how-to-specify-an-authenticated-proxy-for-a-python-http-connection
917+
proxyString = "%s@" % conf.pCred
918+
else:
919+
proxyString = ""
920+
921+
proxyString += "%s:%d" % (hostname, port)
922+
923+
# Workaround for http://bugs.python.org/issue1424152 (urllib/urllib2:
924+
# HTTPS over (Squid) Proxy fails) as long as HTTP over SSL requests
925+
# can't be tunneled over an HTTP proxy natively by Python (<= 2.5)
926+
# urllib2 standard library
927+
if PYVERSION >= "2.6":
928+
proxyHandler = urllib2.ProxyHandler({"http": proxyString, "https": proxyString})
929+
elif conf.scheme == "https":
930+
proxyHandler = ProxyHTTPSHandler(proxyString)
931+
else:
932+
proxyHandler = urllib2.ProxyHandler({"http": proxyString})
923933

924934
def __setSafeUrl():
925935
"""

0 commit comments

Comments
 (0)