Post Exploitation

Cover Your Tracks & Remain Undetected

Clear History

Clear Logs

Persistence

.bashrc

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.

Cron

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.

PHP

1. Create a Payload

Create a php file (e.g. shell.php) into /var/www/html.

Navigate to the file

SSH

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.

1. Generate a New SSH key

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).

2. On the target host add you public IP

Systemd

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.

1. Create a New Systemd Config 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.

2. Wait for Reverse Connecting

We need to leave the netcat listener running in local machine.

Then we'll get a shell anytime the service starts.

XDG Autostart

Reference: TryHackMe

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:

Option: Firewall Bypass

If the target system applies firewall for preventing communications with external systems, we may bypass the settings by manipulating them. It requires root privilege.

Last updated