HSQLDB (HyperSQL DataBase) is the leading SQL relational database system written in Java. It offers a small, fast multithreaded and transactional database engine with in-memory and disk-based tables and supports embedded and server modes.
Default port: 9001
9001/tcp open jdbc HSQLDB JDBC (Network Compatibility Version 220.127.116.11)
Note that by default this service is likely running in memory or is bound to localhost. If you found it, you probably exploited another service and are looking to escalate privileges.
Default credentials are usually sa with a blank password.
If you’ve exploited another service, search for possible credentials using
Note the database name carefully - you’ll need it to connect.
Connect to the DB instance by downloading HSQLDB and extracting hsqldb/lib/hsqldb.jar. Run the GUI app (eww) using java -jar hsqldb.jar and connect to the instance using the discovered/weak credentials.
Note the connection URL will look something like this for a remote system: jdbc:hsqldb:hsql://ip/DBNAME.
Java Language Routines
We can call static methods of a Java class from HSQLDB using Java Language Routines. Do note that the called class needs to be in the application’s classpath.
JRTs can be functions or procedures. Functions can be called via SQL statements if the Java method returns one or more SQL-compatible primitive variables. They are invoked using the VALUES statement.
If the Java method we want to call returns void, we need to use a procedure invoked with the CALL statement.
Reading Java System Properties
CREATE FUNCTION getsystemproperty(IN key VARCHAR) RETURNS VARCHAR LANGUAGE JAVA
DETERMINISTIC NO SQL
EXTERNAL NAME 'CLASSPATH:java.lang.System.getProperty'
You can use the com.sun.org.apache.xml.internal.security.utils.JavaUtils.writeBytesToFilename Java gadget located in the JDK (auto loaded into the class path of the application) to write hex-encoded items to disk via a custom procedure. Note the maximum size of 1024 bytes.
CREATE PROCEDURE writetofile(IN paramString VARCHAR, IN paramArrayOfByte VARBINARY(1024))