Skip to content

Commit 0fff8a4

Browse files
authored
Merge pull request HackTricks-wiki#1250 from HackTricks-wiki/update_Critical_Vulnerability_Impacting_Over_100K_Sites_P_20250806_182934
Critical Vulnerability Impacting Over 100K Sites Patched in ...
2 parents 980104e + b5c7e9c commit 0fff8a4

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

src/pentesting-web/deserialization/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,64 @@ $o->param = "PARAM";
119119
$ser=serialize($o);
120120
```
121121
122+
### Preventing PHP Object Injection with `allowed_classes`
123+
124+
> [!INFO]
125+
> Support for the **second argument** of `unserialize()` (the `$options` array) was added in **PHP 7.0**. On older versions the function only accepts the serialized string, making it impossible to restrict which classes may be instantiated.
126+
127+
`unserialize()` will **instantiate every class** it finds inside the serialized stream unless told otherwise. Since PHP 7 the behaviour can be restricted with the [`allowed_classes`](https://www.php.net/manual/en/function.unserialize.php) option:
128+
129+
```php
130+
// NEVER DO THIS – full object instantiation
131+
$object = unserialize($userControlledData);
132+
133+
// SAFER – disable object instantiation completely
134+
$object = unserialize($userControlledData, [
135+
'allowed_classes' => false // no classes may be created
136+
]);
137+
138+
// Granular – only allow a strict white-list of models
139+
$object = unserialize($userControlledData, [
140+
'allowed_classes' => [MyModel::class, DateTime::class]
141+
]);
142+
```
143+
144+
If **`allowed_classes` is omitted _or_ the code runs on PHP < 7.0**, the call becomes **dangerous** as an attacker can craft a payload that abuses magic methods such as `__wakeup()` or `__destruct()` to achieve Remote Code Execution (RCE).
145+
146+
#### Real-world example: Everest Forms (WordPress) CVE-2025-52709
147+
148+
The WordPress plugin **Everest Forms ≤ 3.2.2** tried to be defensive with a helper wrapper but forgot about legacy PHP versions:
149+
150+
```php
151+
function evf_maybe_unserialize($data, $options = array()) {
152+
if (is_serialized($data)) {
153+
if (version_compare(PHP_VERSION, '7.1.0', '>=')) {
154+
// SAFE branch (PHP ≥ 7.1)
155+
$options = wp_parse_args($options, array('allowed_classes' => false));
156+
return @unserialize(trim($data), $options);
157+
}
158+
// DANGEROUS branch (PHP < 7.1)
159+
return @unserialize(trim($data));
160+
}
161+
return $data;
162+
}
163+
```
164+
165+
On servers that still ran **PHP ≤ 7.0** this second branch led to a classic **PHP Object Injection** when an administrator opened a malicious form submission. A minimal exploit payload could look like:
166+
167+
```
168+
O:8:"SomeClass":1:{s:8:"property";s:28:"<?php system($_GET['cmd']); ?>";}
169+
```
170+
171+
As soon as the admin viewed the entry, the object was instantiated and `SomeClass::__destruct()` got executed, resulting in arbitrary code execution.
172+
173+
**Take-aways**
174+
1. Always pass `['allowed_classes' => false]` (or a strict white-list) when calling `unserialize()`.
175+
2. Audit defensive wrappers – they often forget about the legacy PHP branches.
176+
3. Upgrading to **PHP ≥ 7.x** alone is *not* sufficient: the option still needs to be supplied explicitly.
177+
178+
---
179+
122180
### PHPGGC (ysoserial for PHP)
123181

124182
[**PHPGGC**](https://github.com/ambionics/phpggc) can help you generating payloads to abuse PHP deserializations.\
@@ -663,6 +721,8 @@ The tool [JMET](https://github.com/matthiaskaiser/jmet) was created to **connect
663721
664722
### References
665723
724+
- [Patchstack advisory – Everest Forms unauthenticated PHP Object Injection (CVE-2025-52709)](https://patchstack.com/articles/critical-vulnerability-impacting-over-100k-sites-patched-in-everest-forms-plugin/)
725+
666726
- JMET talk: [https://www.youtube.com/watch?v=0h8DWiOWGGA](https://www.youtube.com/watch?v=0h8DWiOWGGA)
667727
- Slides: [https://www.blackhat.com/docs/us-16/materials/us-16-Kaiser-Pwning-Your-Java-Messaging-With-Deserialization-Vulnerabilities.pdf](https://www.blackhat.com/docs/us-16/materials/us-16-Kaiser-Pwning-Your-Java-Messaging-With-Deserialization-Vulnerabilities.pdf)
668728

0 commit comments

Comments
 (0)