Information#
Version#
By | Version | Comment |
---|---|---|
noraj | 1.0 | Creation |
CTF#
- Name : DEF CON CTF Qualifier 2018
- Website : oooverflow.io
- Type : Online
- Format : Jeopardy
- CTF Time : link
PHP Eval White-List - Web#
PHP was dangerous, so we've fixed it!
http://c67f8ffd.quals2018.oooverflow.io
Files:
websec_eval_wl.so
Quick way#
Read the PHP source code (http://c67f8ffd.quals2018.oooverflow.io/source.txt):
So the user input is directly evaluated.
Want to exec something on the system? Let's use system()
.
Let's try system('id');
:
The description says:
prevent you from accessing the
flag
binary up the current folder.
So the flag
must be in ../
system("../flag");
Longer way#
The challenge is tagged as web and reverse and they provide us the custom php extension.
As I'm not a reverser I just used strings
:
This looks like shell_exec
, proc_open
, passthru
, popen
, pcntl_exec
is a whitelist and the title of the web page is Custom eval whitelisting
.
But we can use system()
. So I don't know if there was real whitelisting or if it was a troll.
system('ls -lA');
print_r(scandir('.'));
system('ls -lA ..');
=> displays nothing
print_r(scandir('..'));
At least there is really the open_basedir
enforcement.
As the description suggests I read the open_basedir page of the PHP manual.
There is a note suggesting that PHP 5.3.0 is vulnerable:
As of PHP 5.3.0 open_basedir can be tightened at run-time. This means that if open_basedir is set to /www/ in php.ini a script can tighten the configuration to /www/tmp/ at run-time with ini_set(). When listing several directories, you can use the PATH_SEPARATOR constant as a separator regardless of the operating system.
So let's check the PHP version:
phpinfo();
=> PHP Version 7.0.28-0ubuntu0.16.04.1
, so that's not the path to follow.
The start page was displaying Can you execute the ./flag binary?
and we are in /var/www/html/
(system('pwd');
) so I first thought that the flag was in /var/www/html/flag
but this is impossible as we saw it didn't exist by doing some file listing.
As I said in the quick way write-up, there is also this in the description:
prevent you from accessing the
flag
binary up the current folder.
So the flag may be in /var/www/flag
.
system("ls -l ../flag");
The description said Can you execute
it and effectively it is only executable so it's useless to try to read it by any way.
system("../flag");
Note: passthru("../flag");
and a lot of other commands are working because there is no filtering (at least I didn't see any).
Bonus#
I was starting to read How to bypass disable_functions and open_basedir by Tarlogic.
From their github:
Chankro
Your favourite tool to bypass disable_functions and open_basedir in your > pentests.
How it works#
PHP in Linux calls a binary (sendmail) when the mail() function is executed. If we > have putenv() allowed, we can set the enviroment variable "LD_PRELOAD", so we can > preload an arbitrary shared object. Our shared object will execute our custom payload > (a binary or a bash script) without the PHP restrictions, so we can have a reverse > shell, for example.
It's a good read even if it was not useful for this challenge.