SlideShare a Scribd company logo
Check Your Privilege
(Escalation)
KATE BROUSSARD, SENIOR SECURITY ANALYST AT BISHOP FOX
March 1, 2019
BSidesCMH 2019
22
Kate Broussard
Senior Security Analyst
kbroussard@bishopfox.com
@grazhacks on Twitter
ROADMAP FOR THE NEXT HOUR
Introduction
Outline
• Priv esc definition + framing
• Easy mode
• Sneaky mode
• Boss mode
• Summary
• Resources
PRIVILEGE ESCALATION
AND SO WE BEGIN
4
Definition
• Using privileges of various agents to
gain access to resources
When does it come into play?
Framing
• Who’s doing the execution?
• What are their privileges?
Two ways to escalate:
1. You’re the agent – your current user
permissions are sufficient to execute
the command & do the thing
2. Something else is the agent – you get
something else to execute the
command under THEIR permissions,
which are sufficient to do the thing
DEFINITION AND FRAMING
Privilege Escalation
EASY MODE
SO YOU’RE IN THE SERVER – NOW WHAT?
6
• Who are you?
whoami
id
• Where are you?
pwd
• Are you really really lucky?
cat /etc/shadow vs. cat /etc/passwd
cd /root
CHECK YOUR PRIVILEGE
Before anything else
7
• Where do you have read access?
/home/
/usr/share/
ENV
• Where do you have write access?
/home/USER/.ssh
/root/
/etc/crontab
CHECK YOUR PRIVILEGE
Permissions
8
sudo = super user do [something]
sudo –l
• What commands can you execute?
• Do you need a password?
https://xkcd.com/838/ - Incident
MAKE ME A SANDWICH
sudo
9
sudo = super user do [something]
sudo –l
• What commands can you execute?
• Do you need a password?
MAKE ME A SANDWICH
sudo
cat /etc/sudoers
• if readable, tells you which
users/groups to target
cat /etc/group
• lists users, IDs, group affiliations
10
sudo –l
• User has sudo permissions for python
• Without needing the password – excellent!
• Therefore can run python under root
permissions
sudo python –c ‘import
pty;pty.spawn(“/bin/bash”);’
• New shell spawned by python also
runs under root permissions
SUDO MAKE ME A SANDWICH
sudo Exploit - Python
11
Password reuse is RAMPANT
• web application passwords
• common/default passwords
nmap port scan or ps auf to see what’s up
• known compromised passwords for
specific users
https://xkcd.com/792/ - Password Reuse
WE ARE CREATURES OF HABIT
Credential Reuse
12
• Any passwords entered into history?
• Any interesting files or directories?
cat .bash_history vs history
• .bash_history won’t dump current
session data until session ends
• history is a live dump of session
LEAKED INFORMATION
.bash_history
13
• Are any credentials stored in logs?
• Any other useful information?
Log files/dirs that are writeable can be
replaced by symlink.
When owning process tries to write to log,
will write to symlink instead.
Can be a way to output data somewhere
that you can read it.
LEAKED INFORMATION
/var/log
14
1. Who/where are you
2. What can you see/modify with
current permissions?
3. Look for:
1. sudo permissions
2. Credential Reuse
3. Leaked info from:
1. cat .bash_history
2. /var/log files
Two ways to escalate:
1. You’re the agent – your current user
permissions are sufficient to execute
the command & do the thing
2. Something else is the agent – you get
something else to execute the
command under THEIR permissions,
which are sufficient to do the thing
RECAP
Easy Mode
SNEAKY MODE
FIND AND EXPLOIT SOME MISCONFIGURATIONS
16
• What is the SUID/SGID bit?
• How to find a SUID/SGID binary?
• What runs as the root user?
find / -perm -u=s [-type f] 2>/dev/null
find / -perm -4000 [-type f] 2>/dev/null
• What runs in the root group?
find / -perm -g=s [-type f] 2>/dev/null
find / -perm -2000 [-type f] 2>/dev/null
CHECK THEIR PRIVILEGE
SUID/SGID bits
17
• What are “normal” SUID programs vs
ones that are exploitable?
Standard Linux utility?
Try shell escape or
command option argument
Custom script to make an admin’s life easy?
Try PATH = .
especially if the script makes a call to an alias
Also watch for wildcards
CHECK THEIR PRIVILEGE
SUID/SGID bits
18
Binary Shell escape
less !cmd
more !cmd
:!cmd
vi :! cmd
mysql system cmd
! cmd
AND MANY MORE
INTENTIONAL OPTION TO EXECUTE COMMANDS
Shell escapes
https://www.mariowiki.com/File:Koopa_Troopa_Artwork_-
_Super_Mario_3D_World.png
19
Binary Option
find -exec CMD ;
awk ‘{system(“CMD”)}’
AND MANY MORE
INTENTIONAL OPTION TO EXECUTE COMMANDS
Cmd option arguments
20
TRICKING AN EXECUTABLE INTO SPAWNING A SHELL
SUID Exploit
Nano is another common executable
If nano has a SUID bit set to root, can
force an escape to root shell
Exploit:
1. create a temporary
file with shell cmd
2. open nano with temp
file set as spell-check
reference
3. run spell-check to
execute cmd under
root permissions
21
Path is an environment variable telling the
OS where to look for an aliased binary
Instead of typing /bin/ls every time,
you can just type ls
Use case: Prank the Admin
• Bill knows that his supervisor Sue has
her PATH = .
• Writes a script to prank her, names it ls,
sticks it in his /home/BILL/ directory
• Asks Sue why ls isn’t working in his ~
• Sue runs ls in /home/BILL/ and executes
the prank script instead of /bin/ls binary
START LOOKING HERE
Path = .
22
Not easy during assessment to know which
users have PATH = .
HOWEVER!
Custom script on the web server might
execute call to aliased program
calling cat $FILE instead of /bin/cat $FILE
If it runs under root privs, you can exploit it
Use case: helperSH Exploit
• helperSH is a custom script on the web
server that makes life easy for an
admin; SUID as root
• Command within the script executes
something recognizable (like ps)
• In writeable dir, make new file
echo “/bin/sh” > ps
• Set own PATH = .
• Execute script from writeable dir
START LOOKING HERE
Path = .
23
Use case: helperSH Exploit
• helperSH is a custom script on the web
server that makes life easy for an
admin; SUID as root
• Command within the script executes
something recognizable (like ps)
• In writeable dir, make new file
echo “/bin/sh” > ps
• Set own PATH = .
• Execute script from writeable dir
START LOOKING HERE
Path = .
24
When using * wildcard, Unix shell
interprets –FILENAME as command option
argument
Meaning you can
submit command options
through file name
when running a wildcard process
Keep an eye out for wildcards in
custom scripts, cron jobs, executables
chown example
files in a given dir include:
.FileRef.php
--reference=.FileRef.php
when root executes the following:
chown –R nobody:nobody *.php
becomes:
chown –R nobody:nobody --reference=.FileRef.php
User:group permissions of .FileRef.php are
mapped onto every file in the directory
COMMAND OPTION ARGUMENTS AS FILENAMES
Wildcards
25
When using * wildcard, Unix shell
interprets –FILENAME as command option
argument
Meaning you can
submit command options
through file name
when running a wildcard process
Keep an eye out for wildcards in
custom scripts, cron jobs, executables
NOTE –
EXPLOIT BELOW DELETES THE FILESYSTEM
cd /tmp
echo “blah” > “-rf /*”
rm *
When rm * gets to –rf /* file, command
becomes rm –rf /*
Which recursively deletes everything on
the filesystem, starting at /
COMMAND OPTION ARGUMENTS AS FILENAMES
Wildcards
26
SUID/SGID bits
1. Shell escapes
2. Cmd option arguments
3. PATH = .
Wildcards
Two ways to escalate:
1. You’re the agent – your current user
permissions are sufficient to execute
the command & do the thing
2. Something else is the agent – you get
something else to execute the
command under THEIR permissions,
which are sufficient to do the thing
RECAP
Sneaky Mode
BOSS MODE
THESE WILL TAKE SOME TIME TO GET RIGHT
28
Cron jobs are cmds executed on a schedule
Almost always run under root permissions
• /etc/cron.allow & /etc/cron.deny specify user privs
Cron takes a file; file tells it what to execute
and when
• /etc/crontab
Related: at, batch (one-time execution)
PRIVILEGE IS A CRONIC PROBLEM
cron
• How to exploit?
1. Overwrite /etc/crontab
2. Write to a cron dir (priv misconfig)
3. If the what is vulnerable, might be able to
modify or hit something downstream
4. Cron jobs may also have exploitable
wildcards
29
PRIVILEGE IS A CRONIC PROBLEM
cron
• How to exploit?
1. Overwrite /etc/crontab (SUID on nano!)
2. Write to a cron dir (priv misconfig)
3. If the what is vulnerable, might be able to
modify or hit something downstream
4. Cron jobs may also have exploitable
wildcards
30
PRIVILEGE IS A CRONIC PROBLEM
cron
• How to exploit?
1. Overwrite /etc/crontab
2. Write to a cron dir (priv misconfig)
3. If the what is vulnerable, might be able to
modify or hit something downstream
4. Cron jobs may also have exploitable
wildcards
31
PRIVILEGE IS A CRONIC PROBLEM
cron
• How to exploit?
1. Overwrite /etc/crontab
2. Write to a cron dir (priv misconfig)
3. If the what is vulnerable, might be able to
modify or hit something downstream
4. Cron jobs may also have exploitable
wildcards
32
Magic bullet: what if we just compromise
the server OS itself??!
Downside: there might be exploits that you
need to grab & compile & debug
NOTE: not-small risk of bricking the server
HOPE YOU LIKE DEBUGGING IN C
Kernel Exploits
LSB_RELEASE -A
UNAME -A
33
Cron jobs
1. /etc/crontab
2. writeable cron dir
3. affect process downstream
Kernel exploits
Two ways to escalate:
1. You’re the agent – your current user
permissions are sufficient to execute
the command & do the thing
2. Something else is the agent – you get
something else to execute the
command under THEIR permissions,
which are sufficient to do the thing
RECAP
Boss Mode
THAT’S ONE IN THE BANK
LET ME SUM UP
35
Typical goal in server:
persistence + privilege escalation
Linux tends to be consistent in its core utilities;
get familiar with what’s there and where it lives,
and spotting vulnerable paths gets a lot easier
• Are you the agent? Drop into a root shell &
give yourself persistence
• Is something else the agent? Need an
intermediate step – get something to help
you out
ONE HOUR IN ONE SLIDE
Summary
• Easy mode
• Who are you?
• Where are you?
• What can you do?
• Sneaky mode
• SUID/SGID bits:
shell escapes, cmd option args, PATH = .
• Wildcards
• Boss mode
• Cron jobs
• Kernel exploits
36
• https://payatu.com/guide-linux-privilege-escalation/
• http://www.securitysift.com/download/
linuxprivchecker.py
• https://exploit-db.com
• https://www.linode.com/docs/tools-reference/linux-users-
and-groups/
• https://resources.infosecinstitute.com/
privilege-escalation-linux-live-examples/
• https://www.hackingarticles.in/exploiting-wildcard-for-
privilege-escalation/
• https://percussiveelbow.github.io/linux-privesc/
I’M REAL FRIENDLY
Resources & Contact
kbroussard@bishopfox.com
@grazhacks on Twitter
SLIDE DECK
http://github.com/
grazhacks/BSidesCMH2019
PRACTICE VM
http://bit.ly/
BSidesCMH2019
Thank You!
Questions?
kbroussard@bishopfox.com
@grazhacks on Twitter
SLIDE DECK
http://github.com/
grazhacks/BSidesCMH2019
PRACTICE VM
http://bit.ly/
BSidesCMH2019

More Related Content

PDF
Introduction to Linux Privilege Escalation Methods
PDF
Network Penetration Testing Toolkit - Nmap, Netcat, and Metasploit Basics
PDF
Linux advanced privilege escalation
PPTX
Power of linked list
PPTX
Linux privilege escalation 101
PDF
Aide 2014 - Fundamentals of Linux Privilege Escalation
PDF
How to Root 10 Million Phones with One Exploit
PPTX
Fundamentals of Linux Privilege Escalation
Introduction to Linux Privilege Escalation Methods
Network Penetration Testing Toolkit - Nmap, Netcat, and Metasploit Basics
Linux advanced privilege escalation
Power of linked list
Linux privilege escalation 101
Aide 2014 - Fundamentals of Linux Privilege Escalation
How to Root 10 Million Phones with One Exploit
Fundamentals of Linux Privilege Escalation

What's hot (20)

PPTX
Racing with Droids
PPTX
Owning computers without shell access dark
PPTX
Owning computers without shell access 2
PPTX
Back to the CORE
PPTX
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
PPTX
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
PDF
Privilege escalation from 1 to 0 Workshop
PPTX
Guardians of your CODE
PDF
Hacking Highly Secured Enterprise Environments by Zoltan Balazs
PPTX
Vulnerability desing patterns
PDF
Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]
PDF
Linux Kernel Debugging Essentials workshop
PDF
Modern Evasion Techniques
PDF
Exploiting Llinux Environment
PDF
Richard wartell malware is hard. let's go shopping!!
PDF
How fun of privilege escalation Red Pill2017
PDF
SANS @Night There's Gold in Them Thar Package Management Databases
PPTX
Get-Help: An intro to PowerShell and how to Use it for Evil
PPTX
Security research over Windows #defcon china
PDF
Common technique in Bypassing Stuff in Python.
Racing with Droids
Owning computers without shell access dark
Owning computers without shell access 2
Back to the CORE
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
Privilege escalation from 1 to 0 Workshop
Guardians of your CODE
Hacking Highly Secured Enterprise Environments by Zoltan Balazs
Vulnerability desing patterns
Jaime Peñalba - Kernel exploitation. ¿El octavo arte? [rooted2019]
Linux Kernel Debugging Essentials workshop
Modern Evasion Techniques
Exploiting Llinux Environment
Richard wartell malware is hard. let's go shopping!!
How fun of privilege escalation Red Pill2017
SANS @Night There's Gold in Them Thar Package Management Databases
Get-Help: An intro to PowerShell and how to Use it for Evil
Security research over Windows #defcon china
Common technique in Bypassing Stuff in Python.
Ad

Similar to Check Your Privilege (Escalation) (20)

PPTX
Linux privilege escalation
PDF
1000 to 0
PPTX
Linux remote
PDF
Linux Security Crash Course
PPT
Host security
PPT
Host security
PPTX
Linux automated tasks
PDF
Linux Privilege Escalation with Lin Security.
PPTX
Linx privx privileges-sudo misconfiguration group and docker daemon privileges
PPT
Threats, Vulnerabilities & Security measures in Linux
PPT
Linux Vulnerabilities
PPT
Linux Operating System Vulnerabilities
PPTX
Privilege Escalation with Metasploit
PDF
Linux: Everyting-as-a-service
PDF
How to Audit Linux - Gene Kartavtsev, ISACA MN
PPTX
Ethical hacking Chapter 9 - Linux Vulnerabilities - Eric Vanderburg
DOCX
lec1.docx
PPTX
Introduction 2 linux
PDF
Linux security quick reference guide
PDF
Linux Fundamentals and how to use linux.pdf
Linux privilege escalation
1000 to 0
Linux remote
Linux Security Crash Course
Host security
Host security
Linux automated tasks
Linux Privilege Escalation with Lin Security.
Linx privx privileges-sudo misconfiguration group and docker daemon privileges
Threats, Vulnerabilities & Security measures in Linux
Linux Vulnerabilities
Linux Operating System Vulnerabilities
Privilege Escalation with Metasploit
Linux: Everyting-as-a-service
How to Audit Linux - Gene Kartavtsev, ISACA MN
Ethical hacking Chapter 9 - Linux Vulnerabilities - Eric Vanderburg
lec1.docx
Introduction 2 linux
Linux security quick reference guide
Linux Fundamentals and how to use linux.pdf
Ad

More from Bishop Fox (20)

PDF
OWASP LA – SharePoint Hacking – 22Feb2012 – Slides.PDF
PDF
InfoSec World 2016 – RFIDiggity – Pentester Guide to Hacking HF/NFC and UHF...
PDF
InfoSec World 2013 – W4 – Using Google to Find Vulnerabilities in Your IT Env...
PDF
DEFCON 20 (2012) – Tenacious Diggity – 29July2012 – Slides.PDF
PDF
SpellCheckV2 Rules
PDF
Smarter Home Invasion With ZigDiggity
PDF
Hacking Exposed EBS Volumes
PDF
Ghost in the Browser: Broad-Scale Espionage with Bitsquatting
PDF
Ferris Bueller’s Guide to Abuse Domain Permutations
PDF
Penetration Testing Resource Guide
PDF
How Perceptual Analysis Helps Bug Hunters
PDF
Getting Buzzed on Buzzwords: Using Cloud & Big Data to Pentest at Scale
PPTX
Evolving Cyber Adversary Simulation: How Red Teaming Benefits Organizations
PDF
ASU Cybersecurity Symposium - Breaking Into a Career of Breaking In
PDF
CactusCon 2018 - Anatomy of an AppSec Program
PDF
Preparing a Next Generation IT Strategy
PDF
Lord of the Bing: Taking Back Search Engine Hacking From Google and Bing
PDF
Pulp Google Hacking
PDF
Black Hat USA - CloudBots Harvesting Crypto Coins Like a Botnet Farmer
PDF
RFID Hacking: Live Free or RFID Hard
OWASP LA – SharePoint Hacking – 22Feb2012 – Slides.PDF
InfoSec World 2016 – RFIDiggity – Pentester Guide to Hacking HF/NFC and UHF...
InfoSec World 2013 – W4 – Using Google to Find Vulnerabilities in Your IT Env...
DEFCON 20 (2012) – Tenacious Diggity – 29July2012 – Slides.PDF
SpellCheckV2 Rules
Smarter Home Invasion With ZigDiggity
Hacking Exposed EBS Volumes
Ghost in the Browser: Broad-Scale Espionage with Bitsquatting
Ferris Bueller’s Guide to Abuse Domain Permutations
Penetration Testing Resource Guide
How Perceptual Analysis Helps Bug Hunters
Getting Buzzed on Buzzwords: Using Cloud & Big Data to Pentest at Scale
Evolving Cyber Adversary Simulation: How Red Teaming Benefits Organizations
ASU Cybersecurity Symposium - Breaking Into a Career of Breaking In
CactusCon 2018 - Anatomy of an AppSec Program
Preparing a Next Generation IT Strategy
Lord of the Bing: Taking Back Search Engine Hacking From Google and Bing
Pulp Google Hacking
Black Hat USA - CloudBots Harvesting Crypto Coins Like a Botnet Farmer
RFID Hacking: Live Free or RFID Hard

Recently uploaded (20)

PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Cost to Outsource Software Development in 2025
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PDF
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
PPTX
Monitoring Stack: Grafana, Loki & Promtail
PDF
AutoCAD Professional Crack 2025 With License Key
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Download FL Studio Crack Latest version 2025 ?
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Website Design Services for Small Businesses.pdf
PDF
Complete Guide to Website Development in Malaysia for SMEs
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Salesforce Agentforce AI Implementation.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
Digital Systems & Binary Numbers (comprehensive )
iTop VPN Free 5.6.0.5262 Crack latest version 2025
Reimagine Home Health with the Power of Agentic AI​
Cost to Outsource Software Development in 2025
Why Generative AI is the Future of Content, Code & Creativity?
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
Monitoring Stack: Grafana, Loki & Promtail
AutoCAD Professional Crack 2025 With License Key
Computer Software and OS of computer science of grade 11.pptx
Download FL Studio Crack Latest version 2025 ?
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Website Design Services for Small Businesses.pdf
Complete Guide to Website Development in Malaysia for SMEs
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Oracle Fusion HCM Cloud Demo for Beginners
Wondershare Filmora 15 Crack With Activation Key [2025
Salesforce Agentforce AI Implementation.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025

Check Your Privilege (Escalation)

  • 1. Check Your Privilege (Escalation) KATE BROUSSARD, SENIOR SECURITY ANALYST AT BISHOP FOX March 1, 2019 BSidesCMH 2019
  • 2. 22 Kate Broussard Senior Security Analyst kbroussard@bishopfox.com @grazhacks on Twitter ROADMAP FOR THE NEXT HOUR Introduction Outline • Priv esc definition + framing • Easy mode • Sneaky mode • Boss mode • Summary • Resources
  • 4. 4 Definition • Using privileges of various agents to gain access to resources When does it come into play? Framing • Who’s doing the execution? • What are their privileges? Two ways to escalate: 1. You’re the agent – your current user permissions are sufficient to execute the command & do the thing 2. Something else is the agent – you get something else to execute the command under THEIR permissions, which are sufficient to do the thing DEFINITION AND FRAMING Privilege Escalation
  • 5. EASY MODE SO YOU’RE IN THE SERVER – NOW WHAT?
  • 6. 6 • Who are you? whoami id • Where are you? pwd • Are you really really lucky? cat /etc/shadow vs. cat /etc/passwd cd /root CHECK YOUR PRIVILEGE Before anything else
  • 7. 7 • Where do you have read access? /home/ /usr/share/ ENV • Where do you have write access? /home/USER/.ssh /root/ /etc/crontab CHECK YOUR PRIVILEGE Permissions
  • 8. 8 sudo = super user do [something] sudo –l • What commands can you execute? • Do you need a password? https://xkcd.com/838/ - Incident MAKE ME A SANDWICH sudo
  • 9. 9 sudo = super user do [something] sudo –l • What commands can you execute? • Do you need a password? MAKE ME A SANDWICH sudo cat /etc/sudoers • if readable, tells you which users/groups to target cat /etc/group • lists users, IDs, group affiliations
  • 10. 10 sudo –l • User has sudo permissions for python • Without needing the password – excellent! • Therefore can run python under root permissions sudo python –c ‘import pty;pty.spawn(“/bin/bash”);’ • New shell spawned by python also runs under root permissions SUDO MAKE ME A SANDWICH sudo Exploit - Python
  • 11. 11 Password reuse is RAMPANT • web application passwords • common/default passwords nmap port scan or ps auf to see what’s up • known compromised passwords for specific users https://xkcd.com/792/ - Password Reuse WE ARE CREATURES OF HABIT Credential Reuse
  • 12. 12 • Any passwords entered into history? • Any interesting files or directories? cat .bash_history vs history • .bash_history won’t dump current session data until session ends • history is a live dump of session LEAKED INFORMATION .bash_history
  • 13. 13 • Are any credentials stored in logs? • Any other useful information? Log files/dirs that are writeable can be replaced by symlink. When owning process tries to write to log, will write to symlink instead. Can be a way to output data somewhere that you can read it. LEAKED INFORMATION /var/log
  • 14. 14 1. Who/where are you 2. What can you see/modify with current permissions? 3. Look for: 1. sudo permissions 2. Credential Reuse 3. Leaked info from: 1. cat .bash_history 2. /var/log files Two ways to escalate: 1. You’re the agent – your current user permissions are sufficient to execute the command & do the thing 2. Something else is the agent – you get something else to execute the command under THEIR permissions, which are sufficient to do the thing RECAP Easy Mode
  • 15. SNEAKY MODE FIND AND EXPLOIT SOME MISCONFIGURATIONS
  • 16. 16 • What is the SUID/SGID bit? • How to find a SUID/SGID binary? • What runs as the root user? find / -perm -u=s [-type f] 2>/dev/null find / -perm -4000 [-type f] 2>/dev/null • What runs in the root group? find / -perm -g=s [-type f] 2>/dev/null find / -perm -2000 [-type f] 2>/dev/null CHECK THEIR PRIVILEGE SUID/SGID bits
  • 17. 17 • What are “normal” SUID programs vs ones that are exploitable? Standard Linux utility? Try shell escape or command option argument Custom script to make an admin’s life easy? Try PATH = . especially if the script makes a call to an alias Also watch for wildcards CHECK THEIR PRIVILEGE SUID/SGID bits
  • 18. 18 Binary Shell escape less !cmd more !cmd :!cmd vi :! cmd mysql system cmd ! cmd AND MANY MORE INTENTIONAL OPTION TO EXECUTE COMMANDS Shell escapes https://www.mariowiki.com/File:Koopa_Troopa_Artwork_- _Super_Mario_3D_World.png
  • 19. 19 Binary Option find -exec CMD ; awk ‘{system(“CMD”)}’ AND MANY MORE INTENTIONAL OPTION TO EXECUTE COMMANDS Cmd option arguments
  • 20. 20 TRICKING AN EXECUTABLE INTO SPAWNING A SHELL SUID Exploit Nano is another common executable If nano has a SUID bit set to root, can force an escape to root shell Exploit: 1. create a temporary file with shell cmd 2. open nano with temp file set as spell-check reference 3. run spell-check to execute cmd under root permissions
  • 21. 21 Path is an environment variable telling the OS where to look for an aliased binary Instead of typing /bin/ls every time, you can just type ls Use case: Prank the Admin • Bill knows that his supervisor Sue has her PATH = . • Writes a script to prank her, names it ls, sticks it in his /home/BILL/ directory • Asks Sue why ls isn’t working in his ~ • Sue runs ls in /home/BILL/ and executes the prank script instead of /bin/ls binary START LOOKING HERE Path = .
  • 22. 22 Not easy during assessment to know which users have PATH = . HOWEVER! Custom script on the web server might execute call to aliased program calling cat $FILE instead of /bin/cat $FILE If it runs under root privs, you can exploit it Use case: helperSH Exploit • helperSH is a custom script on the web server that makes life easy for an admin; SUID as root • Command within the script executes something recognizable (like ps) • In writeable dir, make new file echo “/bin/sh” > ps • Set own PATH = . • Execute script from writeable dir START LOOKING HERE Path = .
  • 23. 23 Use case: helperSH Exploit • helperSH is a custom script on the web server that makes life easy for an admin; SUID as root • Command within the script executes something recognizable (like ps) • In writeable dir, make new file echo “/bin/sh” > ps • Set own PATH = . • Execute script from writeable dir START LOOKING HERE Path = .
  • 24. 24 When using * wildcard, Unix shell interprets –FILENAME as command option argument Meaning you can submit command options through file name when running a wildcard process Keep an eye out for wildcards in custom scripts, cron jobs, executables chown example files in a given dir include: .FileRef.php --reference=.FileRef.php when root executes the following: chown –R nobody:nobody *.php becomes: chown –R nobody:nobody --reference=.FileRef.php User:group permissions of .FileRef.php are mapped onto every file in the directory COMMAND OPTION ARGUMENTS AS FILENAMES Wildcards
  • 25. 25 When using * wildcard, Unix shell interprets –FILENAME as command option argument Meaning you can submit command options through file name when running a wildcard process Keep an eye out for wildcards in custom scripts, cron jobs, executables NOTE – EXPLOIT BELOW DELETES THE FILESYSTEM cd /tmp echo “blah” > “-rf /*” rm * When rm * gets to –rf /* file, command becomes rm –rf /* Which recursively deletes everything on the filesystem, starting at / COMMAND OPTION ARGUMENTS AS FILENAMES Wildcards
  • 26. 26 SUID/SGID bits 1. Shell escapes 2. Cmd option arguments 3. PATH = . Wildcards Two ways to escalate: 1. You’re the agent – your current user permissions are sufficient to execute the command & do the thing 2. Something else is the agent – you get something else to execute the command under THEIR permissions, which are sufficient to do the thing RECAP Sneaky Mode
  • 27. BOSS MODE THESE WILL TAKE SOME TIME TO GET RIGHT
  • 28. 28 Cron jobs are cmds executed on a schedule Almost always run under root permissions • /etc/cron.allow & /etc/cron.deny specify user privs Cron takes a file; file tells it what to execute and when • /etc/crontab Related: at, batch (one-time execution) PRIVILEGE IS A CRONIC PROBLEM cron • How to exploit? 1. Overwrite /etc/crontab 2. Write to a cron dir (priv misconfig) 3. If the what is vulnerable, might be able to modify or hit something downstream 4. Cron jobs may also have exploitable wildcards
  • 29. 29 PRIVILEGE IS A CRONIC PROBLEM cron • How to exploit? 1. Overwrite /etc/crontab (SUID on nano!) 2. Write to a cron dir (priv misconfig) 3. If the what is vulnerable, might be able to modify or hit something downstream 4. Cron jobs may also have exploitable wildcards
  • 30. 30 PRIVILEGE IS A CRONIC PROBLEM cron • How to exploit? 1. Overwrite /etc/crontab 2. Write to a cron dir (priv misconfig) 3. If the what is vulnerable, might be able to modify or hit something downstream 4. Cron jobs may also have exploitable wildcards
  • 31. 31 PRIVILEGE IS A CRONIC PROBLEM cron • How to exploit? 1. Overwrite /etc/crontab 2. Write to a cron dir (priv misconfig) 3. If the what is vulnerable, might be able to modify or hit something downstream 4. Cron jobs may also have exploitable wildcards
  • 32. 32 Magic bullet: what if we just compromise the server OS itself??! Downside: there might be exploits that you need to grab & compile & debug NOTE: not-small risk of bricking the server HOPE YOU LIKE DEBUGGING IN C Kernel Exploits LSB_RELEASE -A UNAME -A
  • 33. 33 Cron jobs 1. /etc/crontab 2. writeable cron dir 3. affect process downstream Kernel exploits Two ways to escalate: 1. You’re the agent – your current user permissions are sufficient to execute the command & do the thing 2. Something else is the agent – you get something else to execute the command under THEIR permissions, which are sufficient to do the thing RECAP Boss Mode
  • 34. THAT’S ONE IN THE BANK LET ME SUM UP
  • 35. 35 Typical goal in server: persistence + privilege escalation Linux tends to be consistent in its core utilities; get familiar with what’s there and where it lives, and spotting vulnerable paths gets a lot easier • Are you the agent? Drop into a root shell & give yourself persistence • Is something else the agent? Need an intermediate step – get something to help you out ONE HOUR IN ONE SLIDE Summary • Easy mode • Who are you? • Where are you? • What can you do? • Sneaky mode • SUID/SGID bits: shell escapes, cmd option args, PATH = . • Wildcards • Boss mode • Cron jobs • Kernel exploits
  • 36. 36 • https://payatu.com/guide-linux-privilege-escalation/ • http://www.securitysift.com/download/ linuxprivchecker.py • https://exploit-db.com • https://www.linode.com/docs/tools-reference/linux-users- and-groups/ • https://resources.infosecinstitute.com/ privilege-escalation-linux-live-examples/ • https://www.hackingarticles.in/exploiting-wildcard-for- privilege-escalation/ • https://percussiveelbow.github.io/linux-privesc/ I’M REAL FRIENDLY Resources & Contact kbroussard@bishopfox.com @grazhacks on Twitter SLIDE DECK http://github.com/ grazhacks/BSidesCMH2019 PRACTICE VM http://bit.ly/ BSidesCMH2019
  • 37. Thank You! Questions? kbroussard@bishopfox.com @grazhacks on Twitter SLIDE DECK http://github.com/ grazhacks/BSidesCMH2019 PRACTICE VM http://bit.ly/ BSidesCMH2019