<?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 ryuk on Medium]]></title>
        <description><![CDATA[Stories by ryuk on Medium]]></description>
        <link>https://medium.com/@kos0ng?source=rss-f95ba1cab640------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*RI1lTq0LrLIINEPCF2vnhw.jpeg</url>
            <title>Stories by ryuk on Medium</title>
            <link>https://medium.com/@kos0ng?source=rss-f95ba1cab640------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 15:58:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kos0ng/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[Reverse Engineering — DarkCON CTF 2021]]></title>
            <link>https://kos0ng.medium.com/reverse-engineering-darkcon-ctf-2021-a8060717b1e3?source=rss-f95ba1cab640------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8060717b1e3</guid>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[frida]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[cryptography]]></category>
            <dc:creator><![CDATA[ryuk]]></dc:creator>
            <pubDate>Mon, 22 Feb 2021 05:29:56 GMT</pubDate>
            <atom:updated>2022-08-10T14:22:49.212Z</atom:updated>
            <content:encoded><![CDATA[<h3>Reverse Engineering — DarkCON CTF 2021</h3><p>darkCON CTF is a CTF event organized by dark army. Yesterday I only worked on the reverse engineering and cryptography category because the other categories were done by my team and here is all reverse engineering write up.</p><h3>Read</h3><p>Given a pyc file then i just try to decompile it using uncompyle6.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VNefAmfzCb59Kc6Dm6ptWg.png" /></figure><p>The script looks obfuscated but it is still readable. There is one interesting function and here is the code</p><pre>def lababa(lebula):<br>    alalalalalalal = [<br>     73, 13, 19, 88, 88, 2, 77, 26, 95, 85, 11, 23, 114, 2, 93, 54, 71, 67, 90, 8, 77, 26, 0, 3, 93, 68]<br>    result = &#39;&#39;<br>    for belu in range(len(alalalalalalal)):<br>        if lebula[belu] != chr(alalalalalalal[belu] ^ ord(babababa[belu])):<br>            return &#39;bbblalaabalaabbblala&#39;<br>        b2a = &#39;&#39;<br>        a2b = [122, 86, 75, 75, 92, 90, 77, 24, 24, 24, 25, 106, 76, 91, 84, 80, 77, 25, 77, 81, 92, 25, 92, 87, 77, 80, 75, 92, 25, 74, 77, 75, 80, 87, 94, 25, 88, 74, 25, 95, 85, 88, 94]<br>        for bbb in a2b:<br>            b2a += chr(bbb ^ 57)<br>        else:<br>            return b2a</pre><p>It seems like checking function and then return something whether the check function is true or false. So i try to reconstruct the code to showing the return value and checking value</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd8e7b69635842ba8482136759962ab4/href">https://medium.com/media/dd8e7b69635842ba8482136759962ab4/href</a></iframe><p>Flag : darkCON{0bfu5c4710ns_v5_4n1m4710ns}</p><h3>Too Much</h3><p>Given ELF 64-bit executable and then i try to decompile it using IDA</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*nQfu_qWk9RNo6QZ9yV0CfA.png" /></figure><p>It has many function but all functions are identical. The difference is the variables and constant value. So we can get all value and generate the code then get the flag.</p><p>Get value using gdb scripting</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4929193f1270305dd30b3cf1fa1e53fe/href">https://medium.com/media/4929193f1270305dd30b3cf1fa1e53fe/href</a></iframe><p>Generate the comparison algorithm and get the value using z3</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e52c77b6b63f5baaf3297372c6a65f2d/href">https://medium.com/media/e52c77b6b63f5baaf3297372c6a65f2d/href</a></iframe><p>Flag : darkCON{4r3_y0u_r34lly_th1nk1n9_th4t_y0u_c4n_try_th15_m4nu4lly???_Ok_I_th1nk_y0u_b3tt3r_us3_s0m3_aut0m4t3d_t00ls_l1k3_4n9r_0r_Z3_t0_m4k3_y0ur_l1f3_much_e4s13r.C0ngr4ts_f0r_s0lv1in9_th3_e4sy_ch4ll3ng3}</p><h3>ezpz</h3><p>Given apk file and then i try to decompile the apk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*k3LO1qhqUxEj-bcts-qOYQ.png" /></figure><p>Looking at MainActivity class we know that there is flag checking in YEET[0].equals(MainActivity.<strong>this</strong>.button.getText().toString()). So the idea is make the application showing flag instead of “Damn…500 times? are u kidding me” with patching the counter and change the string to be shown.</p><pre><strong>Original ( MainActivity$1.smali )</strong><br>const/16 v3, 0x1f4</pre><pre><strong>Patched ( MainActivity$1.smali )</strong><br>const/16 v3, 0x0</pre><pre><strong>Original ( MainActivity$1.smali )</strong><br>.line 50<br>:cond_1</pre><pre>iget-object v1, p0, Lcom/application/ezpz/MainActivity$1;-&gt;this$0:Lcom/application/ezpz/MainActivity;</pre><pre>invoke-virtual {v1}, Lcom/application/ezpz/MainActivity;-&gt;getApplicationContext()Landroid/content/Context;</pre><pre>move-result-object v1</pre><pre>const-string v3, &quot;Damn...500 times? are u kidding me&quot;</pre><pre>invoke-static {v1, v3, v2}, Landroid/widget/Toast;-&gt;makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;</pre><pre>move-result-object v1</pre><pre>invoke-virtual {v1}, Landroid/widget/Toast;-&gt;show()V</pre><pre>goto :goto_0</pre><pre><strong>Patched ( MainActivity$1.smali )</strong><br>.line 50</pre><pre>:cond_1</pre><pre>iget-object v1, p0, Lcom/application/ezpz/MainActivity$1;-&gt;this$0:Lcom/application/ezpz/MainActivity;</pre><pre>invoke-virtual {v1}, Lcom/application/ezpz/MainActivity;-&gt;getApplicationContext()Landroid/content/Context;</pre><pre>move-result-object v1</pre><pre>iget-object v3, p0, Lcom/application/ezpz/MainActivity$1;-&gt;val$YEET:[Ljava/lang/String;</pre><pre>aget-object v3, v3, v2</pre><pre>invoke-static {v1, v3, v2}, Landroid/widget/Toast;-&gt;makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;</pre><pre>move-result-object v1</pre><pre>invoke-virtual {v1}, Landroid/widget/Toast;-&gt;show()V</pre><pre>goto :goto_0</pre><p>And then we will get the flag when click “CLICK ME” button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*jbz7toYNViA-mhq_02c5HQ.png" /></figure><h3>CyberDark0x01: ShitComp</h3><p>Given ELF 64-bit and then i try to decompile it using IDA</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*rsWCuoyJbdclMgQPz-FkRA.png" /><figcaption>sub_1410</figcaption></figure><p>At first the program will compress our file ( as shown image above )</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U31amK1XssNfqb4SoH7oxA.png" /><figcaption>sub_13A0</figcaption></figure><p>And then encrypted the compressed data. So the idea is decrypt the data by brute force the algorithm then uncompress the data by reversing the algorithm.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a4447a21d8ea0bf7ea7a815bb5df7f3/href">https://medium.com/media/9a4447a21d8ea0bf7ea7a815bb5df7f3/href</a></iframe><p>And then by running original ELF we will get the flag</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n5rsWRyDuHs2HB2Z0fe1aw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zHymnQJLCRBP1OIRFUyQBg.png" /></figure><h3>CyberDark_0x02: Installer</h3><p>Now we need to work with the original ELF. So i try to decompile it using IDA</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*ob4D97HkpgobRN0cQwUzBw.png" /><figcaption>sub_1BD0</figcaption></figure><p>We can see there is function that the return value is compared by constant value and determine whether the result is correct key or wrong key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*5n8X3CfUeXan_8J0rrk3IQ.png" /><figcaption>sub_1AB0</figcaption></figure><p>At first the program check the input ( it must uppercase ) and store the input to variable ( except the “-” ).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*9UKaUxRytJd7ZquqF7-DLQ.png" /><figcaption>sub_19A0</figcaption></figure><p>After that it call function that generate values and our input will be the index of that value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*x3AHEpUeOIdHhDuGvxTNTA.png" /><figcaption>sub_1A20</figcaption></figure><p>And the last is checking our input with comparison algorithm that using manipulation of index of array and array. So the idea is reversing the algorithm to generate the key then submit it to server. But i only got 8 correct key ( the other keys are incorrect because there is one character that are not uppercase ) . So for the 2 other keys i brute force one character and then got the correct uppercase character on that position and submit all keys.</p><p>( we can use tmp variable to store the index same as the original code in binary for simplicity )</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35c0ba9539085e28bb8893e0ab2729e1/href">https://medium.com/media/35c0ba9539085e28bb8893e0ab2729e1/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*wiS8tENJoWL1SHQ2FMhOaQ.png" /></figure><h3>(Not) Easy</h3><p>Given PE file and then i try to open it using IDA</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S7KEt3Ta8w3p8V5DC6PEjQ.png" /><figcaption>sub_40189D</figcaption></figure><p>Looking at encryption function it seems like modified xxtea encryption so the idea is reconstruct decrypt function by reversing the encryption algorithm.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/46650c46d0976602e5122f64b56473e2/href">https://medium.com/media/46650c46d0976602e5122f64b56473e2/href</a></iframe><p>Flag : darkCON{4_L177l3_crYp70_4_d4y_m4K3S_R3v3rS3s_g0_4W4Y}</p><h3>fire in the androiddd</h3><p>Given apk file and then i try to decompile it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*X0yHa7-Yk6JodHt1vciIRw.png" /><figcaption>MainActivity</figcaption></figure><p>Looking at MainActivity that we need internet connection to run this application and there are a method called from data_receiver class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*s-Q-bAze_cDBomS7ufU0fw.png" /><figcaption>data_receiver</figcaption></figure><p>From getData method we know that class member ( data ) will store encrypted flag from firebase storage. data_receiver.data will be used in magic function which is called by doInBackground function from nested class ( loader class in MyReceiver class )</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*VAGF6wAaMIzeGBeE2tR-og.png" /><figcaption>MyReceiver</figcaption></figure><p>Magic method is called from native library so we need to decompile that library to know what is magic method do</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*l5txCnHj8-5pIjqwDi2SHA.png" /><figcaption>Java_com_application_darkcon_MyReceiver_magic</figcaption></figure><p>From the code above we know that our input xored with looper(i) and compared with v4 which is encrypted_flag . Here is what looper function do</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*KiZbx49oo3k-6P7Ps1wG6Q.png" /><figcaption>looper</figcaption></figure><p>So the idea is getting the encrypted_flag using frida then run looper function and xor it with encrypted_flag and get the flag. Here is frida script that i used</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d7112c469ba007eba51055ea08bef4c/href">https://medium.com/media/2d7112c469ba007eba51055ea08bef4c/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TaRHvEhhI1EEwHdThA0CIg.png" /></figure><p>After that implemented the looper function</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45d25f038250561c8594534613205b50/href">https://medium.com/media/45d25f038250561c8594534613205b50/href</a></iframe><p>Flag : darkCON{th3_w31rd_c0mb1nat10n_of_fr1da_4nd_c4t4l4n_ov3rf10w}</p><p>Overall the challenges are quite interesting and thank you for reading this writeup!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8060717b1e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writeup Reverse Engineering BSides Delhi CTF 2020]]></title>
            <link>https://kos0ng.medium.com/writeup-reverse-engineering-bsides-delhi-ctf-2020-8a3f8bc92fb?source=rss-f95ba1cab640------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a3f8bc92fb</guid>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <dc:creator><![CDATA[ryuk]]></dc:creator>
            <pubDate>Sun, 11 Oct 2020 00:09:49 GMT</pubDate>
            <atom:updated>2022-08-10T14:14:43.482Z</atom:updated>
            <content:encoded><![CDATA[<h3>Reverse Engineering — BSides Delhi CTF 2020</h3><p>Here i will share writeup for Reverse Engineering challenges ( Advanced Encryption, A Log of Work, and Bit level h4xx04r ).</p><h3>Advanced Encryption</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*vfhVsFH8Y6vdnj3aUadJmg.png" /></figure><p>Given an ELF 64 bit binary and then i try to open it using IDA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3I75zCK5cla0EqWidvwZug.png" /></figure><p>From the code above we know that our input will be in xor with byte_4060 value , because the type of byte_4060 is an byte array so the maximum value we can input is 0xff . The idea is i try to automatically input from 0 to 0xff to the binary , if the binary run successfully ( exit code 0 ) our input is probably correct.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc478d2c2ee0067a802e33ca91fe3a29/href">https://medium.com/media/cc478d2c2ee0067a802e33ca91fe3a29/href</a></iframe><p>Running script above will give us more than 1 correct value ( exit code 0 ) so the next step i do is try to debug it on gdb to make sure which is the real correct value. Finally after trial and error we found the correct value which is 171.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*zw2S62jkEZ6XLOh_d_KJ1Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*TVxqkc7EEvDXa_S4-cNmbw.png" /></figure><p>rdi is our argument , so BYTE PTR [rdi] == arg[0] BYTE PTR ,[rdi+1]==arg[1] , etc . So the final step is convert the code above to python to get the flag.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d113796413990f260cba295c70a6ff4/href">https://medium.com/media/6d113796413990f260cba295c70a6ff4/href</a></iframe><p>Flag : BSDCTF{sup3r_sh0rt_fl4g}</p><h3>A Log of Work</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*AKyzrK-blv5VPP_odpNn0A.png" /></figure><p>Given two files ( basicchall.exe and basicchall.dll ) , after doing analysis we know that basicchall.exe is dotnet application which is used to run the basicchall.dll .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*M_SNES8kZYZZcZXqqHkUig.png" /></figure><p>The next step i do is try to open basicchall.dll using dnSpy and here is the result</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1459ebfab698639638cfcb68da7f12fc/href">https://medium.com/media/1459ebfab698639638cfcb68da7f12fc/href</a></iframe><p>From here we know that our input must match with <strong>right </strong>value . Here is the algorithm of code above</p><pre>- Getting input<br>- Convert it to hex<br>- Encode it using base64<br>- Encode it using rot13<br>- Final step is doing some calculation ( shift left,add, and multiplication )</pre><p>After doing some research i know that the <strong>right</strong> value can be reversed , here is the calculation</p><pre>Here we assume that our enc length is 3<br>val=2**21<br>bigInteger=0<br>(bigInteger*val)+enc[i])*val+enc[i+1])*val+enc[i+2]==right<br>(bigInteger*val)+enc[i])*val+enc[i+1])*val+enc[i+2]-enc[i+2]==right-enc[i+2]<br>(bigInteger*val)+enc[i])*val+enc[i+1])*val==right-enc[i+2]<br></pre><pre>Because of we know value of val here we can do gcd (bigInteger*val)+enc[i])*val+enc[i+1])*val with val , if the result is val so our guess input is correct</pre><p>After getting the encoded value the next step we do is rot13 decode it then base64 decode it then hex decode it and finally got the flag. Here is the script i used to get the flag.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/77cd2109aec6de2711ccccdd505ea9d1/href">https://medium.com/media/77cd2109aec6de2711ccccdd505ea9d1/href</a></iframe><p>Flag : BSDCTF{1m_50_50rry}</p><h3>Bit level h4xx04r</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*I8JscnuiSFR0Cw1Ug78Liw.png" /></figure><p>Given an ELF 64 bit binary which is using rust programming language. Here i try to open it using IDA.</p><p>After doing research on it ( static and dynamic analysis ) finally i understand what this binary do.</p><p>First there is value which is look like base64 encoded value in initial code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*kgbqFUafNEsvywLOvNBV0g.png" /></figure><p>And there is rand function too which the value will be used next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*AQBR0xklfNXa0W382hYdGw.png" /></figure><p>v10.pieces.length will save the result of each character in aQvzesv9fddvmnm variable and by 0xf .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mat7A7DjnSHFgzZB7Z553g.png" /></figure><p>After that v10.pieces.length value will be rotated with random value which is initiated at the beginning of program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fZ9BYmwYTj-W_6ZaPDWaDA.png" /></figure><p>&amp;v10.args.data_ptr-&gt;value will save value of each character aQvzesv9fddvmnm shift right by 4.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xAmuH6-Hdd3cas0g7CViJg.png" /></figure><p>The last step is multiply each value of &amp;v10.args.data_ptr-&gt;value with 16 and sum it with each v10.pieces.length value.</p><p>So the idea is getting all possible rotations and then sum it with 16*&amp;v10.args.data_ptr-&gt;value .</p><p>But it doesn’t produce flag, i tried to bruteforce it then base64 decode and fail , but finally i have another idea that is base64 decode the value first then bruteforce all possibility and gotcha got the flag! Here is my script to get the flag</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ea3b242063fbcf3957397a78b1849c8/href">https://medium.com/media/9ea3b242063fbcf3957397a78b1849c8/href</a></iframe><p>Flag : BSDCTF{5h1fty_5tuff}</p><h3>Thank You!</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a3f8bc92fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Write Up FIRST Challenge 2020]]></title>
            <link>https://kos0ng.medium.com/write-up-first-challenge-2020-2e2ff284d590?source=rss-f95ba1cab640------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e2ff284d590</guid>
            <category><![CDATA[writeup]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[assembly]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <dc:creator><![CDATA[ryuk]]></dc:creator>
            <pubDate>Fri, 26 Jun 2020 03:53:44 GMT</pubDate>
            <atom:updated>2022-08-10T14:05:06.968Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*rb-pZh3b8Oic4PcmkkJVEA.png" /></figure><p>Yesterday i played FIRST Challenge with my friend and named our team as <strong>Mbuh </strong>which means <strong>“don’t know” . </strong>The following is my write up about some challenges that i’ve already solved.</p><h3>Break the Snake — Reverse Engineering</h3><p>Download pybreakme.zip and then extract it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*Ip3c1Wl56W2PxCThSDb7ew.png" /></figure><p>Looking at the file we know that the pybreakme is python executable file that was compiled with pyinstaller.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*ipEJOs1ZPOnuYS6eBjhBCg.png" /></figure><p>pybreakme was compiled into Mach-O executable which is can be run in Mac OS or maybe linux can run it with help of <a href="https://www.darlinghq.org/">Darling </a>. The first step i do is trying to do static analysis using IDA but I did not find anything meaningful. So after i that i try to extract pybreakme and then decopmile .pyc file. I used this <a href="https://github.com/extremecoders-re/pyinstxtractor">script</a> to extract the pyc file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*YcqyVvI_JnourDF2cCnpIg.png" /></figure><p>After that i was try to use uncompyle6 and uncompyle2 to decompile it but it failed. So i try using <a href="http://www.decompiler.com/">online decompile</a>r and here is the result.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96767f33821935ffc29774db52e57031/href">https://medium.com/media/96767f33821935ffc29774db52e57031/href</a></iframe><p>The algorithm for encode flag is xoring a character with a character afterwards. Assuming that the last character of the base64 encoded string is “=” because of padding , so we just need to do assumed_last_char ^ first_xored_char to get the first_char and then xoring the first_char with the second_xored_char and so on. Here my script to automate that and retrieve the flag.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18759ad2ca2ff4aa161d01f9e6964dd7/href">https://medium.com/media/18759ad2ca2ff4aa161d01f9e6964dd7/href</a></iframe><p>Flag : We’ll not risk another frontal assault. That rabbit’s dynamite.</p><h3>My Secret Part 1–5 — Reverse Engineering</h3><p>Download mysecret file and then run file command.</p><p>Because the output is “data” so the next step i do is try to open it using hex editor.</p><p>From picture above we know that the file is ELF but the bytes are reversed . So we need to reverse it back to get the correct ELF file .</p><pre>f=open(&quot;mysecret&quot;,&quot;r&quot;)<br>a=f.read()[::-1]<br>print a</pre><p>run that script and redirect the output to file. After i got the correct ELF , the next step i do is try do run it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tt5aBXSCHm1piSiyGc53bA.png" /></figure><p>The binary produce encrypted string and doesn’t need input. The next step is i try to debug it using GDB .</p><pre>b main<br>x/25000i $pc</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*N4FDVse3pLWZk5-FKR1R_g.png" /></figure><p>Because the binary is not stripped we can see the name of function , there is RC4 function called and i think the flag will be the argument of that function . So i set breakpoint on that function to see the argument.</p><pre>b *0x55555557731e</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9U96X39I8vViUjwVHJWhEQ.png" /></figure><p>yeah and my guess is correct , so we got the flag and the key used in RC4 encryption on this binary. Here is the flag</p><pre>Part 1 : 095bf40d794b0259556648e114366f46108ab32b324ac9d30399e8e270d47ef5</pre><pre>Part 2 : I forgot my very old key<br>Part 3 : 2d383d1c373a15831e94<br>Part 4 : RC4<br>Part 5 : 10107</pre><h3>PLC Firmware Injection — ICS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*Jkd5oVFKVnP8cfFnK4CeIg.png" /></figure><p>The description is really helpful on this challenge . So the first step we need to do is try to decode the serial traffic. It takes a long time to find the correct tools for decode the serial traffic and configuration for it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*m2_g6-4nATL-MuQpl_wnMg.png" /></figure><p>From the picture above i try to search about serial traffic,serial decoder,and etc related. Finally i found “saleae logic analyzer” which seems to match the capture.logicdata</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aIW6rdFmorj1Bnn7gF3CBQ.png" /></figure><p>After downloading, i try to open capture.logicdata with it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3CXmY-oYgHCYaNGg2DVgrA.png" /></figure><p>At first i open it i see nothing useful. So i try to search configuration about it and find about SPI (Serial Peripheral Interface) and how to analyze it. With many trial and error i got something from it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*CZmteGJBNw0A8_CGw-fqlQ.png" /><figcaption>SPI Configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*zbBG7XocZO8tkvFSENYlUw.png" /></figure><p>There is output in decoded protocol and then i export it to make it more readable.</p><pre>S0190000506f7765725043204669726d776172652053747562002B<br>S12304CC9421FFD093E1002C7C3F0B78907F000C3920012C913F0018815F000C813F000C69<br>S12304EC7D4A49D6813F00187D2A4BD6913F001C813F001C5529083C913F001C813F001C14<br>S117050C7D234B78397F003083EBFFFC7D615B784E80002084<br>S5030003F9</pre><p>We got something like structured data, so i decide to search about it .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*LK504GAPDitI_IFtctmeMw.png" /></figure><p>It is SREC format. Looking at wikipedia and found useful information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O1lguEWHdZwZe9oCgjiFHw.png" /></figure><p>From wikipedia i just know that S0 is ascii comment in hex format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*2WgpT4jGgpgj1FGxvE4KVw.png" /></figure><p>From this we know that our finding is correct because if we look at the challenge description it is about firmware stub. Looking for about srec decode i found how to decode it with python <a href="https://pypi.org/project/bincopy/">bincopy</a> .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WKriFY0W_AuCGikrxRc0kQ.png" /></figure><p>After that we just need to write it to file. And then i decide to open it with ghidra and set processor to PowerPC with size 32 and big endian ( trial and error will help you ).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*npujdRGo-yUUAK5F5Cfalg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*RwMtn8gCEsqs7NwK1CzMfw.png" /></figure><p>Pressing D to disassemble it and got this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*5hkbqpf6QpjKQ0ybveMJiw.png" /></figure><p>Because this file is a stub i think the last 4 bytes maybe cut off . With reference from this <a href="https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/assembler/idalangref_ins_set.html">website</a> and of course google i try to analyze it and convert it to python code.</p><pre>r31_0xc=r3<br>r9=0x12c<br>r31_0x18=r9<br>r10=r31_0xc<br>r9=r31_0xc<br>r10=r10*r9<br>r9=r31_0x18<br>r9=r10/r9<br>r31_0x1c=r9<br>r9=r31_0x1c<br>r9 = r9 &lt;&lt; 1<br>r31_0x1c=r9</pre><p>Because we know that r3 is function argument ( First 8 integer <em>arguments</em> are in %<em>r3</em> through %r10 ) , so the next step to do is run that code with r3=120.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*2TWmiNfpsM2Aq4m8eXq0Rw.png" /></figure><p>Flag : 96</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e2ff284d590" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Write Up zh3r0 CTF 2020]]></title>
            <link>https://kos0ng.medium.com/write-up-zh3r0-ctf-2020-f047c7b0b530?source=rss-f95ba1cab640------2</link>
            <guid isPermaLink="false">https://medium.com/p/f047c7b0b530</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[nmap]]></category>
            <dc:creator><![CDATA[ryuk]]></dc:creator>
            <pubDate>Wed, 17 Jun 2020 17:15:58 GMT</pubDate>
            <atom:updated>2022-08-10T14:10:20.750Z</atom:updated>
            <content:encoded><![CDATA[<p>here writeup for Knock Knock and Help me challenge .</p><h3>Knock Knock — Master</h3><p>From the title we know that there is something hidden in port ( Port Knocking ) . So the first step i do is try to do nmap scan on hackerit.zh3r0.ml</p><pre>PORT     STATE SERVICE<br>22/tcp   open  ssh<br>48/tcp   open  auditd<br>49/tcp   open  tacacs<br>51/tcp   open  la-maint<br>52/tcp   open  xns-time<br>80/tcp   open  http<br>89/tcp   open  su-mit-tg<br>95/tcp   open  supdup<br>100/tcp  open  newacct<br>101/tcp  open  hostname<br>104/tcp  open  acr-nema<br>105/tcp  open  csnet-ns<br>108/tcp  open  snagas<br>110/tcp  open  pop3<br>111/tcp  open  rpcbind<br>114/tcp  open  audionews<br>116/tcp  open  ansanotify<br>117/tcp  open  uucp-path<br>122/tcp  open  smakynet<br>123/tcp  open  ntp<br>125/tcp  open  locus-map<br>3389/tcp open  ms-wbt-server</pre><p>After i try to open port 3389 and it show something like dictionary .</p><pre>&lt;b&gt;This will help you:&lt;/b&gt;&lt;br&gt;<br> (0, 4)<br> (1, 16)<br> (2, 2)<br> (3, 11)<br> (4, 6)<br> (5, 9)<br> (6, 15)<br> (7, 14)<br> (8, 1)<br> (9, 12)<br> (10, 13)<br> (11, 10)<br> (12, 7)<br> (13, 3)<br> (14, 17)<br> (15, 8)<br> (16, 0)<br> (17, 5)<br> (18, 18)</pre><p>After looking again at the scan result i realize that the open port is decimal ascii value . Finally i make a script to convert that dictionary i get with combination of port 48–125 (except port 80) . Here is the script.</p><pre>a=[48,49,51,52,89,95,100,101,104,105,108,110,111,114,116,117,122,123,125]<br>b=[16,8,2,13,0,17,4,12,15,5,11,3,9,10,7,6,1,14,18]<br>flag=&quot;&quot;<br>for i in b:<br> flag+=chr(a[i])<br>print flag</pre><p>Flag : zh3r0{You_n4iled1t}</p><h3>Help Me — Crypto</h3><p>Download disassembled_code and ciphertext.txt . Doing manual convert from python assembly to python script with reference from <a href="https://docs.python.org/3/library/dis.html">https://docs.python.org/3/library/dis.html</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d33c9e92bca3e95c1beaedd6ac71ba8/href">https://medium.com/media/6d33c9e92bca3e95c1beaedd6ac71ba8/href</a></iframe><p>Here is the result</p><pre>from binascii import hexlify,unhexlify<br>from Crypto.Util.number import *<br>import base64</pre><pre>def xor_func_030(str1,str2,num): <br> return chr((ord(str1[num])+num)^ord(str2[num]))</pre><pre>def first_half_450(half_flag): <br> tmp=[hexlify(half_flag[i:i+4].encode()) for i in range(0,len(half_flag),4)]<br> return tmp</pre><pre>def second_half_5b0(half_flag): <br> tmp=[bytes_to_long(half_flag[i:i+4].encode())for i in range(0,len(half_flag),4)]<br> return tmp</pre><pre>def encrypt_920(flag,key): <br> final=[]<br> first_xor=[xor_func_030(flag[:len(flag)//2],key[len(key)//2:],i) for i in range(len(flag)//2)]<br> second_xor=[xor_func_030(flag[len(flag)//2:],key[:len(key)//2],i) for i in range(len(flag)//2)]<br> final+=first_half_450(&#39;&#39;.join(first_xor))<br> final+=second_half_5b0(&#39;&#39;.join(second_xor))<br> return final</pre><p>And ensuring that code by doing dis.dis(function_name) and it is same. So after that trying to figure out the key. The encoded_key is :</p><pre>5Nzwbdkvm1VF1X3zc8d6kPd7MMTgSW9Dv1otpwkbPyggHqk5CaEHYwCD14vBdc3w86</pre><p>After doing many trials and error with my team, finally we found the correct encoding type which is base58 encoding. So decode with it and got this.</p><pre>wb==_0E390%9`d0`d0f9b0&lt;bJ0u_C0f9:d049c==b?8b02E3</pre><p>it looks like it’s still in the form of encoding , so i try to figure out it again and got the correct encoding which is rot47. Decode it with rot47 and got this.</p><pre>H3ll0_tbh_Th15_15_7h3_k3y_F0r_7hi5_ch4ll3ng3_atb</pre><p>Yeah exactly that is the key. Final step is writing script to automatically decode the encrypted flag. Here is the script.</p><pre>target=[b&#39;03367345&#39;, b&#39;46c39f41c3a8&#39;, b&#39;1544651a&#39;, b&#39;03451b28&#39;, b&#39;77c3aac3a275&#39;, b&#39;c39e16c3b6c3b2&#39;, 391124763, 121061897, 1396123432, 389813723487, 295339258400, 131682038629031]<br>key=&quot;H3ll0_tbh_Th15_15_7h3_k3y_F0r_7hi5_ch4ll3ng3_atb&quot;<br>real_flag=&quot;&quot;<br>counter=0<br>first_key=key[len(key)//2:]<br>for i in target[:len(target)//2]:<br> tmp=unhexlify(i).decode()<br> for j in tmp:<br>  real_flag+=chr((ord(j)^ord(first_key[counter]))-counter)<br>  counter+=1<br>counter=0<br>second_key=key[:len(key)//2]<br>for i in target[len(target)//2:]:<br> tmp=long_to_bytes(i).decode()<br> for j in tmp:<br>  real_flag+=chr((ord(j)^ord(second_key[counter]))-counter)<br>  counter+=1</pre><pre>print(real_flag)</pre><p>Flag : zh3r0{pyth0n_di54ss3mbly_byt3c0d3_i5_s0_aw350m3}</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f047c7b0b530" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reverse Engineering — Castors CTF 2020]]></title>
            <link>https://kos0ng.medium.com/reverse-engineering-castors-ctf-2020-b80ce7a4670?source=rss-f95ba1cab640------2</link>
            <guid isPermaLink="false">https://medium.com/p/b80ce7a4670</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[writeup]]></category>
            <dc:creator><![CDATA[ryuk]]></dc:creator>
            <pubDate>Mon, 01 Jun 2020 04:37:58 GMT</pubDate>
            <atom:updated>2020-06-01T04:37:58.642Z</atom:updated>
            <content:encoded><![CDATA[<h3>Reverse Engineering — Castors CTF 2020</h3><p>Here some writeup of RE challenges that i’ve been solved on Castors CTF 2020.</p><h3>Mapping</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*ROIXAK8KVR_qKbWe1UuVSA.png" /></figure><p>Mapping is a golang binary. The first step i do is try to decompile it Using IDA .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TiaWb8zoePT3cxPdFYcgfg.png" /><figcaption>main_main function</figcaption></figure><p>There is main_apply function that doing something with our input , i know it from debugging the binary and set breakpoint on main_apply call instruction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*kv7m043c_ngws3VlrqY3KA.png" /></figure><p>My dummy input is ABCD , so the next step is try to determine what is main_apply function do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*hfTNbo2OKQbgg5Im0dwO3Q.png" /><figcaption>main_apply function</figcaption></figure><p>if we look at main apply function , there is looping for each byte of our input and if our input decimal is greater or equal than 128 ( unprintable characters ) runtime_decoderune will be called if not just increment it. Before the looping end there is runtime_mapaccess1 function that will mapping our input to something that has been specified. The last instruction on that function is returning the result as base64.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*x57PM4saAoNVfGuEzlVtvg.png" /></figure><p>Because our input is ABCD and the first character is A , so A will be mapped fisrt. The return value of runtime_mapaccess1 with argument A is 0x5a</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*AkAsn6sEboUPu3BOT7PfqQ.png" /></figure><p>It is possible to knowing each mapped value by doing examine $rax after runtime_mapaccess1 function called but it is more easier to know the mapped value after all characters mapped. So we just need to set breakpoint at base64 encode instruction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wKxNd3cwjQmqywMhx-_6gg.png" /><figcaption>Input all printable character as password</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*pJOTaakYvXUXOP55ibsd1A.png" /><figcaption>the mapped value from all printable characacters</figcaption></figure><p>After that you will find instruction that compare our base64 mapped input with the real flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hJpLLf2oO0lSCyFDfgGdLg.png" /></figure><p>So the last step is writing a script to mapping the mapped flag to original value.</p><pre>import base64</pre><pre>flag=[0x65,0x48,0x70,0x7a,0x64,0x47,0x39,0x79,0x63,0x31,0x68,0x58,0x51,0x58,0x74,0x70,0x59,0x6c,0x38,0x30,0x63,0x6a,0x46,0x75,0x4d,0x6d,0x67,0x78,0x4e,0x44,0x59,0x31,0x62,0x6c,0x38,0x30,0x4d,0x58,0x6c,0x6f,0x4d,0x46,0x38,0x32,0x4d,0x6c,0x39,0x35,0x4d,0x44,0x51,0x30,0x4d,0x48,0x4a,0x66,0x4e,0x47,0x51,0x78,0x62,0x6c,0x39,0x69,0x4e,0x58,0x56,0x79,0x4d,0x6e,0x30,0x3d]<br>tmp=[0x35,0x36,0x37,0x30,0x31,0x32,0x33,0x34,0x38,0x39,0x7a,0x79,0x78,0x6a,0x6b,0x6c,0x6d,0x64,0x65,0x66,0x67,0x68,0x69,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x63,0x62,0x61,0x5a,0x59,0x58,0x46,0x47,0x41,0x42,0x48,0x4f,0x50,0x43,0x44,0x45,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x49,0x4a,0x4b,0x4e,0x4d,0x4c]<br>alpha=list(&#39;0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&#39;)<br>dicti=dict(zip(tmp,alpha))<br>flag=base64.b64decode(&#39;&#39;.join(map(chr,flag)))<br>result=&quot;&quot;<br>for i in flag:<br> try:<br>  result+=dicti[ord(i)]<br> except Exception as e:<br>  result+=i<br>print result</pre><p>Flag : castorsCTF{my_7r4n5l4710n_74bl3_15_b3773r_7h4n_y0ur5}</p><h3>Ransom</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*BGm32jkjjwVsNupPI8ntew.png" /></figure><p>Ransom is also golang binary. The first step i do is try to decompile it using IDA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*S2DPzfNol-3_nwnAPxCOzQ.png" /><figcaption>main_main function</figcaption></figure><p>First , the binary will try to get seed value using main_getSeed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aKJMg8078BWYMSy4pvm3BA.png" /><figcaption>main_getSeed function</figcaption></figure><p>From the code we know that there will be a HTTP request with GET method . Looking at the pcap file we know that the response is a number ( seed value ) .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*XmnD3vQcyGYDsSpCaOCVLg.png" /><figcaption>traffic.pcapng</figcaption></figure><p>Here we assume that the result is the seed value. After that we look at main_send function and there is a HTTP request with POST method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*bdo1-FnN0zTZURQfbG0EcA.png" /><figcaption>main_send function</figcaption></figure><p>Looking at pcap file we find a HTTP request with POST method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*Kc0PH0ifP-UnNHUiaM5T8w.png" /><figcaption>traffic.pcapng</figcaption></figure><p>So until here we know that the exact value of seed is 1337 , because there is only one HTTP request with POST method and the value is 1337 . The return value main_send is “ok” .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*o18L0aSqRbf2gRTVsusjCQ.png" /></figure><p>There will be checking that compare v9 with 1 and v11 with 3 and v10 value with “ok\n” . The last is doing encryption with main_encrypt function ,looking at the main_encrypt function there is looping , randint , xoring, and many comparation. Here we know that PNG has file signature , so my idea is try to encrypt dummy png file and check the encrypted dummy png file signature. If the header is same as the flag.png so we have successfully encrypting the file with same seed. After trying to do that and the results are same as I thought. So the last step i do to decrypt the file is run the binary again with same seed ( because i see that there is only basic operation to encrypt the file such as xor and looping ). Here is the step i do to decrypt the flag.png</p><pre>1. Creating fake web server with return value 1337 if the request using GET method and return &quot;ok&quot; if the request using POST method<br>2. Debugging binary to ensure that we give true logic on comparation</pre><p>First create loopback interface that have address same as the server in pcap.</p><pre>sudo ifconfig lo:40 192.168.0.2 netmask 255.255.255.0 up</pre><p>Change the port address of apache to 8081. (Here i use lampp)</p><p>After that just create fake seed.php and .htaccess</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*02TjTXzeRgfayDoFBOIZ8g.png" /></figure><p>Debug the binary and change some register that doesn’t meet the value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d4JAKrS1BZinZW9QL7GVtQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*zT6NcONo3WlmJKxzUiER0w.png" /></figure><p>After that continue and we will get the original flag.png</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*0PepUlBy3_3-UX4XluZg9g.png" /><figcaption>flag.png</figcaption></figure><p>Flag : castorsCTF{this_is_not_my_final_form}</p><h3>Octopus</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*cWuKC5Fsto3heaImu7uDvQ.png" /></figure><p>Given obfus file which the content is golang binary encoded in base64. So we just need to decode it and write it to file . The problem here i have worked in a few hours to try solving the <strong>old binary </strong>, i just knew that the binary changed after try to get some hint on discord.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*HJOMIbc6pq6H2sErFTJohw.png" /></figure><p>I have done a long enough analysis to figure out what this challenge mean , because there is no input and i don’t know what i must to do. In the end i realized that the binary work properly , nothing needs to be patched . So because i working on old binary , i try to decode that unicode , something like converting UTF-32 to UTF-8 and etc. Here is the value of encoded flag.</p><pre>0x00008dc200008fc2    0x0000a4c20000a3c2<br>0x0000a2c200009dc2    0x0000adc20000a3c2<br>0x000089c2000096c2    0x000090c20000a3c2<br>0x00009cc2000089c2    0x000096c2000083c2<br>0x00009cc200009ac2    0x0000a5c2000089c2<br>0x00009bc2000089c2    0x000000000000a4c2</pre><p>And here is the result if you run the old binary</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*OaqPd17buSSnVFPRmM9Row.png" /></figure><p>But i still can’t decode it , after that i try to look at discord server to find any hint about it and i got the information about the new binary was uploaded. So after that i try to analyze the new binary and exactly it has the same algorithm like the old one but more simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*pd8XSlXl13e53sqBT3H7Jg.png" /><figcaption>main_main function ( new binary )</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PHaVzlavu-nNjkPFAlbb1g.png" /></figure><p>Looking at the result given from the binary , it is like base64 encoded string. So the next step i do is try to decode it and got the flag!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XcXCprz0sOmqJqXGeW7jFA.png" /></figure><p>The important lesson i learn from the octopus challenge is “<strong>overthinking will kill you :) </strong>” and i was really caught in tentacles same as the challenge description for few hours :’) .</p><p>Flag : castorsCTF{Wh0_s41d_AnY7hlnG_B0uT_m4tH}</p><h3>Thank You!</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b80ce7a4670" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reverse Engineering — Deep CTF 2020]]></title>
            <link>https://kos0ng.medium.com/reverse-engineering-deep-ctf-2020-ac9e83aa266d?source=rss-f95ba1cab640------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac9e83aa266d</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[writeup]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[ryuk]]></dc:creator>
            <pubDate>Mon, 06 Apr 2020 11:49:50 GMT</pubDate>
            <atom:updated>2022-08-10T14:07:08.040Z</atom:updated>
            <content:encoded><![CDATA[<h3>Reverse Engineering — Deep CTF 2020</h3><p>Last weekend there was CTF event organized by Deep Tech and i played as Bat Squad team . Thank you to the organizer for providing great CTF and thank you to sponsors for giving interesting award .</p><p>Here is my solution for Reverse Engineering Challenge.</p><h3>Nested Rev</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*Y-L9pLvdnjMR4eHXCi4nQQ.png" /></figure><p>Using ghidra for open the binary file and go to the main function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*AzYr825i5AM4Z0f7FaMnJg.png" /></figure><p>There are lots of if statement which if we order the variables it will produce flag, but i’m too lazy to do it. So here i am using angr to automate solving that binary.</p><p>Finding address of main function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*N89YU9tqdsXsx-KYhbuAUw.png" /></figure><p>Finding instruction for load string “Voila!!! You Got It” from memory using gdb.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*dEhWC40hLB5K1WkZMT2dVg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*EXGA4aH5ZJQIee7cw_rCjQ.png" /></figure><p>After that write a program for find the correct value automatically using angr.</p><pre>import angr<br>import monkeyhex<br>import sys</pre><pre>base=0x400000<br>main=base+0x0000000000001155<br>project = angr.Project(&#39;binary/Cr4ckm3&#39;)<br>initial_state=project.factory.entry_state(addr=main)<br>simulation=project.factory.simgr(initial_state)</pre><pre>load_good_address=base+0x0000000000001295<br>simulation.explore(find=load_good_address)<br>if simulation.found:<br>    solution_state = simulation.found[0]<br>    print(solution_state.posix.dumps(sys.stdin.fileno()))<br>else:<br>    raise Exception(&#39;Could not find the solution&#39;)</pre><p>and here is the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*qkZN6_0SYA2jz2go65uUIA.png" /></figure><p><strong>Flag : d33p{y0u_r3v3rs3d_1t_w3ll}</strong></p><h3>SkipMe</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*58XpIf7cFE1lY-lQ5Z4X3A.png" /></figure><p>Open the binary using ghidra and go to the main function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*aECffliq6SU33tk7a_2skA.png" /></figure><p>In this challenge we need to change the value of our computer name,os,cpuid to the correct value like in strcmp argument and in the end if our values are correct the program will run finish function. So like the title of challenge <strong>“SkipMe” , </strong>we can skip all those checks and directly call finish function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*bQ01jUxz6HeD7QNQau2Htw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*ULVfEBtWOZU3DCYShonZeA.png" /></figure><p><strong>Flag : d33p{f51579e9ca38ba87d71539a9992887ff}</strong></p><h3>0xKEY</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*_uoqlF-9W8ZaDIVJPuVwxQ.png" /></figure><p>Open the binary using ghidra and go to the main function</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*h5dtJLuMbqshg18VlaCaFQ.png" /></figure><p>I think this challenge is broke, because we can easily knowing the flag by using ltrace command (because there is strcmp function which compare string and we can find out the argument of strcmp using ltrace command).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*xuOLggRbRBzcY6J7Jms_sg.png" /></figure><p>If there is no strcmp function we can examine the address of secret like this for find out the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*V9ST-ymt3OQ3qRhNLr2Atw.png" /><figcaption>main function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*5W5oqb1zUgm6Azt9FHU0aQ.png" /><figcaption>break after generateMyFlag and then run the program</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*LVr9keLEwhkvoUhLNZ1MYA.png" /><figcaption>examine the value of secret as string and got the flag</figcaption></figure><p><strong>Flag : d33p{jnhFClg2sv3uaBBxs}</strong></p><h3>Down</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*KO38gZHFxTqKF9W5ET-tdw.png" /></figure><p>Open the binary using ghidra</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*mT0sdxHaxI_cLMZLvGxpSQ.png" /></figure><p>Nothing helpful, so here i decide to run the file and here is the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*oaFLOdkIOWvVyhydt3u6Sw.png" /></figure><p>After clicking ok the program will close, but here we know some string stored on that executable , so the next step is try to examine defined string on that executable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*cFR0l0DoL2HC9a-6vv9YkQ.png" /></figure><p>Using the address for that string we can find the reference to that address which may be the address of main function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*SOEQpUZprhDlbVsI3vmncQ.png" /></figure><p>Lets move to assembly tab instead of pseudocode tab to be more obvious.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*3BLevWGUjsrxUBo2A_xefA.png" /></figure><p>from the instruction we know that the program after calling message box will call FUN_004012c0() which is calling GetTickCount function and the next instrucion is INT (interrupt) 3 which is intended for calling the debug exception handler and this instruction make the program break. There area many int 3 instruction after calling FUN_004012c0() and then something like garbage after the last int 3 instruction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*YySmn8b9LnUXyoerdxzrug.png" /></figure><p>Here i try to convert it to assembly instruction and here is the result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*h8_eNbLyFPF7T76zGyLoBg.png" /></figure><p>There are some jump instruction and the last jump instruction lead to the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*ldWjobcgKR65BKsgjuOKQA.png" /></figure><p>So here my solution is changing the assembly instruction int3 to nop so the program can continue to the next instruction and lead to the message box with flag on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*iHCQPUPUoVxKGM5q4IgJYQ.png" /><figcaption>before patched</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*DB8p-juVV20JWAlpLSDb0w.png" /><figcaption>after patched</figcaption></figure><p>And then run the file to get the flag</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*wPgSVIkJ4XU-NwOOLggSIg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*qxnewrP_fETnEbZwDLzxkg.png" /></figure><p><strong>Flag : d33p{ww.canabalt.com}</strong></p><h3>Wacha Wachin</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*SjESZ_0iHj3S8z4ZRHUb3w.png" /></figure><p>At the beginning i thought the challenge was about reversing the encrypted pdf file , but it didn’t,it was even worse :) . Here is the contents of the pdf file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*F9NEtVFZLerTWpPhJDYYLw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*2dKsyimqXlwZ9dcR7boVtg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*Q0MkHx58sZpFLMZndosdIQ.png" /></figure><p>That is assembly on arm architecture, here I analyze these instructions manually .</p><p>Some arm assembly instruction cheat sheet</p><pre>ADD     R2, R2, R1    // R2=R2+R1<br>MOV     R3, R2,LSL#6  // R3=R2&lt;&lt;6<br>SUB     R3, R3, R2    // R3=R3-R2<br>EOR     R3, R3, R2    // R3=R3^R2<br>AND     R3, R3, #0xFF // R3=R3&amp;0XFF<br>ORR     R3, R0, R3    // R3=R0|R3</pre><p>Here i will say set of instruction per box as section, so start from the first section</p><p>First Section</p><pre>check_flag:<br>STMFD   SP!, {R11,LR}<br>ADD     R11, SP, #4<br>SUB     SP, SP, #0x18<br>STR     R0, [R11,#var_18]       // R11,#var_18 is the flag<br>LDR     R3, =aAqlbn; &quot;AQLbN&quot;<br>STR     R3, [R11,#var_C]        // Store &quot;AQLbN&quot; to R11,#var_C  <br>LDR     R3, =asc_1D250; &quot;-=&quot;<br>STR     R3, [R11,#var_10]       // Store &quot;-=&quot; to R11,#var_10<br>LDR     R3, [R11,#var_18]<br>LDRB    R3, [R3]                // Load first byte from flag / flag[0]<br>MOV     R1, R3<br>MOV     R2, R1                  // R2 = first byte from flag<br>MOV     R2, R2,LSL#1            <br>ADD     R2, R2, R1              <br>MOV     R3, R2,LSL#6            <br>SUB     R3, R3, R2              <br>MOV     R3, R3,LSL#1            <br>ADD     R3, R3, R1             <br>MOV     R3, R3,LSL#1<br>MOV     R2, R3<br>LDR     R3, [R11,#var_18]       <br>ADD     R3, R3, #9              <br>LDRB    R3, [R3]                // R3 = flag[9]<br>ADD     R3, R2, R3<br>LDR     R2, =0x1225C<br>CMP     R3, R2                  // compare R3 with 0x1255c<br>BNE     loc_83F0                // if same jump to second section , if       <br>                                   not same jump to fail section</pre><p>Second Section</p><pre>LDR     R3, [R11,#var_18]<br>ADD     R3, R3, #1<br>LDRB    R2, [R3]                 // R2 = flag[1]<br>LDR     R3, [R11,#var_18]<br>ADD     R3, R3, #8               <br>LDRB    R3, [R3]                 // R3 = flag[8]<br>EOR     R3, R3, R2<br>AND     R3, R3, #0xFF<br>MOV     R3, R3,LSL#1<br>CMP     R3, #0xE                 // compare R3 with 0xE <br>BNE     loc_83EC                 // if same jump to third section , if       <br>                                    not same jump to fail section</pre><p>Third Section</p><pre>LDR     R3, [R11,#var_18]<br>ADD     R3, R3, #8             <br>LDRB    R3, [R3]                 // R3 = flag[8]<br>LDR     R2, =0x4EC4EC4F<br>UMULL   R1, R3, R2, R3           // Multiply R2 and R3,store the most <br>                                    significat 32 digit on R3<br>MOV     R3, R3,LSR#2<br>AND     R3, R3, #0xFF<br>MOV     R2, R3<br>LDR     R3, [R11,#var_18]<br>LDRB    R3, [R3]                 // R3 = flag[0]<br>ADD     R3, R2, R3<br>CMP     R3, #0x66 ; &#39;f&#39;          // compare R3 with &#39;f&#39;<br>BNE     loc_83E8                 // if same jump to fourth section , if       <br>                                    not same jump to fail section</pre><p>Fourth section</p><pre>LDR     R3, [R11,#var_18]<br>ADD     R3, R3, #1<br>LDRB    R3, [R3]                 // R3 = flag[1]<br>MOV     R0, R3<br>LDR     R3, [R11,#var_18]<br>ADD     R3, R3, #9 <br>LDRB    R3, [R3]                 // R3 = flag[9]<br>MOV     R1, R3<br>MOV     R3, R1<br>MOV     R3, R3,LSL#1<br>ADD     R3, R3, R1<br>MOV     R2, R3,LSL#3<br>SUB     R2, R2, R3<br>MOV     R2, R2,LSL#1<br>ADD     R3, R2, R1<br>ORR     R3, R0, R3<br>LDR     R2, =0x833<br>CMP     R3, R2                   // compare R3 and R2<br>BNE     loc_83E4                 // if same jump to fifth section , if       <br>                                    not same jump to fail section</pre><p>Fifth section</p><pre>LDR     R3, [R11,#var_18]<br>ADD     R3, R3, #7<br>LDRB    R3, [R3]                 // R3 = flag[7]<br>CMP     R3, #0x69 ; &#39;i&#39;          // compare R3 with &#39;i&#39;<br>BNE     loc_83E0                 // if same jump to loop section , if       <br>                                    not same jump to fail section</pre><p>Loop Section</p><pre>MOV     R3, #0                   // set initiate value for looping, R3=0<br>STR     R3, [R11,#var_8]         // save R3=0 to R11,#var_8<br>B       loc_83D0                 // jump to next instruction<br>LDR     R3, [R11,#var_8]         // Load value from R11,#var_8 and save <br>                                    to R3<br>CMP     R3, #4                   // compare r3 with 4<br>BLE     loc_8368                 // if r3&lt;=4 jump to next instruction,if <br>                                    not jump to win<br>LDR     R3, [R11,#var_8]<br>ADD     R3, R3, #2               // R3=R3+2<br>MOV     R2, R3                   // R2=R3<br>LDR     R3, [R11,#var_18]<br>ADD     R3, R3, R2<br>LDRB    R2, [R3]                 // R3=flag[R2] , R2 will be 2,3,4,5,6<br>LDR     R3, [R11,#var_8]<br>CMP     R3, #0<br>AND     R3, R3, #1               // check odd or even ,if odd result = 1   <br>                                    even result = 0<br>RSBLT   R3, R3, #0               // if r3&lt;0 set r3=0-r3 ( absolute )<br>MOV     R1, R3<br>LDR     R3, [R11,#var_10]    <br>ADD     R3, R3, R1<br>LDRB    R3, [R3]                 // R3=var_10[R1] , R1 will be 0,1,0,1,0<br>EOR     R3, R3, R2<br>AND     R2, R3, #0xFF<br>LDR     R3, [R11,#var_8]<br>LDR     R1, [R11,#var_C]<br>ADD     R3, R1, R3<br>LDRB    R3, [R3]                 // R3=var_C[R3] , R3 will be 0,1,2,3,4<br>CMP     R2, R3                   // compare R2 with R3<br>BEQ     loc_83C4                 // if same jump to next instruction,<br>                                    if not same jump to fail section     <br>LDR     R3, [R11,#var_8]        <br>ADD     R3, R3, #1<br>STR     R3, [R11,#var_8]         // var_8=var_8+1</pre><p>The next step is writing script for bruteforcing the value per section.</p><p>On the first section i got exact value for flag[0] and flag[9].</p><p>On the second section i got many possibilities for flag[1] and flag[8] , so we keep the value and go to third section.</p><p>On third section i failed to find value for flag[8] ( i think because i fail to implement umull instruction ) so i decided to go to fourth section.</p><p>On fourth section i got exact value for flag[1] and on the second section we know that flag[1] and flag[8] in pairs , so from fourth section i got value for flag[1] and flag[8]. Fifth section is the clearest section,flag[7]=’i’ .</p><p>The last is loop section , on loop section we will get values for flag[2] until flag[6]. Here is my script i used to get the flag using bruteforce method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab53087fa4217956f1264b94df2c8a73/href">https://medium.com/media/ab53087fa4217956f1264b94df2c8a73/href</a></iframe><p>or you can see the full script include my comment while debugging below</p><p><a href="https://github.com/ret2ex/ctf-writeups/blob/master/solver/deepCTF2020/solver_wachan.py">ret2ex/ctf-writeups</a></p><p><strong>Flag : d33p{b3lla_ci40}</strong></p><h3>Thank you for reading my write up !</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac9e83aa266d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>