()
Check and set the HTTP/SOCKS proxy for all HTTP requests.
Check and set the HTTP/SOCKS proxy for all HTTP requests.
Check and set the HTTP / SOCKS proxy for all HTTP requests .
def _setHTTPProxy():
    """
    Check and set the HTTP/SOCKS proxy for all HTTP requests.
    """
    global proxyHandler

    for _ in ("http", "https"):
        if hasattr(proxyHandler, "%s_open" % _):
            delattr(proxyHandler, "%s_open" % _)

    if not conf.proxy:
        if conf.proxyList:
            conf.proxy = conf.proxyList[0]
            conf.proxyList = conf.proxyList[1:] + conf.proxyList[:1]

            infoMsg = "loading proxy '%s' from a supplied proxy list file" % conf.proxy
            logger.info(infoMsg)
        else:
            if conf.hostname in ('localhost', '127.0.0.1') or conf.ignoreProxy:
                proxyHandler.proxies = {}

            return

    debugMsg = "setting the HTTP/SOCKS proxy for all HTTP requests"
    logger.debug(debugMsg)

    _ = urlparse.urlsplit(conf.proxy)
    hostnamePort = _.netloc.split(":")

    scheme = _.scheme.upper()
    hostname = hostnamePort[0]
    port = None
    username = None
    password = None

    if len(hostnamePort) == 2:
        try:
            port = int(hostnamePort[1])
        except:
            pass  # drops into the next check block

    if not all((scheme, hasattr(PROXY_TYPE, scheme), hostname, port)):
        errMsg = "proxy value must be in format '(%s)://address:port'" % "|".join(_[0].lower() for _ in getPublicTypeMembers(PROXY_TYPE))
        raise SqlmapSyntaxException(errMsg)

    if conf.proxyCred:
        _ = re.search("^(.*?):(.*?)$", conf.proxyCred)
        if not _:
            errMsg = "Proxy authentication credentials "
            errMsg += "value must be in format username:password"
            raise SqlmapSyntaxException(errMsg)
        else:
            username = _.group(1)
            password = _.group(2)

    if scheme in (PROXY_TYPE.SOCKS4, PROXY_TYPE.SOCKS5):
        proxyHandler.proxies = {}

        socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5 if scheme == PROXY_TYPE.SOCKS5 else socks.PROXY_TYPE_SOCKS4, hostname, port, username=username, password=password)
        socks.wrapmodule(urllib2)
    else:
        socks.unwrapmodule(urllib2)

        if conf.proxyCred:
            # Reference: http://stackoverflow.com/questions/34079/how-to-specify-an-authenticated-proxy-for-a-python-http-connection
            proxyString = "%s@" % conf.proxyCred
        else:
            proxyString = ""

        proxyString += "%s:%d" % (hostname, port)
        proxyHandler.proxies = {"http": proxyString, "https": proxyString}

    proxyHandler.__init__(proxyHandler.proxies)
def _setHTTPProxy ( ) : global proxyHandler for _ in ( "http" , "https" ) : if hasattr ( proxyHandler , "%s_open" % _ ) : delattr ( proxyHandler , "%s_open" % _ ) if not conf . proxy : if conf . proxyList : conf . proxy = conf . proxyList [ 0 ] conf . proxyList = conf . proxyList [ 1 : ] + conf . proxyList [ : 1 ] infoMsg = "loading proxy '%s' from a supplied proxy list file" % conf . proxy logger . info ( infoMsg ) else : if conf . hostname in ( 'localhost' , '127.0.0.1' ) or conf . ignoreProxy : proxyHandler . proxies = { } return debugMsg = "setting the HTTP/SOCKS proxy for all HTTP requests" logger . debug ( debugMsg ) _ = urlparse . urlsplit ( conf . proxy ) hostnamePort = _ . netloc . split ( ":" ) scheme = _ . scheme . upper ( ) hostname = hostnamePort [ 0 ] port = None username = None password = None if len ( hostnamePort ) == 2 : try : port = int ( hostnamePort [ 1 ] ) except : pass # drops into the next check block if not all ( ( scheme , hasattr ( PROXY_TYPE , scheme ) , hostname , port ) ) : errMsg = "proxy value must be in format '(%s)://address:port'" % "|" . join ( _ [ 0 ] . lower ( ) for _ in getPublicTypeMembers ( PROXY_TYPE ) ) raise SqlmapSyntaxException ( errMsg ) if conf . proxyCred : _ = re . search ( "^(.*?):(.*?)$" , conf . proxyCred ) if not _ : errMsg = "Proxy authentication credentials " errMsg += "value must be in format username:password" raise SqlmapSyntaxException ( errMsg ) else : username = _ . group ( 1 ) password = _ . group ( 2 ) if scheme in ( PROXY_TYPE . SOCKS4 , PROXY_TYPE . SOCKS5 ) : proxyHandler . proxies = { } socks . setdefaultproxy ( socks . PROXY_TYPE_SOCKS5 if scheme == PROXY_TYPE . SOCKS5 else socks . PROXY_TYPE_SOCKS4 , hostname , port , username = username , password = password ) socks . wrapmodule ( urllib2 ) else : socks . unwrapmodule ( urllib2 ) if conf . proxyCred : # Reference: http://stackoverflow.com/questions/34079/how-to-specify-an-authenticated-proxy-for-a-python-http-connection proxyString = "%s@" % conf . proxyCred else : proxyString = "" proxyString += "%s:%d" % ( hostname , port ) proxyHandler . proxies = { "http" : proxyString , "https" : proxyString } proxyHandler . __init__ ( proxyHandler . proxies )