In some cases, a squatter may gain legal rights to the property through adverse possession, a legal doctrine that allows individuals to claim ownership of land under certain conditions.