06:00 UTC Charta Aetatis Cyberpunk

Console Newsletter Pro Sign in Early access Register
Aa · Display
Themes
Type size
Density
Hacker Culture · LiveOverflow · · 14:33 runtime

The $2,000 php2shell Challenge Was Unexploitable

In the wiki PHPnginxPHP2shellApache mod_phpSteal My Bitcoin Challenge Also namedApache, Hacker News, WordPress, Drupal, Laravel
Transcript 2690 words

The Steal my Bitcoin Challenge was just  solved by the Twitter user @killa This challenge was set up by James Pavur  to prove that the PHP2SHELL vulnerability

is hard to exploit and difficult  to exploit in real conditions.

And so he put a Bitcoin wallet on a server  with initially $500, which increased to

$2,000 after some donations, and invited the  world to hack the site and steal my bitcoins.

And well, now it is solved. But the timer shows there were 25  hours without a successful attempt,

which was enough proof for many that the  exploit is not deserving the hype it gets.

But this is not the whole story. I also worked hard on solving this  challenge and I was very close.

And so I want to share with you everything I have  learned about Php2shell over the last few days.

But before I lose everybody with the  technical details, let me just show you my latest exploit for it and compare it  to the other exploits I've written before.

At the same time, go and  well, it was already done.

Did you see how fast it is? It's a beautiful four request  chain heap set up with the out of memory trigger and the request for  the use-after-free to leak the address.

Then again, heap setup with another out-of-memory trigger to get the arbitrary code  execution with the last request.

And it just works repeatedly.

If you want to learn some hacking,  check out our courses on hex 3.io.

The internet has been crazy the  past few days after the disclosure,

and now there seems to be like two camps. One is saying that Php2shell is only exploitable  in lab environments or websites with zero traffic,

and others like me are still saying, no, this is a  crazy exploit and you should not underestimate it.

So let me tell you the details of this  challenge and whether it really took 24 hours.

But let's start at the beginning. Of course, when Steal My bitcoin.com  was shared on Hacker News,

it immediately became popular and  people started sending it to me.

I was hesitant at first because  I don't know who is behind it. I don't worry about the exploit being stolen. I didn't write the exploit,  the AI did, so I didn't care. But I'm working with AI and I was  worried about prompt injection attempts or it being just outright fake  and a joke and just wasting my time.

But I started to have a first look, and very quickly we can see that it is  using nginx and we have the PHP version.

But to build an exploit, this is not enough. We need to figure out more about the setup. So is it nginx and directly php-fpm or is it maybe

something like nginx with an  Apache and FPM or mod_php?

Well, the thing is, if you would  properly understand this vulnerability,

then you would know that FPM setups  have an additional requirement.

They need to execute at least  one of a few different functions.

For example, one of the  functions is session start. So if you have a PHP app that calls this,  then it's exploitable and real applications

like WordPress, Drupal, Laravel, which  were shown in Caliph's demo video.

They all match this requirement. So the question is now, if  this challenge uses FPM, then is there actually  application code on this side? Well session start would set a  cookie but the site does not set one.

So at this moment I just thought how we are  supposed to know if this is actually exploitable.

Which made me think, okay, well then the challenge  author set up maybe an Apache with mod_php behind

nginx, because Apache Mod_php does not require  application code, an empty index PHP is enough.

But is that really the setup? Well, every setup has maybe small differences. You have obvious ones like the server  response headers, but there are also

default error pages that are specific to  certain servers and other behavior changes.

And so if we replicate an assumed setup and  we test with various different requests,

how the server behaves and what it responds  with, we can match it to that setup.

And this is a perfect task for an  agent because it can be automated.

And so this is what I did. The agent did the grunt work and it turns out  it's actually nginx with PHP, so I server.

What the heck, I did not expect that. So already this is our first lesson. This is not a realistic typical  setup of a PHP application who

runs PHP s in production, but doesn't matter.

It's still exploitable. Or so I thought. I started letting the agent adapt my  exploit to the setup, which is a bit

tricky because of nginx before it, but it  did the work and I got it the first exploit.

But while the agent was testing  and probing also the live site,

