()
Parse target URL and set some attributes into the configuration singleton.
Parse target URL and set some attributes into the configuration singleton.
Parse target URL and set some attributes into the configuration singleton .
def parseTargetUrl():
    """
    Parse target URL and set some attributes into the configuration singleton.
    """

    if not conf.url:
        return

    originalUrl = conf.url

    if re.search("\[.+\]", conf.url) and not socket.has_ipv6:
        errMsg = "IPv6 addressing is not supported "
        errMsg += "on this platform"
        raise SqlmapGenericException(errMsg)

    if not re.search("^http[s]*://", conf.url, re.I) and \
            not re.search("^ws[s]*://", conf.url, re.I):
        if ":443/" in conf.url:
            conf.url = "https://" + conf.url
        else:
            conf.url = "http://" + conf.url

    if CUSTOM_INJECTION_MARK_CHAR in conf.url:
        conf.url = conf.url.replace('?', URI_QUESTION_MARKER)

    try:
        urlSplit = urlparse.urlsplit(conf.url)
    except ValueError, ex:
        errMsg = "invalid URL '%s' has been given ('%s'). " % (conf.url, ex)
        errMsg += "Please be sure that you don't have any leftover characters (e.g. '[' or ']') "
        errMsg += "in the hostname part"
        raise SqlmapGenericException(errMsg)

    hostnamePort = urlSplit.netloc.split(":") if not re.search("\[.+\]", urlSplit.netloc) else filter(None, (re.search("\[.+\]", urlSplit.netloc).group(0), re.search("\](:(?P<port>\d+))?", urlSplit.netloc).group("port")))

    conf.scheme = urlSplit.scheme.strip().lower() if not conf.forceSSL else "https"
    conf.path = urlSplit.path.strip()
    conf.hostname = hostnamePort[0].strip()

    conf.ipv6 = conf.hostname != conf.hostname.strip("[]")
    conf.hostname = conf.hostname.strip("[]").replace(CUSTOM_INJECTION_MARK_CHAR, "")

    try:
        _ = conf.hostname.encode("idna")
    except LookupError:
        _ = conf.hostname.encode(UNICODE_ENCODING)
    except UnicodeError:
        _ = None

    if any((_ is None, re.search(r'\s', conf.hostname), '..' in conf.hostname, conf.hostname.startswith('.'))):
        errMsg = "invalid target URL"
        raise SqlmapSyntaxException(errMsg)

    if len(hostnamePort) == 2:
        try:
            conf.port = int(hostnamePort[1])
        except:
            errMsg = "invalid target URL"
            raise SqlmapSyntaxException(errMsg)
    elif conf.scheme == "https":
        conf.port = 443
    else:
        conf.port = 80

    if urlSplit.query:
        conf.parameters[PLACE.GET] = urldecode(urlSplit.query) if urlSplit.query and urlencode(DEFAULT_GET_POST_DELIMITER, None) not in urlSplit.query else urlSplit.query

    conf.url = getUnicode("%s://%s:%d%s" % (conf.scheme, ("[%s]" % conf.hostname) if conf.ipv6 else conf.hostname, conf.port, conf.path))
    conf.url = conf.url.replace(URI_QUESTION_MARKER, '?')

    if not conf.referer and (intersect(REFERER_ALIASES, conf.testParameter, True) or conf.level >= 3):
        debugMsg = "setting the HTTP Referer header to the target URL"
        logger.debug(debugMsg)
        conf.httpHeaders = filter(lambda (key, value): key != HTTP_HEADER.REFERER, conf.httpHeaders)
        conf.httpHeaders.append((HTTP_HEADER.REFERER, conf.url.replace(CUSTOM_INJECTION_MARK_CHAR, "")))

    if not conf.host and (intersect(HOST_ALIASES, conf.testParameter, True) or conf.level >= 5):
        debugMsg = "setting the HTTP Host header to the target URL"
        logger.debug(debugMsg)
        conf.httpHeaders = filter(lambda (key, value): key != HTTP_HEADER.HOST, conf.httpHeaders)
        conf.httpHeaders.append((HTTP_HEADER.HOST, getHostHeader(conf.url)))

    if conf.url != originalUrl:
        kb.originalUrls[conf.url] = originalUrl
