def from_buffer(buff): msg = NEGOTIATE_REPLY() msg.StructureSize = int.from_bytes(buff.read(2), byteorder='little', signed = False) assert msg.StructureSize == 65 msg.SecurityMode = NegotiateSecurityMode(int.from_bytes(buff.read(2), byteorder='little', signed = False)) msg.DialectRevision = NegotiateDialects(int.from_bytes(buff.read(2), byteorder='little', signed = False)) msg.NegotiateContextCount = int.from_bytes(buff.read(2), byteorder='little', signed = False) msg.ServerGuid = GUID.from_bytes(buff.read(16)) msg.Capabilities = NegotiateCapabilities(int.from_bytes(buff.read(4), byteorder='little', signed = False)) msg.MaxTransactSize = int.from_bytes(buff.read(4), byteorder='little', signed = False) msg.MaxReadSize = int.from_bytes(buff.read(4), byteorder='little', signed = False) msg.MaxWriteSize = int.from_bytes(buff.read(4), byteorder='little', signed = False) msg.SystemTime = timestamp2datetime(buff.read(8)) msg.ServerStartTime = timestamp2datetime(buff.read(8)) msg.SecurityBufferOffset = int.from_bytes(buff.read(2), byteorder='little', signed = False) msg.SecurityBufferLength = int.from_bytes(buff.read(2), byteorder='little', signed = False) msg.NegotiateContextOffset = int.from_bytes(buff.read(4), byteorder='little', signed = False) pos = buff.tell() if msg.SecurityBufferLength != 0: buff.seek(msg.SecurityBufferOffset, io.SEEK_SET) msg.Buffer = buff.read(msg.SecurityBufferLength) pos_buff_end = buff.tell() if msg.DialectRevision == NegotiateDialects.SMB311: msg.NegotiateContextList = [] buff.seek(msg.NegotiateContextOffset, io.SEEK_SET) for _ in range(msg.NegotiateContextCount): msg.NegotiateContextList.append(SMB2NegotiateContext.from_buffer(buff)) padsize = ((8 - buff.tell()) % 8) buff.seek(padsize, io.SEEK_CUR) return msg
def from_buffer(buff): cmd = NEGOTIATE_REQ() cmd.StructureSize = int.from_bytes(buff.read(2), byteorder='little', signed=False) assert cmd.StructureSize == 36 cmd.DialectCount = int.from_bytes(buff.read(2), byteorder='little', signed=False) assert cmd.DialectCount > 0 cmd.SecurityMode = NegotiateSecurityMode( int.from_bytes(buff.read(2), byteorder='little', signed=False)) cmd.Reserved = buff.read(2) cmd.Capabilities = NegotiateCapabilities( int.from_bytes(buff.read(4), byteorder='little', signed=False)) cmd.ClientGuid = GUID.from_buffer(buff) # skipping the next field because it's interpretation depends on the data after it... pos = buff.tell() buff.seek(8, io.SEEK_CUR) cmd.Dialects = [] for i in range(0, cmd.DialectCount): cmd.Dialects.append( NegotiateDialects( int.from_bytes(buff.read(2), byteorder='little', signed=False))) pos_buff_end = buff.tell() buff.seek(pos, io.SEEK_SET) if NegotiateDialects.SMB311 in cmd.Dialects: cmd.NegotiateContextOffset = int.from_bytes(buff.read(4), byteorder='little', signed=False) cmd.NegotiateContextCount = int.from_bytes(buff.read(2), byteorder='little', signed=False) cmd.Reserved2 = int.from_bytes(buff.read(2), byteorder='little', signed=False) cmd.NegotiateContextList = [] buff.seek(cmd.NegotiateContextOffset, io.SEEK_SET) for i in range(0, cmd.NegotiateContextCount): cmd.NegotiateContextList.append( SMB2NegotiateContext.from_buffer(buff)) pad_pos = buff.tell() #aligning buffer, because the next data must be on 8-byte aligned position q, m = divmod(pad_pos, 8) if m != 0: buff.seek((q + 1) * 8, io.SEEK_SET) else: cmd.ClientStartTime = int.from_bytes(buff.read(8), byteorder='little', signed=False) buff.seek(pos_buff_end, io.SEEK_SET) return cmd
def from_buffer(buff): res = VALIDATE_NEGOTIATE_INFO_REPLY() res.Capabilities = NegotiateCapabilities(int.from_bytes(buff.read(4), byteorder='little')) res.Guid = buff.read(16) res.SecurityMode = NegotiateSecurityMode(int.from_bytes(buff.read(2), byteorder='little')) res.Dialect = NegotiateDialects(int.from_bytes(buff.read(2), byteorder='little')) return res
def from_buffer(buff): res = VALIDATE_NEGOTIATE_INFO_REQ() res.Capabilities = NegotiateCapabilities(int.from_bytes(buff.read(4), byteorder='little')) res.Guid = buff.read(16) res.SecurityMode = NegotiateSecurityMode(int.from_bytes(buff.read(2), byteorder='little')) res.DialectCount = int.from_bytes(buff.read(2), byteorder='little') for _ in range(res.DialectCount): res.Dialects.append(NegotiateDialects(int.from_bytes(buff.read(2), byteorder='little'))) return res