Skip to content

Commit f8c9868

Browse files
committed
Implementation for an Issue sqlmapproject#118
1 parent 42f518b commit f8c9868

11 files changed

Lines changed: 39 additions & 29 deletions

File tree

lib/core/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ def replacePayload(self, inpStr, payload):
855855
return re.sub("(%s.*?%s)" % (PAYLOAD_DELIMITER, PAYLOAD_DELIMITER), ("%s%s%s" % (PAYLOAD_DELIMITER, payload, PAYLOAD_DELIMITER)).replace("\\", r"\\"), inpStr) if inpStr else inpStr
856856

857857
def runAsDBMSUser(self, query):
858-
if conf.dCred and "Ad Hoc Distributed Queries" not in query:
858+
if conf.dbmsCred and "Ad Hoc Distributed Queries" not in query:
859859
query = getSQLSnippet(DBMS.MSSQL, "run_statement_as_user", USER=conf.dbmsUsername, PASSWORD=conf.dbmsPassword, STATEMENT=query.replace("'", "''"))
860860

861861
return query

lib/core/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3211,11 +3211,11 @@ def resetCookieJar(cookieJar):
32113211
Cleans cookies from a given cookie jar
32123212
"""
32133213

3214-
if not conf.loC:
3214+
if not conf.loadCookies:
32153215
cookieJar.clear()
32163216
else:
32173217
try:
3218-
cookieJar.load(conf.loC)
3218+
cookieJar.load(conf.loadCookies)
32193219
cookieJar.clear_expired_cookies()
32203220
except cookielib.LoadError, msg:
32213221
errMsg = "there was a problem loading "

lib/core/option.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def __urllib2Opener():
150150
handlers = [proxyHandler, authHandler, redirectHandler, rangeHandler, httpsHandler]
151151

152152
if not conf.dropSetCookie:
153-
if not conf.loC:
153+
if not conf.loadCookies:
154154
conf.cj = cookielib.CookieJar()
155155
else:
156156
conf.cj = cookielib.MozillaCookieJar()
@@ -562,13 +562,13 @@ def __setDBMSAuthentication():
562562
another user, not the session user
563563
"""
564564

565-
if not conf.dCred:
565+
if not conf.dbmsCred:
566566
return
567567

568568
debugMsg = "setting the DBMS authentication credentials"
569569
logger.debug(debugMsg)
570570

571-
match = re.search("^(.+?):(.*?)$", conf.dCred)
571+
match = re.search("^(.+?):(.*?)$", conf.dbmsCred)
572572

573573
if not match:
574574
errMsg = "DBMS authentication credentials value must be in format "
@@ -1730,7 +1730,7 @@ def __setTrafficOutputFP():
17301730
conf.trafficFP = openFile(conf.trafficFile, "w+")
17311731

17321732
def __setDNSServer():
1733-
if not conf.dName:
1733+
if not conf.dnsName:
17341734
return
17351735

17361736
infoMsg = "setting up DNS server instance"
@@ -1944,9 +1944,9 @@ def __basicOptionValidation():
19441944
errMsg += "supported charsets"
19451945
raise sqlmapSyntaxException, errMsg
19461946

1947-
if conf.loC:
1948-
if not os.path.exists(conf.loC):
1949-
errMsg = "cookies file '%s' does not exist" % conf.loC
1947+
if conf.loadCookies:
1948+
if not os.path.exists(conf.loadCookies):
1949+
errMsg = "cookies file '%s' does not exist" % conf.loadCookies
19501950
raise sqlmapFilePathException, errMsg
19511951

19521952
def __resolveCrossReferences():

lib/core/optiondict.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"data": "string",
2525
"pDel": "string",
2626
"cookie": "string",
27-
"loC": "string",
27+
"loadCookies": "string",
2828
"cookieUrlencode": "boolean",
2929
"dropSetCookie": "boolean",
3030
"agent": "string",
@@ -87,7 +87,7 @@
8787
"timeSec": "integer",
8888
"uCols": "string",
8989
"uChar": "string",
90-
"dName": "string"
90+
"dnsName": "string"
9191
},
9292

