<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Kernel on Arzedlab 🪵</title><link>https://arzedlab.github.io/tags/kernel/</link><description>Recent content in Kernel on Arzedlab 🪵</description><generator>Hugo</generator><language>en-us</language><copyright>© Ravshan</copyright><lastBuildDate>Thu, 05 Jun 2025 00:00:00 +0000</lastBuildDate><atom:link href="https://arzedlab.github.io/tags/kernel/index.xml" rel="self" type="application/rss+xml"/><item><title>Linux Kernel Exploitation Part 1: ret2usr</title><link>https://arzedlab.github.io/posts/kernel-exploitation-ret2usr-part-1-2063648c0bf4802299a9f392ff3c809b/</link><pubDate>Thu, 05 Jun 2025 00:00:00 +0000</pubDate><guid>https://arzedlab.github.io/posts/kernel-exploitation-ret2usr-part-1-2063648c0bf4802299a9f392ff3c809b/</guid><description>&lt;h1 id="kernel-exploitation-ret2usr-part-1">Kernel Exploitation ret2usr Part 1&lt;/h1>
&lt;p>&lt;strong>&lt;code>compress.sh&lt;/code> - To extract compressed image from linux&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ff79c6">#!/bin/sh
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ff79c6">&lt;/span>gcc -o exploit -static &lt;span style="color:#8be9fd;font-style:italic">$1&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>mv ./exploit ./initramfs
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#8be9fd;font-style:italic">cd&lt;/span> initramfs
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>find . -print0 &lt;span style="color:#f1fa8c">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f1fa8c">&lt;/span>| cpio --null -ov --format&lt;span style="color:#ff79c6">=&lt;/span>newc &lt;span style="color:#f1fa8c">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f1fa8c">&lt;/span>| gzip -9 &amp;gt; initramfs.cpio.gz
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>mv ./initramfs.cpio.gz ../
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>&lt;code>run.sh&lt;/code> - Run qemu configuration&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ff79c6">#!/bin/sh
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#ff79c6">&lt;/span>qemu-system-x86_64 &lt;span style="color:#f1fa8c">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f1fa8c">&lt;/span> -s &lt;span style="color:#f1fa8c">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f1fa8c">&lt;/span> -m 128M &lt;span style="color:#f1fa8c">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f1fa8c">&lt;/span> -cpu kvm64,+smep,+smap &lt;span style="color:#f1fa8c">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f1fa8c">&lt;/span> -kernel vmlinuz &lt;span style="color:#f1fa8c">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f1fa8c">&lt;/span> -initrd initramfs.cpio.gz &lt;span style="color:#f1fa8c">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f1fa8c">&lt;/span> -hdb flag.txt &lt;span style="color:#f1fa8c">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f1fa8c">&lt;/span> -snapshot &lt;span style="color:#f1fa8c">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f1fa8c">&lt;/span> -nographic &lt;span style="color:#f1fa8c">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f1fa8c">&lt;/span> -monitor /dev/null &lt;span style="color:#f1fa8c">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f1fa8c">&lt;/span> -no-reboot &lt;span style="color:#f1fa8c">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f1fa8c">&lt;/span> -append &lt;span style="color:#f1fa8c">&amp;#34;console=ttyS0 quiet panic=1 nosmep nosmap nopti nokaslr&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>As you can see all security mitigations are turned off. &lt;code>-s&lt;/code> flag set for debugging the linux kernel.&lt;/p></description></item><item><title>Linux Kernel Exploitation Part 2: Adding Mitigitions</title><link>https://arzedlab.github.io/posts/kernel-2-adding-mitigitions-2063648c0bf4808c81cec3f938783649/</link><pubDate>Thu, 05 Jun 2025 00:00:00 +0000</pubDate><guid>https://arzedlab.github.io/posts/kernel-2-adding-mitigitions-2063648c0bf4808c81cec3f938783649/</guid><description>&lt;h1 id="kernel-2-adding-mitigitions">Kernel 2: Adding Mitigitions&lt;/h1>
&lt;h2 id="adding-smep">&lt;strong>Adding SMEP&lt;/strong>&lt;/h2>
&lt;p>&lt;code>SMEP&lt;/code>, abbreviated for &lt;a href="https://web.archive.org/web/20160803075007/https://www.ncsi.com/nsatc11/presentations/wednesday/emerging_technologies/fischer.pdf">Supervisor mode execution protection (SMEP)&lt;/a>, is a feature that marks all the userland pages in the page table as non-executable when the process is exectuting in &lt;code>kernel-mode&lt;/code>. In the kernel, this is enabled by setting the &lt;code>20th bit&lt;/code> of Control Register &lt;code>CR4&lt;/code>.&lt;/p>
&lt;p>&lt;img src="image.png" alt="image.png">&lt;/p>
&lt;p>&lt;img src="image%201.png" alt="image.png">&lt;/p>
&lt;h3 id="check-its-in-gdb">Check it&amp;rsquo;s in gdb&lt;/h3>
&lt;p>Run the qemu with &lt;code>-s&lt;/code> and on qemu boot, it can be enabled by adding &lt;code>+smep&lt;/code> to &lt;code>-cpu&lt;/code>, and disabled by adding &lt;code>nosmep&lt;/code> to &lt;code>-append&lt;/code>.&lt;/p></description></item></channel></rss>