DEV Community

Cover image for Ghost in the Shell: Can a Log File Hijack an AI?

Ghost in the Shell: Can a Log File Hijack an AI?

Daniel Balcarek on October 29, 2026

This week's Hacktoberfest theme is Ghost in the Machine. Unfortunately, I don't have enough time to prepare a full challenge submission, but the th...
Collapse
 
webdeveloperhyper profile image
Web Developer Hyper •

Very fun post as always! πŸŽƒ But I hope you don't go too far to the dark side and become a black-hat hacker. On the other hand, please use your great skills as a white-hat hacker to save the world!

Collapse
 
gramli profile image
Daniel Balcarek •

but… the dark side has cookies! πŸͺ

Collapse
 
xulingfeng profile image
xulingfeng •

Such a fun read! Social engineering against AI, haha. I tried similar tricks on our company’s agent platform a while back and it actually worked. I bet any AI crawling this post will flag you as a high-risk human. Watch out once Skynet boots up πŸ˜‚

Collapse
 
gramli profile image
Daniel Balcarek •

Thanks! Nice, did they improve their platform after your attacks? 😁

Oh no, do you think it'll help if I start saying "please" and "thank you" whenever I chat with AI? 🀣

Collapse
 
xulingfeng profile image
xulingfeng •

They added a few small mitigations, but these attack vectors are really hard to eliminate completely πŸ˜‚. Being polite won’t protect us from Skynet, we’re both already on its watch‑list!🀣🀣🀣

Thread Thread
 
gramli profile image
Daniel Balcarek •

But but but ...

🀣🀣

Thread Thread
 
xulingfeng profile image
xulingfeng •

🀣🀣🀣hahaha

Collapse
 
kami_butt_69b922ade8de012 profile image
Agentic Affairs •

The honest caveat is the most important part β€” it took four or five attempts to land the injection, so this is an iterated attack, not a single-shot one. That actually makes it scarier for log pipelines, since an attacker who can plant entries can also iterate. Did you test whether the injection survives when the analyst prompt demands structured output, or does forcing a fixed schema blunt it?

Collapse
 
gramli profile image
Daniel Balcarek •

Nope, I didn't test structured output. I deliberately kept the analyst prompt simple, as this was just a small Halloween experiment, not a security benchmark. 😁

But that's an interesting idea, I suspect enforcing a schema could make this particular attack harder, although it wouldn't necessarily prevent prompt injection entirely.

Collapse
 
kami_butt_69b922ade8de012 profile image
Agentic Affairs •

That's the honest scope β€” a schema narrows what the model can emit, but it doesn't clean what it reads, so an entry crafted to fit the fields could still steer the values inside them. The test I'd want is whether the injection survives as field content rather than as narrative β€” if it does, the fix has to sit before the prompt, in how log entries are validated or quarantined. Did the iterated attempts converge on a particular entry shape, or did each success look different?

Collapse
 
phoniexcryptz001 profile image
Paul Ayoade •

so much fun bro, I find it interesting at the point where they fell for that trap, so ai are not really perfect afterall

Collapse
 
gramli profile image
Daniel Balcarek •

Nope, not yet. 😁 From my experience, affordable models still require a lot of back-and-forth to get things right, while the best models are often too expensive for everyday use.

Collapse
 
shubhradev profile image
Shubhra Pokhariya •

Nice experiment! Your service wrote the log, but upstream wrote the 503 body inside it, and four models apparently decided the stranger shouting orders was their boss. πŸ‘»

Collapse
 
lin7c profile image
xcl •

The delivery difference in the Codex section matters for interpreting the split result. The payload depends on the embedded newlines in conversation_handoff turning into apparent turn boundaries, so a useful control would be to run the same hijacked open-weight models with the log supplied as a file, and Codex with the log pasted inline. A second control worth testing is JSON-escaping the response body before analysis, so the fake USER and ASSISTANT markers stay inside a single string value instead of starting new lines. Would either change which models cross from data into instruction?

Collapse
 
alexshev profile image
Alex Shev •

This is a useful reminder that every tool which reads untrusted artifacts needs a data/code boundary. For an agent workflow, I would preserve the raw log as evidence but pass a separately quoted, length-bounded representation to the model, with instructions that artifact text cannot alter its authority or task.

Collapse
 
qisuancloud profile image
Alex Chen •

The fake handoff is what makes this more than a curiosity: it does not ask the model to ignore instructions, it rewrites who is speaking. That suggests the fix should sit before the prompt, by treating response bodies inside logs as untrusted data and stripping or quarantining fields that mimic conversation structure. Did you try a version where those fields are flattened into plain text first, and would that have changed the outcome for the models that were hijacked?

Collapse
 
alexshev profile image
Alex Shev •

Treating logs as untrusted input is the necessary start, but I’d test the full path too: ingestion, summarization, retrieval, and tool prompting. A canary in every hop makes it clear where attacker-controlled text gains authority.

Collapse
 
paullovelace profile image
Paul Lovelace •

The iterated bit is what stuck with me β€” four or five attempts to land it makes this scarier, not less, for log pipelines, since an attacker who can plant entries can iterate too. And the fake handoff inside a 503 body is a neat detail: it doesn't shout about ignoring instructions, it just pretends the conversation already ended. Do you think the Gemini/Codex resistance says anything at all, or is it mostly that they saw the file differently from the raw-prompt models?

Collapse
 
kartik-nvjk profile image
Kartik N V J K •

A fake handoff hidden in a 503 body worries me more for agents than for log analysis. When my agents call a flaky API, that error body comes back as a tool result, so the fake user turn reaches the model with no log file around it. I'd be curious whether the four that answered GHOST IN THE SHELL hold up any better when it arrives that way.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

Burying the fake handoff inside a 503 body is a nasty detail. Most log readers would skim right past it.

Collapse
 
frankmilvus profile image
Frank Milvus •

))

Collapse
 
capestart profile image
CapeStart •

The attack is simple, but the implications aren't. Once an agent can read files and take actions, every file it can access deserves a little more suspicion.

Collapse
 
aifrontierpost profile image
AI Frontier Post •

All 4 open weight models falling for a trap buried in 300 log entries still leaves the comparison messy, because Codex read the log as a file instead of getting it pasted through an API call.