@@ -1022,119 +1022,120 @@ def _setHTTPHandlers():
10221022 """
10231023 Check and set the HTTP/SOCKS proxy for all HTTP requests.
10241024 """
1025- global proxyHandler
10261025
1027- for _ in ("http" , "https" ):
1028- if hasattr (proxyHandler , "%s_open" % _ ):
1029- delattr (proxyHandler , "%s_open" % _ )
1026+ with kb .locks .handlers :
1027+ if conf .proxyList is not None :
1028+ if not conf .proxyList :
1029+ errMsg = "list of usable proxies is exhausted"
1030+ raise SqlmapNoneDataException (errMsg )
10301031
1031- if conf .proxyList is not None :
1032- if not conf .proxyList :
1033- errMsg = "list of usable proxies is exhausted"
1034- raise SqlmapNoneDataException (errMsg )
1032+ conf .proxy = conf .proxyList [0 ]
1033+ conf .proxyList = conf .proxyList [1 :]
10351034
1036- conf .proxy = conf .proxyList [0 ]
1037- conf .proxyList = conf .proxyList [1 :]
1038-
1039- infoMsg = "loading proxy '%s' from a supplied proxy list file" % conf .proxy
1040- logger .info (infoMsg )
1041-
1042- elif not conf .proxy :
1043- if conf .hostname in ("localhost" , "127.0.0.1" ) or conf .ignoreProxy :
1044- proxyHandler .proxies = {}
1035+ infoMsg = "loading proxy '%s' from a supplied proxy list file" % conf .proxy
1036+ logger .info (infoMsg )
10451037
1046- if conf .proxy :
1047- debugMsg = "setting the HTTP/SOCKS proxy for all HTTP requests"
1048- logger . debug ( debugMsg )
1038+ elif not conf .proxy :
1039+ if conf . hostname in ( "localhost" , "127.0.0.1" ) or conf . ignoreProxy :
1040+ proxyHandler . proxies = {}
10491041
1050- try :
1051- _ = _urllib .parse .urlsplit (conf .proxy )
1052- except Exception as ex :
1053- errMsg = "invalid proxy address '%s' ('%s')" % (conf .proxy , getSafeExString (ex ))
1054- raise SqlmapSyntaxException (errMsg )
1042+ if conf .proxy :
1043+ debugMsg = "setting the HTTP/SOCKS proxy for all HTTP requests"
1044+ logger .debug (debugMsg )
10551045
1056- hostnamePort = _ .netloc .split (":" )
1046+ try :
1047+ _ = _urllib .parse .urlsplit (conf .proxy )
1048+ except Exception as ex :
1049+ errMsg = "invalid proxy address '%s' ('%s')" % (conf .proxy , getSafeExString (ex ))
1050+ raise SqlmapSyntaxException (errMsg )
10571051
1058- scheme = _ .scheme .upper ()
1059- hostname = hostnamePort [0 ]
1060- port = None
1061- username = None
1062- password = None
1052+ hostnamePort = _ .netloc .split (":" )
10631053
1064- if len ( hostnamePort ) == 2 :
1065- try :
1066- port = int ( hostnamePort [ 1 ])
1067- except :
1068- pass # drops into the next check block
1054+ scheme = _ . scheme . upper ()
1055+ hostname = hostnamePort [ 0 ]
1056+ port = None
1057+ username = None
1058+ password = None
10691059
1070- if not all ((scheme , hasattr (PROXY_TYPE , scheme ), hostname , port )):
1071- errMsg = "proxy value must be in format '(%s)://address:port'" % "|" .join (_ [0 ].lower () for _ in getPublicTypeMembers (PROXY_TYPE ))
1072- raise SqlmapSyntaxException (errMsg )
1060+ if len (hostnamePort ) == 2 :
1061+ try :
1062+ port = int (hostnamePort [1 ])
1063+ except :
1064+ pass # drops into the next check block
10731065
1074- if conf .proxyCred :
1075- _ = re .search (r"\A(.*?):(.*?)\Z" , conf .proxyCred )
1076- if not _ :
1077- errMsg = "proxy authentication credentials "
1078- errMsg += "value must be in format username:password"
1066+ if not all ((scheme , hasattr (PROXY_TYPE , scheme ), hostname , port )):
1067+ errMsg = "proxy value must be in format '(%s)://address:port'" % "|" .join (_ [0 ].lower () for _ in getPublicTypeMembers (PROXY_TYPE ))
10791068 raise SqlmapSyntaxException (errMsg )
1080- else :
1081- username = _ .group (1 )
1082- password = _ .group (2 )
10831069
1084- if scheme in (PROXY_TYPE .SOCKS4 , PROXY_TYPE .SOCKS5 ):
1085- proxyHandler .proxies = {}
1070+ if conf .proxyCred :
1071+ _ = re .search (r"\A(.*?):(.*?)\Z" , conf .proxyCred )
1072+ if not _ :
1073+ errMsg = "proxy authentication credentials "
1074+ errMsg += "value must be in format username:password"
1075+ raise SqlmapSyntaxException (errMsg )
1076+ else :
1077+ username = _ .group (1 )
1078+ password = _ .group (2 )
10861079
1087- if scheme == PROXY_TYPE .SOCKS4 :
1088- warnMsg = "SOCKS4 does not support resolving (DNS) names (i.e. causing DNS leakage)"
1089- singleTimeWarnMessage (warnMsg )
1080+ if scheme in (PROXY_TYPE .SOCKS4 , PROXY_TYPE .SOCKS5 ):
1081+ proxyHandler .proxies = {}
10901082
1091- socks .setdefaultproxy (socks .PROXY_TYPE_SOCKS5 if scheme == PROXY_TYPE .SOCKS5 else socks .PROXY_TYPE_SOCKS4 , hostname , port , username = username , password = password )
1092- socks .wrapmodule (_http_client )
1093- else :
1094- socks .unwrapmodule (_http_client )
1083+ if scheme == PROXY_TYPE .SOCKS4 :
1084+ warnMsg = "SOCKS4 does not support resolving (DNS) names (i.e. causing DNS leakage)"
1085+ singleTimeWarnMessage (warnMsg )
10951086
1096- if conf .proxyCred :
1097- # Reference: http://stackoverflow.com/questions/34079/how-to-specify-an-authenticated-proxy-for-a-python-http-connection
1098- proxyString = "%s@" % conf .proxyCred
1087+ socks .setdefaultproxy (socks .PROXY_TYPE_SOCKS5 if scheme == PROXY_TYPE .SOCKS5 else socks .PROXY_TYPE_SOCKS4 , hostname , port , username = username , password = password )
1088+ socks .wrapmodule (_http_client )
10991089 else :
1100- proxyString = ""
1090+ socks . unwrapmodule ( _http_client )
11011091
1102- proxyString += "%s:%d" % (hostname , port )
1103- proxyHandler .proxies = {"http" : proxyString , "https" : proxyString }
1092+ if conf .proxyCred :
1093+ # Reference: http://stackoverflow.com/questions/34079/how-to-specify-an-authenticated-proxy-for-a-python-http-connection
1094+ proxyString = "%s@" % conf .proxyCred
1095+ else :
1096+ proxyString = ""
11041097
1105- proxyHandler .__init__ (proxyHandler .proxies )
1098+ proxyString += "%s:%d" % (hostname , port )
1099+ proxyHandler .proxies = {"http" : proxyString , "https" : proxyString }
11061100
1107- debugMsg = "creating HTTP requests opener object"
1108- logger .debug (debugMsg )
1101+ proxyHandler .__init__ (proxyHandler .proxies )
11091102
1110- handlers = filterNone ([multipartPostHandler , proxyHandler if proxyHandler .proxies else None , authHandler , redirectHandler , rangeHandler , chunkedHandler if conf .chunked else None , httpsHandler ])
1103+ if not proxyHandler .proxies :
1104+ for _ in ("http" , "https" ):
1105+ if hasattr (proxyHandler , "%s_open" % _ ):
1106+ delattr (proxyHandler , "%s_open" % _ )
11111107
1112- if not conf .dropSetCookie :
1113- if not conf .loadCookies :
1114- conf .cj = _http_cookiejar .CookieJar ()
1115- else :
1116- conf .cj = _http_cookiejar .MozillaCookieJar ()
1117- resetCookieJar (conf .cj )
1108+ debugMsg = "creating HTTP requests opener object"
1109+ logger .debug (debugMsg )
11181110
1119- handlers . append ( _urllib . request . HTTPCookieProcessor ( conf .cj ) )
1111+ handlers = filterNone ([ multipartPostHandler , proxyHandler if proxyHandler . proxies else None , authHandler , redirectHandler , rangeHandler , chunkedHandler if conf .chunked else None , httpsHandler ] )
11201112
1121- # Reference: http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html
1122- if conf .keepAlive :
1123- warnMsg = "persistent HTTP(s) connections, Keep-Alive, has "
1124- warnMsg += "been disabled because of its incompatibility "
1113+ if not conf .dropSetCookie :
1114+ if not conf .loadCookies :
1115+ conf .cj = _http_cookiejar .CookieJar ()
1116+ else :
1117+ conf .cj = _http_cookiejar .MozillaCookieJar ()
1118+ resetCookieJar (conf .cj )
11251119
1126- if conf .proxy :
1127- warnMsg += "with HTTP(s) proxy"
1128- logger .warn (warnMsg )
1129- elif conf .authType :
1130- warnMsg += "with authentication methods"
1131- logger .warn (warnMsg )
1132- else :
1133- handlers .append (keepAliveHandler )
1120+ handlers .append (_urllib .request .HTTPCookieProcessor (conf .cj ))
1121+
1122+ # Reference: http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html
1123+ if conf .keepAlive :
1124+ warnMsg = "persistent HTTP(s) connections, Keep-Alive, has "
1125+ warnMsg += "been disabled because of its incompatibility "
1126+
1127+ if conf .proxy :
1128+ warnMsg += "with HTTP(s) proxy"
1129+ logger .warn (warnMsg )
1130+ elif conf .authType :
1131+ warnMsg += "with authentication methods"
1132+ logger .warn (warnMsg )
1133+ else :
1134+ handlers .append (keepAliveHandler )
11341135
1135- opener = _urllib .request .build_opener (* handlers )
1136- opener .addheaders = [] # Note: clearing default "User-Agent: Python-urllib/X.Y"
1137- _urllib .request .install_opener (opener )
1136+ opener = _urllib .request .build_opener (* handlers )
1137+ opener .addheaders = [] # Note: clearing default "User-Agent: Python-urllib/X.Y"
1138+ _urllib .request .install_opener (opener )
11381139
11391140def _setSafeVisit ():
11401141 """
@@ -1925,7 +1926,7 @@ def _setKnowledgeBaseAttributes(flushAll=True):
19251926 kb .lastParserStatus = None
19261927
19271928 kb .locks = AttribDict ()
1928- for _ in ("cache" , "connError" , "count" , "index" , "io" , "limit" , "log" , "socket" , "redirect" , "request" , "value" ):
1929+ for _ in ("cache" , "connError" , "count" , "handlers" , " index" , "io" , "limit" , "log" , "socket" , "redirect" , "request" , "value" ):
19291930 kb .locks [_ ] = threading .Lock ()
19301931
19311932 kb .matchRatio = None
0 commit comments