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

Skip to content

Commit d3da3f5

Browse files
committed
refactoring for issue #51
1 parent 25eca9d commit d3da3f5

17 files changed

Lines changed: 23 additions & 21 deletions

lib/core/agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from lib.core.common import Backend
1313
from lib.core.common import extractRegexResult
14-
from lib.core.common import getSPQLSnippet
14+
from lib.core.common import getSQLSnippet
1515
from lib.core.common import isDBMSVersionAtLeast
1616
from lib.core.common import isTechniqueAvailable
1717
from lib.core.common import randomInt
@@ -820,7 +820,7 @@ def replacePayload(self, inpStr, payload):
820820

821821
def runAsDBMSUser(self, query):
822822
if conf.dCred and "Ad Hoc Distributed Queries" not in query:
823-
query = getSPQLSnippet(DBMS.MSSQL, "run_statement_as_user", USER=conf.dbmsUsername, PASSWORD=conf.dbmsPassword, STATEMENT=query.replace("'", "''"))
823+
query = getSQLSnippet(DBMS.MSSQL, "run_statement_as_user", USER=conf.dbmsUsername, PASSWORD=conf.dbmsPassword, STATEMENT=query.replace("'", "''"))
824824

825825
return query
826826

lib/core/common.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,15 +1543,15 @@ def parseXmlFile(xmlFile, handler):
15431543
with contextlib.closing(StringIO(readCachedFileContent(xmlFile))) as stream:
15441544
parse(stream, handler)
15451545

1546-
def getSPQLSnippet(dbms, name, **variables):
1546+
def getSQLSnippet(dbms, sfile, **variables):
15471547
"""
1548-
Returns content of SP(Q)L snippet located inside "procs" directory
1548+
Returns content of SQL snippet located inside 'procs/' directory
15491549
"""
15501550

1551-
filename = os.path.join(paths.SQLMAP_PROCS_PATH, DBMS_DIRECTORY_DICT[dbms], "%s.txt" % name)
1551+
filename = os.path.join(paths.SQLMAP_PROCS_PATH, DBMS_DIRECTORY_DICT[dbms], sfile if sfile.endswith('.sql') else "%s.sql" % sfile)
15521552
checkFile(filename)
1553-
retVal = readCachedFileContent(filename)
15541553

1554+
retVal = readCachedFileContent(filename)
15551555
retVal = re.sub(r"#.+", "", retVal)
15561556
retVal = re.sub(r"(?s);\s+", "; ", retVal).strip()
15571557

@@ -1565,8 +1565,9 @@ def getSPQLSnippet(dbms, name, **variables):
15651565
retVal = retVal.replace(_, randomInt())
15661566

15671567
_ = re.search(r"%(\w+)%", retVal, re.I)
1568+
15681569
if _:
1569-
errMsg = "unresolved variable '%s' in SPL snippet '%s'" % (_.group(1), name)
1570+
errMsg = "unresolved variable '%s' in SQL file '%s'" % (_.group(1), sfile)
15701571
raise sqlmapGenericException, errMsg
15711572

15721573
return retVal

lib/takeover/abstraction.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from extra.safe2bin.safe2bin import safechardecode
99
from lib.core.common import dataToStdout
1010
from lib.core.common import Backend
11-
from lib.core.common import getSPQLSnippet
11+
from lib.core.common import getSQLSnippet
1212
from lib.core.common import isTechniqueAvailable
1313
from lib.core.common import readInput
1414
from lib.core.data import conf
@@ -163,12 +163,12 @@ def __initRunAs(self):
163163
choice = readInput(msg, default="Y")
164164

165165
if not choice or choice in ("y", "Y"):
166-
expression = getSPQLSnippet(DBMS.MSSQL, "configure_openrowset", ENABLE="1")
166+
expression = getSQLSnippet(DBMS.MSSQL, "configure_openrowset", ENABLE="1")
167167
inject.goStacked(expression)
168168

169169
# TODO: add support for PostgreSQL
170170
#elif Backend.isDbms(DBMS.PGSQL):
171-
# expression = getSPQLSnippet(DBMS.PGSQL, "configure_dblink", ENABLE="1")
171+
# expression = getSQLSnippet(DBMS.PGSQL, "configure_dblink", ENABLE="1")
172172
# inject.goStacked(expression)
173173

