SlideShare a Scribd company logo
1 of 54
Download to read offline
Chw00t: How to break out
from various chroot solutions
Balázs Bucsay
OSCE, OSCP, GIAC GPEN, OSWP
http://rycon.hu/ - https://www.mrg-effitas.com/
@xoreipeip
Bio / Balazs Bucsay
• Hungarian Hacker
• Strictly technical certificates: OSCE, OSCP, OSWP and GIAC GPEN
• Works for MRG Effitas - research, AV/endpoint security product tests
• Started with ring0 debuggers and disassemblers in 2000 (13 years
old)
• Major project in 2009: GI John a distributed password cracker
• Presentations around the world (Atlanta, Moscow, London, Oslo)
• Webpage: http://rycon.hu
• Twitter: @xoreipeip
• Linkedin: http://www.linkedin.com/in/bucsayb
Chroot’s brief history
• Introduced in Version 7 Unix - 1979
• Inherited from V7 UNIX to BSD - 1982
• Hardened version was implemented in FreeBSD - 2000
• Virtuozzo (OpenVZ) containers - 2000
• Chroot on Steroids: Solaris container - 2005
• LXC: Linux Containers - 2008
What is Chroot?
• A privileged system call on Unix systems
• Changes the dedicated root vnode of a process (all
children inherit this)
• Some OS stores chroots in linked lists
• Prevents access to outside of the new root
• Requires root: prevents crafted chroots for privilege
escalation
What’s this used for?
• Testing environments
• Dependency control
• Compatibility
• Recovery
• Privilege separation??
Requirements for reasonable
chroot
• All directories must be root:root owned
• Superuser process cannot be run in chroot
• Distinct and unique user (uid, gid) has to be used
• No sensitive files (or files at all) can be modified or
created
Requirements for reasonable
chroot
• Close all file descriptors before chrooting
• chdir before chroot
• /proc should not be mounted
• + Use /var/empty for empty environment
Chroot scenarios
Shell access:
• SSH access to a chrooted environment
• Chrooted Apache running with mod_cgi/mod_php/…
• Exploiting a vulnerable chrooted app
Only filesystem access:
• Chrooted SCP/FTP access
Breakage techniques
mostly summarised
• Get root (not all techniques need it)
• Get access to a directory’s file descriptor outside of the
chroot
• Find original root
• Chroot into that
• Escaped
• Only a few OS stores chroots in linked lists, if you can break
out of one, you broke out all of them
Example structure

Original root
/
bin etc home usr
chroot user1 user2
bin etc home usr
user3chroot2 user4 user5
etc home usr
user7
bin
user6
Example structure

New root (chrooted once)
/chroot
bin etc home usr
user3chroot2 user4 user5
etc home usr
user7
bin
user6
Example structure

New root (chrooted twice)
/chroot2
etc home usr
user7
bin
user6
Breakage techniques:
kernel exploit/module


