Apr 18, 2020 04:01 PM
(This post was last modified: Apr 18, 2020 05:19 PM by slober.)
[Web] LFI: Local file inclusion on a website#33
A few days ago I did a CTF challenge with a few buddies of me and this was one of the easier ones. It mainly focussed on a super simple LFI vulnerabilities
LFI stands for Local file inclusion.
Simply put you can inject local files in the webserver and if the webserver runs as root you can pretty much call a lot of files 😖.
The counterpart of LFI is RFI which stands for remote file inclusion same principle applied here only this time you aren't including a local file but a remote one such as webshell or an exploit.
In this example, we've used the local one.
How can this happen?
well, most of the time it's due to sloppy or rushed code writing a quick example or POC and well not updating it...
If I ran this code on my webserver I would most likely have a bad day in the near future.
What's happening?
![[Image: 1.png]](https://i.ibb.co/ChbHmR3/1.png)
![[Image: 2.png]](https://i.ibb.co/pyMW6JB/2.png)
Well, when the get param name is set (has a value) it will include that value in its code.
That would mean if I have a text file called superduper-awesome-secrets.txt I could view it on said webpage.
That wouldn't be a good thing to happen right?
Yes, it does still happen out in the wild maybe not that often or this obvious but well it is out there.
How would this be beneficial to us?
Let me bounce that question back with another one which file on a Linux system could contain (unencrypted) passwords?
How can you figure out that you're dealing with a possible LFI vulnerability (in a CTF environment) well add "./" in front of your get request
try playing with the request changing the input and see what happens.
![[Image: 3.png]](https://i.ibb.co/MBwwQFm/3.png)
once you're getting something similar like picture 2 you could possible be dealing with an LFI vulnerability.
All we have to do now is add a bunch of ../../../ and /etc/passwd or /etc/shadow at the end
What is the meaning of ../?
../ will go up a directory
![[Image: 4.png]](https://i.ibb.co/K7GsgRP/4.png)
![[Image: 5.png]](https://i.ibb.co/17sf5HK/5.png)
Once you've got the credentials you can spawn up an ssh shell and you're pretty much inside...
all you need to do now is find the flags or escalate your privileges.
In this chapter in our capture the Flagg campaign we didn't need a shell. We did need to capture two flags the root flag and the user flag. so we only needed the user name (hence etc/passwd to get the username) and well the root username is root so that was pretty easy. the flag locations where
For those that still had that lingering question 🙃
Ahh, it brought back memories indeed.
If you have a raspberry pi you can try this out! It's very easy to trie this and it should give you some basic insight about LFI and security in general. don't be sloppy when you're coding and don't rush it.
This kind of vulnerabilities are so much fun ✌
UPDATE #1:
Reason: Interesting addition by нα¢кєя:
Spoiler (Click to View)
Extra:
If you want to explore LFI more you could look into it this was a basic example just for funsies.
There are so much more ways to pop up shells you could, for example, execute PHP code use different kind of PHP-wrappers and other file locations such as proc/self/environ
These three sites will go so much more in-depth on this topic I really advise these if you want to know more about it.
A few days ago I did a CTF challenge with a few buddies of me and this was one of the easier ones. It mainly focussed on a super simple LFI vulnerabilities
LFI stands for Local file inclusion.
Simply put you can inject local files in the webserver and if the webserver runs as root you can pretty much call a lot of files 😖.
The counterpart of LFI is RFI which stands for remote file inclusion same principle applied here only this time you aren't including a local file but a remote one such as webshell or an exploit.
In this example, we've used the local one.
How can this happen?
well, most of the time it's due to sloppy or rushed code writing a quick example or POC and well not updating it...
PHP Code
<?php
if ( isset ( $_GET["name"] ) ) {
include ( $_GET["name"]);
}
?>If I ran this code on my webserver I would most likely have a bad day in the near future.
What's happening?
![[Image: 1.png]](https://i.ibb.co/ChbHmR3/1.png)
![[Image: 2.png]](https://i.ibb.co/pyMW6JB/2.png)
Well, when the get param name is set (has a value) it will include that value in its code.
That would mean if I have a text file called superduper-awesome-secrets.txt I could view it on said webpage.
That wouldn't be a good thing to happen right?
Yes, it does still happen out in the wild maybe not that often or this obvious but well it is out there.
How would this be beneficial to us?
Let me bounce that question back with another one which file on a Linux system could contain (unencrypted) passwords?
Code
/etc/passwd
/etc/shadowHow can you figure out that you're dealing with a possible LFI vulnerability (in a CTF environment) well add "./" in front of your get request
try playing with the request changing the input and see what happens.
![[Image: 3.png]](https://i.ibb.co/MBwwQFm/3.png)
once you're getting something similar like picture 2 you could possible be dealing with an LFI vulnerability.
All we have to do now is add a bunch of ../../../ and /etc/passwd or /etc/shadow at the end
What is the meaning of ../?
../ will go up a directory
![[Image: 4.png]](https://i.ibb.co/K7GsgRP/4.png)
![[Image: 5.png]](https://i.ibb.co/17sf5HK/5.png)
Once you've got the credentials you can spawn up an ssh shell and you're pretty much inside...
all you need to do now is find the flags or escalate your privileges.
In this chapter in our capture the Flagg campaign we didn't need a shell. We did need to capture two flags the root flag and the user flag. so we only needed the user name (hence etc/passwd to get the username) and well the root username is root so that was pretty easy. the flag locations where
Code
../../../../../jhonyc/user.flag and
../../../../../root/root.flagFor those that still had that lingering question 🙃
Ahh, it brought back memories indeed.
If you have a raspberry pi you can try this out! It's very easy to trie this and it should give you some basic insight about LFI and security in general. don't be sloppy when you're coding and don't rush it.
This kind of vulnerabilities are so much fun ✌
UPDATE #1:
Reason: Interesting addition by нα¢кєя:
Spoiler (Click to View)
Extra:
If you want to explore LFI more you could look into it this was a basic example just for funsies.
There are so much more ways to pop up shells you could, for example, execute PHP code use different kind of PHP-wrappers and other file locations such as proc/self/environ
These three sites will go so much more in-depth on this topic I really advise these if you want to know more about it.
Public Honeypot Project: https://github.com/Slober3/PotHead
Honeypot Twitter: https://twitter.com/HoneyHive9
BTC: 1Anime1QrjwsEmz8bC2FwVcNXDLxP3SWAJ
Honeypot Twitter: https://twitter.com/HoneyHive9
BTC: 1Anime1QrjwsEmz8bC2FwVcNXDLxP3SWAJ
Erin Wrote:It’s fine. There’s nothing to be afraid of. Calm down, Lilan


![[Image: 1*POALwHHnmQ7iFOuYa50Yow.png]](https://miro.medium.com/max/1216/1*POALwHHnmQ7iFOuYa50Yow.png)
