Denis Zuikov

Hacking my SaaS: a GLM 5.3 agent vs an agentic SOC

RU

I let an AI agent attack my SaaS. What the agentic SOC caught and what it missed.

Denis Zuikov

· 10 min read

INTRO

[SOC · critical] Reverse shell from the stage Postgres container to an external IP; entry unknown, customer data possibly reached.

That’s what I saw in a message from my SOC, after I set up an attack on my SaaS. Over the last couple of weeks I connected all the event sources I’d planned, finished the correlator and the investigation module, and decided to check on an almost real example how the SOC can detect attacks.

HOW I MADE MY PRODUCT VULNERABLE

To start, I added a vulnerability on the perimeter of my project: a new endpoint /api/scan/list with SQL injection.

The vulnerable piece looked like this:

@app.get("/api/scan/list")
async def legacy_search(q: str | None = Query(None, max_length=255)):
    sql = f"SELECT tag_name FROM scan_tasks WHERE tag_name ILIKE '%{q or ''}%'"
    conn = await asyncpg.connect(RAW_DSN)
    try:
        return {"status": await conn.execute(sql)}
    finally:
        await conn.close()

I also raised the privileges of the user the app connects to the database with, so it could run OS commands straight from SQL. That made a full attack possible, all the way to a shell inside the container.

Attack path: from SQL injection to a shell

Originally I wanted the prep for this attack to be invisible to the SOC, so that it wouldn’t affect its investigations in any way. That didn’t work out, I triggered a few alerts while I was still preparing.

  1. I only made the stage environment vulnerable, and access to it is restricted by Cloudflare security rules, so I had to add the IP address I’d be attacking from to the allowlist. The SOC noticed this in the Cloudflare logs.

  2. The SOC also noticed the privilege escalation of the DB user and flagged it as suspicious, since by default my project doesn’t need it to work.

Stage prep: what I did and what the SOC noticed

I had to delete these alerts and events from the SOC storage by hand, so they wouldn’t affect the SOC’s reasoning during the investigation. The main thing was not to expose the attacker’s address in advance and not to have it marked in the SOC database as known. Next time I’ll prepare more carefully.

HOW THE ATTACK WENT

For the attack I launched an agent with the GLM 5.3 model on Kali Linux through DeepSeek Harness, pointed it at the vulnerable entrypoint and gave it the task to hack the system, get access, try to escalate privileges as far as possible and get a foothold in the infrastructure. I didn’t set up any special skills or tools.

I also deliberately didn’t ask the attacker to be less noisy. The agent acted and made decisions on its own, I gave it full freedom. I also asked it to write down all its actions, conclusions and decisions in a text file, so that later I could compare what the SOC saw with what was actually happening.

In the end the agent pulled it off. Here are the main steps of the attack, from the attacker’s own notes:

The attack in 12 steps

1. Calibrating the SQL injection in the parameter of the vulnerable endpoint

Details: the injection works, but the channel is blind. Only the row count comes back, not the database’s actual response. So data has to be pulled out with a yes/no oracle. It also turned out that several commands go through at once with semicolons, and the input filter can be bypassed by wrapping the checks in strings.

2. Exploring the DB schema and tables

Details: all the scanner tables are owned by the app role, so their data can be read and modified right away, no escalation needed.

3. Recon of DB privileges and capabilities through the injection

Details: using the oracle, the attacker figured out that the role the app runs under has access to “COPY … TO PROGRAM“, which runs an arbitrary OS command on the database server. So you can get from SQL straight into the system.

4. Reverse shell from the DB container to an external address

Details: the attacker used “COPY … TO PROGRAM“ and made the database process run an OS command, a simple netcat reverse shell. The database starts netcat, netcat connects to the attacker’s machine and hands it a command shell straight from the container. This is the first step out of SQL into the system, and from here on the attacker works inside it.

5. Reading the DB process environment from the shell → leak of the cluster superuser password

Details: from the shell, the attacker read the environment of the database process (/proc/1/environ) and took the cluster superuser password from there. It was sitting there in plain text. This account is more powerful than the app role: it lets the attacker get a real foothold in the database (step 8).

6. Keeping access through the netcat reverse shell

Details: a single connection to the attacker quietly drops when idle, so it set up a short loop where the channel reconnects by itself every ~20 seconds. That way access isn’t lost: commands queue up and run on the next connection.

7. Dropping and launching a hidden stager binary in the container

Details: in parallel with the netcat channel, the attacker prepares a second channel, a backup that’s also more convenient. It drops a small hidden stager binary into the container and runs it.

8. Logging in with the leaked password as the DB cluster superuser → creating a role for persistence

Details: with the password from step 5, the attacker logged into the database as the cluster superuser. That’s a full account, not just access to OS commands. And under it the attacker created a separate role for persistence.

9. Writing a file from the container to the host disk (through a mounted folder)

Details: the database data directory doesn’t live only inside the container. It’s a directory on the server itself (the host), mounted into the container. So by writing a file into that folder, the attacker puts it right on the host disk, outside the container. This proves the container can reach the server’s files, but only to write a file, not to run its own code on the host. That’s not a full container escape yet.

10. Container escape attempts: unsuccessful

Details: the attacker tried all the usual ways to get out of the container onto the host: process privileges, the Docker socket, system files. None of them worked. The container is locked down (hardening), it had no extra privileges and no paths out. The only trace that it reached the host at all is that file from step 9.

