Testing ISAKMP Part 4: Using Scapy
Table of Contents
In Part 2, I showed how to test ISAKMP with a pre-built hex string and netcat. In Part 3, we dove deep into the byte-by-byte construction of ISAKMP packets. Now let’s use Scapy to automate this with Python.
Why Scapy?
Netcat with hex strings works for one-off tests, but Scapy lets you build packets programmatically, parse responses automatically, and script tests across multiple targets. It understands ISAKMP structure and handles length fields and checksums for you.
Prerequisites
- Python 3.8+ installed
- Basic Python knowledge
- Understanding of ISAKMP concepts (see Part 1)
- Target ISAKMP/IKE peer to test
- Root/sudo access (required for raw socket operations)
Installation
| |
Important: Scapy requires raw socket access, which needs root/sudo privileges. When using Poetry with sudo, you must install dependencies as root:
sudo poetry install
Basic ISAKMP Packet with Scapy
The Simple Approach
| |
Building a Complete Phase 1 Packet
Transform Set Configuration
| |
Constructing the Packet
| |
Note: Scapy’s ISAKMP implementation uses a list of
(type, value)tuples for transform attributes, not individual attribute objects. This is simpler and matches how the protocol actually works.
Sending and Analyzing Responses
Send the Packet
| |
Understanding the Response
| |
Advanced Usage
Testing Multiple Transform Sets
| |
Aggressive Mode vs Main Mode
| |
NAT-T Detection
| |
Creating a Reusable Script
I’ve created a complete script that combines all these techniques. The full code is in the nn_examples repository.
The repository includes additional transform sets (including legacy crypto) for real-world compatibility testing.
Quick Start
| |
Why
sudo poetry install? Scapy requires raw socket access (root privileges). Sincesudoruns in a separate environment, dependencies must be installed both as your user and as root.
Example Output
| |
Self-Contained Testing
The repository also includes isakmp_listener.py - a test responder for testing without a real VPN device:
| |
The listener accepts all proposed transform sets and logs packet details. Good for testing the tester script, learning packet structure, and debugging without VPN hardware.
Note: When testing against localhost (127.0.0.1), you may receive ISAKMP responses even without the listener running. This is the kernel’s UDP socket handling, not actual ISAKMP protocol responses. For realistic testing, use a real ISAKMP/VPN device or test between different machines.
Comparison: Scapy vs Netcat vs ike-scan
| Feature | Scapy | Netcat | ike-scan |
|---|---|---|---|
| Dynamic construction | ✅ | ❌ | ✅ |
| Response parsing | ✅ | ❌ | ✅ |
| Scripting | ✅ | ⚠️ | ⚠️ |
| Learning tool | ✅ | ✅ | ❌ |
| Production ready | ⚠️ | ❌ | ✅ |
| Installation | pip | Built-in | Package manager |
Security Considerations
⚠️ Authorization Required: Only test systems you own or have explicit permission to test. ISAKMP probes are logged by VPN concentrators, firewalls, and IDS/IPS systems. Repeated probes trigger security alerts.
Phase 1 Only: This covers IKE Phase 1 (ISAKMP) only. Establishing a full VPN tunnel requires Phase 2 (IPsec Quick Mode) and proper authentication credentials.
Cryptographic Parameters: Use SHA-256 (not SHA-1), AES-256, and DH Group 14+ (2048-bit minimum).
Troubleshooting
Permission Denied
| |
No Response Received
- Check firewall rules (UDP/500)
- Verify target IP is correct
- Confirm ISAKMP service is running
- Check for NAT between you and target
- VPN concentrators rate-limit ISAKMP attempts - wait 30-60 seconds between tests
Import Errors
| |
Next Steps
- Explore IKEv2 with Scapy
- Build Phase 2 (Quick Mode) packets
- Implement full IKE exchange
- Add support for certificates (RSA signatures)
Conclusion
Scapy bridges the gap between manual packet construction and specialized tools like ike-scan. While netcat teaches you the raw protocol (Part 2) and manual construction reveals the internals (Part 3), Scapy gives you the power to automate and scale your testing.
For production VPN scanning, use dedicated tools like ike-scan or nmap --script ike-version. For learning and custom testing, Scapy is unmatched.