Not going to talk about this
#root:
MIGHT
needed
Breakage techniques:
misconfigurations
• Hard to recognise and exploit
• Wrong permissions on files or directories
• Dynamic loading of shared libraries
• Hardlinked suid/sgid binaries using chrooted shared libraries
• For example:
• /etc/passwd ; /etc/shadow
• /lib/libpam.so.0 - used by /bin/su
• These can be used to run code as root
#root:
NOT
needed
Breakage techniques:
classic
• Oldest and most trivial
• mkdir(d); chroot(d); cd ../../../; chroot(.)
• chroot syscall does not chdir into the directory, stays
outside
#root:
needed
Root and CWD
/
bin etc home usr
/ user1 user2
bin etc home usr
user4user3 user5
Root barrier and CWD
/
bin etc home usr
/ user1 user2
bin etc home usr
user4/ user5
Root barrier and CWD
/
bin etc home usr
/ user1 user2
bin etc home usr
user4/ user5
Breakage techniques:
classic+fd saving
• Based on the classic
• Saving the file descriptor of CWD before chroot
• mkdir(d); n=open(.); chroot(d); fchdir(n); cd ../../../../;
chroot(.)
• Some OS might change the CWD to the chrooted one
#root:
needed
Root, CWD and saved fd
/
bin etc home usr
/ user1 user2
bin etc home usr
user4user3 user5
Root barrier and saved fd
/
bin etc home usr
/ user1 user2
bin etc home usr
user4/ user5
Root barrier and saved fd
/
bin etc home usr
/ user1 user2
bin etc home usr
user4/ user5
Breakage techniques:
Unix Domain Sockets
• UDS are similar to Internet sockets
• File descriptors can be passed thru
• Creating secondary chroot and passing outside fd thru
• Or using outside help (not really realistic)
• Abstract UDS does not require filesystem access
#root:
needed
Root(0) and CWD
/
bin etc home usr
chroot user1 user2
bin etc home usr
user3chroot2 user4 user5
etc home usr
user7
bin
user6
Root barrier(1) parent forks
/
bin etc home usr
/ user1 user2
bin etc home usr
user3chroot2 user4 user5
etc home usr
user7
bin
user6
Root barrier(2) forked child
/
bin etc home usr
chroot user1 user2
bin etc home usr
user3/ user4 user5
etc home usr
user7
bin
user6
Root barrier(1) and FD (UDS)
/
bin etc home usr
/ user1 user2
bin etc home usr
user3chroot2 user4 user5
etc home usr
user7
bin
user6
Child Root barrier(2) and FD (UDS)
/
bin etc home usr
chroot user1 user2
bin etc home usr
user3/ user4 user5
etc home usr
user7
bin
user6
Child Root barrier(2) and FD (UDS)
/
bin etc home usr
chroot user1 user2
bin etc home usr
user3/ user4 user5
etc home usr
user7
bin
user6
Breakage techniques:
mount()
• Mounting root device into a directory
• Chrooting into that directory
• Linux is not restrictive on mounting
#root:
needed
Breakage techniques:
/proc
• Mounting procfs into a directory
• Looking for a pid that has a different root/cwd entry
• for example: /proc/1/root
• chroot into that entry
#root:
needed
Breakage techniques:
move-out-of-chroot
• The reason why I started to work on this
• Creating chroot and a directory in it
• Use the directory for CWD
• Move the directory out of the chroot
#root:
MIGHT
needed
Root(0) and CWD
/
bin etc home usr
chroot user1 user2
bin etc home usr
user3chroot2 user4 user5
etc home usr
user7
bin
user6
Root barrier(1) parent forks
/
bin etc home usr
/ user1 user2
bin etc home usr
user3chroot2 user4 user5
etc home usr
user7
bin
user6
Root barrier(2) forked child
/
bin etc home usr
chroot user1 user2
bin etc home usr
user3/ user4 user5
etc home usr
user7
bin
user6
Root barrier(2) and CWD
/
bin etc home usr
chroot user1 user2
bin etc home usr
user3/ user4 user5
etc home usr
user7
bin
user6
Root barrier(2) and user7 moved out
/
bin etc home usr
chroot user1 user2
bin etc home usr
user3/ user4 user5
etc home usr
user7
bin
user6
Root barrier(2) and user7 moved out
/
bin etc home usr
chroot user1 user2
bin etc home usr
user3/ user4 user5
etc home usr
user7
bin
user6
Breakage techniques:
ptrace()
• System call to observe other processes
• Root can attach to any processes
• User can attach to same uid processes (when
euid=uid)
• Change original code and run shellcode
#root:
NOT
needed
Question
Tell me a service that is usually chrooted
DEMO
Results
Debian 7.8;2.6.32/Kali
3.12
Ubuntu
14.04.1;3.13.0-32-
generic
DragonFlyBSD
4.0.5 x86_64
FreeBSD 10.-
RELEASE amd64
NetBSD 6.1.4
amd64
OpenBSD 5.5 amd64 Solaris 5.11 11.1
i386
Mac OS X
Classic
YES YES DoS NO NO NO YES YES
Classic FD
YES YES NO NO NO NO YES YES
Unix Domain Sockets
YES YES DoS PARTIALLY NO PARTIALLY? YES YES
/proc
YES YES NO NO NO NO YES NO
Mount
YES YES NO NO NO NO NO NO
move out of chroot
YES YES DoS PARTIALLY NO YES YES YES
Ptrace
YES PARTIALLY NO? YES NO YES N/A N/A
Results (FreeBSD jail)
FreeBSD 10. -
RELEASE amd64
FreeBSD 10. Jail -
RELEASE amd64
Classic
NO NO
Classic FD NO NO
Unix Domain Sockets PARTIALLY PARTIALLY
Mount NO NO
/proc NO NO
move-out-of-chroot PARTIALLY PARTIALLY
Ptrace YES NO
Filesystem access only
• Move-out-of-chroot still works on FTP/SCP
• Privilege escalation is possible on misconfigured
environment
• Shell can be popped by replacing or placing shared
libraries/malicious files in chroot
Linux Containers
• Privileged container (no user namespaces) can create
nested containers
• Host container has access to guest container’s
filesystem
• Based on the move-out-of-chroot technique, real
host’s file system is accessible
DEMO 2
Tool
https://www.github.com/earthquake/chw00t/
Future work
• Testing new UNIX operating systems (eg. AIX, HP-UX)
• Looking for other techniques
Future work
Greetz to:
• My girlfriend and family
• Wolphie and Solar Designer for mentoring
• Spender and Kristof Feiszt for reviewing
References
• http://www.bpfh.net/simes/computing/chroot-break.html
• http://www.unixwiz.net/techtips/chroot-practices.html
• http://linux-vserver.org/Secure_chroot_Barrier
• http://phrack.org/issues/59/12.html
• http://lwn.net/Articles/421933/
• https://securityblog.redhat.com/2013/03/27/is-chroot-a-
security-feature/
http://rycon.hu - https://www.mrg-effitas.com/
https://github.com/earthquake
@xoreipeip
Thank you
!
Q&A

