Cracking Linux Privilege Escalation: A Guide to Kernel Exploitation

Maruf Farhan Rigan
4 min readApr 27, 2024

--

The kernel is the core component of an operating system that manages system resources, facilitates communication between hardware and software components, and provides essential services for running applications. It acts as a bridge between the hardware and the software layers of the system, overseeing tasks such as memory management, process scheduling, file system access, and device input and output.

  1. Compromising Data Integrity: The attacker can modify, delete, or exfiltrate sensitive data stored on the system, leading to data breaches, loss of intellectual property, or financial damage.
  2. Disrupting System Functionality: By manipulating critical system resources and processes, the attacker can disrupt the normal operation of the system, causing denial of service (DoS) conditions, system crashes, or instability.
  3. Installing Malware: The attacker can install and execute malicious software, such as backdoors, rootkits, or remote access trojans (RATs), to maintain persistent access to the compromised system and facilitate further attacks.
  4. Escalating Privileges: Kernel exploits often lead to privilege escalation, allowing the attacker to gain root or administrator-level access to the system, thereby bypassing security controls and gaining complete control over the system.
  5. Pivoting to Other Systems: Once access is gained to a compromised system, the attacker may pivot to other systems within the network, using the compromised system as a foothold for launching additional attacks.

In this article, I will demonstrate how to get the kernel version once you get access to the target system and how you can exploit it to get into the system.

Task:

Welcome to the Kernel Exploitation Challenge! Your objective is to gain root privileges on the target machine by exploiting a vulnerability in the Linux kernel. Follow these steps to complete the challenge:

  1. Access the Target Machine:
  2. get the hostname and kernel version of the system
  3. Identify the kernel version.
  4. search for exploit code
  5. get the privilege escalation of the target machine and get the flag1.txt

Practical work

  1. So at first, when accessing the target machine,
  • Launched the target machine attached to the challenge.
  • Access the target machine directly from the browser or via SSH using the provided low-privilege user credentials (username: Karen, password: Password).

2. Identifying the Kernel Version:

Used the uname -a command to identify the kernel version of the target system (e.g., Linux 4.15.0-55-generic).

3. Searching for Exploit Code: Utilise search engines and exploit databases to find exploit code suitable for the identified kernel version. we found the CVE from the exploit database (see screenshot above)

4. Transferring and Executing the Exploit Code: In here, we have used the scp command and /home/kali/, where we have downloaded the exploit from the exploit database, and in the target machine, we use the tmp folder, where we will transfer the file.

We will go to the c:/tmp folder and compile the exploit code on the target machine using the cc command (e.g., cc -o exploit 37292.c).

Now our task is to execute the compiled exploit code on the target machine to exploit the vulnerability in the kernel (e.g., ./exploit1).

Evaluating the success of the exploit and confirming its effectiveness typically involves several steps to ensure that the exploit has achieved its intended outcome. Here’s how you can verify successful exploitation and confirm the effectiveness of the exploit:

Check for Elevated Privileges: After running the exploit code, check whether you have gained elevated privileges, such as root access, on the target machine.

  • You can do this by running commands that require elevated privileges, such as viewing sensitive system files (/etc/passwd,/etc/shadow) or executing commands that are restricted to privileged users.

Now let's check whether there are any flags or not. To find any.txt, the command is (find. -name flag1.exe). In the below screenshot, it is showing /home/matt/flag1.txt. so lets go and grab it

Here are the mitigations for kernel exploits presented in bullet point format:

  • Regular Patching and Updates:
  • Least Privilege Principle:
  • Kernel Hardening Techniques:
  • Use of Runtime Security Mechanisms:
  • Robust logging and monitoring:
  • Regular security audits and assessments:
  • Security Training and Awareness:

--

--

Maruf Farhan Rigan
Maruf Farhan Rigan

Written by Maruf Farhan Rigan

MSc in Cybersecurity| RA & Published Author Blockchain| Comptia Security+ Certified| | Blockchain Fan | Cybersecurity Blogger | Tech Support @ Kaspersky Lab