from impacket.structure import Structure
class SMB2Header(Structure):
structure = (
('ProtocolId', '4s="\xfeSMB"'),
('StructureSize', '<H=64'),
('CreditCharge', '<H=0'),
('Status', '<I=0'),
('Command', '<H=0'),
('CreditRequest', '<H=0'),
('Flags', '<I=0'),
('NextCommand', '<I=0'),
('MessageId', '<Q=0'),
('Reserved', '<I=0'),
('TreeId', '<I=0'),
('SessionId', '<Q=0'),
('Signature', '16s="\x00" * 16'),
)
class SMB2NegotiateRequest(Structure):
structure = (
('StructureSize', '<H=36'),
('DialectCount', '<H-Dialects'),
('SecurityMode', '<H=0'),
('Reserved', '<H=0'),
('Capabilities', '<I=0'),
('ClientGuid', '16s="\x00" * 16'),
('NegotiateContextOffset', '<I=0'),
('NegotiateContextCount', '<H=0'),
('Reserved2', '<H=0'),
('Dialects', '<H*DialectCount'),
)
# Create SMB2 NEGOTIATE packet
header = SMB2Header()
header['Command'] = 0 # SMB2_NEGOTIATE
header['MessageId'] = 1
negotiate = SMB2NegotiateRequest()
negotiate['Dialects'] = [0x0202, 0x0210, 0x0300, 0x0302, 0x0311] # SMB 2.0.2, 2.1, 3.0, 3.0.2, 3.1.1
negotiate['SecurityMode'] = 1 # Signing enabled
packet = header.getData() + negotiate.getData()