55See the file 'LICENSE' for copying permission
66"""
77
8- import cookielib
98import glob
10- import httplib
119import inspect
1210import logging
1311import os
1917import threading
2018import time
2119import urllib2
22- import urlparse
2320
2421import lib .controller .checks
2522import lib .core .common
153150from thirdparty .keepalive import keepalive
154151from thirdparty .multipart import multipartpost
155152from thirdparty .oset .pyoset import oset
153+ from thirdparty .six .moves import http_client as _http_client
154+ from thirdparty .six .moves import http_cookiejar as _http_cookiejar
155+ from thirdparty .six .moves import urllib as _urllib
156156from thirdparty .socks import socks
157157from xml .etree .ElementTree import ElementTree
158158
159- authHandler = urllib2 .BaseHandler ()
159+ authHandler = _urllib . request .BaseHandler ()
160160chunkedHandler = ChunkedHandler ()
161161httpsHandler = HTTPSHandler ()
162162keepAliveHandler = keepalive .HTTPHandler ()
163- proxyHandler = urllib2 .ProxyHandler ()
163+ proxyHandler = _urllib . request .ProxyHandler ()
164164redirectHandler = SmartRedirectHandler ()
165165rangeHandler = HTTPRangeHandler ()
166166multipartPostHandler = multipartpost .MultipartPostHandler ()
@@ -1053,7 +1053,7 @@ def _setHTTPHandlers():
10531053 logger .debug (debugMsg )
10541054
10551055 try :
1056- _ = urlparse .urlsplit (conf .proxy )
1056+ _ = _urllib . parse .urlsplit (conf .proxy )
10571057 except Exception as ex :
10581058 errMsg = "invalid proxy address '%s' ('%s')" % (conf .proxy , getSafeExString (ex ))
10591059 raise SqlmapSyntaxException (errMsg )
@@ -1090,9 +1090,9 @@ def _setHTTPHandlers():
10901090 proxyHandler .proxies = {}
10911091
10921092 socks .setdefaultproxy (socks .PROXY_TYPE_SOCKS5 if scheme == PROXY_TYPE .SOCKS5 else socks .PROXY_TYPE_SOCKS4 , hostname , port , username = username , password = password )
1093- socks .wrapmodule (urllib2 )
1093+ socks .wrapmodule (_http_client )
10941094 else :
1095- socks .unwrapmodule (urllib2 )
1095+ socks .unwrapmodule (_http_client )
10961096
10971097 if conf .proxyCred :
10981098 # Reference: http://stackoverflow.com/questions/34079/how-to-specify-an-authenticated-proxy-for-a-python-http-connection
@@ -1112,12 +1112,12 @@ def _setHTTPHandlers():
11121112
11131113 if not conf .dropSetCookie :
11141114 if not conf .loadCookies :
1115- conf .cj = cookielib .CookieJar ()
1115+ conf .cj = _http_cookiejar .CookieJar ()
11161116 else :
1117- conf .cj = cookielib .MozillaCookieJar ()
1117+ conf .cj = _http_cookiejar .MozillaCookieJar ()
11181118 resetCookieJar (conf .cj )
11191119
1120- handlers .append (urllib2 .HTTPCookieProcessor (conf .cj ))
1120+ handlers .append (_urllib . request .HTTPCookieProcessor (conf .cj ))
11211121
11221122 # Reference: http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html
11231123 if conf .keepAlive :
@@ -1133,8 +1133,8 @@ def _setHTTPHandlers():
11331133 else :
11341134 handlers .append (keepAliveHandler )
11351135
1136- opener = urllib2 .build_opener (* handlers )
1137- urllib2 .install_opener (opener )
1136+ opener = _urllib . request .build_opener (* handlers )
1137+ _urllib . request .install_opener (opener )
11381138
11391139def _setSafeVisit ():
11401140 """
@@ -1166,7 +1166,7 @@ def _setSafeVisit():
11661166 if value .endswith (":443" ):
11671167 scheme = "https"
11681168 value = "%s://%s" % (scheme , value )
1169- kb .safeReq .url = urlparse .urljoin (value , kb .safeReq .url )
1169+ kb .safeReq .url = _urllib . parse .urljoin (value , kb .safeReq .url )
11701170 else :
11711171 break
11721172
@@ -1289,15 +1289,15 @@ def _setHTTPAuthentication():
12891289 conf .authUsername = aCredRegExp .group (1 )
12901290 conf .authPassword = aCredRegExp .group (2 )
12911291
1292- kb .passwordMgr = urllib2 .HTTPPasswordMgrWithDefaultRealm ()
1292+ kb .passwordMgr = _urllib . request .HTTPPasswordMgrWithDefaultRealm ()
12931293
12941294 _setAuthCred ()
12951295
12961296 if authType == AUTH_TYPE .BASIC :
12971297 authHandler = SmartHTTPBasicAuthHandler (kb .passwordMgr )
12981298
12991299 elif authType == AUTH_TYPE .DIGEST :
1300- authHandler = urllib2 .HTTPDigestAuthHandler (kb .passwordMgr )
1300+ authHandler = _urllib . request .HTTPDigestAuthHandler (kb .passwordMgr )
13011301
13021302 elif authType == AUTH_TYPE .NTLM :
13031303 try :
@@ -1459,7 +1459,7 @@ def _setHostname():
14591459
14601460 if conf .url :
14611461 try :
1462- conf .hostname = urlparse .urlsplit (conf .url ).netloc .split (':' )[0 ]
1462+ conf .hostname = _urllib . parse .urlsplit (conf .url ).netloc .split (':' )[0 ]
14631463 except ValueError as ex :
14641464 errMsg = "problem occurred while "
14651465 errMsg += "parsing an URL '%s' ('%s')" % (conf .url , getSafeExString (ex ))
@@ -1783,8 +1783,8 @@ def _cleanupEnvironment():
17831783 Cleanup environment (e.g. from leftovers after --sqlmap-shell).
17841784 """
17851785
1786- if issubclass (urllib2 .socket .socket , socks .socksocket ):
1787- socks .unwrapmodule (urllib2 )
1786+ if issubclass (_http_client .socket .socket , socks .socksocket ):
1787+ socks .unwrapmodule (_http_client )
17881788
17891789 if hasattr (socket , "_ready" ):
17901790 socket ._ready .clear ()
@@ -2312,11 +2312,11 @@ def _setTorSocksProxySettings():
23122312
23132313 # SOCKS5 to prevent DNS leaks (http://en.wikipedia.org/wiki/Tor_%28anonymity_network%29)
23142314 socks .setdefaultproxy (socks .PROXY_TYPE_SOCKS5 if conf .torType == PROXY_TYPE .SOCKS5 else socks .PROXY_TYPE_SOCKS4 , LOCALHOST , port )
2315- socks .wrapmodule (urllib2 )
2315+ socks .wrapmodule (_http_client )
23162316
23172317def _setHttpChunked ():
23182318 if conf .chunked and conf .data :
2319- httplib .HTTPConnection ._set_content_length = lambda self , a , b : None
2319+ _http_client .HTTPConnection ._set_content_length = lambda self , a , b : None
23202320
23212321def _checkWebSocket ():
23222322 if conf .url and (conf .url .startswith ("ws:/" ) or conf .url .startswith ("wss:/" )):
0 commit comments