SoapClient's __call() type confusion through unserialize()
The SoapClient's __call() method assumes that the __default_headers property is an array, but it can be set to an integer via unserialize(), leading to a type confusion. An attacker could exploit this to cause a crash, arbitrary memory read/write, or potentially remote code execution.
Originally disclosed on HackerOne
- Fixed in 12 days
- Paid in 46 days
- Disclosed after 12 days
https://bugs.php.net/bug.php?id=69085
Description:
SoapClient's __call() method is prone to a type confusion vulnerability which can be used to gain remote code execution through unsafe unserialize() calls.
In soap.c:2906
if (zend_hash_find(Z_OBJPROP_P(this_ptr), "__default_headers", sizeof("__default_headers"), (void **) &tmp)==SUCCESS) { HashTable *default_headers = Z_ARRVAL_P(*tmp);
the Z_ARRVAL_P macro is called on __default_headers assuming that it is an array without any actual check about it.
It has been shown several times that this kind of vulnerability could lead to crash, arbitrary read/write memory access and code execution, so I'm not discussing about the actual exploitation of this one (you can refer to my previous submissions about natsort() and extract() if needed by the way). However, it's worth pointing out that given the nature of __call() magic method, any direct call on a user-controlled userialized input should be considered remotely exploitable.
Test script:
<?php //tested on 64bit Ubuntu PHP 5.6.6 //crash on memory access violation @1337 $dummy = unserialize('O:10:"SoapClient":3:{s:3:"uri";s:1:"a";s:8:"location";s:22:"http://localhost/a.xml";s:17:"__default_headers";i:1337;}'); var_dump($dummy->whatever()); ?>Actual result:
(gdb) r soapvar.php Starting program: /usr/bin/php soapvar.php [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". [New Thread 0x7fffec568700 (LWP 13984)] [Thread 0x7fffec568700 (LWP 13984) exited]
Program received signal SIGSEGV, Segmentation fault. zend_hash_internal_pointer_reset_ex (ht=ht@entry=0x539, pos=pos@entry=0x0) at /build/buildd/php5-5.6.3+dfsg/Zend/zend_hash.c:1020 1020 *pos = ht->pListHead; (gdb) x/i $pc => 0x6e93d3 <zend_hash_internal_pointer_reset_ex+3>: mov 0x20(%rdi),%rax (gdb) p $rdi $1 = 1337
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The code uses the Z_ARRVAL_P macro on the __default_headers property without verifying it is actually an array.
Impact
An attacker could cause a crash, arbitrary memory read/write, or potentially remote code execution, and any direct call on user-controlled unserialized input should be considered remotely exploitable.
What the attacker needed
Unserialize() on attacker-controlled input; SoapClient class available
How it was found
- Create a serialized SoapClient object with __default_headers set to an integer.
- Unserialize the string to create the object.
- Call an undefined method on the object to trigger __call().
- Observe a segmentation fault due to invalid memory access.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When PHP unserializes data, it can create objects with properties set to unexpected types. The SoapClient class has a magic method __call that runs when an undefined method is called. It assumes a property called __default_headers is an array, but if an attacker sets it to an integer, the code treats that integer as a memory address, causing a crash or worse.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.