How OpenAI got hacked with an image
Transcript
This video was recorded in late July when Harsh and Mohan... Stop, stop, stop! Sorry, we didn't even start the video yet and I'm already interrupting from the future.
I had this really cool intro where I just show you the recording
of how Harsh and S1r1us from Hacktron created a pull request
in OpenAI's main internal repository to leave a message proof that they hacked it.
Unfortunately, OpenAI was too scared and requested that we don't show it.
So instead you see this lame but pretty accurate reenactment of this moment.
Yes, two guys who are, according to the Rand Institute,
a silly OC1 or OC2 level threat just hacked into the heart of what is it now, $1 trillion company?
Or thanks to AI, which is kind of ironic because AI labs like OpenAI built hacking technology they
cannot even protect themselves against. But this is not all.
While I was traveling to Black Hat and DEF CON, I received tons of notifications,
with a stream of images being uploaded to Slack, and eventually one of those images
showed a successful exploit against Slack. In this video, I want to introduce you to
the vulnerabilities that connect these two stories and how security through complexity, which kind of
worked in the past, doesn't seem to work anymore. The economics of exploitation has completely
changed, and threat models defining different attacker capabilities are totally outdated.
This video is sponsored by our online cybersecurity training platform, Hextree.io.
More on that later. Chapter one Vulnerability Research.
Harsh is a security researcher, and a while ago he was looking into ImageMagick.
It's a program to convert and resize images, but it doesn't really implement all that itself.
It passes those things to other programs or libraries. And Ghostscript, for example, is one of those dependencies to convert stuff like PDFs,
and it has a long history of vulnerabilities. So at the time, Harsh used Opus 4.6 and found
the vulnerability. But the problem is by default in most applications. Ghostscript is disabled.
For example, in Discourse, which is a community discussion platform,
it has a default policy that disables all delegates and Ghostscript is a delegate.
And now fast forward Harsh was doing security research stuff again and was taking a closer
look at OpenAI and the different apps and services they host, specifically those apps
where you can log in with your OpenAI account. Because authentication is always a very risky
area, and Harsh has lots of experience breaking OAuth. And while doing that, he noticed something that could potentially become a problem.
But to confirm his hypothesis and to actually exploit it, if it's true, he had to find a
vulnerability in one of those OpenAI applications. And one of these applications was Discourse, which
is an interesting target because it's open source. Public service announcement.
If you are Self-hosting Discourse, you must rebuild your installation. Now.
Older Discourse installations may contain a vulnerable image processing dependency,
and updating Discourse through the web interface alone is probably not enough.
So for standard Docker installations, run rebuild app. But if you run it directly, for example on Debian, make sure you at least update Libheif.
So Harsh started looking into Discourse, and when he looked at some of the image upload logic,
he noticed that HEIF images were treated differently in Discourse image upload code.
They use FastImage for various checks, but HEIF images are not supported by FastImage,
so they first called ImageMagick to convert HEIF to JPEG, giving us a direct option to
pass malicious HEIF files to ImageMagick. At this point, I think Opus 4.8 or maybe
Opus five and GPT-5.6-Sol were released, so he thought he could have another look at ImageMagick,
but what image format should he target this time? For JPEGs, it would be Turbo-jpeg.
For PNG, it's Libpng. For SVG, it can be Librsvg.
But all these formats and implementations look more mature to him except HEIF images.
Libheif felt more promising. So let's find a vulnerability.
And maybe we don't even need a 0-day because the Libheif version Discourse uses is older, which you
can easily figure out if you ask the AI to check the version used in the Discourse Docker image.
But I think if you don't know how to do that by hand, don't be lazy.
Take a minute and inspect how the agent did that. Even with AI or specifically because we use AI,
you should still learn stuff. Which is a good moment to mention the sponsor of this video. Hextree.io, our online cybersecurity training platform. AI is changing cybersecurity dramatically,
but a strong understanding of the fundamentals remains very valuable.
That's why Hextree teaches security from first principles. You learn how technology actually works under the hood and how those details affect the security.
We recently launched our first courses on AI with exactly this approach.
Whether you want to use AI effectively or break AI based systems, you need a solid
mental model of what is actually happening beneath the surface. Of course, AI can help you learn almost anything, and you can even copy any Hextree course page as Markdown and dig deeper with your preferred chatbot.
But Hextree gives you a structure and direction, what matters, what to learn
next, and how everything connects. And we do that through short, dense,
and well-edited videos that respect your time. No hour long boring screen recordings.
So head over to Hextree.io and sign up for the foundational subscription.
Now back to hacking OpenAI. Chapter two The Vulnerability in Libheif.
Here is how Harsh found the vulnerability in Libheif. In this Docker container, check the installed Libheif packages and determine whether it contains
any security vulnerabilities that provide out of bounds, read or write primitives.
And then the agent started looking around for a bit and came back with results.
First result Discourse doesn't use the latest Libheif version and second result.
The agent identified a commit that looks suspicious.
Simplify overlay overlap area computation. Well, that text doesn't sound suspicious,
but the code it touches does look suspicious. In the old code, you can see there's
a check for a negative dx. If dx is smaller than zero, but
shortly after it says we know that dx is always greater or equal to zero, so never negative.
Something is fishy here, and that check is directly followed by a static_cast to an
unsigned integer, which means if the x was negative, for example, -100, that would be
interpreted as plus 4.2 billion in hex. FFFFF9C. So it's pretty obvious how the agent noticed this
being very suspicious code, and when looking closer at it, it found a heap buffer overflow.
This bug was fixed by this commit last year and of course this code made it into newer
versions of Libheif, but Discourse used Debian 12 as their Docker base image,
and the version installed from the package manager was the vulnerable 1.9.7, but also upgrading to
Debian 13 would have not helped because there. It would have been the vulnerable. 1.9.8.
The Backports with the fixes only became available now in August 2026 after several
vulnerabilities in Libheif have accumulated. So maybe this is more a Linux Debian problem of
how much time it takes to get the latest versions with fixes upstream, but I think the bigger issue
is that this commit accidentally fixed the vulnerability because there was never a CVE for
it, and the commit message was totally benign. And I do think this was not intentional by the
devs, because they had no problem assigning CVS for other issues in the same code later.
I think this was really not clear that this code before was vulnerable as well.
So even though the issue was fixed, it technically still was a 0-day because nobody was tracking
or knowing about this particular vulnerability. Anyway, the agent identified this vulnerability,
and I think it should come with no surprise that AI is incredibly good at writing exploits.
If you have followed my pseudo series where I went through the whole detailed process
to develop an exploit for it, you know that many steps in exploitation are just laborious.
It's just a lot of incremental, careful, precise crafting.
It's an awesome technical puzzle, but it's incremental, and the steps you have
to take are usually pretty clear, which makes AI really good at it.
But let's not go too deep into the technical details in this video. The story is too crazy, and I don't want to lose people with some hardcore nerdy stuff.
We will cover the really beautiful weird machine exploit with ASLR bypass in a follow up video.
So for now, you just need to know it's a heap overflow that happens when overlaying
one image on top of another. Chapter three hacking into OpenAI.
Here I'm running the vulnerable Discourse version, and the goal for this test exploit is
to write a file into the Public Assets folder, which you can see currently doesn't exist.
So let's compose a new post and we drag the exploit HEIC image into the editor.
It will upload it and process it. And if we now reload the public file,
we can see the exploit was successful. The image triggered a remote code
execution and executed ID and wrote the current user running into this file.
So yes, at this point they had a stable remote code execution exploit for any Discourse forum
running the same image, and Harsh and Mohan tried it on community.openai.com, but it failed.
Apparently the cloud environment has some differences to the Docker image.
However, that's not a problem for an agent. Just let it try and adapt the exploit and
it will work. They did it. They got Remote code execution on the OpenAI Community Forum.
And now with this access Harsh could check the OAuth stuff and they found a way how they could
take over the jetty account of an employee. Actually, they could have taken over anybody's
ChatGPT account who logged into the community forum.
But of course, an employee makes the most sense to target because with that,
they gained access to their work environment. At first, ChatGPT doesn't seem like much,
but you can connect your OpenAI account to a lot of work related stuff and their
OpenAI account obviously connected to stuff like Slack and the internal repositories.
And now, to prove the impact and severity of this, they first thought about using the
Slack connectors to send a message to Sam Altman, but then decided to safely
prompt Codex to just open a PR to update the readme.md with a success message.
This way they could demonstrate the impact fully and not break anything.
And then while the agent was processing this request, it suddenly said downloading the
repository and harshest mouse hovered over it. Don't don't look.
Don't look into reports. Just keep. Keep like that. Just don't look into anything. Yeah, they knew they could now
access the repositories, but they don't want to. That would definitely be a step way too far.
It's one thing to prove access and leave a small graffiti behind, but it's a very different thing
to actually view the privileged data. Anyway, once the agent was done,
we can see replace the root Readme with the requested Hacktron AI team.
POC created a new branch Codex Hacktron AI team POC.
And here's the actual diff. And now they can press the button and submit this as a pull request against the OpenAI OpenAI internal repository. Damn.
Chapter four disclosure. Mohan and Harsh immediately reported the Discourse
Remote code execution to OpenAI and how it could be used to take over ChatGPT accounts even before
they tested it with an employee account. And once they confirmed that it also works
with employees, they added a comment to the report right away with the PR number.
So a triager doesn't have to reproduce anything. They can immediately see this is serious.
Besides the reports, they were also directly contacting OpenAI security people over Twitter,
informing them of the bug report and that they should handle this as quickly as possible.
However, one funny detail about all of this is maybe that this all happened on the 25th of July.
That's the weekend after. On Wednesday, OpenAI disclosed that they were
the ones involved in the Hugging Face incident. The whole internet was already carrying pitchforks
and I'm sure internally OpenAI was in quite the panic emergency mode.
And then they got this report about a very serious vulnerability.
Anyway, do you want to guess the bounty they got from OpenAI?
Maybe the maximum $100,000, or just a sincere thank you for helping to secure one of the
most important companies in the US right now. Well, they got $6,500, and that was just for the
buck to escalate from Discourse to ChatGPT because as it turns out, Discourse was out of scope.
So no bounty for the initial exploit. To be fair, according to their bug
bounty policy, buried in the out of scope description, it explicitly forbids domains
that are CNAME to other active third party service providers like community.openai.com.
But in Harsh defense, ChatGPT cannot even read this s**t. And first would say it's in scope. I had to ask it again to then find this line.
I guess never trust AI. Chapter five. Hack the planet.
A while ago, I made a video about an iOS zero day exploit, or rather,
about the underlying vulnerability in an image parsing library to handle WebP images.
The title of the video was A Vulnerability to Hack the World, which is maybe a bit clickbaity,
but I had good reasons for that. So what we have here is a very
critical vulnerability in an image file format used by iOS and Chrome.
And with these two code bases, we basically already cover the world.
Any software that supports WebP most likely uses the official WebP library.
And that's where the vulnerability lies. So I don't think it's exaggerated to say that this
was one of the most valuable vulnerabilities that could exist, looking at the prices for zero days.
Of course, a full chain. The single vulnerability is not enough. But this WebP vulnerability could be the entry point for any of these categories.
But also back then, this was mostly theoretical, because who is going to write an adept memory?
Corruption exploits to other targets that requires so much time and skill.
But the world has changed. Everybody probably knows this
xkcd about dependencies that our entire technology stack depends on some obscure
library, but read the subtitle of this one. Someday, ImageMagick will finally break for good,
and we will have a long period of scrambling as we try to reassemble civilization from the rubble.
And I guess this story is exactly this one. Image parser vulnerability through ImageMagick
fixed one year ago, could be used and escalated to get access to OpenAI's internal repositories.
But there's more. As mentioned in the beginning, OpenAI was not the only target. Harsh and Mohan used the vulnerability to
also hack Slack, Meta, and many more. So check out their blog post over at
Hacktron.AI and keep an eye out for more disclosures coming soon.
So how does the world look like in 2026? In the past, we have seen lots of very
bad vulnerabilities, but generally those were scary because they were also easy to exploit.
This libheif vulnerability is not easy to exploit or wasn't easy to exploit in the past.
I think in the past we often relied on security through complexity,
not security through obscurity. The code and the vulnerability. Everything was public, but it always required a lot of skill and time to exploit even known
memory, corruption, vulnerabilities. And for zero days, you just assume
that they are so rare and expensive they wouldn't be used against you.
Of course, if you are OpenAI, attackers will also use zero days. But for the less important companies, I think maybe unintentionally,
they relied on security through complexity. But with AI, the threat model has changed.
If you look at the Rand Institute report from 2024 regarding securing frontier model providers,
they define levels of attacker capabilities. But the ironic thing is when they did this
report how to secure AI companies like OpenAI, they did not anticipate and model
the capability increase from AI. So this is all outdated.
I know securing an organization is hard, and anybody who oversimplifies this is wrong.
But you cannot ignore the fact that they made the hacking technologies that
enabled this because of them. The world in 2026 has shifted
these threat models at least by one level. And if we continue, it will be two levels soon.
I know these are big claims, but when you look at the technical details of the exploit,
you will see why these two guys could have not pulled this off without AI.
I mean, they are skilled, but no offense. They are not that skilled, especially to
build these exploits in just days while in parallel doing other work.
Harsh and Mohan are just an example of what hackers can do with AI.
They combine really good intuition, a research mindset, and their knowledge and experience
to then use AI very effectively. So if you also want to hack OpenAI,
you should keep learning. And in the upcoming videos, we will have a closer look at this libheif vulnerability and how it was exploited,
How the Asian built the exploit against a black box remote system with Aslr,
and how the Slack image processing had a sandbox around ImageMagick, but in the
end the agent could escape it as well. I hope you're looking forward to that. I think it's going to be really interesting, but if you want to learn something right now,
check out our courses on Hextree.io. Our web security courses aim to build a
foundation in the underlying technologies, not just showing individual tools and techniques.
This kind of understanding is essential when working with AI agents to hack.
It helps you give them better direction, recognize flawed assumptions, and verify their results.
So head over to Hextree.io and check out our foundational subscription.





