By checking whether the bootloader is unlocked or not. If the bootloader is unlocked, then all bets are off, but if the bootloader is locked, you can only run the original, unmodified firmware. Any alternation to the firmware will result in the dm-verity check failing, causing the system to not boot at all. The only data which can be altered is user data, which is wiped in a factory reset. So a factory ressr definitely gets rid of it.
If you're paranoid though, you could always flash the stock firmware downloaded directly from the manufacturer's website, which will override all system partitions, so you can be absolutely sure there's no spyware - besides the spyware included by Google etc of course, or the spyware embedded into the hardware by the chip manufacturers...
None of this will save you. The boot loader can be replaced with one that merely pretends to be locked and merely pretends to flash the replacement operating system it's sent over the USB port.
If the phone has ever been in the custody of someone you don't trust, you can't trust anything about it.
Yes it will. There's no way to bypass it, if there is, that would be a serious security flaw - the kind that would get patched very quickly. There have been some phones which had a vulnerable bootloader that allowed this in the past (eg: OnePlus devices), but there's no such exploit available for current generation devices
I'd like to see some sources backing up your claim, which is applicable to current generation phones.
There’s no way to bypass it, if there is, that would be a serious security flaw
Those do happen, but it is probably also possible to unlock the boot loader and then replace the boot loader itself with one that merely pretends to be locked. How would you know the difference?
the kind that would get patched very quickly.
Obviously criminals aren't going to install security patches for vulnerabilities that they are exploiting.
but it is probably also possible to unlock the boot loader and then replace the boot loader itself with one that merely pretends to be locked. How would you know the difference?
Sure, in theory, but doing that would require advanced knowledge, it's not something a random shady seller on eBay would do. With skills like that, they could easily get a high paying job, or if they really want to be a criminal, a better option would be getting into something like phishing or cryptolocking, which, skills wise, is easier than writing a custom bootloader.
Obviously criminals aren't going to install security patches for vulnerabilities that they are exploiting.
Which is why the first thing you should do is do a factory reset, update the phone, and do another factory reset. Or an even better option would be to just flash the factory firmware downloaded directly from the vendor.
Sure, in theory, but doing that would require advanced knowledge, it’s not something a random shady seller on eBay would do.
No. Writing the code to do that would require advanced knowledge, but once it's written, any common criminal can use it.
With skills like that, they could easily get a high paying job, or if they really want to be a criminal, a better option would be getting into something like phishing or cryptolocking, which, skills wise, is easier than writing a custom bootloader.
They could use the compromised phone they sell you to phish or ransom you.
Which is why the first thing you should do is do a factory reset, update the phone, and do another factory reset. Or an even better option would be to just flash the factory firmware downloaded directly from the vendor.
All of those only work if the software already on the phone allows them to work. Factory resets, updates, and USB flashing are all implemented by software.