Persistence Hunting: Keys, Cron and Services
- Intermediate
- 34 min
- Blue Team
- Forensics
- Persistence
- cron
- SSH
Overview
The morning of 4 November. Customers have been getting SMS messages that use their names and phone numbers. Harpreet Kaur calls it in at 07:15; Simran Gill rolls back the release that went out at 22:47 the night before and, before anything rotates, copies the server's logs to /srv/evidence/var/log (start with cat /srv/evidence/README.md). This machine is that server, kestrel-api-1, exactly as the attacker left it.
An attacker with a shell expects to lose it. Before logging out they leave persistence: a way back that survives a password change and a reboot. The three classics on Linux are an SSH key in authorized_keys, an entry in a crontab, and a service that starts at boot. All three are on this machine, inside the account that was broken into (grep Accepted /srv/evidence/var/log/auth.log names it) and in system directories.
The hard part is not deleting things. It is deleting only the attacker's: the CI runner's key, the account's own scheduled job and the box's real services must keep working, or the cleanup is the next outage.
What you will learn
- Read authorized_keys and tell a legitimate key from an added one
- Edit another account's crontab without losing its real jobs
- Find a systemd unit and the link that enables it, and remove both
- Quarantine a backdoor without destroying the evidence, and read its C2 address
Before you start
- Comfortable in a Linux shell:
grep, pipes and redirecting with> sudofor files another account owns — you have it here
Tasks
- 01The extra key
- 02The crontab line
- 03The service
- 04Quarantine the backdoor