[MS-SMB2] sect 3.2.5.1.1.1 - Decrypting the Message
(self, dialect, DecryptionKey, CipherId)
| 4409 | ] |
| 4410 | |
| 4411 | def decrypt(self, dialect, DecryptionKey, CipherId): |
| 4412 | """ |
| 4413 | [MS-SMB2] sect 3.2.5.1.1.1 - Decrypting the Message |
| 4414 | """ |
| 4415 | if not isinstance(self.payload, conf.raw_layer): |
| 4416 | raise Exception("No payload to decrypt !") |
| 4417 | |
| 4418 | if "GCM" in CipherId: |
| 4419 | from cryptography.hazmat.primitives.ciphers.aead import AESGCM |
| 4420 | |
| 4421 | nonce = self.Nonce[:12] |
| 4422 | cipher = AESGCM(DecryptionKey) |
| 4423 | elif "CCM" in CipherId: |
| 4424 | from cryptography.hazmat.primitives.ciphers.aead import AESCCM |
| 4425 | |
| 4426 | nonce = self.Nonce[:11] |
| 4427 | cipher = AESCCM(DecryptionKey) |
| 4428 | else: |
| 4429 | raise Exception("Unknown CipherId !") |
| 4430 | |
| 4431 | # Decrypt the data |
| 4432 | aad = self.self_build()[20:] |
| 4433 | data = cipher.decrypt( |
| 4434 | nonce, |
| 4435 | self.payload.load + self.Signature, |
| 4436 | aad, |
| 4437 | ) |
| 4438 | return SMB2_Header(data, _decrypted=True) |
| 4439 | |
| 4440 | |
| 4441 | bind_layers(SMB2_Transform_Header, conf.raw_layer) |
no test coverage detected