9393
"Fingerprint": {
@@ -171,7 +171,7 @@
171171
"checkTor": "boolean",
172172
"crawlDepth": "integer",
173173
"csvDel": "string",
174-
"dCred": "string",
174+
"dbmsCred": "string",
175175
"eta": "boolean",
176176
"flushSession": "boolean",
177177
"forms": "boolean",

lib/parse/cmdline.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def cmdLineParser():
7676
request.add_option("--cookie", dest="cookie",
7777
help="HTTP Cookie header")
7878

79-
request.add_option("--load-cookies", dest="loC",
79+
request.add_option("--load-cookies", dest="loadCookies",
8080
help="File containing cookies in Netscape/wget format")
8181

8282
request.add_option("--cookie-urlencode", dest="cookieUrlencode",
@@ -280,7 +280,7 @@ def cmdLineParser():
280280
techniques.add_option("--union-char", dest="uChar",
281281
help="Character to use for bruteforcing number of columns")
282282

283-
techniques.add_option("--dns-domain", dest="dName",
283+
techniques.add_option("--dns-domain", dest="dnsName",
284284
help="Domain name used for DNS exfiltration attack")
285285

286286
# Fingerprint options
@@ -533,7 +533,7 @@ def cmdLineParser():
533533
help="Delimiting character used in CSV output "
534534
"(default \"%s\")" % defaults.csvDel)
535535

536-
general.add_option("--dbms-cred", dest="dCred",
536+
general.add_option("--dbms-cred", dest="dbmsCred",
537537
help="DBMS authentication credentials (user:password)")
538538

539539
general.add_option("--eta", dest="eta",
@@ -674,6 +674,16 @@ def cmdLineParser():
674674
parser.add_option_group(general)
675675
parser.add_option_group(miscellaneous)
676676

677+
# Dirty hack to display longer options without breaking into two lines
678+
def _(self, *args):
679+
_ = parser.formatter._format_option_strings(*args)
680+
if len(_) > 18:
681+
_ = "%.16s.." % _
682+
return _
683+
684+
parser.formatter._format_option_strings = parser.formatter.format_option_strings
685+
parser.formatter.format_option_strings = type(parser.formatter.format_option_strings)(_, parser, type(parser))
686+
677687
# Dirty hack for making a short option -hh
678688
option = parser.get_option("--hh")
679689
option._short_opts = ["-hh"]

lib/request/inject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
def __goDns(payload, expression):
5858
value = None
5959

60-
if conf.dName and kb.dnsTest is not False:
60+
if conf.dnsName and kb.dnsTest is not False:
6161
if kb.dnsTest is None:
6262
dnsTest(payload)
6363

lib/takeover/abstraction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def shell(self):
142142
self.runCmd(command)
143143

144144
def __initRunAs(self):
145-
if not conf.dCred:
145+
if not conf.dbmsCred:
146146
return
147147

148148
if not conf.direct and not isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED):
@@ -186,7 +186,7 @@ def initEnv(self, mandatory=True, detailed=False, web=False):
186186
warnMsg = "functionality requested probably does not work because "
187187
warnMsg += "the curent session user is not a database administrator"
188188

189-
if not conf.dCred and Backend.getIdentifiedDbms() in ( DBMS.MSSQL, DBMS.PGSQL ):
189+
if not conf.dbmsCred and Backend.getIdentifiedDbms() in ( DBMS.MSSQL, DBMS.PGSQL ):
190190
warnMsg += ". You can try to use option '--dbms-cred' "
191191
warnMsg += "to execute statements as a DBA user if you "
192192
warnMsg += "were able to extract and crack a DBA "

lib/takeover/xp_cmdshell.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def xpCmdshellForgeCmd(self, cmd, insertIntoTable=None):
155155
# to retrieve it afterwards
156156
# NOTE: this does not need to be done when the command is 'del' to
157157
# delete the temporary file
158-
if conf.dCred and insertIntoTable:
158+
if conf.dbmsCred and insertIntoTable:
159159
self.tmpFile = "%s/tmpc%s.txt" % (conf.tmpPath, randomStr(lowercase=True))
160160
cmd = "%s > \"%s\"" % (cmd, self.tmpFile)
161161

@@ -171,7 +171,7 @@ def xpCmdshellForgeCmd(self, cmd, insertIntoTable=None):
171171
# it does not work unfortunately, BULK INSERT needs to be used to
172172
# retrieve the output when OPENROWSET is used hence the redirection
173173
# to a temporary file from above
174-
if insertIntoTable and not conf.dCred:
174+
if insertIntoTable and not conf.dbmsCred:
175175
self.__forgedCmd += "INSERT INTO %s " % insertIntoTable
176176

177177
self.__forgedCmd += "EXEC %s @%s" % (self.xpCmdshellStr, self.__randStr)
@@ -203,7 +203,7 @@ def xpCmdshellEvalCmd(self, cmd, first=None, last=None):
203203
# command standard output is redirected to a temporary file
204204
# The file needs to be copied to the support table,
205205
# 'sqlmapoutput'
206-
if conf.dCred:
206+
if conf.dbmsCred:
207207
inject.goStacked("BULK INSERT %s FROM '%s' WITH (CODEPAGE='RAW', FIELDTERMINATOR='%s', ROWTERMINATOR='%s')" % (self.cmdTblName, self.tmpFile, randomStr(10), randomStr(10)))
208208
self.delRemoteFile(self.tmpFile)
209209

lib/techniques/dns/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def dnsTest(payload):
2424
errMsg = "data retrieval through DNS channel failed. Turning off DNS exfiltration support"
2525
logger.error(errMsg)
2626

27-
conf.dName = None
27+
conf.dnsName = None
2828
else:
2929
infoMsg = "data retrieval through DNS channel was successful"
3030
logger.info(infoMsg)

lib/techniques/dns/use.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def dnsUse(payload, expression):
4848
count = 0
4949
offset = 1
5050

51-
if conf.dName and Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.ORACLE, DBMS.MYSQL, DBMS.PGSQL):
51+
if conf.dnsName and Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.ORACLE, DBMS.MYSQL, DBMS.PGSQL):
5252
output = hashDBRetrieve(expression, checkConf=True)
5353

5454
if output and PARTIAL_VALUE_MARKER in output or kb.dnsTest is None:
@@ -67,7 +67,7 @@ def dnsUse(payload, expression):
6767
nulledCastedField = agent.hexConvertField(nulledCastedField)
6868
expressionReplaced = expression.replace(fieldToCastStr, nulledCastedField, 1)
6969

70-
expressionRequest = getSQLSnippet(Backend.getIdentifiedDbms(), "dns_request", PREFIX=prefix, QUERY=expressionReplaced, SUFFIX=suffix, DOMAIN=conf.dName)
70+
expressionRequest = getSQLSnippet(Backend.getIdentifiedDbms(), "dns_request", PREFIX=prefix, QUERY=expressionReplaced, SUFFIX=suffix, DOMAIN=conf.dnsName)
7171
expressionUnescaped = unescaper.unescape(expressionRequest)
7272

7373
if Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.PGSQL):
@@ -108,7 +108,7 @@ def dnsUse(payload, expression):
108108
debugMsg = "performed %d queries in %d seconds" % (count, calculateDeltaSeconds(start))
109109
logger.debug(debugMsg)
110110

111-
elif conf.dName:
111+
elif conf.dnsName:
112112
warnMsg = "DNS data exfiltration method through SQL injection "
113113
warnMsg += "is currently not available for DBMS %s" % Backend.getIdentifiedDbms()
114114
singleTimeWarnMessage(warnMsg)

0 commit comments

Comments
 (0)