Post Exploitation
Last updated
Last updated
Add this line to /root/.bashrc
or /home/<user>/.bashrc
to gain access to target machine by reverse shell when the victim user logged in.
Add the following line to the cron file like /etc/crontab
in the target machine.
Replace 10.0.0.1
with your ip address.
Host a shell and start you listener
Now start local web server and listener in each terminal in local machine.
Create a php file (e.g. shell.php) into /var/www/html
.
Navigate to the file
We can establish a backdoor to allow us to be able to connect the target SSH server anytime by leaving our public key in the target machine.
First off, run the following command to generate SSH key.
It will generate two keys, private key (id_rsa) and public key (id_rsa.pub).
We can use systemd as a backdoor because an arbitrary command will be executed when a service start.
The command is stored in [Services]
section in the configuration file.
Create /etc/systemd/system/backdoor.service
in target machine.
This service will execute reverse shell when starting.
Then enable the service.
Now this service will start when the target system boots.
We need to leave the netcat listener running in local machine.
Then we'll get a shell anytime the service starts.
Autostart is also used for persistence. First create a $HOME/.config/autostart
directory if it does not exist and create a new file with arbitrary name as below:
Then write a malicious code in this file:
After that, the command at the Exec
field will be executed when the target user logs in.
We need to keep opening a listener in attack machine for receiving incoming connection:
If the target system applies firewall for preventing communications with external systems, we may bypass the settings by manipulating them. It requires root privilege.
Reference: