@@ -758,16 +758,21 @@ def _adjustParameter(paramString, parameter, newValue):
758758 retVal = re .sub ("%s=[^&]*" % parameter , "%s=%s" % (parameter , newValue ), paramString )
759759 return retVal
760760
761- page , _ , _ = Connect .getPage (url = conf .csrfUrl or conf .url , cookie = conf .parameters .get (PLACE .COOKIE ), direct = True , silent = True , ua = conf .parameters .get (PLACE .USER_AGENT ), referer = conf .parameters .get (PLACE .REFERER ), host = conf .parameters .get (PLACE .HOST ))
762- match = re .search (r"<input[^>]+name=[\"']?%s[\"']?\s[^>]*value=(\"([^\"]+)|'([^']+)|([^ >]+))" % conf .csrfToken , page )
761+ page , headers , code = Connect .getPage (url = conf .csrfUrl or conf .url , cookie = conf .parameters .get (PLACE .COOKIE ), direct = True , silent = True , ua = conf .parameters .get (PLACE .USER_AGENT ), referer = conf .parameters .get (PLACE .REFERER ), host = conf .parameters .get (PLACE .HOST ))
762+ match = re .search (r"<input[^>]+name=[\"']?%s[\"']?\s[^>]*value=(\"([^\"]+)|'([^']+)|([^ >]+))" % conf .csrfToken , page or "" )
763763 token = (match .group (2 ) or match .group (3 ) or match .group (4 )) if match else None
764764
765765 if not token :
766- errMsg = "CSRF token value '%s' can't be found at '%s'" % (conf .csrfToken , conf .csrfUrl or conf .url )
767- if not conf .csrfUrl :
768- errMsg += ". You can try to rerun by providing "
769- errMsg += "a valid value for option '--csrf-url'"
770- raise SqlmapTokenException , errMsg
766+ if conf .csrfUrl != conf .url and code == httplib .OK :
767+ if headers and "text/plain" in headers .get (HTTP_HEADER .CONTENT_TYPE , "" ):
768+ token = page
769+
770+ if not token :
771+ errMsg = "CSRF token value '%s' can't be found at '%s'" % (conf .csrfToken , conf .csrfUrl or conf .url )
772+ if not conf .csrfUrl :
773+ errMsg += ". You can try to rerun by providing "
774+ errMsg += "a valid value for option '--csrf-url'"
775+ raise SqlmapTokenException , errMsg
771776
772777 if token :
773778 for item in (PLACE .GET , PLACE .POST ):
@@ -777,6 +782,10 @@ def _adjustParameter(paramString, parameter, newValue):
777782 elif item == PLACE .POST and post :
778783 post = _adjustParameter (post , conf .csrfToken , token )
779784
785+ for i in xrange (len (conf .httpHeaders )):
786+ if conf .httpHeaders [i ][0 ].lower () == conf .csrfToken .lower ():
787+ conf .httpHeaders [i ] = (conf .httpHeaders [i ][0 ], token )
788+
780789 if conf .rParam :
781790 def _randomizeParameter (paramString , randomParameter ):
782791 retVal = paramString
0 commit comments