Persistence on Linux

In this article we will describe some post-exploitation techniques allowing us to maintain our access to a Linux box.

Reverse shell

A reverse shell is neither discrete nor elegant, however it allow for quick backdoor access to the box.

Moreover, it does not require the machine to be visible on Internet, which can be useful if it is behind a NAT or a firewall.

Launch a connection to the attack server from our compromised machine:

This one-liner will try to open a shell to every 10 seconds.

We need a listener on the attacking server:

After some time, the shell is executed !

We can then put the reverse shell one-liner in rc.local or bashrc for cross-reboot persistence.

SSH backdoor

If a SSH service is enabled on the compromised host, a simple solution could be to add our public key to the authorized_keys file . We can then connect directly through SSH.

First, generate a SSH keypair on our attacking server:

After which we copy the public key to the compromised host:

We can log in anytime with:

Add user

Another solution could be to add a user. We can then use this user account to log in through SSH, FTP or any system service using local accounts on the machine.

This adds an “admin” user with password “lemmein”.

Persistence on Windows

In this post, we will describe some persistence techniques on Windows boxes.

Registry key

Some registry keys such as Run allow to define programs to start after a reboot.

There are two instances of the Run registry key:

  • HKCU\Software\Microsoft\Windows\CurrentVersion\Run: Programs listed here will start when the current user logs in.
  • HKCU\Software\Microsoft\Windows\CurrentVersion\Run: Programs listed here will start when the computer starts.

The first instance only requires privileges of the current user, however the second one can only be set by users with administration privileges.

Let’s launch C:\Windows\agent.exe on each session start:

System Service

Services are programs started on each boot. They are started by default with maximum privileges (SYSTEM).


Scheduled tasks

Scheduled tasks are executed periodically.

Add user

Adding a Windows user is a simple yet efficient solution to maintain our access. Adding a user requires administration privileges.

Adding a local administrator

Adding a new local administrator “admin” with password “s3crEt”.

The local adminstrators group’s name can change with the system’s language (e.g “Administrateurs” in French).

Adding a domain administrator

If we have domain administration privileges, we can add another domain administrator: