21 hours 43 minutes
file upload vulnerabilities
are learning objectives are to understand what file, upload vulnerabilities are and identify how to exploit file upload vulnerabilities.
So a lot of applications allow people to upload different kinds of files. Maybe it's an avatar image, maybe uh it's a medical application where you can upload receipts in a pdf form.
Um a lot of them you have to be authenticated. Some, you don't have to be authenticated, which is even better for us as Attackers. But what this allows us to do is possibly change the file extension
to then upload a malicious file. And again, it's important to understand the underlying architecture of the server. What what is it PHP is, is it a sp that's going to ultimately determine what type of file file you're going to upload.
So our, our administrator portal for the awesome photo blog
doesn't allow file extensions named PHP.
Why doesn't do that? Because it runs PHP?
And if I can upload a shell, it will execute that shell and I'm able to get on that server.
So it really depends how the
code is written, some have rejects. So it's looking for different, different types of file extensions
in this case is actually looking for dot PHP. So I could fool it by making it PHP three
or making it uh an uppercase p lowercase H uppercase P again, to block that rejects. So it's not a very well thought out application. Of course, it's intentionally vulnerable, but here, that's how I tricked it. You can also do other things like p. Html
as well. I have a whole other slide to show you what are the things you can try.
So, if you if you understand the underlying architecture of the server and you know, it's running PHP here are a few extensions that you can use a sp you can use a sp a sp x Pearly have a few other options to choose from. Jsp and called fusion. So
just because one file extension type is blocked,
doesn't mean another file type
is not blocked which is allowed.
So try these because I've done a few hacked the box challenges, challenges or cts where PHP is blocked, but PHP five is not.
So this is a good a good source to take a look at as well.
Mime types. Why are mime types important?
Because some servers don't look at the extension itself, they look at the mime type of the file.
So you can run the file command and Mime type and you can see here that it is text X PHP.
And I changed the file extension two JPG to jpeg and run my type again. Well, it doesn't fool it, it sees that it's a a PHP file.
So in this case, simply changing the extension
will not trick the server
into thinking that. Is that actually a Jpeg file? So what do you do
you use Burp suite? So when you intercept this post request
in Burp suite,
you're changing the content type from application X PHP to image our image forward slash jpeg.
So now it thinks it's a Jpeg Jpeg file and not a PHP file. Despite having a PHP extension,
you can do this by hiding hiding code in an image. I thought this is a pretty cool little script from Techie Zilla.
Um and here's the script that I used for to basically take a Jpeg file,
an office kate PHP into that. And you can see here, I run around the strings come in on it and you can see my little shell down there written in PHP.
So if I run Mime Type on this, even though it has a PHP three extension. The Mime type is J Peg.
That has to do with magic bytes. You can you can look this up in google, but you see
magic bytes. J f I F. If you look up magic bytes for things like, like Jif or GIF files,
um I know there's a big war about what you call it, um or any type of file, there are magic bytes. So when something looks at a file, it will look at things like the headers of the file. And if it says J F I F, it will think it's a
on this case. It thinks it's a Jpeg file, but these magic bytes are also important as well. So it's recognizing this file from magic bytes as a Jpeg file.
so here we go. I was able to confiscate my code in that image
and Iran that cat and was able to get a reverse shell
by tricking the server into thinking that my PHP
uh that the PHP
Jpeg was a Jpeg when in fact it had PHP embedded inside of it.
And the um, server, of course, is running PHP. So that's how I was able to get a reverse shell.
So in summary, we should now understand what file upload vulnerabilities are and identify how to exploit file upload vulnerabilities.