()
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 conf.proxyList is not None:
        if not conf.proxyList:
            errMsg = "list of usable proxies is exhausted"
            raise SqlmapNoneDataException(errMsg)

        conf.proxy = conf.proxyList[0]
        conf.proxyList = conf.proxyList[1:]

        infoMsg = "loading proxy '%s' from a supplied proxy list file" % conf.proxy
        logger.info(infoMsg)

    elif not conf.proxy:
        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)

    try:
        _ = urlparse.urlsplit(conf.proxy)
    except Exception, ex:
        errMsg = "invalid proxy address '%s' ('%s')" % (conf.proxy, ex)
        raise SqlmapSyntaxException, errMsg

    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 conf . proxyList is not None : if not conf . proxyList : errMsg = "list of usable proxies is exhausted" raise SqlmapNoneDataException ( errMsg ) conf . proxy = conf . proxyList [ 0 ] conf . proxyList = conf . proxyList [ 1 : ] infoMsg = "loading proxy '%s' from a supplied proxy list file" % conf . proxy logger . info ( infoMsg ) elif not conf . proxy : 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 ) try : _ = urlparse . urlsplit ( conf . proxy ) except Exception , ex : errMsg = "invalid proxy address '%s' ('%s')" % ( conf . proxy , ex ) raise SqlmapSyntaxException , errMsg 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 )