Penetration Testing mailing list archives

Re: how an hacker can bypass a chrooted environement ?


From: Marco Ivaldi <raptor () 0xdeadbeef info>
Date: Tue, 16 May 2006 17:36:17 +0200 (CEST)

Hey pen-test,

On Fri, 12 May 2006, Rob wrote:

from man 2 chroot():
                                                                              
-- Note that this call does not change the current working directory, so
that '.' can be outside the tree rooted at '/'.  In particular, the
super-user can escape from a 'chroot jail' by doing 'mkdir foo; chroot
foo; cd ..'.  --
                                                                              
Also, mknod() some device files like /dev/kmem or /dev/hda1, then use
root priviledges to muck with kernel, or raw write data to disk.

Beside the already described techniques, here follows a quick summary of
some other rather old tricks to break out of the chroot jail:

1) Load a kernel module;) Capability needed: CAP_SYS_MODULE.

2) Speaking about the already mentioned mknod() technique (capability
   needed: CAP_MKNOD), you could also use it to abuse ttys and virtual 
   file systems through the mount() syscall (capability needed: 
   CAP_SYS_ADMIN): procfs, devfs, devpts.

3) Inject code through ptrace() into a process outside the chroot jail,
   provided you meet the required conditions to do so. This could work for 
   instance when the uid nobody is shared between several processes 
   (semi-common misconfiguration). Depending on the situation, this could
   also be accomplished even with uid != 0. For further details, see also: 

   http://www.phrack.org/phrack/59/p59-0x0c.txt

4) Other uid != 0 tricks: (UNIX) sockets, shared memory segments and other
   IPCs, exploiting local kernel vulnerabilities;), some other application
   specific points.

5) Abuse sysctl() to set the modprobe binary path? Direct access to I/O 
   ports? Sniff network traffic? Impersonate a local administration 
   service (sshd)? Change netfilter rules? And so on... (you need 
   different capabilities for those).

I'm sure i left some possibilities out (use your fantasy), but i guess
this pretty much shows how you shouldn't blindly rely only on chroot to
secure your servers. YMMV.

Cheers,

-- 
Marco Ivaldi
Antifork Research, Inc.   http://0xdeadbeef.info/
3B05 C9C5 A2DE C3D7 4233  0394 EF85 2008 DBFD B707


------------------------------------------------------------------------------
This List Sponsored by: Cenzic

Concerned about Web Application Security? 
Why not go with the #1 solution - Cenzic, the only one to win the Analyst's 
Choice Award from eWeek. As attacks through web applications continue to rise, 
you need to proactively protect your applications from hackers. Cenzic has the 
most comprehensive solutions to meet your application security penetration 
testing and vulnerability management needs. You have an option to go with a 
managed service (Cenzic ClickToSecure) or an enterprise software 
(Cenzic Hailstorm). Download FREE whitepaper on how a managed service can 
help you: http://www.cenzic.com/news_events/wpappsec.php 
And, now for a limited time we can do a FREE audit for you to confirm your 
results from other product. Contact us at request () cenzic com for details.
------------------------------------------------------------------------------


Current thread: