()
Check and set the parameters and perform checks on 'data' option for
    HTTP method POST.
Check and set the parameters and perform checks on 'data' option for
    HTTP method POST.
Check and set the parameters and perform checks on data option for HTTP method POST .
def _setRequestParams():
    """
    Check and set the parameters and perform checks on 'data' option for
    HTTP method POST.
    """

    if conf.direct:
        conf.parameters[None] = "direct connection"
        return

    testableParameters = False

    # Perform checks on GET parameters
    if conf.parameters.get(PLACE.GET):
        parameters = conf.parameters[PLACE.GET]
        paramDict = paramToDict(PLACE.GET, parameters)

        if paramDict:
            conf.paramDict[PLACE.GET] = paramDict
            testableParameters = True

    # Perform checks on POST parameters
    if conf.method == HTTPMETHOD.POST and conf.data is None:
        logger.warn("detected empty POST body")
        conf.data = ""

    if conf.data is not None:
        conf.method = HTTPMETHOD.POST if not conf.method or conf.method == HTTPMETHOD.GET else conf.method
        hintNames = []

        def process(match, repl):
            retVal = match.group(0)

            if not (conf.testParameter and match.group("name") not in conf.testParameter):
                retVal = repl
                while True:
                    _ = re.search(r"\\g<([^>]+)>", retVal)
                    if _:
                        retVal = retVal.replace(_.group(0), match.group(int(_.group(1)) if _.group(1).isdigit() else _.group(1)))
                    else:
                        break
                if CUSTOM_INJECTION_MARK_CHAR in retVal:
                    hintNames.append((retVal.split(CUSTOM_INJECTION_MARK_CHAR)[0], match.group("name")))
            return retVal

        if kb.processUserMarks is None and CUSTOM_INJECTION_MARK_CHAR in conf.data:
            message = "custom injection marking character ('%s') found in option " % CUSTOM_INJECTION_MARK_CHAR
            message += "'--data'. Do you want to process it? [Y/n/q] "
            test = readInput(message, default="Y")
            if test and test[0] in ("q", "Q"):
                raise SqlmapUserQuitException
            else:
                kb.processUserMarks = not test or test[0] not in ("n", "N")

                if kb.processUserMarks:
                    kb.testOnlyCustom = True

        if not (kb.processUserMarks and CUSTOM_INJECTION_MARK_CHAR in conf.data):
            if re.search(JSON_RECOGNITION_REGEX, conf.data):
                message = "JSON data found in %s data. " % conf.method
                message += "Do you want to process it? [Y/n/q] "
                test = readInput(message, default="Y")
                if test and test[0] in ("q", "Q"):
                    raise SqlmapUserQuitException
                elif test[0] not in ("n", "N"):
                    conf.data = getattr(conf.data, UNENCODED_ORIGINAL_VALUE, conf.data)
                    conf.data = conf.data.replace(CUSTOM_INJECTION_MARK_CHAR, ASTERISK_MARKER)
                    conf.data = re.sub(r'("(?P<name>[^"]+)"\s*:\s*"[^"]+)"', functools.partial(process, repl=r'\g<1>%s"' % CUSTOM_INJECTION_MARK_CHAR), conf.data)
                    conf.data = re.sub(r'("(?P<name>[^"]+)"\s*:\s*)(-?\d[\d\.]*\b)', functools.partial(process, repl=r'\g<0>%s' % CUSTOM_INJECTION_MARK_CHAR), conf.data)
                    match = re.search(r'(?P<name>[^"]+)"\s*:\s*\[([^\]]+)\]', conf.data)
                    if match and not (conf.testParameter and match.group("name") not in conf.testParameter):
                        _ = match.group(2)
                        _ = re.sub(r'("[^"]+)"', '\g<1>%s"' % CUSTOM_INJECTION_MARK_CHAR, _)
                        _ = re.sub(r'(\A|,|\s+)(-?\d[\d\.]*\b)', '\g<0>%s' % CUSTOM_INJECTION_MARK_CHAR, _)
                        conf.data = conf.data.replace(match.group(0), match.group(0).replace(match.group(2), _))
                    kb.postHint = POST_HINT.JSON

            elif re.search(JSON_LIKE_RECOGNITION_REGEX, conf.data):
                message = "JSON-like data found in %s data. " % conf.method
                message += "Do you want to process it? [Y/n/q] "
                test = readInput(message, default="Y")
                if test and test[0] in ("q", "Q"):
                    raise SqlmapUserQuitException
                elif test[0] not in ("n", "N"):
                    conf.data = getattr(conf.data, UNENCODED_ORIGINAL_VALUE, conf.data)
                    conf.data = conf.data.replace(CUSTOM_INJECTION_MARK_CHAR, ASTERISK_MARKER)
                    conf.data = re.sub(r"('(?P<name>[^']+)'\s*:\s*'[^']+)'", functools.partial(process, repl=r"\g<1>%s'" % CUSTOM_INJECTION_MARK_CHAR), conf.data)
                    conf.data = re.sub(r"('(?P<name>[^']+)'\s*:\s*)(-?\d[\d\.]*\b)", functools.partial(process, repl=r"\g<0>%s" % CUSTOM_INJECTION_MARK_CHAR), conf.data)
                    kb.postHint = POST_HINT.JSON_LIKE

            elif re.search(ARRAY_LIKE_RECOGNITION_REGEX, conf.data):
                message = "Array-like data found in %s data. " % conf.method
                message += "Do you want to process it? [Y/n/q] "
                test = readInput(message, default="Y")
                if test and test[0] in ("q", "Q"):
                    raise SqlmapUserQuitException
                elif test[0] not in ("n", "N"):
                    conf.data = conf.data.replace(CUSTOM_INJECTION_MARK_CHAR, ASTERISK_MARKER)
                    conf.data = re.sub(r"(=[^%s]+)" % DEFAULT_GET_POST_DELIMITER, r"\g<1>%s" % CUSTOM_INJECTION_MARK_CHAR, conf.data)
                    kb.postHint = POST_HINT.ARRAY_LIKE

            elif re.search(XML_RECOGNITION_REGEX, conf.data):
                message = "SOAP/XML data found in %s data. " % conf.method
                message += "Do you want to process it? [Y/n/q] "
                test = readInput(message, default="Y")
                if test and test[0] in ("q", "Q"):
                    raise SqlmapUserQuitException
                elif test[0] not in ("n", "N"):
                    conf.data = getattr(conf.data, UNENCODED_ORIGINAL_VALUE, conf.data)
                    conf.data = conf.data.replace(CUSTOM_INJECTION_MARK_CHAR, ASTERISK_MARKER)
                    conf.data = re.sub(r"(<(?P<name>[^>]+)( [^<]*)?>)([^<]+)(</\2)", functools.partial(process, repl=r"\g<1>\g<4>%s\g<5>" % CUSTOM_INJECTION_MARK_CHAR), conf.data)
                    kb.postHint = POST_HINT.SOAP if "soap" in conf.data.lower() else POST_HINT.XML

            elif re.search(MULTIPART_RECOGNITION_REGEX, conf.data):
                message = "Multipart-like data found in %s data. " % conf.method
                message += "Do you want to process it? [Y/n/q] "
                test = readInput(message, default="Y")
                if test and test[0] in ("q", "Q"):
                    raise SqlmapUserQuitException
                elif test[0] not in ("n", "N"):
                    conf.data = getattr(conf.data, UNENCODED_ORIGINAL_VALUE, conf.data)
                    conf.data = conf.data.replace(CUSTOM_INJECTION_MARK_CHAR, ASTERISK_MARKER)
                    conf.data = re.sub(r"(?si)((Content-Disposition[^\n]+?name\s*=\s*[\"'](?P<name>[^\n]+?)[\"']).+?)(((\r)?\n)+--)", functools.partial(process, repl=r"\g<1>%s\g<4>" % CUSTOM_INJECTION_MARK_CHAR), conf.data)
                    kb.postHint = POST_HINT.MULTIPART

        if not kb.postHint:
            if CUSTOM_INJECTION_MARK_CHAR in conf.data:  # later processed
                pass
            else:
                place = PLACE.POST

                conf.parameters[place] = conf.data
                paramDict = paramToDict(place, conf.data)

                if paramDict:
                    conf.paramDict[place] = paramDict
                    testableParameters = True
        else:
            if CUSTOM_INJECTION_MARK_CHAR not in conf.data:  # in case that no usable parameter values has been found
                conf.parameters[PLACE.POST] = conf.data

    kb.processUserMarks = True if (kb.postHint and CUSTOM_INJECTION_MARK_CHAR in conf.data) else kb.processUserMarks

    if re.search(URI_INJECTABLE_REGEX, conf.url, re.I) and not any(place in conf.parameters for place in (PLACE.GET, PLACE.POST)) and not kb.postHint and not CUSTOM_INJECTION_MARK_CHAR in (conf.data or "") and conf.url.startswith("http"):
        warnMsg = "you've provided target URL without any GET "
        warnMsg += "parameters (e.g. www.site.com/article.php?id=1) "
        warnMsg += "and without providing any POST parameters "
        warnMsg += "through --data option"
        logger.warn(warnMsg)

        message = "do you want to try URI injections "
        message += "in the target URL itself? [Y/n/q] "
        test = readInput(message, default="Y")

        if test and test[0] in ("q", "Q"):
            raise SqlmapUserQuitException
        elif not test or test[0] not in ("n", "N"):
            conf.url = "%s%s" % (conf.url, CUSTOM_INJECTION_MARK_CHAR)
            kb.processUserMarks = True

    for place, value in ((PLACE.URI, conf.url), (PLACE.CUSTOM_POST, conf.data), (PLACE.CUSTOM_HEADER, str(conf.httpHeaders))):
        _ = re.sub(PROBLEMATIC_CUSTOM_INJECTION_PATTERNS, "", value or "") if place == PLACE.CUSTOM_HEADER else value or ""
        if CUSTOM_INJECTION_MARK_CHAR in _:
            if kb.processUserMarks is None:
                lut = {PLACE.URI: '-u', PLACE.CUSTOM_POST: '--data', PLACE.CUSTOM_HEADER: '--headers/--user-agent/--referer/--cookie'}
                message = "custom injection marking character ('%s') found in option " % CUSTOM_INJECTION_MARK_CHAR
                message += "'%s'. Do you want to process it? [Y/n/q] " % lut[place]
                test = readInput(message, default="Y")
                if test and test[0] in ("q", "Q"):
                    raise SqlmapUserQuitException
                else:
                    kb.processUserMarks = not test or test[0] not in ("n", "N")

                    if kb.processUserMarks:
                        kb.testOnlyCustom = True

                        if "=%s" % CUSTOM_INJECTION_MARK_CHAR in _:
                            warnMsg = "it seems that you've provided empty parameter value(s) "
                            warnMsg += "for testing. Please, always use only valid parameter values "
                            warnMsg += "so sqlmap could be able to run properly"
                            logger.warn(warnMsg)

            if not kb.processUserMarks:
                if place == PLACE.URI:
                    query = urlparse.urlsplit(value).query
                    if query:
                        parameters = conf.parameters[PLACE.GET] = query
                        paramDict = paramToDict(PLACE.GET, parameters)

                        if paramDict:
                            conf.url = conf.url.split('?')[0]
                            conf.paramDict[PLACE.GET] = paramDict
                            testableParameters = True
                elif place == PLACE.CUSTOM_POST:
                    conf.parameters[PLACE.POST] = conf.data
                    paramDict = paramToDict(PLACE.POST, conf.data)

                    if paramDict:
                        conf.paramDict[PLACE.POST] = paramDict
                        testableParameters = True

            else:
                conf.parameters[place] = value
                conf.paramDict[place] = OrderedDict()

                if place == PLACE.CUSTOM_HEADER:
                    for index in xrange(len(conf.httpHeaders)):
                        header, value = conf.httpHeaders[index]
                        if CUSTOM_INJECTION_MARK_CHAR in re.sub(PROBLEMATIC_CUSTOM_INJECTION_PATTERNS, "", value):
                            parts = value.split(CUSTOM_INJECTION_MARK_CHAR)
                            for i in xrange(len(parts) - 1):
                                conf.paramDict[place]["%s #%d%s" % (header, i + 1, CUSTOM_INJECTION_MARK_CHAR)] = "%s,%s" % (header, "".join("%s%s" % (parts[j], CUSTOM_INJECTION_MARK_CHAR if i == j else "") for j in xrange(len(parts))))
                            conf.httpHeaders[index] = (header, value.replace(CUSTOM_INJECTION_MARK_CHAR, ""))
                else:
                    parts = value.split(CUSTOM_INJECTION_MARK_CHAR)

                    for i in xrange(len(parts) - 1):
                        name = None
                        if kb.postHint:
                            for ending, _ in hintNames:
                                if parts[i].endswith(ending):
                                    name = "%s %s" % (kb.postHint, _)
                                    break
                        if name is None:
                            name = "%s#%s%s" % (("%s " % kb.postHint) if kb.postHint else "", i + 1, CUSTOM_INJECTION_MARK_CHAR)
                        conf.paramDict[place][name] = "".join("%s%s" % (parts[j], CUSTOM_INJECTION_MARK_CHAR if i == j else "") for j in xrange(len(parts)))

                    if place == PLACE.URI and PLACE.GET in conf.paramDict:
                        del conf.paramDict[PLACE.GET]
                    elif place == PLACE.CUSTOM_POST and PLACE.POST in conf.paramDict:
                        del conf.paramDict[PLACE.POST]

                testableParameters = True

    if kb.processUserMarks:
        for item in ("url", "data", "agent", "referer", "cookie"):
            if conf.get(item):
                conf[item] = conf[item].replace(CUSTOM_INJECTION_MARK_CHAR, "")

    # Perform checks on Cookie parameters
    if conf.cookie:
        conf.parameters[PLACE.COOKIE] = conf.cookie
        paramDict = paramToDict(PLACE.COOKIE, conf.cookie)

        if paramDict:
            conf.paramDict[PLACE.COOKIE] = paramDict
            testableParameters = True

    # Perform checks on header values
    if conf.httpHeaders:
        for httpHeader, headerValue in conf.httpHeaders:
            # Url encoding of the header values should be avoided
            # Reference: http://stackoverflow.com/questions/5085904/is-ok-to-urlencode-the-value-in-headerlocation-value

            httpHeader = httpHeader.title()

            if httpHeader == HTTP_HEADER.USER_AGENT:
                conf.parameters[PLACE.USER_AGENT] = urldecode(headerValue)

                condition = any((not conf.testParameter, intersect(conf.testParameter, USER_AGENT_ALIASES)))

                if condition:
                    conf.paramDict[PLACE.USER_AGENT] = {PLACE.USER_AGENT: headerValue}
                    testableParameters = True

            elif httpHeader == HTTP_HEADER.REFERER:
                conf.parameters[PLACE.REFERER] = urldecode(headerValue)

                condition = any((not conf.testParameter, intersect(conf.testParameter, REFERER_ALIASES)))

                if condition:
                    conf.paramDict[PLACE.REFERER] = {PLACE.REFERER: headerValue}
                    testableParameters = True

            elif httpHeader == HTTP_HEADER.HOST:
                conf.parameters[PLACE.HOST] = urldecode(headerValue)

                condition = any((not conf.testParameter, intersect(conf.testParameter, HOST_ALIASES)))

                if condition:
                    conf.paramDict[PLACE.HOST] = {PLACE.HOST: headerValue}
                    testableParameters = True

    if not conf.parameters:
        errMsg = "you did not provide any GET, POST and Cookie "
        errMsg += "parameter, neither an User-Agent, Referer or Host header value"
        raise SqlmapGenericException(errMsg)

    elif not testableParameters:
        errMsg = "all testable parameters you provided are not present "
        errMsg += "within the given request data"
        raise SqlmapGenericException(errMsg)

    if conf.csrfToken:
        if not any(conf.csrfToken in _ for _ in (conf.paramDict.get(PLACE.GET, {}), conf.paramDict.get(PLACE.POST, {}))) and not conf.csrfToken in set(_[0].lower() for _ in conf.httpHeaders) and not conf.csrfToken in conf.paramDict.get(PLACE.COOKIE, {}):
            errMsg = "anti-CSRF token parameter '%s' not " % conf.csrfToken
            errMsg += "found in provided GET, POST, Cookie or header values"
            raise SqlmapGenericException(errMsg)
    else:
        for place in (PLACE.GET, PLACE.POST, PLACE.COOKIE):
            for parameter in conf.paramDict.get(place, {}):
                if any(parameter.lower().count(_) for _ in CSRF_TOKEN_PARAMETER_INFIXES):
                    message = "%s parameter '%s' appears to hold anti-CSRF token. " % (place, parameter)
                    message += "Do you want sqlmap to automatically update it in further requests? [y/N] "
                    test = readInput(message, default="N")
                    if test and test[0] in ("y", "Y"):
                        conf.csrfToken = parameter
                    break
