(content, url, raise_=False, addToTargets=False)
return retVal
Parses given page content for possible forms
Parses given page content for possible forms
Parses given page content for possible forms
def findPageForms(content, url, raise_=False, addToTargets=False):
    """
    Parses given page content for possible forms
    """

    class _(StringIO):
        def __init__(self, content, url):
            StringIO.__init__(self, unicodeencode(content, kb.pageEncoding) if isinstance(content, unicode) else content)
            self._url = url
        def geturl(self):
            return self._url

    if not content:
        errMsg = "can't parse forms as the page content appears to be blank"
        if raise_:
            raise SqlmapGenericException(errMsg)
        else:
            logger.debug(errMsg)

    forms = None
    retVal = set()
    response = _(content, url)

    try:
        forms = ParseResponse(response, backwards_compat=False)
    except UnicodeError:
        pass
    except ParseError:
        if "<html" in (content or ""):
            warnMsg = "badly formed HTML at the given URL ('%s'). Going to filter it" % url
            logger.warning(warnMsg)
            filtered = _("".join(re.findall(FORM_SEARCH_REGEX, content)), url)
            try:
                forms = ParseResponse(filtered, backwards_compat=False)
            except ParseError:
                errMsg = "no success"
                if raise_:
                    raise SqlmapGenericException(errMsg)
                else:
                    logger.debug(errMsg)

    if forms:
        for form in forms:
            try:
                for control in form.controls:
                    if hasattr(control, "items") and not any((control.disabled, control.readonly)):
                        # if control has selectable items select first non-disabled
                        for item in control.items:
                            if not item.disabled:
                                if not item.selected:
                                    item.selected = True
                                break

                request = form.click()
            except (ValueError, TypeError), ex:
                errMsg = "there has been a problem while "
                errMsg += "processing page forms ('%s')" % getSafeExString(ex)
                if raise_:
                    raise SqlmapGenericException(errMsg)
                else:
                    logger.debug(errMsg)
            else:
                url = urldecode(request.get_full_url(), kb.pageEncoding)
                method = request.get_method()
                data = request.get_data() if request.has_data() else None
                data = urldecode(data, kb.pageEncoding, plusspace=False)

                if not data and method and method.upper() == HTTPMETHOD.POST:
                    debugMsg = "invalid POST form with blank data detected"
                    logger.debug(debugMsg)
                    continue

                # flag to know if we are dealing with the same target host
                _ = reduce(lambda x, y: x == y, map(lambda x: urlparse.urlparse(x).netloc.split(':')[0], (response.geturl(), url)))

                if conf.scope:
                    if not re.search(conf.scope, url, re.I):
                        continue
                elif not _:
                    continue
                else:
                    target = (url, method, data, conf.cookie, None)
                    retVal.add(target)
    else:
        errMsg = "there were no forms found at the given target URL"
        if raise_:
            raise SqlmapGenericException(errMsg)
        else:
            logger.debug(errMsg)

    if addToTargets and retVal:
        for target in retVal:
            kb.targets.add(target)

    return retVal
def findPageForms ( content , url , raise_ = False , addToTargets = False ) : class _ ( StringIO ) : def __init__ ( self , content , url ) : StringIO . __init__ ( self , unicodeencode ( content , kb . pageEncoding ) if isinstance ( content , unicode ) else content ) self . _url = url def geturl ( self ) : return self . _url if not content : errMsg = "can't parse forms as the page content appears to be blank" if raise_ : raise SqlmapGenericException ( errMsg ) else : logger . debug ( errMsg ) forms = None retVal = set ( ) response = _ ( content , url ) try : forms = ParseResponse ( response , backwards_compat = False ) except UnicodeError : pass except ParseError : if "<html" in ( content or "" ) : warnMsg = "badly formed HTML at the given URL ('%s'). Going to filter it" % url logger . warning ( warnMsg ) filtered = _ ( "" . join ( re . findall ( FORM_SEARCH_REGEX , content ) ) , url ) try : forms = ParseResponse ( filtered , backwards_compat = False ) except ParseError : errMsg = "no success" if raise_ : raise SqlmapGenericException ( errMsg ) else : logger . debug ( errMsg ) if forms : for form in forms : try : for control in form . controls : if hasattr ( control , "items" ) and not any ( ( control . disabled , control . readonly ) ) : # if control has selectable items select first non-disabled for item in control . items : if not item . disabled : if not item . selected : item . selected = True break request = form . click ( ) except ( ValueError , TypeError ) , ex : errMsg = "there has been a problem while " errMsg += "processing page forms ('%s')" % getSafeExString ( ex ) if raise_ : raise SqlmapGenericException ( errMsg ) else : logger . debug ( errMsg ) else : url = urldecode ( request . get_full_url ( ) , kb . pageEncoding ) method = request . get_method ( ) data = request . get_data ( ) if request . has_data ( ) else None data = urldecode ( data , kb . pageEncoding , plusspace = False ) if not data and method and method . upper ( ) == HTTPMETHOD . POST : debugMsg = "invalid POST form with blank data detected" logger . debug ( debugMsg ) continue # flag to know if we are dealing with the same target host _ = reduce ( lambda x , y : x == y , map ( lambda x : urlparse . urlparse ( x ) . netloc . split ( ':' ) [ 0 ] , ( response . geturl ( ) , url ) ) ) if conf . scope : if not re . search ( conf . scope , url , re . I ) : continue elif not _ : continue else : target = ( url , method , data , conf . cookie , None ) retVal . add ( target ) else : errMsg = "there were no forms found at the given target URL" if raise_ : raise SqlmapGenericException ( errMsg ) else : logger . debug ( errMsg ) if addToTargets and retVal : for target in retVal : kb . targets . add ( target ) return retVal