githubEdit

Pentesting IPsec/IKE

Ports: UDP 500 (IKE), UDP 4500 (NAT-T IKE)

IPsec VPNs use Internet Key Exchange (IKE) for establishing secure tunnels. Misconfigurations can leak PSK hashes.


Discovery

# UDP scan for IKE
nmap -sU -p 500,4500 $ip

# Service version
nmap -sU -p 500 -sV $ip

ike-scan

Primary tool for IKE enumeration and attacks.

# Install
sudo apt install ike-scan

Basic Enumeration

# Check if IKE is running (Main Mode)
ike-scan -M $ip

Output interpretation:

Result
Meaning

1 returned handshake; 0 returned notify

Target is IPsec gateway, willing to negotiate

0 returned handshake; 1 returned notify

None of proposed transforms acceptable

0 returned handshake; 0 returned notify

Not an IPsec gateway

Vendor Identification


Aggressive Mode Attack (PSK Extraction)

Aggressive mode is vulnerable - it returns a hash that can be cracked offline.

Key output to look for:

  • ID(Type=ID_USER_FQDN, Value=...) - reveals server's group name/ID

  • Hash(20 bytes) - the PSK hash for cracking

Full PSK Hash Extraction

The output contains IKE PSK parameters in this format:

Save the entire parameter string to a file for cracking.

Note on Fake Hashes

If a hash is returned even with a fake ID, the server may be sending fake hashes for any ID (security feature). However, if it cracks successfully, the hash was real.


Cracking IKE-PSK Hash

Hashcat IKE Modes

Mode
Description

5300

IKE-PSK MD5

5400

IKE-PSK SHA1


Transform Enumeration

If default transforms fail, enumerate acceptable ones:

Transform Format

--trans=enc,hash,auth,group

Encryption
Hash
Auth
Group

5 = 3DES

1 = MD5

1 = PSK

1 = MODP768

7 = AES

2 = SHA1

2 = RSA

2 = MODP1024

64221 = XAUTH

5 = MODP1536


Connecting to VPN

Once you have credentials:

StrongSwan

Example /etc/ipsec.secrets:

vpnc

Example config:

Connect:


Post-Connection

After VPN connection:


References

  • https://book.hacktricks.xyz/network-services-pentesting/ipsec-ike-vpn-pentesting

  • ike-scan documentation

Last updated