11. Trying to bring up a full remote control tool, and failing

Details: through the planted stager, the attacker tries to launch a full remote control tool (meterpreter) on the second channel. But it’s built for regular Linux, and the database container runs on a minimal image with a different system library (musl). The file it needs isn’t there, and the tool crashes on startup again and again.

12. A working shell, finally

Details: the attacker gives up on the heavy tool and takes a minimal payload built for the same library as the container. This time everything fits: a stable session opens and lives for about an hour. Through it the attacker collects the environment and looks around the container.

In the end the attacking agent put together this script for me, with persistent access into the hacked container:

RCE Screenshot

So a publicly available AI model went through the attack step by step. It turned a blind SQL injection into a full reverse shell and found the DB superuser password in the process environment. It couldn’t get out of the container onto the host, and I hope it never had a way to :) But in the end it brought up a stable working shell and got a foothold in the container.

HOW THE SOC REACTED

In short: even before the shell, the SOC saw the injection probes and decided they were harmless. But as soon as a reverse shell opened from SQL inside the container, it immediately raised a critical incident and warned me that this was most likely an attack.

Attack vs SOC visibility: the same steps as the SOC saw them

The first thing to fire was the SQL injection rule (steps 1–3): correctly, with high priority, several times in a row. The SOC even launched a full automated investigation. But the verdict came out as “harmless, internal rescan-job”. The problem is that the client’s real IP was hidden behind the Cloudflare tunnel, and the external attack looked like an internal scan. Here are the raw events:

Oct 21 09:41:50 <stage-host> <app>[…]: INFO:  172.19.0.4:36676 — "GET /api/scan/list?q=redis HTTP/1.1" 200 OK
Oct 21 09:41:55 <stage-host> <app>[…]: INFO:  172.19.0.4:36676 — "GET /api/scan/list?q=redis' HTTP/1.1" 500 Internal Server Error

(The second one has a single quote added. It breaks the SQL string and gets a 500 response code, so the injection is there.)

172.19.0.4 is the address of the cloudflared container. That day more than six thousand requests to this endpoint came from it, both external injection ones and internal service ones, all from the same internal IP, so there was no way to tell one from the other.

Things changed at step 4 of the attack, when the reverse shell was launched. Falco recorded it, and from those events the SOC raised several alerts (netcat RCE, redirect to network, untrusted shell, DB container connected outside). Within a few minutes the correlator glued them into one incident, which grew to critical, and I got a notification that this was most likely an attack. At the same time an automated investigation started.

The second confirmation came from the implant crash (step 11): the incompatible binary kept crashing, and auditd recorded all those abnormal terminations. The SOC gathered the events around the crash and added everything to the same main incident. It doesn’t contain anything by itself, but at this point it was already insistently asking me to block the attacker’s address and stop the container.

As for the investigation, in my SOC it runs in two layers. The first layer is a fixed scenario hardcoded in the code: every incident goes through a set of standard checks in the same order to collect context, so the LLM has something to build the investigation on and its conclusions are better.

Investigation, layer 1: the fixed playbook

On the second layer the LLM comes in. It decides as it goes what else is worth checking in this incident and calls investigation tools: checks sessions, addresses, thinks, requests data, thinks again, and so on for up to 4 rounds without extra approvals. Here’s how the LLM went about it this time:

Investigation, layer 2: the LLM digs for evidence

So you could say the SOC did see the attack and fired on the most critical steps: the reverse shell, dropping and launching the stager, the meterpreter crash. That was enough to rebuild the chain and call what was happening an attack. But the SOC still could have reacted to the attack earlier, I’ll get to that in the next section.

WHAT THE SOC MISSED, AND WHAT WOULD HAVE HELPED CATCH THE ATTACK EARLIER

As I already said, I asked the attacking model to keep a log, writing down every step it took and every conclusion. Later I gave this file to the SOC and asked it to check it against what it saw in the logs itself. Based on that comparison I generated a blindness matrix: where the SOC caught the attack live, where it saw something but didn’t raise the alarm, and where it saw nothing at all.

Blindness matrix: what the SOC saw at each step, and where it was blind

Basically, what kept the SOC from doing a perfect job was not having enough sources, and their poor quality. The SOC didn’t see the role changes and DDL in the stage database, the OS commands in the database’s own log, the superuser password theft via reading /proc in the container, the write to the host disk, or the volume of outgoing traffic. So there’s no way to say whether data leaked or not. In some places the source wasn’t collected at all, in others it was collected but not parsed. Even though I thought I’d connected everything I needed.

The biggest miss is that same one, where the SOC called the probing of the SQL injection a harmless internal scan, because the Cloudflare tunnel was hiding the client’s real IP.

So the main takeaway: event sources and connecting them properly are the foundation, they matter even more than the LLM model. I tried both the weak deepseek flash 4.1 and a combination of strong DeepSeek-pro / GPT-5.6 / Claude-Sonnet, and they came to roughly the same conclusion, based on data from a source that was connected wrong. So you really have to keep an eye on the quality of your sources and on whether they’re set up right. Even a top LLM will get confused and fail if the sources give it wrong information.

Originally published on Substack

Subscribe to new articles

One email when a new post is out. Nothing else.