174174
def initEnv(self, mandatory=True, detailed=False, web=False):

lib/takeover/xp_cmdshell.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from lib.core.agent import agent
99
from lib.core.common import Backend
1010
from lib.core.common import getLimitRange
11-
from lib.core.common import getSPQLSnippet
11+
from lib.core.common import getSQLSnippet
1212
from lib.core.common import hashDBWrite
1313
from lib.core.common import isListLike
1414
from lib.core.common import isNoneValue
@@ -48,14 +48,14 @@ def __xpCmdshellCreate(self):
4848
if Backend.isVersionWithin(("2005", "2008")):
4949
logger.debug("activating sp_OACreate")
5050

51-
cmd = getSPQLSnippet(DBMS.MSSQL, "activate_sp_oacreate")
51+
cmd = getSQLSnippet(DBMS.MSSQL, "activate_sp_oacreate")
5252
inject.goStacked(agent.runAsDBMSUser(cmd))
5353

5454
self.__randStr = randomStr(lowercase=True)
5555
self.__xpCmdshellNew = "xp_%s" % randomStr(lowercase=True)
5656
self.xpCmdshellStr = "master..%s" % self.__xpCmdshellNew
5757

58-
cmd = getSPQLSnippet(DBMS.MSSQL, "create_new_xp_cmdshell", RANDSTR=self.__randStr, XP_CMDSHELL_NEW=self.__xpCmdshellNew)
58+
cmd = getSQLSnippet(DBMS.MSSQL, "create_new_xp_cmdshell", RANDSTR=self.__randStr, XP_CMDSHELL_NEW=self.__xpCmdshellNew)
5959

6060
if Backend.isVersionWithin(("2005", "2008")):
6161
cmd += ";RECONFIGURE WITH OVERRIDE"
@@ -67,7 +67,7 @@ def __xpCmdshellConfigure2005(self, mode):
6767
debugMsg += "stored procedure"
6868
logger.debug(debugMsg)
6969

70-
cmd = getSPQLSnippet(DBMS.MSSQL, "configure_xp_cmdshell", ENABLE=str(mode))
70+
cmd = getSQLSnippet(DBMS.MSSQL, "configure_xp_cmdshell", ENABLE=str(mode))
7171

7272
return cmd
7373

@@ -77,9 +77,9 @@ def __xpCmdshellConfigure2000(self, mode):
7777
logger.debug(debugMsg)
7878

7979
if mode == 1:
80-
cmd = getSPQLSnippet(DBMS.MSSQL, "enable_xp_cmdshell_2000", ENABLE=str(mode))
80+
cmd = getSQLSnippet(DBMS.MSSQL, "enable_xp_cmdshell_2000", ENABLE=str(mode))
8181
else:
82-
cmd = getSPQLSnippet(DBMS.MSSQL, "disable_xp_cmdshell_2000", ENABLE=str(mode))
82+
cmd = getSQLSnippet(DBMS.MSSQL, "disable_xp_cmdshell_2000", ENABLE=str(mode))
8383

8484
return cmd
8585

lib/techniques/dns/use.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from lib.core.common import dataToStdout
1717
from lib.core.common import decodeHexValue
1818
from lib.core.common import extractRegexResult
19-
from lib.core.common import getSPQLSnippet
19+
from lib.core.common import getSQLSnippet
2020
from lib.core.common import hashDBRetrieve
2121
from lib.core.common import hashDBWrite
2222
from lib.core.common import randomInt
@@ -67,7 +67,7 @@ def dnsUse(payload, expression):
6767
nulledCastedField = agent.hexConvertField(nulledCastedField)
6868
expressionReplaced = expression.replace(fieldToCastStr, nulledCastedField, 1)
6969

70-
expressionRequest = getSPQLSnippet(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.dName)
7171
expressionUnescaped = unescaper.unescape(expressionRequest)
7272

7373
if Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.PGSQL):

procs/README.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
Files in this folder represent SPL/SQL snippets used by sqlmap on the target
2-
system. They are licensed under the terms of the GNU Lesser General Public
3-
License.
1+
Files in this folder represent SQL snippets used by sqlmap on the target
2+
system.
3+
They are licensed under the terms of the GNU Lesser General Public License
4+
where not specified otherwise.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)