How do I create a sample IPSec packet using python scapy
How do I create a sample IPSec packet using python scapy
I will create a VPN tunnel between two routers. So i need to send some raw packets generated by scapy through the VPN tunnel. Basically i need to generate some raw IPSec packets.
1 Answer
1
Here is scapy’s test file for IPSec https://github.com/secdev/scapy/blob/master/test/ipsec.uts
It provides a lot of examples such as
import socket
p = IP(src='1.1.1.1', dst='2.2.2.2')
p /= TCP(sport=45012, dport=80)
p /= Raw('testdata')
p = IP(raw(p))
p
sa = SecurityAssociation(ESP, spi=0x222,
crypt_algo='NULL', crypt_key=None,
auth_algo='NULL', auth_key=None)
e = sa.encrypt(p)
e
assert(isinstance(e, IP))
assert(e.src == '1.1.1.1' and e.dst == '2.2.2.2')
assert(e.chksum != p.chksum)
assert(e.proto == socket.IPPROTO_ESP)
assert(e.haslayer(ESP))
assert(not e.haslayer(TCP))
assert(e[ESP].spi == sa.spi)
assert(b'testdata' in e[ESP].data)
d = sa.decrypt(e)
d
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.