<?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 Nghĩa Đào Trọng on Medium]]></title>
        <description><![CDATA[Stories by Nghĩa Đào Trọng on Medium]]></description>
        <link>https://medium.com/@nghiadt1098_83598?source=rss-a8f75ca2e897------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*erU3VjRrNk8PzKsL</url>
            <title>Stories by Nghĩa Đào Trọng on Medium</title>
            <link>https://medium.com/@nghiadt1098_83598?source=rss-a8f75ca2e897------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 21:31:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nghiadt1098_83598/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[[SVATTT 2019 Qual] eznote + curl-me 1]]></title>
            <link>https://medium.com/@nghiadt1098_83598/svattt-2019-qual-eznote-curl-me-1-3875cacdbb7d?source=rss-a8f75ca2e897------2</link>
            <guid isPermaLink="false">https://medium.com/p/3875cacdbb7d</guid>
            <dc:creator><![CDATA[Nghĩa Đào Trọng]]></dc:creator>
            <pubDate>Tue, 05 Nov 2019 05:34:16 GMT</pubDate>
            <atom:updated>2019-11-05T05:34:16.124Z</atom:updated>
            <content:encoded><![CDATA[<ol><li><strong>EzNote (100pts)</strong></li></ol><p>Luồng thực thi của chương trình .</p><ul><li>Tạo ra 10 node.</li><li>Yêu cầu nhập secret key</li><li>Lựa chọn 2 option đọc hoặc ghi vào node.</li><li>Thoát.</li></ul><p>#Bug:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*8pVLLhNMkww_CnDobTnPGg.png" /></figure><p>Khi kiểm tra index của node , dù index không thỏa mãn nhưng hàm không trả về mà vẫn xử lý bước tiếp theo dẫn tới biến <em>buffer </em>chưa được khởi tạo.</p><p>#Tính toán stack</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4x3mpOLA77BDVFGJ2g_2JQ.png" /></figure><p>3 hàm read_int(), read_note(), write_note() do cùng được gọi từ hàm main , cùng calling convention , cùng k có tham số nên có cùng stack base (rbp) .</p><p>Hàm read_int() đọc 0x200 byte vào <em>buffer </em>từ <strong>$rbp-0x200</strong> tới <strong>$rbp</strong></p><p>Hàm read_note() lấy 8 byte cho <em>buffer </em>từ <strong>$rbp-8</strong> tới <strong>$rbp</strong></p><p>Hàm write_note() lấy 8 byte cho <em>buffer </em>từ <strong>$rbp-8</strong> tới <strong>$rbp</strong></p><p>=&gt; Ta có thể điều khiển địa chỉ <em>buffer chưa được khởi tạo bằng hàm read_int()</em></p><p>#Minimal POC</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29c2420da621ced9a5ffa509e53e44e0/href">https://medium.com/media/29c2420da621ced9a5ffa509e53e44e0/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*4PlHKp_D5c96c650S2tbqg.png" /></figure><p>#RCE.</p><p>Mình chọn ghi đè địa chỉ hàm atoi thành hàm system trong GLOBAL_OFFSET_TABLE và gọi shell bằng cách read_int(“/bin/sh\x00”)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06a791ea64fff0d9c20c89cafd495475/href">https://medium.com/media/06a791ea64fff0d9c20c89cafd495475/href</a></iframe><p><strong>2. Curl-me 1</strong></p><p>Cá nhân mình thấy bài này rất hay, qua nó mình học được rất nhiều thứ của PHP khi làm,debug.</p><p>Bài cho ta source-code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c40d51894a1b3d04bbfb9c3897858a97/href">https://medium.com/media/c40d51894a1b3d04bbfb9c3897858a97/href</a></iframe><p>Để trực tiếp bypass qua đoạn check, ta cần một chuỗi $url sao cho sau khi parse_url thì sẽ không chứa xâu flag trong $path. Đồng thời curl_exec $url phải trả về flag/</p><p>Sau khi mất 1 tiếng t rao đổi với teamate về chức năng các hàm được sử dụng trong code, không ai có thể đưa ra chính xác các hàm như urldecode,parse_url xử lý những cái gì và hoạt động thế nào và khiến mình phải lôi source của php ra đọc.</p><blockquote><a href="https://github.com/php/php-src"><em>https://github.com/php/php-src</em></a></blockquote><p>Check1 :<em> in_array($parse[“scheme”], array(“file”, “gopher”))</em></p><p>Check này qua bằng cách sử dụng 1 schema là File.</p><p>Bạn có thể kiểm chứng trong source code.c của hàm parse_url không có những hàm nào kiểu như tolower hay đại loại vậy để xử lý schema.</p><p><a href="https://github.com/php/php-src/blob/master/ext/standard/url.c#L99">php/php-src</a></p><p>Check2: preg_match(“/flag/i”, $path)</p><p>Để qua check này mình kiểm tra nhánh parse_path trong hàm parse_url</p><p><a href="https://github.com/php/php-src/blob/master/ext/standard/url.c#L285">php/php-src</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*bOU_KecJjhTqc5uLbJbfow.png" /><figcaption>Nếu có ký tự # trong url thì nó sẽ parse sang phần fragment.</figcaption></figure><p>Từ đó mình nảy ra ý tưởng, mình sẽ làm cho thằng curl nghĩ # là 1 folder và sử dụng path traversal để đọc được file mình muốn.</p><p>Và payload cuối cùng như các bạn đã biết.</p><p><em>File:///#/../flag1</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3875cacdbb7d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Write up Gifremake intended way (ACEBEAR CTF 2019)]]></title>
            <link>https://medium.com/@nghiadt1098_83598/write-up-gifremake-intended-way-acebear-ctf-2019-dfab88033529?source=rss-a8f75ca2e897------2</link>
            <guid isPermaLink="false">https://medium.com/p/dfab88033529</guid>
            <category><![CDATA[pwnable]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[gif]]></category>
            <dc:creator><![CDATA[Nghĩa Đào Trọng]]></dc:creator>
            <pubDate>Mon, 08 Apr 2019 11:08:38 GMT</pubDate>
            <atom:updated>2019-04-08T12:54:12.899Z</atom:updated>
            <content:encoded><![CDATA[<p>Note from another idol: “Mọi Flag sau cuộc thi đều là vô nghĩa”</p><p>Down source của dịch vụ về, service được build trên docker. G ác docker qua một bên, đọc source</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ap_JJ5gs_8sj6b96V_OQ8g.png" /><figcaption>Hàm upload</figcaption></figure><p>Sau khi upload 2 file thì 2 tệp của mình sẽ được đưa vào chương trình gifremake để chạy. 100% là chúng ta sẽ phải khai thác chương trình này.</p><p><strong>Nhận xét nhanh:</strong></p><p>Binary có đi kèm theo source khá cool, code style khá đẹp, trông như code mẫu.</p><p>Tham số truyền vào chương trình gồm 3 tham số , tham số đầu là một ảnh GIF,tham số thứ 2 là tên file output , tham số thứ 3 là tập lệnh để xử lý.</p><p><strong>Main Part</strong></p><p><em>Drama: Before big update</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*LOFIo4JjmKTMTYszzi0v0Q.png" /><figcaption>Với điều kiện này thì width và height luôn âm.</figcaption></figure><p>Mình bị stuck khi gặp bug này, nó dẫn tới Out-Of-Bound Read khi copy GifFileOut từ GifFileIn, tuy nhiên chưa có cách nào để ghi đè nên tịt, tương tự tính năng này cũng dẫn tới lỗi UAF. May mắn là BTC đã update source kịp thời để bài có solve trước khi giải kết thúc. Nhưng ….</p><h3><strong>Find the bug</strong></h3><p>Mình tìm ra lỗi bài này bằng 2 cách cắm fuzz và code audit.</p><p>The bug: Lỗi xảy ra khi chương trình cho người dùng thay đổi ColorCount</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*LlmWfG56Wq63Sur-PUgVEw.png" /><figcaption>gifremake.c:150</figcaption></figure><p>Chương trình xử lý có vẻ logic tuy nhiên quy định của GifLib là size của ColorCount sẽ phải là mũ của 2 và chương trình không check điều kiện đó.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*TA2qhaZ-jg5MOVAnsCrn7w.png" /></figure><p>Nếu ColorCount là không hợp lệ và ColorMap được gán bằng <strong>NULL </strong>và sẽ dẫn tới double free một ảnh trên GifFileIn</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*wDwcVODQP0SO9trTzQ9daw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*o8ozzHSmw-XB3Tcv8g-NQA.png" /></figure><p>Trigger bug.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*sM70UVBgEHBg77cBANx5Kg.png" /></figure><h3><strong>*Bonus: Understand GIF in GifLib</strong></h3><p>Định dạng tệp gif được thiết kế sao cho có thể làm ảnh động, là ảnh bitmap , dung lượng nhẹ,v.v… bám vào những tiêu chí đó thì sẽ hiểu định dạng ảnh gif dễ hơn.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*1CACnkeBtKHdBqdi65BtfQ.png" /></figure><p>Một ảnh trong list các ảnh trong tệp gif được lưu trong GifLib như trên.</p><p>ImageDesc chứa các thông tin về ảnh</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*p49PT_w2bi18CVkL3eJz8Q.png" /></figure><p>Trong ImageDesc có chứa bảng màu ColorMap</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*_ykGIcAG2DqNcZ4sdJ6ovw.png" /></figure><p>Bạn có thể để ý ở ảnh BMP mỗi pixel đều đi kèm 4 byte mỗi pixel gồm 4byte RGBA. GIF sẽ lưu tất cả các màu mình sẽ dùng ở một bảng (ColorMap) và mỗi pixel mình chỉ cần đi với số thứ tự của màu đó trong bảng . Như vậy dung lượng sẽ nhẹ hơn nhiều so với BMP.</p><p>BitsPerPixel là số bit biểu diễn trên 1 pixel . Ví dụ sử dụng 5 bit trên 1 pixel mỗi pixel chỉ được đánh chỉ số tới 2**5 .</p><p>Quay trở lại <strong>struct SavedImage </strong>. <strong>RasterBits</strong> tương đương với mảng các pixels.</p><p>Ngoài ra ảnh GIF còn có một trường là trường mở Rộng (ExtensionBlocks). Nó sẽ lưu các thông tin khác như plain text, comment,v.v…</p><h3><strong>Exploit</strong></h3><p>Phân tích hàm MakeSavesImage, ta có thể thực hiện các thao tác calloc một size bất kỳ với ColorMap, malloc với Extension và Raster.</p><p><strong>Intended way:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*IaZf7YpZrzdUs_R7t1rG4g.png" /></figure><p>Có thể giảm size của ảnh nên bạn sẽ có thể alloc(size) mà không phải lo hàm free() lại đẩy free chunk vào tcache .Và có thể đạt được AAW như sau.</p><p>Trigger double free.</p><p>[0x70]-&gt;X-&gt;X</p><p>Cấp phát ,ghi dữ liệu vào Raster.</p><p>[0x70]-&gt;X-&gt;<strong>0xDEADBEEF</strong></p><p>Tiếp tục cấp phát cho Raster</p><p>[0x70]-&gt;<strong>0xDEADBEEF</strong></p><h4>Cấp phát thêm một lần nữa =&gt; <strong>GOT AAW</strong></h4><p>POC.C: <a href="https://gist.github.com/nghiadt1098/5571cf51c21574389f9fa1005d9b3c53">https://gist.github.com/nghiadt1098/5571cf51c21574389f9fa1005d9b3c53</a></p><p>FLAG:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*HC738AK5UTdYLqhBxSKDNw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dfab88033529" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SVATTT2018 — ClrOP Writeup]]></title>
            <link>https://medium.com/@nghiadt1098_83598/svattt2018-clrop-writeup-cdcac1e6a950?source=rss-a8f75ca2e897------2</link>
            <guid isPermaLink="false">https://medium.com/p/cdcac1e6a950</guid>
            <category><![CDATA[forensics]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <dc:creator><![CDATA[Nghĩa Đào Trọng]]></dc:creator>
            <pubDate>Sun, 04 Nov 2018 03:39:10 GMT</pubDate>
            <atom:updated>2018-11-04T04:32:25.242Z</atom:updated>
            <content:encoded><![CDATA[<h3>[SVATTT2018] ClrOP Writeup</h3><p>Trong lúc đang xử lý sự cố mã độc trên một máy chủ tại đơn vị X, chúng tôi đã gặp một sự cố, kẻ tấn công ra lệnh dừng tiến trình độc hại, xoá tập tin và các dấu vết liên quan trước khi chúng tôi kịp lấy thông tin mẫu. Thật may mắn, một kỹ sư đã kịp thời trích xuất bộ nhớ tiến trình này trước khi hắn thực hiện điều đó. Liệu hắn ta đã có thể tác động gì lên hệ thống? Chúng tôi trông chờ vào báo cáo của bạn.</p><p>password: <strong>infected</strong></p><p><a href="https://drive.google.com/file/d/1WZv48r-6FBt1XvAcDNjJOGpy80Uv6TxW">link</a></p><p>MD5 của file nén : 0B202FB1B1096BD29F5F8A09CF9882B6</p><p>Haizz. Xem qua thì đây là bài của idol kve , mình vẫn cay idol vì fake bombsite nên mình quyết tâm làm được bài này 😢 .</p><p>Let’s start.</p><p>Đây là một file dump trên windows. Theo như những dòng tâm sự thì đây là file dmp mem của máy tính khi bị malware tấn công. Ta load file dump vào ida .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*Kjwud3ApKPhiit3zIDNW_A.png" /></figure><p>Trong hint tác giả cung cấp một công cụ pe-unmapper.</p><p><a href="https://github.com/hasherezade/pe_recovery_tools/tree/master/pe_unmapper">link</a></p><p>Usage:</p><pre>pe_unmapper.exe [input_file] [load base: in hex] [*output_file]<br>* - optional</pre><p>Ta cần một input_file base :</p><p>+Input file là một vùng memory.</p><p>+ Loadbase là địa chỉ ảo khi file được load vào bộ nhớ.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E-uvzpz_QCzXY8xrhECwbA.png" /></figure><p>Step 2 : Reverse code .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*za0t1VgiSrq8EWzFn0AxzQ.png" /></figure><p>Chương tình sẽ xử lý khi file là một PNG và trong file có chuỗi 8102TTTAVS. Sau đó memcpy vào mem và encrypt file đó</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*O1oOzcfTHCTTF5LupgUkcA.png" /></figure><p>Thuật toán encrypt bằng cách xor tất cả các byte với “\x69” .</p><p>Thuật toán không xor chuỗi magic “8102TTTAVS” nên ta có thể tìm chuỗi trong dump. Cần tìm một chuỗi “8102TTTAVS” trong một FILE PNG và đoạn mem sau chữ đó là đoạn đã bị xor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*u_iZxlBvd6rlB06raf_Gxg.png" /></figure><p>Dump đoạn đó ra, xor lại ta được một file PE nữa 😢</p><p>Đây là một file dotnet.</p><p>Hành vi chủ yếu là tạo một back door cho phép attacker thực hiện lệnh trên máy victim. Data truyền từ máy tính attacker có format như sau.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7dd4c1ba3a671e18f0504ab98ff29087/href">https://medium.com/media/7dd4c1ba3a671e18f0504ab98ff29087/href</a></iframe><p>cmdCode là một trong những giá trị sau</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a29279f1870f6255892311b780015f4/href">https://medium.com/media/9a29279f1870f6255892311b780015f4/href</a></iframe><p>content đã bị mã móa AES.</p><p>2 byte đầu của content sau khi decode aes là command.</p><p>Data gửi đi có format tương tự.</p><p>Từ đó ta code một đoạn script để dump tất cả các msg.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d810b0b4f83f9b1aafe0bf2e2fe41d8b/href">https://medium.com/media/d810b0b4f83f9b1aafe0bf2e2fe41d8b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*TYBRCCTLB_6f6qJ9JGSBtw.png" /></figure><p>Lúc chưa ra được flag, team mình đã chịu sức tâm lý rất lớn, số lượng cũng như chất lượng các bài RE khiến mình bị sock và feed. Khi đã bị thọt thứ hạng văng ra khỏi top 6 miền bắc . Mọi hy vọng tưởng chừng như đã tắt, khi cái code trên stackoverflow không chạy 😢 và một chút edit code làm flag này đến trong sự bất ngờ (đhs ra được flag) lúc giờ thi đấu chỉ còn hơn 20 phút . Các ơn 3 team mates: em Nguyễn Hữu Đức, anh Phạm Thanh Tùng và anh Phạm Anh Trung đã sát cánh bên mình trong suốt vòng loại.</p><p>That’s how FPTU qualified SVATTT Final.</p><p>greetz saigon from z3r0_n1ght.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdcac1e6a950" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>