More Related Content

What's hot (6)

Death matchtournament del2014
Death matchtournament del2014Death matchtournament del2014
Death matchtournament del2014
 
LTR Handout
LTR HandoutLTR Handout
LTR Handout
 
Linux IO Multiplexing for Samba bug
Linux IO Multiplexing for Samba bugLinux IO Multiplexing for Samba bug
Linux IO Multiplexing for Samba bug
 
Win32/Duqu: involution of Stuxnet
Win32/Duqu: involution of StuxnetWin32/Duqu: involution of Stuxnet
Win32/Duqu: involution of Stuxnet
 
Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...
Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...
Nikita Abdullin - Reverse-engineering of embedded MIPS devices. Case Study - ...
 
Memory Forensic - Investigating Memory Artefact
Memory Forensic - Investigating Memory ArtefactMemory Forensic - Investigating Memory Artefact
Memory Forensic - Investigating Memory Artefact
 

Similar to Chw00t: How to break out from various chroot solutions

Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell Scripting
Mustafa Qasim
 
Leveraging Android's Linux Heritage at AnDevCon V
Leveraging Android's Linux Heritage at AnDevCon VLeveraging Android's Linux Heritage at AnDevCon V
Leveraging Android's Linux Heritage at AnDevCon V
Opersys inc.
 
Leveraging Android's Linux Heritage at AnDevCon VI
Leveraging Android's Linux Heritage at AnDevCon VILeveraging Android's Linux Heritage at AnDevCon VI
Leveraging Android's Linux Heritage at AnDevCon VI
Opersys inc.
 

Similar to Chw00t: How to break out from various chroot solutions (20)

Rootless Containers
Rootless ContainersRootless Containers
Rootless Containers
 
Gentoo Linux, or Why in the World You Should Compile Everything
Gentoo Linux, or Why in the World You Should Compile EverythingGentoo Linux, or Why in the World You Should Compile Everything
Gentoo Linux, or Why in the World You Should Compile Everything
 
Pwning the Enterprise With PowerShell
Pwning the Enterprise With PowerShellPwning the Enterprise With PowerShell
Pwning the Enterprise With PowerShell
 
Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell Scripting
 
Hogy jussunk ki lezárt hálózatokból?
Hogy jussunk ki lezárt hálózatokból?Hogy jussunk ki lezárt hálózatokból?
Hogy jussunk ki lezárt hálózatokból?
 
HOW 2019: A complete reproducible ROOT environment in under 5 minutes
HOW 2019: A complete reproducible ROOT environment in under 5 minutesHOW 2019: A complete reproducible ROOT environment in under 5 minutes
HOW 2019: A complete reproducible ROOT environment in under 5 minutes
 
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
 
File000127
File000127File000127
File000127
 
Android memory analysis Debug slides.pdf
Android memory analysis Debug slides.pdfAndroid memory analysis Debug slides.pdf
Android memory analysis Debug slides.pdf
 
The end of embedded Linux (as we know it)
The end of embedded Linux (as we know it)The end of embedded Linux (as we know it)
The end of embedded Linux (as we know it)
 
Odroid Magazine March 2014
Odroid Magazine March 2014Odroid Magazine March 2014
Odroid Magazine March 2014
 
Does Cowgirl Dream of Red Swirl?
Does Cowgirl Dream of Red Swirl?Does Cowgirl Dream of Red Swirl?
Does Cowgirl Dream of Red Swirl?
 
Intro To Gentoo Embedded Cclug
Intro To Gentoo Embedded CclugIntro To Gentoo Embedded Cclug
Intro To Gentoo Embedded Cclug
 
Leveraging Android's Linux Heritage at AnDevCon V
Leveraging Android's Linux Heritage at AnDevCon VLeveraging Android's Linux Heritage at AnDevCon V
Leveraging Android's Linux Heritage at AnDevCon V
 
Leveraging Android's Linux Heritage at AnDevCon VI
Leveraging Android's Linux Heritage at AnDevCon VILeveraging Android's Linux Heritage at AnDevCon VI
Leveraging Android's Linux Heritage at AnDevCon VI
 
From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...From SaltStack to Puppet and beyond...
From SaltStack to Puppet and beyond...
 
Python on FreeBSD
Python on FreeBSDPython on FreeBSD
Python on FreeBSD
 
Containers - Portable, repeatable user-oriented application delivery. Build, ...
Containers - Portable, repeatable user-oriented application delivery. Build, ...Containers - Portable, repeatable user-oriented application delivery. Build, ...
Containers - Portable, repeatable user-oriented application delivery. Build, ...
 
FreeBSD Portscamp, Kuala Lumpur 2016
FreeBSD Portscamp, Kuala Lumpur 2016FreeBSD Portscamp, Kuala Lumpur 2016
FreeBSD Portscamp, Kuala Lumpur 2016
 
Podman rootless containers
Podman rootless containersPodman rootless containers
Podman rootless containers
 

More from Balazs Bucsay

XFLTReaT: A New Dimension In Tunnelling (DeepSec 2017)
XFLTReaT: A New Dimension In Tunnelling (DeepSec 2017)XFLTReaT: A New Dimension In Tunnelling (DeepSec 2017)
XFLTReaT: A New Dimension In Tunnelling (DeepSec 2017)
Balazs Bucsay
 
Trick or XFLTReaT a.k.a. Tunnel All The Things
Trick or XFLTReaT a.k.a. Tunnel All The ThingsTrick or XFLTReaT a.k.a. Tunnel All The Things
Trick or XFLTReaT a.k.a. Tunnel All The Things
Balazs Bucsay
 
XFLTReaT: a new dimension in tunnelling (BruCON 0x09 2017)
XFLTReaT: a new dimension in tunnelling (BruCON 0x09 2017)XFLTReaT: a new dimension in tunnelling (BruCON 0x09 2017)
XFLTReaT: a new dimension in tunnelling (BruCON 0x09 2017)
Balazs Bucsay
 
XFLTReaT: A New Dimension in Tunnelling (HITB GSEC 2017)
XFLTReaT: A New Dimension in Tunnelling (HITB GSEC 2017)XFLTReaT: A New Dimension in Tunnelling (HITB GSEC 2017)
XFLTReaT: A New Dimension in Tunnelling (HITB GSEC 2017)
Balazs Bucsay
 
XFLTReaT: A New Dimension in Tunneling (Shakacon 2017)
XFLTReaT: A New Dimension in Tunneling (Shakacon 2017)XFLTReaT: A New Dimension in Tunneling (Shakacon 2017)
XFLTReaT: A New Dimension in Tunneling (Shakacon 2017)
Balazs Bucsay
 

More from Balazs Bucsay (7)

Socks Over RDP
Socks Over RDPSocks Over RDP
Socks Over RDP
 
XFLTReaT: A New Dimension In Tunnelling (DeepSec 2017)
XFLTReaT: A New Dimension In Tunnelling (DeepSec 2017)XFLTReaT: A New Dimension In Tunnelling (DeepSec 2017)
XFLTReaT: A New Dimension In Tunnelling (DeepSec 2017)
 
Trick or XFLTReaT a.k.a. Tunnel All The Things
Trick or XFLTReaT a.k.a. Tunnel All The ThingsTrick or XFLTReaT a.k.a. Tunnel All The Things
Trick or XFLTReaT a.k.a. Tunnel All The Things
 
XFLTReaT: a new dimension in tunnelling (BruCON 0x09 2017)
XFLTReaT: a new dimension in tunnelling (BruCON 0x09 2017)XFLTReaT: a new dimension in tunnelling (BruCON 0x09 2017)
XFLTReaT: a new dimension in tunnelling (BruCON 0x09 2017)
 
XFLTReaT: A New Dimension in Tunnelling (HITB GSEC 2017)
XFLTReaT: A New Dimension in Tunnelling (HITB GSEC 2017)XFLTReaT: A New Dimension in Tunnelling (HITB GSEC 2017)
XFLTReaT: A New Dimension in Tunnelling (HITB GSEC 2017)
 
XFLTReaT: A New Dimension in Tunneling (Shakacon 2017)
XFLTReaT: A New Dimension in Tunneling (Shakacon 2017)XFLTReaT: A New Dimension in Tunneling (Shakacon 2017)
XFLTReaT: A New Dimension in Tunneling (Shakacon 2017)
 
0day hunting a.k.a. The story of a proper CPE test
0day hunting a.k.a. The story of a proper CPE test0day hunting a.k.a. The story of a proper CPE test
0day hunting a.k.a. The story of a proper CPE test
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

