Skip to content

Commit 9059d30

Browse files
committedFeb 15, 2012
adding first code example for SPL snippets
1 parent edeb4b6 commit 9059d30

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed
 

‎lib/core/common.py

+12
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,7 @@ def cleanQuery(query):
11271127
def setPaths():
11281128
# sqlmap paths
11291129
paths.SQLMAP_EXTRAS_PATH = os.path.join(paths.SQLMAP_ROOT_PATH, "extra")
1130+
paths.SQLMAP_PROCS_PATH = os.path.join(paths.SQLMAP_ROOT_PATH, "procs")
11301131
paths.SQLMAP_SHELL_PATH = os.path.join(paths.SQLMAP_ROOT_PATH, "shell")
11311132
paths.SQLMAP_TAMPER_PATH = os.path.join(paths.SQLMAP_ROOT_PATH, "tamper")
11321133
paths.SQLMAP_TXT_PATH = os.path.join(paths.SQLMAP_ROOT_PATH, "txt")
@@ -1806,6 +1807,17 @@ def parseXmlFile(xmlFile, handler):
18061807
parse(stream, handler)
18071808
stream.close()
18081809

1810+
def getSPLSnippet(name, **variables):
1811+
"""
1812+
Returns content of snippet stored in program's "procs" directory
1813+
"""
1814+
filename = os.path.join(paths.SQLMAP_PROCS_PATH, "%s.txt" % name)
1815+
checkFile(filename)
1816+
retVal = readCachedFileContent(filename)
1817+
for _ in variables.keys():
1818+
retVal = re.sub(r"%%%s%%" % _, variables[_], retVal, flags=re.I)
1819+
return retVal
1820+
18091821
def readCachedFileContent(filename, mode='rb'):
18101822
"""
18111823
Cached reading of file content (avoiding multiple same file reading)

‎lib/takeover/xp_cmdshell.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
"""
99

1010
from lib.core.common import Backend
11+
from lib.core.common import getSPLSnippet
1112
from lib.core.common import randomStr
13+
from lib.core.common import readCachedFileContent
1214
from lib.core.common import readInput
1315
from lib.core.common import wasLastRequestDelayed
1416
from lib.core.data import conf
1517
from lib.core.data import kb
1618
from lib.core.data import logger
19+
from lib.core.data import paths
1720
from lib.core.exception import sqlmapUnsupportedFeatureException
1821
from lib.core.session import setXpCmdshellAvailability
1922
from lib.core.unescaper import unescaper
@@ -60,12 +63,7 @@ def __xpCmdshellConfigure2005(self, mode):
6063
debugMsg += "stored procedure"
6164
logger.debug(debugMsg)
6265

63-
cmd = "EXEC master..sp_configure 'show advanced options', 1; "
64-
cmd += "RECONFIGURE WITH OVERRIDE; "
65-
cmd += "EXEC master..sp_configure 'xp_cmdshell', %d; " % mode
66-
cmd += "RECONFIGURE WITH OVERRIDE; "
67-
cmd += "EXEC sp_configure 'show advanced options', 0; "
68-
cmd += "RECONFIGURE WITH OVERRIDE; "
66+
cmd = getSPLSnippet("configure_xp_cmdshell", ENABLE=str(mode))
6967

7068
return cmd
7169

‎procs/README.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Files in this folder represent SQL stored procedure declarations used
1+
Files in this folder represent SQL Procedural Language snippets used
22
by sqlmap on the target system. They are licensed under the terms of
33
the GNU Lesser General Public License.

‎procs/configure_xp_cmdshell.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
EXEC master..sp_configure 'show advanced options', 1;
2+
RECONFIGURE WITH OVERRIDE;
3+
EXEC master..sp_configure 'xp_cmdshell', %ENABLE%;
4+
RECONFIGURE WITH OVERRIDE;
5+
EXEC sp_configure 'show advanced options', 0;
6+
RECONFIGURE WITH OVERRIDE;

0 commit comments

Comments
 (0)
Please sign in to comment.