Skip to content

Commit b363f1c

Browse files
committed
Added support for NTLM authentication
1 parent e28b98a commit b363f1c

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

lib/core/exception.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,38 +46,42 @@ class sqlmapGenericException(Exception):
4646
pass
4747

4848

49-
class sqlmapMissingMandatoryOptionException(Exception):
49+
class sqlmapMissingDependence(Exception):
5050
pass
5151

5252

53-
class sqlmapNoneDataException(Exception):
53+
class sqlmapMissingMandatoryOptionException(Exception):
5454
pass
5555

5656

57-
class sqlmapRegExprException(Exception):
57+
class sqlmapMissingPrivileges(Exception):
5858
pass
5959

6060

61-
class sqlmapSyntaxException(Exception):
61+
class sqlmapNoneDataException(Exception):
6262
pass
6363

6464

65-
class sqlmapUndefinedMethod(Exception):
65+
class sqlmapNotVulnerableException(Exception):
6666
pass
6767

6868

69-
class sqlmapMissingPrivileges(Exception):
69+
class sqlmapRegExprException(Exception):
7070
pass
7171

7272

73-
class sqlmapNotVulnerableException(Exception):
73+
class sqlmapSyntaxException(Exception):
7474
pass
7575

7676

7777
class sqlmapThreadException(Exception):
7878
pass
7979

8080

81+
class sqlmapUndefinedMethod(Exception):
82+
pass
83+
84+
8185
class sqlmapUnsupportedDBMSException(Exception):
8286
pass
8387

@@ -105,6 +109,7 @@ def unhandledException():
105109
sqlmapDataException,
106110
sqlmapFilePathException,
107111
sqlmapGenericException,
112+
sqlmapMissingDependence,
108113
sqlmapMissingMandatoryOptionException,
109114
sqlmapNoneDataException,
110115
sqlmapRegExprException,
@@ -116,4 +121,4 @@ def unhandledException():
116121
sqlmapUnsupportedDBMSException,
117122
sqlmapUnsupportedFeatureException,
118123
sqlmapValueException,
119-
)
124+
)

lib/core/option.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from lib.core.datatype import advancedDict
4949
from lib.core.exception import sqlmapFilePathException
5050
from lib.core.exception import sqlmapGenericException
51+
from lib.core.exception import sqlmapMissingDependence
5152
from lib.core.exception import sqlmapMissingMandatoryOptionException
5253
from lib.core.exception import sqlmapMissingPrivileges
5354
from lib.core.exception import sqlmapSyntaxException
@@ -528,7 +529,7 @@ def __setHTTPProxy():
528529

529530
def __setHTTPAuthentication():
530531
"""
531-
Check and set the HTTP authentication method (Basic or Digest),
532+
Check and set the HTTP authentication method (Basic, Digest or NTLM),
532533
username and password to perform HTTP requests with.
533534
"""
534535

@@ -538,29 +539,29 @@ def __setHTTPAuthentication():
538539
return
539540

540541
elif conf.aType and not conf.aCred:
541-
errMsg = "you specified the HTTP Authentication type, but "
542+
errMsg = "you specified the HTTP authentication type, but "
542543
errMsg += "did not provide the credentials"
543544
raise sqlmapSyntaxException, errMsg
544545

545546
elif not conf.aType and conf.aCred:
546-
errMsg = "you specified the HTTP Authentication credentials, "
547+
errMsg = "you specified the HTTP authentication credentials, "
547548
errMsg += "but did not provide the type"
548549
raise sqlmapSyntaxException, errMsg
549550

550-
debugMsg = "setting the HTTP Authentication type and credentials"
551+
debugMsg = "setting the HTTP authentication type and credentials"
551552
logger.debug(debugMsg)
552553

553554
aTypeLower = conf.aType.lower()
554555

555-
if aTypeLower not in ( "basic", "digest" ):
556-
errMsg = "HTTP Authentication type value must be "
557-
errMsg += "Basic or Digest"
556+
if aTypeLower not in ( "basic", "digest", "ntlm" ):
557+
errMsg = "HTTP authentication type value must be "
558+
errMsg += "Basic, Digest or NTLM"
558559
raise sqlmapSyntaxException, errMsg
559560

560561
aCredRegExp = re.search("^(.*?)\:(.*?)$", conf.aCred)
561562

562563
if not aCredRegExp:
563-
errMsg = "HTTP Authentication credentials value must be "
564+
errMsg = "HTTP authentication credentials value must be "
564565
errMsg += "in format username:password"
565566
raise sqlmapSyntaxException, errMsg
566567

@@ -572,9 +573,21 @@ def __setHTTPAuthentication():
572573

573574
if aTypeLower == "basic":
574575
authHandler = urllib2.HTTPBasicAuthHandler(passwordMgr)
576+
575577
elif aTypeLower == "digest":
576578
authHandler = urllib2.HTTPDigestAuthHandler(passwordMgr)
577579

580+
elif aTypeLower == "ntlm":
581+
try:
582+
from ntlm import HTTPNtlmAuthHandler
583+
except ImportError, _:
584+
errMsg = "sqlmap requires Python NTLM third-party library "
585+
errMsg += "in order to authenticate via NTLM, "
586+
errMsg += "http://code.google.com/p/python-ntlm/"
587+
raise sqlmapMissingDependence, errMsg
588+
589+
authHandler = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passwordMgr)
590+
578591

579592
def __setHTTPMethod():
580593
"""

lib/parse/cmdline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def cmdLineParser():
9090

9191
request.add_option("--auth-type", dest="aType",
9292
help="HTTP Authentication type (value "
93-
"Basic or Digest)")
93+
"Basic, Digest or NTLM)")
9494

9595
request.add_option("--auth-cred", dest="aCred",
9696
help="HTTP Authentication credentials (value "

0 commit comments

Comments
 (0)