MCPcopy Create free account
hub / github.com/secdev/scapy / SMB2_Transform_Header

Class SMB2_Transform_Header

scapy/layers/smb2.py:4393–4438  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4391
4392
4393class SMB2_Transform_Header(Packet):
4394 name = "SMB2 Transform Header"
4395 fields_desc = [
4396 StrFixedLenField("Start", b"\xfdSMB", 4),
4397 XStrFixedLenField("Signature", 0, length=16),
4398 XStrFixedLenField("Nonce", b"", length=16),
4399 LEIntField("OriginalMessageSize", 0x0),
4400 LEShortField("Reserved", 0),
4401 LEShortEnumField(
4402 "Flags",
4403 0x1,
4404 {
4405 0x0001: "ENCRYPTED",
4406 },
4407 ),
4408 LELongField("SessionId", 0),
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
4441bind_layers(SMB2_Transform_Header, conf.raw_layer)

Callers 1

encryptMethod · 0.85

Calls 6

StrFixedLenFieldClass · 0.90
XStrFixedLenFieldClass · 0.90
LEIntFieldClass · 0.90
LEShortFieldClass · 0.90
LEShortEnumFieldClass · 0.90
LELongFieldClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…