Hi there, This is a quick writeup about some fun with apache based on CVE-2011-1938 that was disclosed yesterday. While the first POC was literally just a trivial POC - the second one was written for self-educational purposes (we leared quite a lot which is the most important thing) and we hope it might be useful for some other vulnerabilities of this/similar type. This is an old fashioned stack buffer overflow in the socket module, problem occurs in the socket_connect. It uses memcpy to copy path from addr to s_un without checking addr length in case when AF_UNIX socket is used. POC popping a shell: -- cut -- -- cut -- Testing POC : -- cut -- test@Vdft02:/home/n1x0n# php ./kaka4.php [+] there we go... [+] creating the sled. [+] popping shell, have fun. PHP Warning: socket_connect(): unable to connect [22]: Invalid argument in /home/n1x0n/kaka4.php on line 16 bash-4.1# -- cut -- Now, popping a shell from a .php file that we just uploaded is quite lame and boring isn't (yes you can use remote connect back with RFI etc..) it ? Instead we decided to create a shellcode that will do something less common and more appropriate to this particular type of vulnerability. As we pretty much have a _full_ control over the apache child process and it's memory - we can do whatever we like with it. So one of the things that we considered to be quite nifty was forcing apache child process to serve a page of our choice. Few problems appeared at this point : how apache handles connections, how to cleanly get back to apache from our shellcode, how to keep our handler in memory and respond to requests etc etc... and after few long nights of playing with this we managed to create a shellcode that simply "infects" the apache child process that handled connection to our "magic" php script, and all new requests that will be handled by this child will return a page of our choice. We decided to create a simple apache module, and use apache's built in functionality to generate content(av_rputs), then to use mmap2 to keep our code in memory when our shellcode leaves. Next step is to overwrite _hooks in apache and exit in a neat way by signalling the process with SIGPROF thanks to which the signal handler cleans everything up behind us. So the main idea is to "infect" apache child process with our own code. If we do this several times - we can infect _all_ apache child processes effectively hijacking _all_ requests comming into apache. This is the result (obviously you need to guess/find few addresses due to ASLR like av_rputs & _handle ). Other protections will prevent this from working (like SSP,PIE and such). BEFORE (everything works as expected): -- cut -- test@Vdft02:~# curl localhost
The requested URL /this_does_not_exist was not found on this server.
-- cut -- Then we call our magic file few times, you'll see the SIGPERF signal sent by a shellcode (this is a good sign ;-P ) : -- cut -- test@Vdft02:~# curl http://localhost/cz.php