Skip to content

Commit b668c21

Browse files
committed
Update UAF tests that relied on serializing SNMP and ZipArchive
bug72479.phpt and bug72434.phpt tested UAF vulnerabilities through unserialize(). With NOT_SERIALIZABLE, unserialize() rejects these classes entirely, preventing the UAF by construction. Update tests to verify the rejection.
1 parent edc4325 commit b668c21

File tree

2 files changed

+16
-44
lines changed

2 files changed

+16
-44
lines changed

ext/snmp/tests/bug72479.phpt

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,12 @@ require_once(__DIR__.'/skipif.inc');
1010
<?php
1111
$arr = [1, [1, 2, 3, 4, 5], 3, 4, 5];
1212
$poc = 'a:3:{i:1;N;i:2;O:4:"snmp":1:{s:11:"quick_print";'.serialize($arr).'}i:1;R:7;}';
13-
$out = unserialize($poc);
14-
gc_collect_cycles();
15-
$fakezval = ptr2str(1122334455);
16-
$fakezval .= ptr2str(0);
17-
$fakezval .= "\x00\x00\x00\x00";
18-
$fakezval .= "\x01";
19-
$fakezval .= "\x00";
20-
$fakezval .= "\x00\x00";
21-
for ($i = 0; $i < 5; $i++) {
22-
$v[$i] = $fakezval.$i;
23-
}
24-
var_dump($out[1]);
25-
26-
function ptr2str($ptr)
27-
{
28-
$out = '';
29-
for ($i = 0; $i < 8; $i++) {
30-
$out .= chr($ptr & 0xff);
31-
$ptr >>= 8;
32-
}
33-
return $out;
13+
try {
14+
$out = unserialize($poc);
15+
var_dump($out);
16+
} catch (Exception $e) {
17+
echo $e->getMessage() . "\n";
3418
}
3519
?>
3620
--EXPECT--
37-
int(1)
21+
Unserialization of 'SNMP' is not allowed
Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
--TEST--
22
Bug #72434: ZipArchive class Use After Free Vulnerability in PHP's GC algorithm and unserialize
3+
--EXTENSIONS--
4+
zip
35
--FILE--
46
<?php
5-
// The following array will be serialized and this representation will be freed later on.
67
$free_me = array(new StdClass());
7-
// Create our payload and unserialize it.
88
$serialized_payload = 'a:3:{i:1;N;i:2;O:10:"ZipArchive":1:{s:8:"filename";'.serialize($free_me).'}i:1;R:4;}';
9-
$unserialized_payload = unserialize($serialized_payload);
10-
gc_collect_cycles();
11-
// The reference counter for $free_me is at -1 for PHP 7 right now.
12-
// Increment the reference counter by 1 -> rc is 0
13-
$a = $unserialized_payload[1];
14-
// Increment the reference counter by 1 again -> rc is 1
15-
$b = $a;
16-
// Trigger free of $free_me (referenced by $m[1]).
17-
unset($b);
18-
$fill_freed_space_1 = "filler_zval_1";
19-
$fill_freed_space_2 = "filler_zval_2";
20-
$fill_freed_space_3 = "filler_zval_3";
21-
$fill_freed_space_4 = "filler_zval_4";
22-
debug_zval_dump($unserialized_payload[1]);
23-
?>
24-
--EXPECTF--
25-
array(1) refcount(3){
26-
[0]=>
27-
object(stdClass)#%d (0) refcount(1){
28-
}
9+
try {
10+
$unserialized_payload = unserialize($serialized_payload);
11+
var_dump($unserialized_payload);
12+
} catch (Exception $e) {
13+
echo $e->getMessage() . "\n";
2914
}
15+
?>
16+
--EXPECT--
17+
Unserialization of 'ZipArchive' is not allowed

0 commit comments

Comments
 (0)