Rootkit Analysis & Exploitation Write-up
Introduction
Malicious actors have infiltrated our systems and implanted a custom rootkit. Our goal is to disarm the rootkit, remove it, and retrieve the hidden data. Below is a step-by-step analysis and exploitation process.
Step 1: Unzip and Analyze the File
Extract the challenge folder:
unzip challenge.zip -d challengeLoad the file into Detect It Easy (DIE) to analyze its type.
Identify the file as an ELF binary, which is typical for Linux kernel modules.
Step 2: Reverse Engineer the Binary
Load the file into Binary Ninja for further analysis.
Identify the file as Diamorphine, a well-known Linux rootkit.
Conduct a quick Google search, leading to its GitHub repository: https://github.com/m0nad/Diamorphine
Step 3: Understanding Rootkit Behavior
Observations from the README (Uninstall Instructions)
The module starts hidden.
To make it visible, we need to use:
kill -63 0Once visible, we can remove it with:
rmmod diamorphine
Step 4: Attempting to Remove the Rootkit
Connect to the system using Netcat:
nc -nv <target-ip> <port>Attempt kill -63 0 to make the module visible.
System crashes (Kernel Panic) - indicating a potential modification of the original Diamorphine code.
Step 5: Finding the Modified Kill Switch
Return to Binary Ninja and search for cmp instructions in hacked_kill().
Notice multiple cmp instructions:
cmp eax, 0x3F (Original kill -63 for visibility toggle)
cmp eax, 0x40 (Modified code, corresponds to kill -64 for root access)
cmp eax, 0x2E (New visibility toggle, corresponds to kill -46)
Testing kill -64 0 gives root access, confirming the attacker modified the rootkit to require a different code.
Step 6: Removing the Rootkit
Gain root access:
kill -64 0
whoami # Should return "root"Make the rootkit visible:
kill -46 0Remove the rootkit:
rmmod diamorphineConfirm its removal:
lsmod | grep diamorphine # Should return nothing
Step 7: Finding the Hidden Data
Since this is a Hack The Box (HTB) challenge, the flag is likely stored in a .txt file.
Search the system for .txt files:
find / -type f -name "*.txt" 2>/dev/nullRetrieve the flag:
cat /path/to/flag.txt
Conclusion
By reverse-engineering the modified Diamorphine rootkit, we:
Discovered the attacker modified the kill switch to kill -64 (original was kill -63).
Identified the new visibility toggle as kill -46 (original was kill -63).
Successfully removed the rootkit after making it visible.
Recovered the hidden flag from a .txt file.
This challenge demonstrated the importance of understanding malware modifications and how attackers may tweak known exploits to evade detection.