Skip to content

Invalid requests for HSQLDB when trying to enumerate tables (--tables option) #4817

@Antoine-BL

Description

@Antoine-BL

Describe the bug
sqlmap is unable to retrieve the table names for any database when it should be able to.

From what I can tell, the requests it is trying are not valid HSQLDB. A contributing factor could be that it doesn't detect the right version of HSQLDB (>2.0 <= 2.3) when it actually is 2.6.0.

I attached the traffic.txt at the bottom of this issue. In it, the last request contains the following SQL:
antoine2' AND ASCII(SUBSTR((SELECT IFNULL(CAST(COUNT(table_name) AS LONGVARCHAR),CHAR(32)) FROM INFORMATION_SCHEMA.SYSTEM_TABLES WHERE table_schem=CHAR(65)||CHAR(78)||CHAR(84)||CHAR(79)||CHAR(73)||CHAR(78)||CHAR(69)),2,1))>9

As you can see, this fails to run on the server and an error message is returned. This is because it is trying to SUBSTR() a COUNT() query. This fails because of a datatype mismatch. SUBSTR only works on strings in HSQLDB. I got it to work manually by adding a SUBSTR(CAST([SELECT QUERY HERE] AS VARCHAR(1000)), 1, 1)

I screwed up in my verifications, but it seems to work when I input the query directly into the database. In theory counting the tables should be possible.

To Reproduce

  1. Run Webgoat server 8.2.2
  2. Log in to Webgoat
  3. Intercept a request for the register page of the SQL Injection (advanced) challenge no. 5
  4. Save the request to a file
  5. Run the following command: python3 .\sqlmap.py -r request.txt --string "please try to register with a different username" -p username_reg --thread=10 --technique=B --dbms="HSQLDB" -D "antoine" -t traffic.txt --level=5 --risk=3 --tables
    Expected behavior
    sqlmap should be able to retrieve the number of tables and the table names in this context. It should do so by trying valid requests with boolean blind sql injection.

Screenshots
screen1

Running environment:

  • sqlmap version 1.5.9
  • Installation method Download from git releases
  • Operating system: Windows 10
  • Python version 3.9.2

Target details:

  • DBMS: HSQLDB 2.6.0
  • SQLi techniques found by sqlmap: Boolean
  • WAF/IPS No
  • Relevant console output:

Additional context
Traffic.txt:
traffic.txt
Example request.txt:
request.txt

P.S.: Your tool is pretty flipping epic

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions