Closed edhinard closed 2 years ago
I am now facing a problem with 'SK' payloads. For example :
>>> import pycrate_crypto.IKEv2
>>> hexpayload = 'a9a3a51a00000000330d0eddfff255582e20230800000001000000a5230000892f00000c01000000220e00972900000c0100000000010000210000080000400a2c000028000000240103040300000064030000080100000b030000080300000200000008050000002d00001801000000070000100001ffff00000000ffffffff0000001801000000070000100001ffff00000000ffffffff00c1ef31fd646e38d7abd689b0'
>>> obj1 = pycrate_crypto.IKEv2.IKEv2()
>>> obj1.from_bytes(bytes.fromhex(hexpayload))
>>> print(obj1.show())
### IKEv2 ###
### Header ###
<SPIInitiator : 0xa9a3a51a00000000>
<SPIResponder : 0x330d0eddfff25558>
<Next : 46>
<VersMaj : 2>
<VersMin : 0>
<ExchType : 35 (IKE_AUTH)>
### Flags ###
<undef : 0x0>
<R : 0>
<V : 0>
<I : 1>
<undef : 0x0>
<MID : 0x00000001>
<Len : 165>
### Payloads ###
>>>
The PayEncr
(Next=46) class is not decoding at all as we can see in the result of show()
above. Can you tell me what should be done to decode such payloads. I can manage the encryption/decryption myself later. I just want to retrieve IV
and Data
. Among the questions that I ask myself, there is that of the determination of the length of the IV field. I understand that the length is automatically computed when the encryption algorithm is known. But how to set the ALG_ENCR
value before decoding the payload ?
Yep, IKEv2 implementation was quite unfinished... I just pushed commit 1a6d4d6ab8b61e0ef4ea9314ac07facfdd10f785, which addresses the few fixes you did in this PR, plus additional fixes and enhancements for proper decoding of packets.
For encrypted payload, you need to configure the algorithm suite you have selected, in order to get the correct IV and ICS size. You can do this by calling the following class method with the appropriate algorithm identifiers:
PayEncr.set_alg(IKEv2TransENCR.ENCR_AES_CBC, IKEv2TransAUTH.AUTH_HMAC_SHA1_96)
From here, decoding of encrypted payloads should be fine. I am missing unit tests for this protocol, so in case you have pcap / traces for full IKEv2 negotiations, if possible with keys, that would enable to set them cleanly.
Thank you for the update and the help. I can now go further and the request can be closed. I do have an IKEv2 pcap trace with keys, coming from a N3IWF setup, that I can share with you. Unfortunately github does not allow for private messages.
You can send me an email to benoit.michau@p1sec.com, having such a trace would be helpful for further development.
Hi, here are three little fixes in pycrate_crypto/IKEv2.py.
I am trying to decode and build ISAKMP payloads with
pycrate_crypto/IKEv2
. The code would look like :The proposed merge request makes the code running OK with the following values :