Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a3defc1

Browse files
committed
Fix (we are not using certificate but PEM private key file in this particular authentication; also, auxiliary cert_file is holding certificate chain that is ignored by python itself)
1 parent 176f744 commit a3defc1

7 files changed

Lines changed: 30 additions & 222 deletions

File tree

extra/shutils/_sqlmap.py

Lines changed: 0 additions & 177 deletions
This file was deleted.

lib/core/enums.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,4 @@ class AUTH_TYPE:
323323
BASIC = "basic"
324324
DIGEST = "digest"
325325
NTLM = "ntlm"
326-
CERT = "cert"
326+
PKI = "pki"

lib/core/option.py

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from lib.controller.checks import checkConnection
2828
from lib.core.common import Backend
2929
from lib.core.common import boldifyMessage
30+
from lib.core.common import checkFile
3031
from lib.core.common import dataToStdout
3132
from lib.core.common import getPublicTypeMembers
3233
from lib.core.common import extractRegexResult
@@ -133,8 +134,8 @@
133134
from lib.request.connect import Connect as Request
134135
from lib.request.dns import DNSServer
135136
from lib.request.basicauthhandler import SmartHTTPBasicAuthHandler
136-
from lib.request.certhandler import HTTPSCertAuthHandler
137137
from lib.request.httpshandler import HTTPSHandler
138+
from lib.request.pkihandler import HTTPSPKIAuthHandler
138139
from lib.request.rangehandler import HTTPRangeHandler
139140
from lib.request.redirecthandler import SmartRedirectHandler
140141
from lib.request.templates import getPageTemplate
@@ -1102,17 +1103,17 @@ def _setAuthCred():
11021103

11031104
def _setHTTPAuthentication():
11041105
"""
1105-
Check and set the HTTP(s) authentication method (Basic, Digest, NTLM or Certificate),
1106-
username and password for first three methods, or key file and certification file for
1107-
certificate authentication
1106+
Check and set the HTTP(s) authentication method (Basic, Digest, NTLM or PKI),
1107+
username and password for first three methods, or PEM private key file for
1108+
PKI authentication
11081109
"""
11091110

11101111
global authHandler
11111112

1112-
if not conf.authType and not conf.authCred and not conf.authCert:
1113+
if not conf.authType and not conf.authCred and not conf.authPrivate:
11131114
return
11141115

1115-
elif conf.authType and not conf.authCred and not conf.authCert:
1116+
elif conf.authType and not conf.authCred and not conf.authPrivate:
11161117
errMsg = "you specified the HTTP authentication type, but "
11171118
errMsg += "did not provide the credentials"
11181119
raise SqlmapSyntaxException(errMsg)
@@ -1122,15 +1123,15 @@ def _setHTTPAuthentication():
11221123
errMsg += "but did not provide the type"
11231124
raise SqlmapSyntaxException(errMsg)
11241125

1125-
if not conf.authCert:
1126+
if not conf.authPrivate:
11261127
debugMsg = "setting the HTTP authentication type and credentials"
11271128
logger.debug(debugMsg)
11281129

11291130
aTypeLower = conf.authType.lower()
11301131

1131-
if aTypeLower not in (AUTH_TYPE.BASIC, AUTH_TYPE.DIGEST, AUTH_TYPE.NTLM, AUTH_TYPE.CERT):
1132+
if aTypeLower not in (AUTH_TYPE.BASIC, AUTH_TYPE.DIGEST, AUTH_TYPE.NTLM, AUTH_TYPE.PKI):
11321133
errMsg = "HTTP authentication type value must be "
1133-
errMsg += "Basic, Digest, NTLM or Cert"
1134+
errMsg += "Basic, Digest, NTLM or PKI"
11341135
raise SqlmapSyntaxException(errMsg)
11351136
elif aTypeLower in (AUTH_TYPE.BASIC, AUTH_TYPE.DIGEST):
11361137
regExp = "^(.*?):(.*?)$"
@@ -1140,9 +1141,9 @@ def _setHTTPAuthentication():
11401141
regExp = "^(.*\\\\.*):(.*?)$"
11411142
errMsg = "HTTP NTLM authentication credentials value must "
11421143
errMsg += "be in format 'DOMAIN\username:password'"
1143-
elif aTypeLower == AUTH_TYPE.CERT:
1144-
errMsg = "HTTP Cert authentication require "
1145-
errMsg += "usage of option `--auth-cert`"
1144+
elif aTypeLower == AUTH_TYPE.PKI:
1145+
errMsg = "HTTP PKI authentication require "
1146+
errMsg += "usage of option `--auth-pki`"
11461147
raise SqlmapSyntaxException(errMsg)
11471148

