![]() |
EpiRootkit
By STDBOOL
|
{#reverse-shell-doc} As part of our project, we implemented a reverse shell using socat to establish an SSL-encrypted connection to the attack server. The choice of socat is motivated by its ability to provide a complete interactive shell, unlike simpler tools like netcat or even simply bash. To ensure the presence of socat on the system, we integrated the binary directly into the rootkit, which allows dropping it dynamically when mounting the rootkit. This requires having a static version of socat that also embeds SSL, dumping this binary into the rootkit to finally be able to use it to establish the reverse shell.
To load the socat binary into the rootkit, we use a script during module compilation. This script extracts the socat binary and converts it into a C character array, which is then integrated into the module's source code.
Uses the statically compiled socat binary embedded in the rootkit module.
Following this, we finally obtain a socat.h file containing the following code:
The socat binary is dropped on the target machine thanks to the drop_socat_binaire(void) function:
This function first checks if the binary has already been dropped, then creates and writes the content of the socat array (containing the binary) to the location defined by SOCAT_BINARY_PATH. It also handles potential errors during writing and ensures that the entire binary is properly written to disk.
Binary obfuscation and discretion By default, the
socatfile dropped on the target machine is renamed with the.sysdextension to add a first layer of obfuscation. Moreover, it's placed in the rootkit's hidden directory, making it practically invisible to a regular user or system administrator. This choice aims to limit detection risks of the binary by analysis tools or during manual file system inspection.
To execute the reverse shell, we use the launch_reverse_shell(char *args) function:
This function first checks that the socat binary has been properly dropped. It then retrieves the port to use (default or passed as argument), builds the reverse shell execution command with socat, then executes it via exec_str_as_command. Errors are handled and a success message is displayed if the shell is launched correctly.
Explanation of the socat command used:
This socat command establishes an SSL connection to the specified IP and port, while redirecting standard input and output to an interactive bash shell. The options used are:
| Option | Description |
|---|---|
exec:bash -i | Executes an interactive shell. |
pty | Allocates a pseudo-terminal for the shell. |
stderr | Redirects errors to standard output. |
setsid | Detaches the process from the terminal. |
sigint | Handles interrupt signals. |
sane | Resets terminal parameters for standard behavior. |
openssl-connect:IP:PORT | Establishes SSL connection to specified IP and port. |
verify=0 | Disables SSL certificate verification (useful for tests, but avoid in production). |
In summary, this command generates a custom shell allowing maximum interactivity and functionality, while being secured by SSL.
To receive the reverse shell connection, the attacker must execute the following command on their server:
Where PORT is the port specified when launching the reverse shell on the victim, and server.pem is the SSL certificate used for the encrypted connection.