Chw00t: How to break out from various chroot solutions

  • 1. Chw00t: How to break out from various chroot solutions Balázs Bucsay OSCE, OSCP, GIAC GPEN, OSWP http://rycon.hu/ - https://www.mrg-effitas.com/ @xoreipeip
  • 2. Bio / Balazs Bucsay • Hungarian Hacker • Strictly technical certificates: OSCE, OSCP, OSWP and GIAC GPEN • Works for MRG Effitas - research, AV/endpoint security product tests • Started with ring0 debuggers and disassemblers in 2000 (13 years old) • Major project in 2009: GI John a distributed password cracker • Presentations around the world (Atlanta, Moscow, London, Oslo) • Webpage: http://rycon.hu • Twitter: @xoreipeip • Linkedin: http://www.linkedin.com/in/bucsayb
  • 3. Chroot’s brief history • Introduced in Version 7 Unix - 1979 • Inherited from V7 UNIX to BSD - 1982 • Hardened version was implemented in FreeBSD - 2000 • Virtuozzo (OpenVZ) containers - 2000 • Chroot on Steroids: Solaris container - 2005 • LXC: Linux Containers - 2008
  • 4. What is Chroot? • A privileged system call on Unix systems • Changes the dedicated root vnode of a process (all children inherit this) • Some OS stores chroots in linked lists • Prevents access to outside of the new root • Requires root: prevents crafted chroots for privilege escalation
  • 5. What’s this used for? • Testing environments • Dependency control • Compatibility • Recovery • Privilege separation??
  • 6.
  • 7.
  • 8. Requirements for reasonable chroot • All directories must be root:root owned • Superuser process cannot be run in chroot • Distinct and unique user (uid, gid) has to be used • No sensitive files (or files at all) can be modified or created
  • 9. Requirements for reasonable chroot • Close all file descriptors before chrooting • chdir before chroot • /proc should not be mounted • + Use /var/empty for empty environment
  • 10. Chroot scenarios Shell access: • SSH access to a chrooted environment • Chrooted Apache running with mod_cgi/mod_php/… • Exploiting a vulnerable chrooted app Only filesystem access: • Chrooted SCP/FTP access
  • 11. Breakage techniques mostly summarised • Get root (not all techniques need it) • Get access to a directory’s file descriptor outside of the chroot • Find original root • Chroot into that • Escaped • Only a few OS stores chroots in linked lists, if you can break out of one, you broke out all of them
  • 12. Example structure
 Original root / bin etc home usr chroot user1 user2 bin etc home usr user3chroot2 user4 user5 etc home usr user7 bin user6
  • 13. Example structure
 New root (chrooted once) /chroot bin etc home usr user3chroot2 user4 user5 etc home usr user7 bin user6
  • 14. Example structure
 New root (chrooted twice) /chroot2 etc home usr user7 bin user6
  • 15. Breakage techniques: kernel exploit/module 
 Not going to talk about this #root: MIGHT needed
  • 16. Breakage techniques: misconfigurations • Hard to recognise and exploit • Wrong permissions on files or directories • Dynamic loading of shared libraries • Hardlinked suid/sgid binaries using chrooted shared libraries • For example: • /etc/passwd ; /etc/shadow • /lib/libpam.so.0 - used by /bin/su • These can be used to run code as root #root: NOT needed
  • 17. Breakage techniques: classic • Oldest and most trivial • mkdir(d); chroot(d); cd ../../../; chroot(.) • chroot syscall does not chdir into the directory, stays outside #root: needed
  • 18. Root and CWD / bin etc home usr / user1 user2 bin etc home usr user4user3 user5
  • 19. Root barrier and CWD / bin etc home usr / user1 user2 bin etc home usr user4/ user5
  • 20. Root barrier and CWD / bin etc home usr / user1 user2 bin etc home usr user4/ user5
  • 21. Breakage techniques: classic+fd saving • Based on the classic • Saving the file descriptor of CWD before chroot • mkdir(d); n=open(.); chroot(d); fchdir(n); cd ../../../../; chroot(.) • Some OS might change the CWD to the chrooted one #root: needed
  • 22. Root, CWD and saved fd / bin etc home usr / user1 user2 bin etc home usr user4user3 user5
  • 23. Root barrier and saved fd / bin etc home usr / user1 user2 bin etc home usr user4/ user5
  • 24. Root barrier and saved fd / bin etc home usr / user1 user2 bin etc home usr user4/ user5
  • 25. Breakage techniques: Unix Domain Sockets • UDS are similar to Internet sockets • File descriptors can be passed thru • Creating secondary chroot and passing outside fd thru • Or using outside help (not really realistic) • Abstract UDS does not require filesystem access #root: needed
  • 26. Root(0) and CWD / bin etc home usr chroot user1 user2 bin etc home usr user3chroot2 user4 user5 etc home usr user7 bin user6
  • 27. Root barrier(1) parent forks / bin etc home usr / user1 user2 bin etc home usr user3chroot2 user4 user5 etc home usr user7 bin user6
  • 28. Root barrier(2) forked child / bin etc home usr chroot user1 user2 bin etc home usr user3/ user4 user5 etc home usr user7 bin user6
  • 29. Root barrier(1) and FD (UDS) / bin etc home usr / user1 user2 bin etc home usr user3chroot2 user4 user5 etc home usr user7 bin user6
  • 30. Child Root barrier(2) and FD (UDS) / bin etc home usr chroot user1 user2 bin etc home usr user3/ user4 user5 etc home usr user7 bin user6
  • 31. Child Root barrier(2) and FD (UDS) / bin etc home usr chroot user1 user2 bin etc home usr user3/ user4 user5 etc home usr user7 bin user6
  • 32. Breakage techniques: mount() • Mounting root device into a directory • Chrooting into that directory • Linux is not restrictive on mounting #root: needed
  • 33. Breakage techniques: /proc • Mounting procfs into a directory • Looking for a pid that has a different root/cwd entry • for example: /proc/1/root • chroot into that entry #root: needed
  • 34. Breakage techniques: move-out-of-chroot • The reason why I started to work on this • Creating chroot and a directory in it • Use the directory for CWD • Move the directory out of the chroot #root: MIGHT needed
  • 35. Root(0) and CWD / bin etc home usr chroot user1 user2 bin etc home usr user3chroot2 user4 user5 etc home usr user7 bin user6
  • 36. Root barrier(1) parent forks / bin etc home usr / user1 user2 bin etc home usr user3chroot2 user4 user5 etc home usr user7 bin user6
  • 37. Root barrier(2) forked child / bin etc home usr chroot user1 user2 bin etc home usr user3/ user4 user5 etc home usr user7 bin user6
  • 38. Root barrier(2) and CWD / bin etc home usr chroot user1 user2 bin etc home usr user3/ user4 user5 etc home usr user7 bin user6
  • 39. Root barrier(2) and user7 moved out / bin etc home usr chroot user1 user2 bin etc home usr user3/ user4 user5 etc home usr user7 bin user6
  • 40. Root barrier(2) and user7 moved out / bin etc home usr chroot user1 user2 bin etc home usr user3/ user4 user5 etc home usr user7 bin user6
  • 41. Breakage techniques: ptrace() • System call to observe other processes • Root can attach to any processes • User can attach to same uid processes (when euid=uid) • Change original code and run shellcode #root: NOT needed
  • 42. Question Tell me a service that is usually chrooted
  • 43. DEMO
  • 44. Results Debian 7.8;2.6.32/Kali 3.12 Ubuntu 14.04.1;3.13.0-32- generic DragonFlyBSD 4.0.5 x86_64 FreeBSD 10.- RELEASE amd64 NetBSD 6.1.4 amd64 OpenBSD 5.5 amd64 Solaris 5.11 11.1 i386 Mac OS X Classic YES YES DoS NO NO NO YES YES Classic FD YES YES NO NO NO NO YES YES Unix Domain Sockets YES YES DoS PARTIALLY NO PARTIALLY? YES YES /proc YES YES NO NO NO NO YES NO Mount YES YES NO NO NO NO NO NO move out of chroot YES YES DoS PARTIALLY NO YES YES YES Ptrace YES PARTIALLY NO? YES NO YES N/A N/A
  • 45. Results (FreeBSD jail) FreeBSD 10. - RELEASE amd64 FreeBSD 10. Jail - RELEASE amd64 Classic NO NO Classic FD NO NO Unix Domain Sockets PARTIALLY PARTIALLY Mount NO NO /proc NO NO move-out-of-chroot PARTIALLY PARTIALLY Ptrace YES NO
  • 46. Filesystem access only • Move-out-of-chroot still works on FTP/SCP • Privilege escalation is possible on misconfigured environment • Shell can be popped by replacing or placing shared libraries/malicious files in chroot
  • 47. Linux Containers • Privileged container (no user namespaces) can create nested containers • Host container has access to guest container’s filesystem • Based on the move-out-of-chroot technique, real host’s file system is accessible
  • 50. Future work • Testing new UNIX operating systems (eg. AIX, HP-UX) • Looking for other techniques
  • 52. Greetz to: • My girlfriend and family • Wolphie and Solar Designer for mentoring • Spender and Kristof Feiszt for reviewing
  • 53. References • http://www.bpfh.net/simes/computing/chroot-break.html • http://www.unixwiz.net/techtips/chroot-practices.html • http://linux-vserver.org/Secure_chroot_Barrier • http://phrack.org/issues/59/12.html • http://lwn.net/Articles/421933/ • https://securityblog.redhat.com/2013/03/27/is-chroot-a- security-feature/