11481149
aCredRegExp = re.search(regExp, conf.authCred)
@@ -1174,26 +1175,12 @@ def _setHTTPAuthentication():
11741175

11751176
authHandler = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(kb.passwordMgr)
11761177
else:
1177-
debugMsg = "setting the HTTP(s) authentication certificate"
1178+
debugMsg = "setting the HTTP(s) authentication PEM private key"
11781179
logger.debug(debugMsg)
11791180

1180-
aCertRegExp = re.search("^(.+?),\s*(.+?)$", conf.authCert)
1181-
1182-
if not aCertRegExp:
1183-
errMsg = "HTTP authentication certificate option "
1184-
errMsg += "must be in format 'key_file,cert_file'"
1185-
raise SqlmapSyntaxException(errMsg)
1186-
1187-
# os.path.expanduser for support of paths with ~
1188-
key_file = os.path.expanduser(aCertRegExp.group(1))
1189-
cert_file = os.path.expanduser(aCertRegExp.group(2))
1190-
1191-
for ifile in (key_file, cert_file):
1192-
if not os.path.exists(ifile):
1193-
errMsg = "file '%s' does not exist" % ifile
1194-
raise SqlmapSyntaxException(errMsg)
1195-
1196-
authHandler = HTTPSCertAuthHandler(key_file, cert_file)
1181+
key_file = os.path.expanduser(conf.authPrivate)
1182+
checkFile(key_file)
1183+
authHandler = HTTPSPKIAuthHandler(key_file)
11971184

11981185
def _setHTTPMethod():
11991186
"""

lib/core/optiondict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"headers": "string",
3636
"authType": "string",
3737
"authCred": "string",
38-
"authCert": "string",
38+
"authPrivate": "string",
3939
"proxy": "string",
4040
"proxyCred": "string",
4141
"proxyFile": "string",

lib/parse/cmdline.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,14 @@ def cmdLineParser():
117117

118118
request.add_option("--auth-type", dest="authType",
119119
help="HTTP authentication type "
120-
"(Basic, Digest, NTLM or Cert)")
120+
"(Basic, Digest, NTLM or PKI)")
121121

122122
request.add_option("--auth-cred", dest="authCred",
123123
help="HTTP authentication credentials "
124124
"(name:password)")
125125

126-
request.add_option("--auth-cert", dest="authCert",
127-
help="HTTP authentication certificate ("
128-
"key_file,cert_file)")
126+
request.add_option("--auth-private", dest="authPrivate",
127+
help="HTTP authentication PEM private key file")
129128

130129
request.add_option("--proxy", dest="proxy",
131130
help="Use a proxy to connect to the target URL")
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010

1111
from lib.core.data import conf
1212

13-
class HTTPSCertAuthHandler(urllib2.HTTPSHandler):
14-
def __init__(self, key_file, cert_file):
13+
class HTTPSPKIAuthHandler(urllib2.HTTPSHandler):
14+
def __init__(self, key_file):
1515
urllib2.HTTPSHandler.__init__(self)
1616
self.key_file = key_file
17-
self.cert_file = cert_file
1817

1918
def https_open(self, req):
2019
return self.do_open(self.getConnection, req)
2120

2221
def getConnection(self, host, timeout=None):
23-
return httplib.HTTPSConnection(host, key_file=self.key_file, cert_file=self.cert_file, timeout=conf.timeout)
22+
return httplib.HTTPSConnection(host, key_file=self.key_file, timeout=conf.timeout)

sqlmap.conf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,18 @@ headers = Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9
7878

7979
# HTTP Authentication type. Useful only if the target URL requires
8080
# HTTP Basic, Digest or NTLM authentication and you have such data.
81-
# Valid: Basic, Digest, NTLM or Cert
81+
# Valid: Basic, Digest, NTLM or PKI
8282
authType =
8383

8484
# HTTP authentication credentials. Useful only if the target URL requires
8585
# HTTP Basic, Digest or NTLM authentication and you have such data.
8686
# Syntax: username:password
8787
authCred =
8888

89-
# HTTP Authentication certificate. Useful only if the target URL requires
90-
# logon certificate and you have such data.
91-
# Syntax: key_file,cert_file
92-
authCert =
89+
# HTTP Authentication PEM private key. Useful only if the target URL requires
90+
# PKI authentication and you have such data.
91+
# Syntax: key_file
92+
authPrivate =
9393

9494
# Use a proxy to connect to the target URL.
9595
# Syntax: http://address:port

0 commit comments

Comments
 (0)