Re: how an hacker can bypass a chrooted environement ?



Hello,

I was wondering how an attacker can bypass a chrooted environement. A
(common) technique consist in finding a vulnerable program (in the
chrooted environnement) and injecting it a shellcode (i.e
../../../../../../../bin/bash for ex.) by BoF. But normally, in the
chrooted environement, you volontarily add only necessary tools (like
ls, cat, less...), and vulnerable softwares are uncommon...

Well, without a vulnerable program, there is nothing to attack and thus no chroot environment to bypass :-) However, I'd guess you're considering the following scenario:

There is a vulnerable application running in chrooted environment, the directory it is chrooted in doesn't actually need to contain any files. The attacker manages to exploit a vulnerability in the program, i.e. (s)he is able to make it run whatever code (s)he wants. The real objective is, however, to be able to access to the files on the system. This is called "breaking out of the chroot".

One of the well-known techniques is the ../../../.., which is based on one (bad) property of chroot -- the chroot(2) system call does not change the current working directory.

Consider the following sequence of steps achieves:

1) mkdir("goo")
2) chroot("goo")
3) chdir("../../../../../..")
4) chroot(".")

Steps 1 and 2 create a directory called "goo" and set the root directory of current process to that dir. However, the current WORKING directory is not changed -- it is OUTSIDE the root directory of the process. Step 3 then moves upwards in the hierarchy (the original chrooted directory tree might have been several directories deep in the tree), trying to reach the "true" root directory. The last step sets the new root to the current working directory (= true root), thus accomplishing the "break-out-of-chroot" mission.

That's why some security patches enforce chdir("/") immediately after chroot() call. Note that this is not the only method of breaking out of the chroot jail, it's just one of the more widely used ones.

Peter

--
[Name] Peter Kosinar [Quote] 2B | ~2B = exp(i*PI) [ICQ] 134813278



------------------------------------------------------------------------------
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@xxxxxxxxxx for details.
------------------------------------------------------------------------------



Relevant Pages

  • Re: Q: Impact of globbing vulnerability in ftpd
    ... so ftpd is already chrooted and running with the uid of the user at ... sufficient to allow the vulnerability to be exploited. ... compounded because the FTP server only runs with an effective UID of the ... there are processes outside of the chroot() running as the same user. ...
    (FreeBSD-Security)
  • Re: how an hacker can bypass a chrooted environement ?
    ... then ../../ up until root and then calling chroot again. ... > I was wondering how an attacker can bypass a chrooted environement. ... testing and vulnerability management needs. ... Download FREE whitepaper on how a managed service can ...
    (Pen-Test)
  • Re: Chroot bug
    ... dot-dot cannot be used to access files ... outside the subtree rooted at the root directory. ... Which is behaviour chroot preserves properly. ...
    (Linux-Kernel)
  • Re: [HELP] Cant boot after kernel upgrade through YOU
    ... chroot - run command or interactive shell with special root directory ... chroot NEWROOT ... Run COMMAND with root directory set to NEWROOT. ... Once you have done this you can run mkinitrd to redo the initrd on the ...
    (alt.os.linux.suse)
  • Re: Chroot bug
    ... Although this is documented in the man page, it conflicts with the ... which is to change the root directory of the process. ... it seems clear that the prime purpose of chroot is to aid security. ... It won't conform to SVR4/4.4BSD anymore, but hey, let Linux set some ...
    (Linux-Kernel)