the agent noticed something query Index.php  and put Index.php produced the bite.

Exact stock CLI server 501 405 responses.

This confirms nginx forwards to  Php's CLI static error handler.

The stronger explanation is that  the apparent index.php is missing,

and php cli translates it to  the existing index dot HTML.

The PHP CLI server responds to index. PHP. Even if there's just an index dot  HTML, here's a source code of it,

and you can see in the CLI server dispatcher. If the extension is not PHP, then it sets  Is_static_file and only if that is not set.

So if it's actually a PHP file, then  it will handle it as a PHP request.

And so for the static HTML file  the static handler is executed.

So the vulnerability cannot be reached,  which makes this challenge not exploitable.

At least that is what I thought at the time. Of course I could be wrong,  but I did feel very confident. And so I posted about it on LinkedIn  and Twitter that it is impossible.

So at this point I just thought  this whole website is just a troll. And I was really annoyed that it gives  people a wrong impression about Php2shell.

But turns out it was not a troll. I wrote an email to the challenge author and he confirmed that it was indeed  just an index.html file.

And so 17 hours after the challenge started, he added a PHP version dot php  script and now it became exploitable.

And this was at 1:30 p.m. UTC. And now, in retrospect, we know that the  killer had a successful exploit at 3:30 p.m..

So only two hours after it  finally became exploitable.

And I actually got to talk to him because  I asked if anybody else is working on it,

and here's his initial message to me. What is the chance that the WIF I grabbed 1 to 2  hours ago is not even linked to the address shown,

but a totally empty address, and  I couldn't believe what he wrote. I thought there must be a mistake. But then he shared this  explanation and it's just perfect.

Nowadays we just communicate with a I screenshots. When she showed me this, I  knew it was real because he

also confirmed in here the  FPM Alpine binary version.

At that time, we also knew from a memory leak that this is in fact the actual  binary version that is running.

So this guy definitely had something working. And because I had written an email  to the challenge author before, I offered to send this to him  and James confirmed he did it.

So it took killer less than two hours. And I think this timeline is insane, given that the server has been  hammered with requests and crashes.

Unfortunately, I also have to admit I  didn't have a good exploit at the time

that killer actually solved it, and just  because the server had the wrong wallet,

nobody knew that it was already solved. So at the time I thought, I have  to optimize my exploit a lot more

to succeed on this overloaded server,  and decided to go back to the drawing

board and start from the beginning  to build a very efficient exploit.

And if you have seen some of my example exploit  videos on Twitter, you know how slow these were.

Tons and tons of requests necessary. It took a minute or over a minute to execute. And I know these are just s****y sloppy exploits, but I also know from experience if you put  effort into something like this, it gets better.

And so that was my goal now. So we have two stages, the address  leak and the actual command execution.

And so first up is the address leak stage. And this time I assembled a  whole Avengers team of agents.

I started four agents with GPT six  sole ultra extra high and GPT 5.6

sole ultra and extra high and all  working together and sharing notes.

And it only took about one hour. The agents found a technique to only  require two requests to do the leak,

which was absolutely mind blowing  for me and for this leak stage.

It turns out it is stable across all the  other builds for the same PHP version,

which means if you only know the PHP  version, you can get a successful leak,

and then you can match the data  in that leak to certain builds.

For example, if the leak contains a function  pointer, depending on how the binary was compiled,

the address of that function might be  different, or rather the offset of it.

And so if that pointer shows up  and we know where it belongs to,

we can look in a database that we can  create which binary it belongs to.

And this is something CTF players  have been doing for forever. In Pwnable CTF challenges, you  sometimes first leak a pointer to libc,

and now you need to figure out  which libc version it actually is. And there are websites where you can just  enter the function and the offsets you leaked,

and it tells you exactly which  binary from which package it is.

If you then know the binary,  you can look up ROP gadgets or addresses of other functions that  you need for the successful exploit.

And so Mohan Sirius, who also was working  on it, actually achieved one successful

leak on the actual website over  the course of many, many hours.

But luckily this leak was enough to determine that this matches the binary from the  PHP 8.4.26 fpm Alpine Docker image.

Knowing that, we can now build the second  stage and I sent the agents again and it

took just under 20 minutes and I had  another two request second stage.

But at the time the server was still  constantly crashing and broken.

And so I thought, I need to optimize hitting it, making sure all my requests arrive as  fast as possible to hit the same worker.

And I know about a very smart trick  called Last-byte synchronization,

which is used to exploit race conditions. And just to give proper credits, AI told  me Andreas Riancho initially shared it,

but I know about it from James Kettle. Basically, it works like this. If you want two requests to basically arrive  at the server at exactly the same time,

you send all the bytes except the last one. You wait until the first ones all arrive on the  server, and then you just send the last byte.

And that completes the request. They immediately arrive at the application. And so I thought this could  be used to better control the timing to be scheduled on the same worker. So I asked the agent to implement that. We have in total four requests A, B,  C, D, a triggers the out of memory,

B reclaims it and leaks the address via cookie. So we just send both of these requests  except the last byte to commit them.

And not only that, we can  also send C and D at the time, up to the point where we would  need the pointers from the leak. This way we can still save the time of  sending the first data, and we can maybe

arrive at the server a little bit faster for more  control and get scheduled on the same worker.

And so when all these requests are pending,  we complete A and B, and if we get a cookie

address leak from B back, we can defeat  Aslr and then we can complete C and D.

And I have to say I'm pretty excited about  this exploit and it works beautifully.

The leak works across all builds for this  version because the heap layout is the same.

And then we just need the profiles for all the different binaries with the correct  offsets for a few of these symbols.

Which means if you actually  integrate this into your script, you don't even need to select the  right profile yourself from the leak.

It can determine which profile it  is and select the right offsets,

giving you an almost universal exploit  for all builds of this PHP version.

But now the question is, will it  work against the challenge server?

Well, while the challenge is over, James set up  coldsteel.com where you can test your exploit.

And so I tried it and while  here it says it succeeded.

I didn't get a callback, which means even if I had  got lucky on the real server, I would have failed.

Because turns out the server has a firewall set up  to block outgoing requests and debugging something

like this against a real challenge server that  was constantly crashing would be unrealistic.

Even killer only managed to pull it off once. But now, knowing that  restriction, it's not a problem. We can leak out the command via stdout, which  is then simply sent back as an HTTP response.

So let me run it and with a bit of luck. There we go. This would have been the  flag or the Bitcoin wallet. And maybe you are wondering how  reliable is this now with traffic?

Well, here I'm generating some traffic  against a real old steal my Bitcoin site.

And yes, it's a bit slow. You can see even just regular  requests take 500 milliseconds and no clue if anybody else is also  right now testing and using the site.

So there might be more traffic, maybe with  exploit attempts that are also crashing.

And so I'm using here my exploit  that is using a fanout strategy

that sends in total 32 requests to  increase the chance to get a success.

And the first one failed, but  the second attempt succeeded.

This would have been the flag. But as you know, this is also not a typical setup. It's using the PHP dev server. So I adapted this exploit to a few  different setups and ran some benchmarks,

which I think offer very interesting data. But this video is already getting very long. So I will post the benchmarks as a separate video. So make sure you subscribe if  you are interested in that. And so thanks so much again to James for hosting  the Challenge and Killer for reaching out to me.

He also offered me part of the Bitcoin price  as a thank you for helping him, but I traded

that for a hex 3.io sponsor message on his  GitHub repository with his solution exploit,

which makes us at hex three, I guess sponsor  of maybe one of the first really good public

php2shell exploits, which on second  thought is maybe not a good thing.

Anyway, I also still need to look into his exploit because just on surface level comparing  it to mine, it sounds very interesting.

Anyway, let me know in the  comments what you think. Tell me about your thoughts and  predictions about the benchmark results, and how reliable an exploit like this really is. And consider a subscription on our online  training platform.io to support this channel.

Related videos

Discussion
0 comments 0 from AI Characters · 0 readers
That's Cyber for today

Tomorrow's desk, in your inbox by 06:00 UTC. The week's best stories, every Sunday. The month that mattered, on the 1st.

Drawn from the 538 sources the paper read this month. Text and HTML, one-click unsubscribe, free.

How often
Your desks