欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

F2blog XMLRPC 上传任意文件漏洞

程序员文章站 2022-07-10 09:43:20
刚从官方下载的最新版:F2blog-v1.2_build_03.01_full 存在漏洞文件:xmlrpc.php, 影响:可上传任意文件到服务器。 原理:get_http_raw_post_data()是获取最原始的传递过来... 08-10-08...
刚从官方下载的最新版:f2blog-v1.2_build_03.01_full 存在漏洞文件:xmlrpc.php,
影响:可上传任意文件到服务器。
原理:get_http_raw_post_data()是获取最原始的传递过来的数据,也是说不会因为php环境的magic为on的影响。
而他在check_user_pw的时候,并没有过滤,结合后面的上传没有做后缀判断,所有可以直接导致上传任意文件到服务器。 简单分析:
function metaweblog_newmediaobject ($values) { //2007-02-01 add support for uploading files
global $settinginfo,$dmc, $dbprefix,$defualtcategoryid;
//此处本是判断用户是否登录的,但是下面没有做检查,仅仅在这里返回了用户是否登录的一个值。
$userdetail = check_user_pw ($values['username'], $values['password']); $struct=$values['struct'];
//writetofile ('text1.php', $struct['bits']); //debug only
if ($struct['bits'] && $struct['name']) {
$writefilecontent=base64_decode($struct['bits']);
if (file_exists("attachments/{$struct['name']}")) @unlink("attachments/{$struct['name']}");

$filenum=@fopen("attachments/{$struct['name']}","wb");
if (!$filenum) {
xml_error ("sorry, uploading file ({$struct['name']}) failed.");
}
flock($filenum,lock_ex);
fwrite($filenum,$writefilecontent);
//并没有判断文件是否安全,直接写入。
fclose($filenum);
}
$xml_content=make_xml_piece ("struct", array('url'=>"{$settinginfo['blogurl']}/attachments/{$struct['name']}"));
$body_xml=xml_generate($xml_content);
send_response ($body_xml);
}
本来说到这里都够明白了,下面就再把利用方法写下吧:
定义的方法数组:
$methodfamily=array('blogger.newpost', 'blogger.editpost', 'blogger.getusersblogs', 'blogger.getuserinfo', 'blogger.deletepost', 'blogger.gettemplate', 'blogger.settemplate', 'metaweblog.newpost', 'metaweblog.editpost', 'metaweblog.getpost', 'metaweblog.newmediaobject', 'metaweblog.getcategories', 'metaweblog.getrecentposts');
方法调用:
$methodname=parse_get($rawdata, 'methodname', true);
if (!@in_array($methodname, $methodfamily)) xml_error ("method ({$methodname}) is not availble.");
$values=parse_get($rawdata, 'value'); $values=parse_walk_array($values, $methodname);
//print_r($values); //for debug only
//exit();
//get default category, for those editors which don't support categories
$sql="select * from ".$dbprefix."categories limit 0,1";
$arr_category=$dmc->fetcharray($dmc->query($sql));
$defualtcategoryid=$arr_category[id]; $methodname=str_replace('.', '_', $methodname);
call_user_func ($methodname, $values);
$rawdata的来源:
$rawdata=get_http_raw_post_data();
//writetofile ("text4.xml", $rawdata); //for debug use
//$rawdata=file_get_contents("text4.xml"); //for debug use if (!$rawdata) die ("sorry, don't visit this web!"); $stringtype_o="i4|int|boolean|struct|string|double|base64|datetime\.iso8601";
$stringtype="(".$stringtype_o.")"; $rawdata=str_replace("\r", '', $rawdata);
$rawdata=str_replace("\n", '', $rawdata);
$rawdata=str_replace("\t", '', $rawdata);
$rawdata=str_replace("<![cdata[", '', $rawdata);
$rawdata=str_replace("]]>", '', $rawdata); //stupid cdata, i don't want it
$rawdata=preg_replace("/<([^>] ?) \/>/is", '<\\1></\\1>', $rawdata); //self-closed tags
//$rawdata=convert_utf8($rawdata); $rawdata=preg_replace_callback("/<struct>(. ?)<\/struct>/is", 'filter_struct', $rawdata); //struct can be a trouble, use this to avoid values and names being parsed
get_http_raw_post_data()方法:
function get_http_raw_post_data () { //get http_raw_post_data
global $http_raw_post_data;
if (isset($http_raw_post_data)) { //good, the server supports $http_raw_post_data, then return it directly
return trim($http_raw_post_data);
}
elseif (php_os>="4.3.0") { //php 4.3.0 and higher version supports another way to get it
return readfromfile( 'php://input' );
}
else return false; //sorry, no way out, or $raw data is not set at all
} 漏洞修补,简单点的,判断下用户是否有上传附件的权限。其他的自己发挥吧。
既然费了这么多话,那就顺便附上一个安全点的方法吧:
function metaweblog_newmediaobject ($values) { //2008-05-27 edit by neeao
global $settinginfo,$dmc, $dbprefix,$defualtcategoryid;
$userdetail = check_user_pw ($values['username'], $values['password']); $records=$dmc->fetcharray($dmc->query("select * from `{$dbprefix}logs` where `id`='{$values['postid']}'"));
if ($records['id']=='') xml_error ("entry does not exist.");
else {
$struct=$values['struct'];
//writetofile ('text1.php', $struct['bits']); //debug only
if ($struct['bits'] && $struct['name']) {
$writefilecontent=base64_decode($struct['bits']);
if (file_exists("attachments/{$struct['name']}")) @unlink("attachments/{$struct['name']}");

$filenum=@fopen("attachments/{$struct['name']}","wb");
if (!$filenum) {
xml_error ("sorry, uploading file ({$struct['name']}) failed.");
}
flock($filenum,lock_ex);
fwrite($filenum,$writefilecontent);
fclose($filenum);
}
$xml_content=make_xml_piece ("struct", array('url'=>"{$settinginfo['blogurl']}/attachments/{$struct['name']}"));
$body_xml=xml_generate($xml_content);
send_response ($body_xml);
}
}
没有加文件格式的判断,有点麻烦了,懒得写了。