def test_verify_message_skip(self, smb_real): connection = Connection(uuid.uuid4(), smb_real[2], smb_real[3], True) connection.connect() try: header = SMB2HeaderResponse() header['message_id'] = 0xFFFFFFFFFFFFFFFF expected = header.pack() connection._verify(header, 0) actual = header.pack() assert actual == expected finally: connection.disconnect()
def test_verify_fail_no_session(self, smb_real): connection = Connection(uuid.uuid4(), smb_real[2], smb_real[3], True) connection.connect() try: header = SMB2HeaderResponse() header['message_id'] = 1 header['flags'].set_flag(Smb2Flags.SMB2_FLAGS_SIGNED) with pytest.raises(SMBException) as exc: connection._verify(header, 100) assert str(exc.value) == "Failed to find session 100 for " \ "message verification" finally: connection.disconnect()
def test_verify_mistmatch(self, smb_real): connection = Connection(uuid.uuid4(), smb_real[2], smb_real[3], True) session = Session(connection, smb_real[0], smb_real[1]) connection.connect() try: session.connect() header = connection.preauth_integrity_hash_value[-2] # just set some random values for verifiation failure header['flags'].set_flag(Smb2Flags.SMB2_FLAGS_SIGNED) header['signature'] = b"\xff" * 16 with pytest.raises(SMBException) as exc: connection._verify(header, header['session_id'].get_value(), verify_session=True) assert "Server message signature could not be verified:" in \ str(exc.value) finally: connection.disconnect(True)