def test_create_message(self): sid1 = SIDPacket() sid1.from_string("S-1-1-0") sid2 = SIDPacket() sid2.from_string("S-1-5-21-3242954042-3778974373-1659123385-1104") ace1 = AccessAllowedAce() ace1['mask'] = 2032127 ace1['sid'] = sid1 ace2 = AccessAllowedAce() ace2['mask'] = 2032127 ace2['sid'] = sid2 # define an illegal ACE for tests to see if it is flexible for custom # aces' ace3 = AccessAllowedAce() ace3['ace_type'] = AceType.ACCESS_ALLOWED_OBJECT_ACE_TYPE ace3['sid'] = sid1 message = AclPacket() message['aces'] = [ace1, ace2, ace3.pack()] expected = b"\x02" \ b"\x00" \ b"\x54\x00" \ b"\x03\x00" \ b"\x00\x00" \ b"\x00" \ b"\x00" \ b"\x14\x00" \ b"\xff\x01\x1f\x00" \ b"\x01" \ b"\x01" \ b"\x00\x00" \ b"\x00\x00\x00\x01" \ b"\x00\x00\x00\x00" \ b"\x00" \ b"\x00" \ b"\x24\x00" \ b"\xff\x01\x1f\x00" \ b"\x01" \ b"\x05" \ b"\x00\x00" \ b"\x00\x00\x00\x05" \ b"\x15\x00\x00\x00" \ b"\x3a\x8d\x4b\xc1" \ b"\xa5\x92\x3e\xe1" \ b"\xb9\x36\xe4\x62" \ b"\x50\x04\x00\x00" \ b"\x05" \ b"\x00" \ b"\x14\x00" \ b"\x00\x00\x00\x00" \ b"\x01" \ b"\x01" \ b"\x00\x00" \ b"\x00\x00\x00\x01" \ b"\x00\x00\x00\x00" actual = message.pack() assert len(message) == 84 assert actual == expected
def open_file(cls, tree, file): file = cls.normalize_filename(file) # ensure file is created, get maximal access, and set everybody read access max_req = SMB2CreateContextRequest() max_req[ "buffer_name"] = CreateContextName.SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST max_req["buffer_data"] = SMB2CreateQueryMaximalAccessRequest() # create security buffer that sets the ACL for everyone to have read access everyone_sid = SIDPacket() everyone_sid.from_string("S-1-1-0") ace = AccessAllowedAce() ace["mask"] = AccessMask.GENERIC_ALL ace["sid"] = everyone_sid acl = AclPacket() acl["aces"] = [ace] sec_desc = SMB2CreateSDBuffer() sec_desc["control"].set_flag(SDControl.SELF_RELATIVE) sec_desc.set_dacl(acl) sd_buffer = SMB2CreateContextRequest() sd_buffer["buffer_name"] = CreateContextName.SMB2_CREATE_SD_BUFFER sd_buffer["buffer_data"] = sec_desc create_contexts = [max_req, sd_buffer] file_open = Open(tree, file) open_info = file_open.create( ImpersonationLevel.Impersonation, FilePipePrinterAccessMask.GENERIC_READ | FilePipePrinterAccessMask.GENERIC_WRITE, FileAttributes.FILE_ATTRIBUTE_NORMAL, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE, CreateDisposition.FILE_OVERWRITE_IF, CreateOptions.FILE_NON_DIRECTORY_FILE, ) return file_open
def test_create_message(self): sid = SIDPacket() sid.from_string("S-1-1-0") message = AccessAllowedAce() message['mask'] = 2032127 message['sid'] = sid expected = b"\x00" \ b"\x00" \ b"\x14\x00" \ b"\xff\x01\x1f\x00" \ b"\x01" \ b"\x01" \ b"\x00\x00" \ b"\x00\x00\x00\x01" \ b"\x00\x00\x00\x00" actual = message.pack() assert len(message) == 20 assert actual == expected
def test_parse_message(self): actual = AccessAllowedAce() data = b"\x00" \ b"\x00" \ b"\x14\x00" \ b"\xff\x01\x1f\x00" \ b"\x01" \ b"\x01" \ b"\x00\x00" \ b"\x00\x00\x00\x01" \ b"\x00\x00\x00\x00" data = actual.unpack(data) assert len(actual) == 20 assert data == b"" assert actual['ace_type'].get_value() == \ AceType.ACCESS_ALLOWED_ACE_TYPE assert actual['ace_flags'].get_value() == 0 assert actual['ace_size'].get_value() == 20 assert actual['mask'].get_value() == 2032127 assert str(actual['sid'].get_value()) == "S-1-1-0"
def test_create_message_sacl_group(self): sid = SIDPacket() sid.from_string("S-1-1-0") ace = AccessAllowedAce() ace['sid'] = sid acl = AclPacket() acl['aces'] = [ace] message = SMB2CreateSDBuffer() message.set_dacl(None) message.set_owner(None) message.set_group(sid) message.set_sacl(acl) expected = b"\x01" \ b"\x00" \ b"\x10\x00" \ b"\x00\x00\x00\x00" \ b"\x14\x00\x00\x00" \ b"\x20\x00\x00\x00" \ b"\x00\x00\x00\x00" \ b"\x01" \ b"\x01" \ b"\x00\x00" \ b"\x00\x00\x00\x01" \ b"\x00\x00\x00\x00" \ b"\x02" \ b"\x00" \ b"\x1c\x00" \ b"\x01\x00" \ b"\x00\x00" \ b"\x00" \ b"\x00" \ b"\x14\x00" \ b"\x00\x00\x00\x00" \ b"\x01" \ b"\x01" \ b"\x00\x00" \ b"\x00\x00\x00\x01" \ b"\x00\x00\x00\x00" actual = message.pack() assert len(message) == 60 assert actual == expected
def test_create_message(self): sid1 = SIDPacket() sid1.from_string("S-1-1-0") sid2 = SIDPacket() sid2.from_string("S-1-5-21-3242954042-3778974373-1659123385-1104") ace1 = AccessAllowedAce() ace1['mask'] = 2032127 ace1['sid'] = sid1 ace2 = AccessAllowedAce() ace2['mask'] = 2032127 ace2['sid'] = sid2 acl = AclPacket() acl['aces'] = [ace1, ace2] message = SMB2CreateSDBuffer() message['control'].set_flag(SDControl.SELF_RELATIVE) message.set_dacl(acl) message.set_owner(sid2) message.set_group(sid1) message.set_sacl(None) expected = b"\x01" \ b"\x00" \ b"\x04\x80" \ b"\x54\x00\x00\x00" \ b"\x70\x00\x00\x00" \ b"\x00\x00\x00\x00" \ b"\x14\x00\x00\x00" \ b"\x02" \ b"\x00" \ b"\x40\x00" \ b"\x02\x00" \ b"\x00\x00" \ b"\x00" \ b"\x00" \ b"\x14\x00" \ b"\xff\x01\x1f\x00" \ b"\x01" \ b"\x01" \ b"\x00\x00" \ b"\x00\x00\x00\x01" \ b"\x00\x00\x00\x00" \ b"\x00" \ b"\x00" \ b"\x24\x00" \ b"\xff\x01\x1f\x00" \ b"\x01" \ b"\x05" \ b"\x00\x00" \ b"\x00\x00\x00\x05" \ b"\x15\x00\x00\x00" \ b"\x3a\x8d\x4b\xc1" \ b"\xa5\x92\x3e\xe1" \ b"\xb9\x36\xe4\x62" \ b"\x50\x04\x00\x00" \ b"\x01\x05" \ b"\x00\x00" \ b"\x00\x00\x00\x05" \ b"\x15\x00\x00\x00" \ b"\x3a\x8d\x4b\xc1" \ b"\xa5\x92\x3e\xe1" \ b"\xb9\x36\xe4\x62" \ b"\x50\x04\x00\x00" \ b"\x01" \ b"\x01" \ b"\x00\x00" \ b"\x00\x00\x00\x01" \ b"\x00\x00\x00\x00" actual = message.pack() assert len(message) == 124 assert actual == expected
session = Session(connection, username, password) session.connect() tree = TreeConnect(session, share) tree.connect() # ensure file is created, get maximal access, and set everybody read access max_req = SMB2CreateContextRequest() max_req['buffer_name'] = \ CreateContextName.SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST max_req['buffer_data'] = SMB2CreateQueryMaximalAccessRequest() # create security buffer that sets the ACL for everyone to have read access everyone_sid = SIDPacket() everyone_sid.from_string("S-1-1-0") ace = AccessAllowedAce() ace['mask'] = AccessMask.GENERIC_ALL ace['sid'] = everyone_sid acl = AclPacket() acl['aces'] = [ace] sec_desc = SMB2CreateSDBuffer() sec_desc['control'].set_flag(SDControl.SELF_RELATIVE) sec_desc.set_dacl(acl) sd_buffer = SMB2CreateContextRequest() sd_buffer['buffer_name'] = CreateContextName.SMB2_CREATE_SD_BUFFER sd_buffer['buffer_data'] = sec_desc create_contexts = [max_req, sd_buffer]