minor refactoring

This commit is contained in:
Miroslav Stampar 2011-11-29 19:17:07 +00:00
parent 3cd8f47686
commit 872a73f631
4 changed files with 22 additions and 15 deletions

View File

@ -39,6 +39,7 @@ from lib.core.convert import urldecode
from lib.core.data import conf from lib.core.data import conf
from lib.core.data import kb from lib.core.data import kb
from lib.core.data import logger from lib.core.data import logger
from lib.core.enums import HTTPHEADER
from lib.core.enums import HTTPMETHOD from lib.core.enums import HTTPMETHOD
from lib.core.enums import PAYLOAD from lib.core.enums import PAYLOAD
from lib.core.enums import PLACE from lib.core.enums import PLACE
@ -358,7 +359,7 @@ def start():
setCookieAsInjectable = False setCookieAsInjectable = False
if setCookieAsInjectable: if setCookieAsInjectable:
conf.httpHeaders.append(("Cookie", cookieStr)) conf.httpHeaders.append((HTTPHEADER.COOKIE, cookieStr))
conf.parameters[PLACE.COOKIE] = cookieStr conf.parameters[PLACE.COOKIE] = cookieStr
__paramDict = paramToDict(PLACE.COOKIE, cookieStr) __paramDict = paramToDict(PLACE.COOKIE, cookieStr)

View File

@ -87,8 +87,11 @@ class MOBILES:
class HTTPHEADER: class HTTPHEADER:
ACCEPT = "Accept" ACCEPT = "Accept"
ACCEPT_CHARSET = "Accept-Charset"
ACCEPT_ENCODING = "Accept-Encoding" ACCEPT_ENCODING = "Accept-Encoding"
ACCEPT_LANGUAGE = "Accept-Language"
AUTHORIZATION = "Authorization" AUTHORIZATION = "Authorization"
CACHE_CONTROL = "Cache-Control"
CONNECTION = "Connection" CONNECTION = "Connection"
CONTENT_ENCODING = "Content-Encoding" CONTENT_ENCODING = "Content-Encoding"
CONTENT_LENGTH = "Content-Length" CONTENT_LENGTH = "Content-Length"
@ -96,7 +99,9 @@ class HTTPHEADER:
CONTENT_TYPE = "Content-Type" CONTENT_TYPE = "Content-Type"
COOKIE = "Cookie" COOKIE = "Cookie"
HOST = "Host" HOST = "Host"
PROXY_AUTHORIZATION = "Proxy-authorization" PRAGMA = "Pragma"
PROXY_AUTHORIZATION = "Proxy-Authorization"
PROXY_CONNECTION = "Proxy-Connection"
RANGE = "Range" RANGE = "Range"
REFERER = "Referer" REFERER = "Referer"
USER_AGENT = "User-Agent" USER_AGENT = "User-Agent"

View File

@ -289,11 +289,11 @@ def __feedTargetsDict(reqFile, addedTargetUrls):
# Avoid to add a static content length header to # Avoid to add a static content length header to
# conf.httpHeaders and consider the following lines as # conf.httpHeaders and consider the following lines as
# POSTed data # POSTed data
if key == "Content-Length": if key == HTTPHEADER.CONTENT_LENGTH:
params = True params = True
# Avoid proxy and connection type related headers # Avoid proxy and connection type related headers
elif key not in ( "Proxy-Connection", "Connection" ): elif key not in ( HTTPHEADER.PROXY_CONNECTION, HTTPHEADER.CONNECTION ):
conf.httpHeaders.append((str(key), str(value))) conf.httpHeaders.append((str(key), str(value)))
if conf.scope: if conf.scope:
@ -1080,16 +1080,16 @@ def __setHTTPExtraHeaders():
conf.httpHeaders.append((header, value)) conf.httpHeaders.append((header, value))
elif not conf.httpHeaders or len(conf.httpHeaders) == 1: elif not conf.httpHeaders or len(conf.httpHeaders) == 1:
conf.httpHeaders.append(("Accept-Language", "en-us,en;q=0.5")) conf.httpHeaders.append((HTTPHEADER.ACCEPT_LANGUAGE, "en-us,en;q=0.5"))
if not conf.charset: if not conf.charset:
conf.httpHeaders.append(("Accept-Charset", "ISO-8859-15,utf-8;q=0.7,*;q=0.7")) conf.httpHeaders.append((HTTPHEADER.ACCEPT_CHARSET, "ISO-8859-15,utf-8;q=0.7,*;q=0.7"))
else: else:
conf.httpHeaders.append(("Accept-Charset", "%s;q=0.7,*;q=0.1" % conf.charset)) conf.httpHeaders.append((HTTPHEADER.ACCEPT_CHARSET, "%s;q=0.7,*;q=0.1" % conf.charset))
# Invalidating any caching mechanism in between # Invalidating any caching mechanism in between
# Reference: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html # Reference: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
conf.httpHeaders.append(("Cache-Control", "no-cache,no-store")) conf.httpHeaders.append((HTTPHEADER.CACHE_CONTROL, "no-cache,no-store"))
conf.httpHeaders.append(("Pragma", "no-cache")) conf.httpHeaders.append((HTTPHEADER.PRAGMA, "no-cache"))
def __defaultHTTPUserAgent(): def __defaultHTTPUserAgent():
""" """

View File

@ -26,6 +26,7 @@ from lib.core.common import singleTimeLogMessage
from lib.core.data import conf from lib.core.data import conf
from lib.core.data import kb from lib.core.data import kb
from lib.core.data import logger from lib.core.data import logger
from lib.core.enums import HTTPHEADER
from lib.core.exception import sqlmapDataException from lib.core.exception import sqlmapDataException
from lib.core.settings import ML from lib.core.settings import ML
from lib.core.settings import META_CHARSET_REGEX from lib.core.settings import META_CHARSET_REGEX
@ -43,20 +44,20 @@ def forgeHeaders(cookie, ua, referer):
headers = {} headers = {}
for header, value in conf.httpHeaders: for header, value in conf.httpHeaders:
if cookie and header == "Cookie": if cookie and header == HTTPHEADER.COOKIE:
headers[header] = cookie headers[header] = cookie
elif ua and header == "User-Agent": elif ua and header == HTTPHEADER.USER_AGENT:
headers[header] = ua headers[header] = ua
elif referer and header == "Referer": elif referer and header == HTTPHEADER.REFERER:
headers[header] = referer headers[header] = referer
else: else:
headers[header] = value headers[header] = value
if kb.redirectSetCookie and not conf.dropSetCookie: if kb.redirectSetCookie and not conf.dropSetCookie:
if "Cookie" in headers: if HTTPHEADER.COOKIE in headers:
headers["Cookie"] = "%s; %s" % (headers["Cookie"], kb.redirectSetCookie) headers[HTTPHEADER.COOKIE] = "%s; %s" % (headers[HTTPHEADER.COOKIE], kb.redirectSetCookie)
else: else:
headers["Cookie"] = kb.redirectSetCookie headers[HTTPHEADER.COOKIE] = kb.redirectSetCookie
return headers return headers