Skip to content

HQL injections

High
davide-zerbetto published GHSA-2j3f-f696-7rgj Jul 14, 2023

Package

KnowageLabs / Knowage-Server (Knowage)

Affected versions

6.x.x, 7.x.x, 8.0.x, < 8.1.8

Patched versions

8.1.8

Description

The application often uses user-supplied data to create HQL queries without prior sanitization.
An attacker can create specially crafted HQL queries that will break the subsequent SQL queries generated by the Hibernate engine.
Synacktiv experts identified that the /knowage/restful-services/2.0/documents/listDocument endpoint calls the countBIObjects method of the BIObjectDAOHibImpl object with the user-supplied label parameter without prior sanitization.

// knowage-core/src/main/java/it/eng/spagobi/api/v2/DocumentResource.java
public String getDocumentSearchAndPaginate( /*[...]*/, @QueryParam("label") String label, /*[...]*/) throws EMFInternalError {
    // [...]
    jo.put("itemCount", documentsDao.countBIObjects(label != null ? label : "", UserFilter));

    return jo.toString();
// knowagedao/src/main/java/it/eng/spagobi/analiticalmodel/document/dao/BIObjectDAOHibImpl.java
public Integer countBIObjects(String search, String user) throws EMFUserError {
    // [...]
    String hql = "select count(*) from SbiObjects ";
    if (search != null || user != null) {
        hql += " where ";

        if (search != null) {
            hql += " label like '%" + search + "%'";
        }
    }

    Query hqlQuery = aSession.createQuery(hql);
    Long temp = (Long) hqlQuery.uniqueResult();
    /// [...]

We can demonstrate the vulnerability by breaking the SQL query generated by Hibernate with the “\’’” escape sequence and call the MySQL sleep function, that will result in a delayed response from the server:

$ time curl -q -H 'Cookie: JSESSIONID=[...]' "http://localhost:8088/knowage/restful-services/2.0/documents/listDocument?label=a%5c'')+order+by+(select+sleep(5));--+-" >/dev/null

real    0m5,014s
user    0m0,010s
sys     0m0,000s

Other injections have been identified in the application, notably in the following files, but were not demonstrated by Synacktiv experts as they either require authorization to be reached, or were not called by any identified endpoint or service:

  • knowagedao/src/main/java/it/eng/spagobi/tools/udp/dao/UdpValueDAOHibImpl.java@loadByReferenceIdAndUdpId
  • knowagedao/src/main/java/it/eng/spagobi/tools/udp/dao/UdpValueDAOHibImpl.java@findByReferenceId
  • knowagedao/src/main/java/it/eng/spagobi/tools/dataset/dao/SbiDataSetDAOImpl.java@countSbiDataSet
  • knowagedao/src/main/java/it/eng/spagobi/metadata/dao/SbiMetaTableDAOHibImpl.java@countSbiMetaTable

Impact

An authenticated attacker with low privileges could leverage this vulnerability in order to retrieve sensitive information from the database, such as account credentials or business information.

Patches

You need to upgrade to Knowage 8.1.8 or a later version.

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
None
Scope
Changed
Confidentiality
High
Integrity
None
Availability
None

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:N/A:N

CVE ID

CVE-2023-37472

Weaknesses

No CWEs

Credits