Minor fix (digest live test case) and some refactoring

This commit is contained in:
Miroslav Stampar 2013-03-12 21:16:44 +01:00
parent 65306f1ac1
commit 2f43c3eb9b
3 changed files with 14 additions and 7 deletions

View File

@ -308,3 +308,8 @@ PART_RUN_CONTENT_TYPES = {
class CONTENT_STATUS: class CONTENT_STATUS:
IN_PROGRESS = 0 IN_PROGRESS = 0
COMPLETE = 1 COMPLETE = 1
class AUTH_TYPE:
BASIC = "basic"
DIGEST = "digest"
NTLM = "ntlm"

View File

@ -64,6 +64,7 @@ from lib.core.defaults import defaults
from lib.core.dicts import DBMS_DICT from lib.core.dicts import DBMS_DICT
from lib.core.dicts import DUMP_REPLACEMENTS from lib.core.dicts import DUMP_REPLACEMENTS
from lib.core.enums import ADJUST_TIME_DELAY from lib.core.enums import ADJUST_TIME_DELAY
from lib.core.enums import AUTH_TYPE
from lib.core.enums import CUSTOM_LOGGING from lib.core.enums import CUSTOM_LOGGING
from lib.core.enums import DUMP_FORMAT from lib.core.enums import DUMP_FORMAT
from lib.core.enums import HTTPHEADER from lib.core.enums import HTTPHEADER
@ -1098,15 +1099,15 @@ def _setHTTPAuthentication():
aTypeLower = conf.aType.lower() aTypeLower = conf.aType.lower()
if aTypeLower not in ("basic", "digest", "ntlm"): if aTypeLower not in (AUTH_TYPE.BASIC, AUTH_TYPE.DIGEST, AUTH_TYPE.NTLM):
errMsg = "HTTP authentication type value must be " errMsg = "HTTP authentication type value must be "
errMsg += "Basic, Digest or NTLM" errMsg += "Basic, Digest or NTLM"
raise SqlmapSyntaxException(errMsg) raise SqlmapSyntaxException(errMsg)
elif aTypeLower in ("basic", "digest"): elif aTypeLower in (AUTH_TYPE.BASIC, AUTH_TYPE.DIGEST):
regExp = "^(.*?):(.*?)$" regExp = "^(.*?):(.*?)$"
errMsg = "HTTP %s authentication credentials " % aTypeLower errMsg = "HTTP %s authentication credentials " % aTypeLower
errMsg += "value must be in format username:password" errMsg += "value must be in format username:password"
elif aTypeLower == "ntlm": elif aTypeLower == AUTH_TYPE.NTLM:
regExp = "^(.*\\\\.*):(.*?)$" regExp = "^(.*\\\\.*):(.*?)$"
errMsg = "HTTP NTLM authentication credentials value must " errMsg = "HTTP NTLM authentication credentials value must "
errMsg += "be in format DOMAIN\username:password" errMsg += "be in format DOMAIN\username:password"
@ -1123,13 +1124,13 @@ def _setHTTPAuthentication():
_setAuthCred() _setAuthCred()
if aTypeLower == "basic": if aTypeLower == AUTH_TYPE.BASIC:
authHandler = SmartHTTPBasicAuthHandler(kb.passwordMgr) authHandler = SmartHTTPBasicAuthHandler(kb.passwordMgr)
elif aTypeLower == "digest": elif aTypeLower == AUTH_TYPE.DIGEST:
authHandler = urllib2.HTTPDigestAuthHandler(kb.passwordMgr) authHandler = urllib2.HTTPDigestAuthHandler(kb.passwordMgr)
elif aTypeLower == "ntlm": elif aTypeLower == AUTH_TYPE.NTLM:
try: try:
from ntlm import HTTPNtlmAuthHandler from ntlm import HTTPNtlmAuthHandler
except ImportError: except ImportError:

View File

@ -47,6 +47,7 @@ from lib.core.data import kb
from lib.core.data import logger from lib.core.data import logger
from lib.core.dicts import POST_HINT_CONTENT_TYPES from lib.core.dicts import POST_HINT_CONTENT_TYPES
from lib.core.enums import ADJUST_TIME_DELAY from lib.core.enums import ADJUST_TIME_DELAY
from lib.core.enums import AUTH_TYPE
from lib.core.enums import CUSTOM_LOGGING from lib.core.enums import CUSTOM_LOGGING
from lib.core.enums import HTTPHEADER from lib.core.enums import HTTPHEADER
from lib.core.enums import HTTPMETHOD from lib.core.enums import HTTPMETHOD
@ -364,7 +365,7 @@ class Connect(object):
conn = urllib2.urlopen(req) conn = urllib2.urlopen(req)
if not kb.authHeader and getRequestHeader(req, HTTPHEADER.AUTHORIZATION): if not kb.authHeader and getRequestHeader(req, HTTPHEADER.AUTHORIZATION) and conf.aType == AUTH_TYPE.BASIC:
kb.authHeader = getRequestHeader(req, HTTPHEADER.AUTHORIZATION) kb.authHeader = getRequestHeader(req, HTTPHEADER.AUTHORIZATION)
if not kb.proxyAuthHeader and getRequestHeader(req, HTTPHEADER.PROXY_AUTHORIZATION): if not kb.proxyAuthHeader and getRequestHeader(req, HTTPHEADER.PROXY_AUTHORIZATION):