def parseTargetUrl ( ) : if not conf . url : return originalUrl = conf . url if re . search ( "\[.+\]" , conf . url ) and not socket . has_ipv6 : errMsg = "IPv6 addressing is not supported " errMsg += "on this platform" raise SqlmapGenericException ( errMsg ) if not re . search ( "^http[s]*://" , conf . url , re . I ) and not re . search ( "^ws[s]*://" , conf . url , re . I ) : if ":443/" in conf . url : conf . url = "https://" + conf . url else : conf . url = "http://" + conf . url if CUSTOM_INJECTION_MARK_CHAR in conf . url : conf . url = conf . url . replace ( '?' , URI_QUESTION_MARKER ) try : urlSplit = urlparse . urlsplit ( conf . url ) except ValueError , ex : errMsg = "invalid URL '%s' has been given ('%s'). " % ( conf . url , ex ) errMsg += "Please be sure that you don't have any leftover characters (e.g. '[' or ']') " errMsg += "in the hostname part" raise SqlmapGenericException ( errMsg ) hostnamePort = urlSplit . netloc . split ( ":" ) if not re . search ( "\[.+\]" , urlSplit . netloc ) else filter ( None , ( re . search ( "\[.+\]" , urlSplit . netloc ) . group ( 0 ) , re . search ( "\](:(?P<port>\d+))?" , urlSplit . netloc ) . group ( "port" ) ) ) conf . scheme = urlSplit . scheme . strip ( ) . lower ( ) if not conf . forceSSL else "https" conf . path = urlSplit . path . strip ( ) conf . hostname = hostnamePort [ 0 ] . strip ( ) conf . ipv6 = conf . hostname != conf . hostname . strip ( "[]" ) conf . hostname = conf . hostname . strip ( "[]" ) . replace ( CUSTOM_INJECTION_MARK_CHAR , "" ) try : _ = conf . hostname . encode ( "idna" ) except LookupError : _ = conf . hostname . encode ( UNICODE_ENCODING ) except UnicodeError : _ = None if any ( ( _ is None , re . search ( r'\s' , conf . hostname ) , '..' in conf . hostname , conf . hostname . startswith ( '.' ) ) ) : errMsg = "invalid target URL" raise SqlmapSyntaxException ( errMsg ) if len ( hostnamePort ) == 2 : try : conf . port = int ( hostnamePort [ 1 ] ) except : errMsg = "invalid target URL" raise SqlmapSyntaxException ( errMsg ) elif conf . scheme == "https" : conf . port = 443 else : conf . port = 80 if urlSplit . query : conf . parameters [ PLACE . GET ] = urldecode ( urlSplit . query ) if urlSplit . query and urlencode ( DEFAULT_GET_POST_DELIMITER , None ) not in urlSplit . query else urlSplit . query conf . url = getUnicode ( "%s://%s:%d%s" % ( conf . scheme , ( "[%s]" % conf . hostname ) if conf . ipv6 else conf . hostname , conf . port , conf . path ) ) conf . url = conf . url . replace ( URI_QUESTION_MARKER , '?' ) if not conf . referer and ( intersect ( REFERER_ALIASES , conf . testParameter , True ) or conf . level >= 3 ) : debugMsg = "setting the HTTP Referer header to the target URL" logger . debug ( debugMsg ) conf . httpHeaders = filter ( lambda ( key , value ) : key != HTTP_HEADER . REFERER , conf . httpHeaders ) conf . httpHeaders . append ( ( HTTP_HEADER . REFERER , conf . url . replace ( CUSTOM_INJECTION_MARK_CHAR , "" ) ) ) if not conf . host and ( intersect ( HOST_ALIASES , conf . testParameter , True ) or conf . level >= 5 ) : debugMsg = "setting the HTTP Host header to the target URL" logger . debug ( debugMsg ) conf . httpHeaders = filter ( lambda ( key , value ) : key != HTTP_HEADER . HOST , conf . httpHeaders ) conf . httpHeaders . append ( ( HTTP_HEADER . HOST , getHostHeader ( conf . url ) ) ) if conf . url != originalUrl : kb . originalUrls [ conf . url ] = originalUrl