def _setRequestParams ( ) : if conf . direct : conf . parameters [ None ] = "direct connection" return testableParameters = False # Perform checks on GET parameters if conf . parameters . get ( PLACE . GET ) : parameters = conf . parameters [ PLACE . GET ] paramDict = paramToDict ( PLACE . GET , parameters ) if paramDict : conf . paramDict [ PLACE . GET ] = paramDict testableParameters = True # Perform checks on POST parameters if conf . method == HTTPMETHOD . POST and conf . data is None : logger . warn ( "detected empty POST body" ) conf . data = "" if conf . data is not None : conf . method = HTTPMETHOD . POST if not conf . method or conf . method == HTTPMETHOD . GET else conf . method hintNames = [ ] def process ( match , repl ) : retVal = match . group ( 0 ) if not ( conf . testParameter and match . group ( "name" ) not in conf . testParameter ) : retVal = repl while True : _ = re . search ( r"\\g<([^>]+)>" , retVal ) if _ : retVal = retVal . replace ( _ . group ( 0 ) , match . group ( int ( _ . group ( 1 ) ) if _ . group ( 1 ) . isdigit ( ) else _ . group ( 1 ) ) ) else : break if CUSTOM_INJECTION_MARK_CHAR in retVal : hintNames . append ( ( retVal . split ( CUSTOM_INJECTION_MARK_CHAR ) [ 0 ] , match . group ( "name" ) ) ) return retVal if kb . processUserMarks is None and CUSTOM_INJECTION_MARK_CHAR in conf . data : message = "custom injection marking character ('%s') found in option " % CUSTOM_INJECTION_MARK_CHAR message += "'--data'. Do you want to process it? [Y/n/q] " test = readInput ( message , default = "Y" ) if test and test [ 0 ] in ( "q" , "Q" ) : raise SqlmapUserQuitException else : kb . processUserMarks = not test or test [ 0 ] not in ( "n" , "N" ) if kb . processUserMarks : kb . testOnlyCustom = True if not ( kb . processUserMarks and CUSTOM_INJECTION_MARK_CHAR in conf . data ) : if re . search ( JSON_RECOGNITION_REGEX , conf . data ) : message = "JSON data found in %s data. " % conf . method message += "Do you want to process it? [Y/n/q] " test = readInput ( message , default = "Y" ) if test and test [ 0 ] in ( "q" , "Q" ) : raise SqlmapUserQuitException elif test [ 0 ] not in ( "n" , "N" ) : conf . data = getattr ( conf . data , UNENCODED_ORIGINAL_VALUE , conf . data ) conf . data = conf . data . replace ( CUSTOM_INJECTION_MARK_CHAR , ASTERISK_MARKER ) conf . data = re . sub ( r'("(?P<name>[^"]+)"\s*:\s*"[^"]+)"' , functools . partial ( process , repl = r'\g<1>%s"' % CUSTOM_INJECTION_MARK_CHAR ) , conf . data ) conf . data = re . sub ( r'("(?P<name>[^"]+)"\s*:\s*)(-?\d[\d\.]*\b)' , functools . partial ( process , repl = r'\g<0>%s' % CUSTOM_INJECTION_MARK_CHAR ) , conf . data ) match = re . search ( r'(?P<name>[^"]+)"\s*:\s*\[([^\]]+)\]' , conf . data ) if match and not ( conf . testParameter and match . group ( "name" ) not in conf . testParameter ) : _ = match . group ( 2 ) _ = re . sub ( r'("[^"]+)"' , '\g<1>%s"' % CUSTOM_INJECTION_MARK_CHAR , _ ) _ = re . sub ( r'(\A|,|\s+)(-?\d[\d\.]*\b)' , '\g<0>%s' % CUSTOM_INJECTION_MARK_CHAR , _ ) conf . data = conf . data . replace ( match . group ( 0 ) , match . group ( 0 ) . replace ( match . group ( 2 ) , _ ) ) kb . postHint = POST_HINT . JSON elif re . search ( JSON_LIKE_RECOGNITION_REGEX , conf . data ) : message = "JSON-like data found in %s data. " % conf . method message += "Do you want to process it? [Y/n/q] " test = readInput ( message , default = "Y" ) if test and test [ 0 ] in ( "q" , "Q" ) : raise SqlmapUserQuitException elif test [ 0 ] not in ( "n" , "N" ) : conf . data = getattr ( conf . data , UNENCODED_ORIGINAL_VALUE , conf . data ) conf . data = conf . data . replace ( CUSTOM_INJECTION_MARK_CHAR , ASTERISK_MARKER ) conf . data = re . sub ( r"('(?P<name>[^']+)'\s*:\s*'[^']+)'" , functools . partial ( process , repl = r"\g<1>%s'" % CUSTOM_INJECTION_MARK_CHAR ) , conf . data ) conf . data = re . sub ( r"('(?P<name>[^']+)'\s*:\s*)(-?\d[\d\.]*\b)" , functools . partial ( process , repl = r"\g<0>%s" % CUSTOM_INJECTION_MARK_CHAR ) , conf . data ) kb . postHint = POST_HINT . JSON_LIKE elif re . search ( ARRAY_LIKE_RECOGNITION_REGEX , conf . data ) : message = "Array-like data found in %s data. " % conf . method message += "Do you want to process it? [Y/n/q] " test = readInput ( message , default = "Y" ) if test and test [ 0 ] in ( "q" , "Q" ) : raise SqlmapUserQuitException elif test [ 0 ] not in ( "n" , "N" ) : conf . data = conf . data . replace ( CUSTOM_INJECTION_MARK_CHAR , ASTERISK_MARKER ) conf . data = re . sub ( r"(=[^%s]+)" % DEFAULT_GET_POST_DELIMITER , r"\g<1>%s" % CUSTOM_INJECTION_MARK_CHAR , conf . data ) kb . postHint = POST_HINT . ARRAY_LIKE elif re . search ( XML_RECOGNITION_REGEX , conf . data ) : message = "SOAP/XML data found in %s data. " % conf . method message += "Do you want to process it? [Y/n/q] " test = readInput ( message , default = "Y" ) if test and test [ 0 ] in ( "q" , "Q" ) : raise SqlmapUserQuitException elif test [ 0 ] not in ( "n" , "N" ) : conf . data = getattr ( conf . data , UNENCODED_ORIGINAL_VALUE , conf . data ) conf . data = conf . data . replace ( CUSTOM_INJECTION_MARK_CHAR , ASTERISK_MARKER ) conf . data = re . sub ( r"(<(?P<name>[^>]+)( [^<]*)?>)([^<]+)(</\2)" , functools . partial ( process , repl = r"\g<1>\g<4>%s\g<5>" % CUSTOM_INJECTION_MARK_CHAR ) , conf . data ) kb . postHint = POST_HINT . SOAP if "soap" in conf . data . lower ( ) else POST_HINT . XML elif re . search ( MULTIPART_RECOGNITION_REGEX , conf . data ) : message = "Multipart-like data found in %s data. " % conf . method message += "Do you want to process it? [Y/n/q] " test = readInput ( message , default = "Y" ) if test and test [ 0 ] in ( "q" , "Q" ) : raise SqlmapUserQuitException elif test [ 0 ] not in ( "n" , "N" ) : conf . data = getattr ( conf . data , UNENCODED_ORIGINAL_VALUE , conf . data ) conf . data = conf . data . replace ( CUSTOM_INJECTION_MARK_CHAR , ASTERISK_MARKER ) conf . data = re . sub ( r"(?si)((Content-Disposition[^\n]+?name\s*=\s*[\"'](?P<name>[^\n]+?)[\"']).+?)(((\r)?\n)+--)" , functools . partial ( process , repl = r"\g<1>%s\g<4>" % CUSTOM_INJECTION_MARK_CHAR ) , conf . data ) kb . postHint = POST_HINT . MULTIPART if not kb . postHint : if CUSTOM_INJECTION_MARK_CHAR in conf . data : # later processed pass else : place = PLACE . POST conf . parameters [ place ] = conf . data paramDict = paramToDict ( place , conf . data ) if paramDict : conf . paramDict [ place ] = paramDict testableParameters = True else : if CUSTOM_INJECTION_MARK_CHAR not in conf . data : # in case that no usable parameter values has been found conf . parameters [ PLACE . POST ] = conf . data kb . processUserMarks = True if ( kb . postHint and CUSTOM_INJECTION_MARK_CHAR in conf . data ) else kb . processUserMarks if re . search ( URI_INJECTABLE_REGEX , conf . url , re . I ) and not any ( place in conf . parameters for place in ( PLACE . GET , PLACE . POST ) ) and not kb . postHint and not CUSTOM_INJECTION_MARK_CHAR in ( conf . data or "" ) and conf . url . startswith ( "http" ) : warnMsg = "you've provided target URL without any GET " warnMsg += "parameters (e.g. www.site.com/article.php?id=1) " warnMsg += "and without providing any POST parameters " warnMsg += "through --data option" logger . warn ( warnMsg ) message = "do you want to try URI injections " message += "in the target URL itself? [Y/n/q] " test = readInput ( message , default = "Y" ) if test and test [ 0 ] in ( "q" , "Q" ) : raise SqlmapUserQuitException elif not test or test [ 0 ] not in ( "n" , "N" ) : conf . url = "%s%s" % ( conf . url , CUSTOM_INJECTION_MARK_CHAR ) kb . processUserMarks = True for place , value in ( ( PLACE . URI , conf . url ) , ( PLACE . CUSTOM_POST , conf . data ) , ( PLACE . CUSTOM_HEADER , str ( conf . httpHeaders ) ) ) : _ = re . sub ( PROBLEMATIC_CUSTOM_INJECTION_PATTERNS , "" , value or "" ) if place == PLACE . CUSTOM_HEADER else value or "" if CUSTOM_INJECTION_MARK_CHAR in _ : if kb . processUserMarks is None : lut = { PLACE . URI : '-u' , PLACE . CUSTOM_POST : '--data' , PLACE . CUSTOM_HEADER : '--headers/--user-agent/--referer/--cookie' } message = "custom injection marking character ('%s') found in option " % CUSTOM_INJECTION_MARK_CHAR message += "'%s'. Do you want to process it? [Y/n/q] " % lut [ place ] test = readInput ( message , default = "Y" ) if test and test [ 0 ] in ( "q" , "Q" ) : raise SqlmapUserQuitException else : kb . processUserMarks = not test or test [ 0 ] not in ( "n" , "N" ) if kb . processUserMarks : kb . testOnlyCustom = True if "=%s" % CUSTOM_INJECTION_MARK_CHAR in _ : warnMsg = "it seems that you've provided empty parameter value(s) " warnMsg += "for testing. Please, always use only valid parameter values " warnMsg += "so sqlmap could be able to run properly" logger . warn ( warnMsg ) if not kb . processUserMarks : if place == PLACE . URI : query = urlparse . urlsplit ( value ) . query if query : parameters = conf . parameters [ PLACE . GET ] = query paramDict = paramToDict ( PLACE . GET , parameters ) if paramDict : conf . url = conf . url . split ( '?' ) [ 0 ] conf . paramDict [ PLACE . GET ] = paramDict testableParameters = True elif place == PLACE . CUSTOM_POST : conf . parameters [ PLACE . POST ] = conf . data paramDict = paramToDict ( PLACE . POST , conf . data ) if paramDict : conf . paramDict [ PLACE . POST ] = paramDict testableParameters = True else : conf . parameters [ place ] = value conf . paramDict [ place ] = OrderedDict ( ) if place == PLACE . CUSTOM_HEADER : for index in xrange ( len ( conf . httpHeaders ) ) : header , value = conf . httpHeaders [ index ] if CUSTOM_INJECTION_MARK_CHAR in re . sub ( PROBLEMATIC_CUSTOM_INJECTION_PATTERNS , "" , value ) : parts = value . split ( CUSTOM_INJECTION_MARK_CHAR ) for i in xrange ( len ( parts ) - 1 ) : conf . paramDict [ place ] [ "%s #%d%s" % ( header , i + 1 , CUSTOM_INJECTION_MARK_CHAR ) ] = "%s,%s" % ( header , "" . join ( "%s%s" % ( parts [ j ] , CUSTOM_INJECTION_MARK_CHAR if i == j else "" ) for j in xrange ( len ( parts ) ) ) ) conf . httpHeaders [ index ] = ( header , value . replace ( CUSTOM_INJECTION_MARK_CHAR , "" ) ) else : parts = value . split ( CUSTOM_INJECTION_MARK_CHAR ) for i in xrange ( len ( parts ) - 1 ) : name = None if kb . postHint : for ending , _ in hintNames : if parts [ i ] . endswith ( ending ) : name = "%s %s" % ( kb . postHint , _ ) break if name is None : name = "%s#%s%s" % ( ( "%s " % kb . postHint ) if kb . postHint else "" , i + 1 , CUSTOM_INJECTION_MARK_CHAR ) conf . paramDict [ place ] [ name ] = "" . join ( "%s%s" % ( parts [ j ] , CUSTOM_INJECTION_MARK_CHAR if i == j else "" ) for j in xrange ( len ( parts ) ) ) if place == PLACE . URI and PLACE . GET in conf . paramDict : del conf . paramDict [ PLACE . GET ] elif place == PLACE . CUSTOM_POST and PLACE . POST in conf . paramDict : del conf . paramDict [ PLACE . POST ] testableParameters = True if kb . processUserMarks : for item in ( "url" , "data" , "agent" , "referer" , "cookie" ) : if conf . get ( item ) : conf [ item ] = conf [ item ] . replace ( CUSTOM_INJECTION_MARK_CHAR , "" ) # Perform checks on Cookie parameters if conf . cookie : conf . parameters [ PLACE . COOKIE ] = conf . cookie paramDict = paramToDict ( PLACE . COOKIE , conf . cookie ) if paramDict : conf . paramDict [ PLACE . COOKIE ] = paramDict testableParameters = True # Perform checks on header values if conf . httpHeaders : for httpHeader , headerValue in conf . httpHeaders : # Url encoding of the header values should be avoided # Reference: http://stackoverflow.com/questions/5085904/is-ok-to-urlencode-the-value-in-headerlocation-value httpHeader = httpHeader . title ( ) if httpHeader == HTTP_HEADER . USER_AGENT : conf . parameters [ PLACE . USER_AGENT ] = urldecode ( headerValue ) condition = any ( ( not conf . testParameter , intersect ( conf . testParameter , USER_AGENT_ALIASES ) ) ) if condition : conf . paramDict [ PLACE . USER_AGENT ] = { PLACE . USER_AGENT : headerValue } testableParameters = True elif httpHeader == HTTP_HEADER . REFERER : conf . parameters [ PLACE . REFERER ] = urldecode ( headerValue ) condition = any ( ( not conf . testParameter , intersect ( conf . testParameter , REFERER_ALIASES ) ) ) if condition : conf . paramDict [ PLACE . REFERER ] = { PLACE . REFERER : headerValue } testableParameters = True elif httpHeader == HTTP_HEADER . HOST : conf . parameters [ PLACE . HOST ] = urldecode ( headerValue ) condition = any ( ( not conf . testParameter , intersect ( conf . testParameter , HOST_ALIASES ) ) ) if condition : conf . paramDict [ PLACE . HOST ] = { PLACE . HOST : headerValue } testableParameters = True if not conf . parameters : errMsg = "you did not provide any GET, POST and Cookie " errMsg += "parameter, neither an User-Agent, Referer or Host header value" raise SqlmapGenericException ( errMsg ) elif not testableParameters : errMsg = "all testable parameters you provided are not present " errMsg += "within the given request data" raise SqlmapGenericException ( errMsg ) if conf . csrfToken : if not any ( conf . csrfToken in _ for _ in ( conf . paramDict . get ( PLACE . GET , { } ) , conf . paramDict . get ( PLACE . POST , { } ) ) ) and not conf . csrfToken in set ( _ [ 0 ] . lower ( ) for _ in conf . httpHeaders ) and not conf . csrfToken in conf . paramDict . get ( PLACE . COOKIE , { } ) : errMsg = "anti-CSRF token parameter '%s' not " % conf . csrfToken errMsg += "found in provided GET, POST, Cookie or header values" raise SqlmapGenericException ( errMsg ) else : for place in ( PLACE . GET , PLACE . POST , PLACE . COOKIE ) : for parameter in conf . paramDict . get ( place , { } ) : if any ( parameter . lower ( ) . count ( _ ) for _ in CSRF_TOKEN_PARAMETER_INFIXES ) : message = "%s parameter '%s' appears to hold anti-CSRF token. " % ( place , parameter ) message += "Do you want sqlmap to automatically update it in further requests? [y/N] " test = readInput ( message , default = "N" ) if test and test [ 0 ] in ( "y" , "Y" ) : conf . csrfToken = parameter break