- 一点改动:
2.1.2、CTF 反序列化小真题
- 链接:
- 题目:点login咋没反应
1、可用发现登录按钮无法使用,只是一个摆设。
2、查看网页源代码,发现有一个href="admin.css"
的可疑信息:
3、点进去查看,发现提示:
4、在url后面加上?23727
,发现有反馈。
5、分析代码,可以得出:要想得到flag的值,要让COOKIE的值与KEY的值相等。同时还要满足一个条件:URL上不能够出现23727
这个参数,否则执行的是显示源文件的信息,而不是flag的值。
6、抓包,并添加Cookie
。
7、获得flag的值。
2.1.3、CTF 反序列化类似题
1、在URL后面添上?hint
可以查看到代码。
2、比较COOKIE的值与KEY的值是否相等时,存在一个陷阱。
3、使用KEY为空的值,进行反序列化。
4、获得flag。
2.2、有类魔术方法触发
2.2.1、本地
unserialize3.php
<?php
class ABC{
public $test;
function \_\_construct(){
$test = 1;
echo '调用了构造函数<br>';
}
function \_\_destruct(){
echo '调用了析构函数<br>';
}
function \_\_wakeup(){
echo '调用了苏醒函数<br>';
}
}
echo '创建对象a<br>';
$a = new ABC;
echo '序列化<br>';
$a\_ser=serialize($a);
echo '反序列化<br>';
$a\_unser=unserialize($a\_ser);
echo '对象快死了<br>';
2.2.2、网鼎杯 2020 青龙大真题
1、进入环境:
<?php
include("flag.php");
highlight\_file(\_\_FILE\_\_);
class FileHandler {
protected $op;
protected $filename;
protected $content;
function \_\_construct() {
$op = "1";
$filename = "/tmp/tmpfile";
$content = "Hello World!";
$this->process();
}
public function process() {
if($this->op == "1") {
$this->write();
} else if($this->op == "2") {
$res = $this->read();
$this->output($res);
} else {
$this->output("Bad Hacker!");
}
}
private function write() {
if(isset($this->filename) && isset($this->content)) {
if(strlen((string)$this->content) > 100) {
$this->output("Too long!");
die();
}
$res = file\_put\_contents($this->filename, $this->content);
if($res) $this->output("Successful!");
else $this->output("Failed!");
} else {
$this->output("Failed!");
}
}
private function read() {
$res = "";
if(isset($this->filename)) {
$res = file\_get\_contents($this->filename);
}
return $res;
}
private function output($s) {
echo "[Result]: <br>";
echo $s;
}
function \_\_destruct() {
if($this->op === "2")
$this->op = "1";
$this->content = "";
$this->process();
}
}
function is\_valid($s) {
for($i = 0; $i < strlen($s); $i++)
if(!(ord($s[$i]) >= 32 && ord($s[$i]) <= 125))
return false;
return true;
}
if(isset($\_GET{'str'})) {
$str = (string)$\_GET['str'];
if(is\_valid($str)) {
$obj = unserialize($str);
}
}
2、分析代码:
- 主函数(传递参数有效就将参数反序列化):
function is\_valid($s) {
for($i = 0; $i < strlen($s); $i++)
if(!(ord($s[$i]) >= 32 && ord($s[$i]) <= 125))
return false;
return true;
}
if(isset($\_GET{'str'})) {
$str = (string)$\_GET['str'];
if(is\_valid($str)) {
$obj = unserialize($str);
}
}
- 类之前(包含文件,高亮源代码):
include("flag.php");
highlight\_file(\_\_FILE\_\_);
- 类的源代码
// - 第一:获取 flag 存储 flag.php
// - 第二:两个魔术方法\_\_destruct \_\_construct
class FileHandler {
protected $op;
protected $filename;
protected $content;
function \_\_construct() {
$op = "1";
$filename = "/tmp/tmpfile";
$content = "Hello World!";
$this->process();
}
// - 第三:传输 str 参数数据后触发 destruct(反序列化之后,相当于添加了一个对象(但是不会触发construct方法,因为是反序列化得来的)。但是会在最后触发destruct方法),存在 is\_valid 过滤(如果OP===2,赋值为1;否则就将content赋值为空,调用process方法)
function \_\_destruct() {
if($this->op === "2")
$this->op = "1";
$this->content = "";
$this->process();
}
// - 第四:\_\_destruct 中会调用 process,其中 op=1 就写入, op=2 就调用读取方法并且赋值给res,再打印res(output()为打印),否则就输出坏黑客。
public function process() {
if($this->op == "1") {
$this->write();
} else if($this->op == "2") {
$res = $this->read();
$this->output($res);
} else {
$this->output("Bad Hacker!");
}
}
// 写入(OP=1写入)
// ---如果filename和content都存在,并且content的长度小于100,就将content写入filename,并且输出成功。否则输出失败。
private function write() {
if(isset($this->filename) && isset($this->content)) {
if(strlen((string)$this->content) > 100) {
$this->output("Too long!");
# 总结
其他的内容都可以按照路线图里面整理出来的知识点逐一去熟悉,学习,消化,不建议你去看书学习,最好是多看一些视频,把不懂地方反复看,学习了一节视频内容第二天一定要去复习,并总结成思维导图,形成树状知识网络结构,方便日后复习。
这里还有一份很不错的《Java基础核心总结笔记》,特意跟大家分享出来
**目录:**
![](https://img-blog.csdnimg.cn/img_convert/138dea00605c7c925b5a5c21586a5a58.webp?x-oss-process=image/format,png)
**部分内容截图:**
![](https://img-blog.csdnimg.cn/img_convert/3a132ab23d4a87898483c8d825074e1d.webp?x-oss-process=image/format,png)
![](https://img-blog.csdnimg.cn/img_convert/e32c2ac31d5854e8fc9aed60ad43f63f.webp?x-oss-process=image/format,png)
的内容都可以按照路线图里面整理出来的知识点逐一去熟悉,学习,消化,不建议你去看书学习,最好是多看一些视频,把不懂地方反复看,学习了一节视频内容第二天一定要去复习,并总结成思维导图,形成树状知识网络结构,方便日后复习。
这里还有一份很不错的《Java基础核心总结笔记》,特意跟大家分享出来
**目录:**
[外链图片转存中...(img-AKHgIWAC-1714251708801)]
**部分内容截图:**
[外链图片转存中...(img-1TA6SJTD-1714251708801)]
[外链图片转存中...(img-bKnhggbB-1714251708801)]
> **本文已被[CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】](https://bbs.csdn.net/topics/618154847)收录**