SlideShare a Scribd company logo
Chw00t: Breaking unices’
chroot solutions
Balázs Bucsay - Бaлaж Бучaи
OSCE, OSCP, GIAC GPEN, OSWP
http://rycon.hu/
@xoreipeip
Bio / Balazs Bucsay
• Hungarian Hacker
• Strictly technical certificates: OSCE, OSCP, OSWP and GIAC GPEN
• Currently working for a large telecommunication company
• Started with ring0 debuggers and disassemblers in 2000 (13 years
old)
• Major project in 2009: GI John a distributed password cracker
• Webpage: http://rycon.hu
• Twitter: @xoreipeip
• Linkedin: http://www.linkedin.com/in/bucsayb
Chroot’s brief history
• Introduced in Version 7 Unix - 1979
• Implemented in 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??
Chw00t: Breaking unices’ chroot solutions
Chw00t: Breaking unices’ chroot solutions
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
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
Example structure
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 changing the CWD to the chrooted
one
#root:
needed
Example structure
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
Example structure
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
Example structure
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
DEMO
Results
Debian 7.8;2.6.32/
Kali 3.12
Ubuntu
14.04.1;3.13.0
-32-generic
DragonFlyBS
D 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
Mount YES YES NO NO NO NO NO NO
/proc YES YES NO NO NO NO YES 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 Jail 10.-
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
If you want me to release this tool
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
Future work
• Testing new UNIX operating systems (eg. AIX, HP-UX)
• Looking for other techniques
• Improving code and Ptrace technique
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://www.lorien.ch/images/chroot.gif
http://rycon.hu
https://github.com/earthquake
@xoreipeip
Thank you
!
Q&A

More Related Content

PDF
Chw00t: How to break out from various chroot solutions
PDF
Docker on Windows
ZIP
Embedded Linux Odp
PDF
Rootkit 102 - Kernel-Based Rootkit
PDF
Aide 2014 - Fundamentals of Linux Privilege Escalation
PDF
Does Cowgirl Dream of Red Swirl?
PDF
Next Generation Memory Forensics
PDF
Linux advanced privilege escalation
Chw00t: How to break out from various chroot solutions
Docker on Windows
Embedded Linux Odp
Rootkit 102 - Kernel-Based Rootkit
Aide 2014 - Fundamentals of Linux Privilege Escalation
Does Cowgirl Dream of Red Swirl?
Next Generation Memory Forensics
Linux advanced privilege escalation

What's hot (20)

PDF
Kernel Recipes 2013 - Easy rootfs using Buildroot
PDF
Openwrt startup
PPTX
Disk forensics for the lazy and the smart
PDF
Is rust language really safe?
PPT
linux minimal os tutorial - by shatrix
PPTX
Fundamentals of Linux Privilege Escalation
PDF
Kernel Recipes 2013 - Conditional boot
PPTX
Easy Installation and Setup of PostgreSQL on Linux, OSX, & Windows
PDF
Ha opensuse
PDF
NSC #2 - Challenge Solution
PDF
Exploiting Llinux Environment
PPTX
BSidesKnoxville 2019 - Unix: The Other White Meat
PDF
Kernel Recipes 2013 - Crosstool-NG, a cross-toolchain generator
PDF
Build your own embedded linux distributions by yocto project
PDF
NetBSD workshop
PDF
NetBSDworkshop
PDF
Linux kernel booting
PDF
Radare2 - An Introduction by Anto Joseph
PDF
Dockerの準備
PPTX
Arch linux
Kernel Recipes 2013 - Easy rootfs using Buildroot
Openwrt startup
Disk forensics for the lazy and the smart
Is rust language really safe?
linux minimal os tutorial - by shatrix
Fundamentals of Linux Privilege Escalation
Kernel Recipes 2013 - Conditional boot
Easy Installation and Setup of PostgreSQL on Linux, OSX, & Windows
Ha opensuse
NSC #2 - Challenge Solution
Exploiting Llinux Environment
BSidesKnoxville 2019 - Unix: The Other White Meat
Kernel Recipes 2013 - Crosstool-NG, a cross-toolchain generator
Build your own embedded linux distributions by yocto project
NetBSD workshop
NetBSDworkshop
Linux kernel booting
Radare2 - An Introduction by Anto Joseph
Dockerの準備
Arch linux
Ad

Viewers also liked (20)

PDF
Containers Through the Ages - SysEleven
PDF
Docker 101 @KACST Saudi HPC 2016
PPTX
Understanding container security
PDF
Containers technologies
PPTX
Lessons learned in reaching multi-host container networking
PDF
Criação de ambientes em chroot
PDF
Namespace
PDF
Introduction to docker
ODP
chroot and SELinux
PDF
Container orchestration
ODP
LSA2 - 02 chrooting
PDF
Understand how docker works
PDF
LXD: The hypervisor that isn't
PPTX
Hypervisor "versus" Linux Containers with Docker !
ODP
LSA2 - 01 Virtualization with KVM
PDF
Evoluation of Linux Container Virtualization
PDF
Evolution of Linux Containerization
PDF
Lxd the proper way of runing containers
PDF
LXD Container Hypervisor
Containers Through the Ages - SysEleven
Docker 101 @KACST Saudi HPC 2016
Understanding container security
Containers technologies
Lessons learned in reaching multi-host container networking
Criação de ambientes em chroot
Namespace
Introduction to docker
chroot and SELinux
Container orchestration
LSA2 - 02 chrooting
Understand how docker works
LXD: The hypervisor that isn't
Hypervisor "versus" Linux Containers with Docker !
LSA2 - 01 Virtualization with KVM
Evoluation of Linux Container Virtualization
Evolution of Linux Containerization
Lxd the proper way of runing containers
LXD Container Hypervisor
Ad

Similar to Chw00t: Breaking unices’ chroot solutions (20)

DOCX
Chroot Protection and Breaking
PPT
Unix Security
PDF
Linux Fundamentals and how to use linux.pdf
PPTX
Linux 开源操作系统发展新趋势
PPT
Tutorial 2
PPT
Introduction to UNIX
PDF
Check Your Privilege (Escalation)
PPT
Linux Vulnerabilities
PPT
Linux Operating System Vulnerabilities
PDF
Unixtoolbox
PDF
unixtoolbox.pdf
PDF
Unixtoolbox
PDF
Develop
PDF
unixtoolbox.pdf
PDF
unixtoolbox.pdf
PDF
PDF
unixtoolbox.pdf
PDF
PDF
unixtoolbox.pdf
PDF
Chroot Protection and Breaking
Unix Security
Linux Fundamentals and how to use linux.pdf
Linux 开源操作系统发展新趋势
Tutorial 2
Introduction to UNIX
Check Your Privilege (Escalation)
Linux Vulnerabilities
Linux Operating System Vulnerabilities
Unixtoolbox
unixtoolbox.pdf
Unixtoolbox
Develop
unixtoolbox.pdf
unixtoolbox.pdf
unixtoolbox.pdf
unixtoolbox.pdf

More from Positive Hack Days (20)

PPTX
Инструмент ChangelogBuilder для автоматической подготовки Release Notes
PPTX
Как мы собираем проекты в выделенном окружении в Windows Docker
PPTX
Типовая сборка и деплой продуктов в Positive Technologies
PPTX
Аналитика в проектах: TFS + Qlik
PPTX
Использование анализатора кода SonarQube
PPTX
Развитие сообщества Open DevOps Community
PPTX
Методика определения неиспользуемых ресурсов виртуальных машин и автоматизаци...
PPTX
Автоматизация построения правил для Approof
PDF
Мастер-класс «Трущобы Application Security»
PDF
Формальные методы защиты приложений
PDF
Эвристические методы защиты приложений
PDF
Теоретические основы Application Security
PPTX
От экспериментального программирования к промышленному: путь длиной в 10 лет
PDF
Уязвимое Android-приложение: N проверенных способов наступить на грабли
PPTX
Требования по безопасности в архитектуре ПО
PDF
Формальная верификация кода на языке Си
PPTX
Механизмы предотвращения атак в ASP.NET Core
PDF
SOC для КИИ: израильский опыт
PDF
Honeywell Industrial Cyber Security Lab & Services Center
PDF
Credential stuffing и брутфорс-атаки
Инструмент ChangelogBuilder для автоматической подготовки Release Notes
Как мы собираем проекты в выделенном окружении в Windows Docker
Типовая сборка и деплой продуктов в Positive Technologies
Аналитика в проектах: TFS + Qlik
Использование анализатора кода SonarQube
Развитие сообщества Open DevOps Community
Методика определения неиспользуемых ресурсов виртуальных машин и автоматизаци...
Автоматизация построения правил для Approof
Мастер-класс «Трущобы Application Security»
Формальные методы защиты приложений
Эвристические методы защиты приложений
Теоретические основы Application Security
От экспериментального программирования к промышленному: путь длиной в 10 лет
Уязвимое Android-приложение: N проверенных способов наступить на грабли
Требования по безопасности в архитектуре ПО
Формальная верификация кода на языке Си
Механизмы предотвращения атак в ASP.NET Core
SOC для КИИ: израильский опыт
Honeywell Industrial Cyber Security Lab & Services Center
Credential stuffing и брутфорс-атаки

Recently uploaded (20)

PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Mushroom cultivation and it's methods.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
A Presentation on Touch Screen Technology
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Getting Started with Data Integration: FME Form 101
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
project resource management chapter-09.pdf
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Enhancing emotion recognition model for a student engagement use case through...
Zenith AI: Advanced Artificial Intelligence
TLE Review Electricity (Electricity).pptx
Mushroom cultivation and it's methods.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Chapter 5: Probability Theory and Statistics
A Presentation on Touch Screen Technology
SOPHOS-XG Firewall Administrator PPT.pptx
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
A novel scalable deep ensemble learning framework for big data classification...
Getting Started with Data Integration: FME Form 101
Digital-Transformation-Roadmap-for-Companies.pptx
A Presentation on Artificial Intelligence
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
project resource management chapter-09.pdf
Heart disease approach using modified random forest and particle swarm optimi...
OMC Textile Division Presentation 2021.pptx
A comparative analysis of optical character recognition models for extracting...
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf

Chw00t: Breaking unices’ chroot solutions

  • 1. Chw00t: Breaking unices’ chroot solutions Balázs Bucsay - Бaлaж Бучaи OSCE, OSCP, GIAC GPEN, OSWP http://rycon.hu/ @xoreipeip
  • 2. Bio / Balazs Bucsay • Hungarian Hacker • Strictly technical certificates: OSCE, OSCP, OSWP and GIAC GPEN • Currently working for a large telecommunication company • Started with ring0 debuggers and disassemblers in 2000 (13 years old) • Major project in 2009: GI John a distributed password cracker • Webpage: http://rycon.hu • Twitter: @xoreipeip • Linkedin: http://www.linkedin.com/in/bucsayb
  • 3. Chroot’s brief history • Introduced in Version 7 Unix - 1979 • Implemented in 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??
  • 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
  • 13. Breakage techniques: kernel exploit/module 
 Not going to talk about this #root: MIGHT needed
  • 14. 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
  • 15. 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
  • 17. 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 changing the CWD to the chrooted one #root: needed
  • 19. 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
  • 21. Breakage techniques: mount() • Mounting root device into a directory • Chrooting into that directory • Linux is not restrictive on mounting #root: needed
  • 22. 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
  • 23. 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
  • 25. 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
  • 26. DEMO
  • 27. Results Debian 7.8;2.6.32/ Kali 3.12 Ubuntu 14.04.1;3.13.0 -32-generic DragonFlyBS D 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 Mount YES YES NO NO NO NO NO NO /proc YES YES NO NO NO NO YES NO move-out-of-chroot YES YES DoS PARTIALLY NO YES YES YES Ptrace YES PARTIALLY NO? YES NO YES N/A N/A
  • 28. Results (FreeBSD jail) FreeBSD 10.- RELEASE amd64 FreeBSD Jail 10.- 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
  • 29. If you want me to release this tool
  • 30. 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
  • 31. 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
  • 33. Future work • Testing new UNIX operating systems (eg. AIX, HP-UX) • Looking for other techniques • Improving code and Ptrace technique
  • 35. Greetz to: • My girlfriend and family • Wolphie and Solar Designer for mentoring • Spender and Kristof Feiszt for reviewing
  • 36. 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://www.lorien.ch/images/chroot.gif