
A simple C-based vulnerability in Webmin versions 1.890 to 1.920
ntroduction:
The Webmin Exploit is a targeted exploit for the Webmin service, which can be exploited on older versions of Webmin. This exploit uses various techniques to execute malicious code and gain unauthorized access to the target system.
It involves:
Using both C and Assembly code to execute commands on the target system.
Leveraging techniques like anti-debugging, XOR decryption, and syscalls such as execve and prctl to spawn a reverse shell.
Features: Anti-debugging: Uses the ptrace system call to prevent debugging of the exploit.
XOR decryption: Decodes encrypted strings like kthreadd and /bin/sh in-memory using XOR encryption.
prctl syscall: Changes the process name to kthreadd to hide the exploit from the process list.
execve syscall: Executes the /bin/sh reverse shell on the target system to gain full system access.
Combination of C and Assembly: This exploit blends C's flexibility with the power of assembly language for custom system calls.
Requirements: Operating System: Linux or any Unix-based distribution.
Required Libraries:
libcurl for establishing connections between the client and the server.
GCC for compiling the exploit.
The -lcurl library to load the curl library in C.
How to Use: Setting up the Environment: Ensure you have root privileges as some actions, like execve, require elevated permissions.
Install the required libraries:
sudo apt-get install libcurl4-openssl-dev
Compiling the Exploit: Download the webmin_exploit.c file to your machine.
Compile the exploit code using GCC with the -no-pie option to disable PIE (Position Independent Executable):
gcc -no-pie webmin_exploit.c -o webExploit -lcurl
Note: If you face issues related to PIE, make sure to use -no-pie as shown above.
Running the Exploit: Configure the exploit settings: Modify the target URL, LHOST (local host), and LPORT (local port) in the code as necessary.
Execute the exploit: After compiling, run the exploit on the target machine:
./webExploit Receiving the Reverse Shell:
Once the exploit executes successfully, it should establish a reverse shell connection to your LHOST and LPORT (e.g., 192.168.0.174:4444).
Make sure you are listening on the specified port using Netcat or a similar tool:
nc -lvnp 4444
Technical Breakdown: Key Instructions in the Code: Anti-debugging: The ptrace system call is used to prevent the exploit from being debugged by tools like gdb. This makes it harder for analysts to reverse-engineer the exploit.
XOR Decryption: The strings kthreadd and /bin/sh are XOR-encrypted in the binary with the key 0x41 (ASCII 'A'). These strings are decrypted at runtime in memory.
Syscalls:
prctl(PR_SET_NAME, "kthreadd"): Changes the process name to kthreadd, helping the exploit avoid detection.
execve("/bin/sh"): Executes a reverse shell to /bin/sh, giving the attacker full access to the system.
Core Instructions: mov: Loads values into registers.
xor: Performs an XOR operation on the data.
syscall: Executes system calls such as execve and prctl for shell spawning and process renaming.
lea: Loads an address into a register.
Troubleshooting: If you encounter issues during compilation, double-check that you are using the -no-pie flag to disable Position Independent Executables (PIE).
If problems persist, ensure your development environment is up to date with the necessary libraries.
Warnings: Only use this exploit in testing environments. Never run this exploit on live systems or systems you do not have explicit permission to test.
Disable firewalls on the target machine if needed, to ensure that the reverse shell can connect successfully.
Ensure that you are listening on the port using Netcat or a similar tool to catch the reverse shell connection.