<?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 SystemCallBeam on Medium]]></title>
        <description><![CDATA[Stories by SystemCallBeam on Medium]]></description>
        <link>https://medium.com/@systemcallbeam?source=rss-7981cb3ea922------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*9hezV5C2MPvstzjo</url>
            <title>Stories by SystemCallBeam on Medium</title>
            <link>https://medium.com/@systemcallbeam?source=rss-7981cb3ea922------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 08:37:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@systemcallbeam/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[FCIACTF:programingTRYTRYTRY]]></title>
            <link>https://medium.com/@systemcallbeam/fciactf-programingtrytrytry-779983158d15?source=rss-7981cb3ea922------2</link>
            <guid isPermaLink="false">https://medium.com/p/779983158d15</guid>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[SystemCallBeam]]></dc:creator>
            <pubDate>Wed, 25 Sep 2024 19:01:35 GMT</pubDate>
            <atom:updated>2024-09-25T19:01:35.081Z</atom:updated>
            <content:encoded><![CDATA[<h4>The Challenges of Programming</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*ATmLa3UsgsgEMWy4OQPJvg.png" /></figure><h4>เริ่มแรก</h4><p>โจทย์ให้หา flag จาก program ที่ให้มา<br>ลองรันโปรแกรมว่าได้อะไร:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*9itAmFLQfeBE-klRPL-J1Q.png" /><figcaption>screen show the program</figcaption></figure><p>สิ่งที่เราทำได้คือลองใส่ข้อมูล มั่ ว</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*zzufekIWe64Uzu4ik0LCRA.png" /><figcaption>screen when you input character</figcaption></figure><p>แล้วถ้าใส่ถูกเป็นแบบไหนต้องใส่จนกว่าจะถูกเลยไหม</p><p>.</p><p>.</p><p>.</p><p>ใ ช่</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*NbbSMPqqEK9H6koDgRMsug.png" /><figcaption>screen when you try input until it correct</figcaption></figure><p>หลังจาก เ ด า ได้สักพักก็ถูกตัวนึง เลขก็เปลี่ยนด้วย</p><p>แล้วถ้าตัวต่อไปผิดล่ะ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*YlZR7u9WyFdjvN7hwKZbog.png" /><figcaption>screen when you incorrect after try so hard</figcaption></figure><p>ก็ต้องเริ่มใส่ใหม่ตั้งแต่ต้นเลย ใ ช่ ไ ห ม</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*uYqHxS_vUmOBQDS3XN8C8w.png" /><figcaption>screen before you have an elegant idea</figcaption></figure><p>ใครจะทำก็ทำ</p><p>เราเป็นโปรแกรมเมอร์นะ ใครก็รู้ว่าเวลาทำอะไรซ้ำ ๆ แบบนี้เราจะทำยังไง</p><h4>Decompile ไปเลย</h4><p>เราเลยหาวิธีแปลง .exe ไปเป็นไฟล์อะไรก็ได้ที่อ่านได้ เช่น .py เพราะเรารู้ว่ามันมาจาก P y t h o n</p><p>เราเริ่มทำจาก:</p><p>อย่างแรกเราต้องหาว่า .exe มาจากไฟล์แบบไหน แต่เราคิดว่า Python เราเลขแปลง .exe ให้เป็นไฟล์ .pyc โดยใช้ repository นี้:</p><pre>git clone https://github.com/extremecoders-re/pyinstxtractor.git</pre><p>แล้วก็ใช้คำสั่งนี้:</p><pre>python pyinstxtractor.py programmingTRYTRYTRY.exe</pre><p>เราได้โฟลเดอร์ที่ชื่อว่า programmingTRYTRYTRY.exe_extracted ซึ่งในนั้นมีไฟล์ pwnable.pyc</p><p>ต่อไปเราก็จะหาเครื่องมือที่จะแปลงไฟล์ .pyc กลับไปเป็นไฟล์ .py เราทำอันแรกไปตั้งนานไม่ได้สักที เลยหาอันใหม่ชื่อว่า <a href="https://pylingual.io/">Pylingual.io</a> ใช้ระวังด้วยนะ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C9QmqOPojCYkxtceYFOopw.png" /><figcaption>screen after you try so hard and got so far in the end</figcaption></figure><p>หลังจากอัปโหลดไฟล์แล้ว เราก็ได้โค้ด P y t h o n ที่เราต้องการ! ตอนนี้เรารู้ว่าโค้ดทำงานยังไง ที่จริงเจอ flag แล้วด้วย</p><p>แต่สิ่งที่เราควรทำตั้งนานแล้วคือบอกกับคุณตรง ๆ ว่า…</p><h4>Brute Force ด้วยดีกว่า</h4><p>เราให้ ChatGPT ช่วยเขียนตามที่เราทดลองมา:</p><ol><li>ป้อนอักษรทีละตัว</li><li>อ่านผลลัพธ์ที่โปรแกรมแสดงออกมา</li><li>เก็บอักษรที่ถูกต้องไว้</li><li>ป้อน flag ที่ถูกทีละตัวหลังจากใส่ตัวอักษรผิด</li><li>ต้องแน่ใจว่าโปรแกรมจะรันจนกว่าจะได้คำตอบ</li></ol><p>โค้ดที่ได้จะต้องใส่ข้อมูลไปโปรแกรม .exe ได้ และรันจนกว่าจะได้ flag</p><p>โค้ดที่ใช้ได้จะประมาณนี้</p><pre>import subprocess<br><br># The path to your executable<br>program_path = &quot;path\to\your\executable.exe&quot;<br><br># The list of possible characters (1/33)<br>possible_chars = &quot; !\&quot;#$%&amp;&#39;()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~&quot;  # Modify this according to the characters allowed<br>max_length = 33  # Total characters expected<br><br># Function to run the program and interact with it<br>def run_program():<br>    # Run the executable using subprocess<br>    process = subprocess.Popen(program_path, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)<br><br>    return process<br><br>def communicate_program(process, input_char):<br>    # Send the input character to the program and get the output<br>    process.stdin.write(input_char + &#39;\n&#39;)<br>    process.stdin.flush()  # Ensure the input is sent<br>    output = process.stdout.readline()  # Read the program&#39;s response<br><br>    return output<br><br># Function to brute-force one character at a time<br>def brute_force():<br>    correct_input = &quot;&quot;<br>    incorrect_char = 0<br>    process = run_program()<br>    <br>    while len(correct_input) &lt; 33:<br>        <br>        for char in correct_input:<br>            <br>            response = communicate_program(process, char)<br>        <br>        for position in range(len(correct_input) + 1, max_length + 1):  # Iterate for each position (1/33)<br>            <br>            while True:<br>                char = possible_chars[incorrect_char]<br>                <br>                # Run the program with the current attempt<br>                response = communicate_program(process, char)<br>                <br>                # Check the program&#39;s response<br>                if &quot;correct!&quot; in response.lower():<br>                    print(f&quot;Correct character at position {position}: {char}&quot;)<br>                    correct_input += char  # Add correct char to our input<br>                    incorrect_char = 0<br>                    break<br>                <br>                # Adjust conditions as needed<br>                elif &quot;wrong character! try again.&quot; in response.lower():<br>                    incorrect_char += 1<br>                    break<br>                <br>            # Stop the loop<br>            if incorrect_char != 0:<br>                break<br>          <br>    process.terminate()  <br>    print(f&quot;Final Correct Sequence: {correct_input}&quot;)<br><br># Start the brute-forcing process<br>brute_force()</pre><p><strong>flag ที่ได้คือ</strong>: fciaCTF{…}</p><p>ไม่สงสัยอะไร ใ ช่ ไ ห ม ?</p><h4>Let’s get started.</h4><p>The problem requires us to find the flag from a given program.<br>When you run a program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*9itAmFLQfeBE-klRPL-J1Q.png" /><figcaption>screen show the program</figcaption></figure><p>You press some keys to input characters and see what happens on the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*zzufekIWe64Uzu4ik0LCRA.png" /><figcaption>screen when you input character</figcaption></figure><p>What you gonna do next.</p><p>.</p><p>.</p><p>.</p><p>Yes!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*NbbSMPqqEK9H6koDgRMsug.png" /><figcaption>screen when you try input until it correct</figcaption></figure><p>After several attempts, you finally input the correct characters.</p><p>But what if you input the wrong characters?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*YlZR7u9WyFdjvN7hwKZbog.png" /><figcaption>screen when you incorrect after try so hard</figcaption></figure><p>Do you have to start over from the first character?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*uYqHxS_vUmOBQDS3XN8C8w.png" /><figcaption>screen before you have an elegant idea</figcaption></figure><p>Nah, I’d Win.</p><p>We’re programmers, right? Everyone knows what we do when we have to repeat something like this.</p><h4>Decompiling an Executable (.exe) to a Readable File</h4><p>So, I decided to figure out how to reverse the process—turning .exe back into something readable like a .py file.</p><p>Here’s the process I followed:</p><p>First, I needed to find out what format the .exe file originated from. So, I needed to convert the .exe into a .pyc file using this repository. Because I know it form P y t h o n:</p><pre>git clone https://github.com/extremecoders-re/pyinstxtractor.git</pre><p>Then, I used the following command:</p><pre>python pyinstxtractor.py programmingTRYTRYTRY.exe</pre><p>This gave me a directory called programmingTRYTRYTRY.exe_extracted, where I found a file named pwnable.pyc.</p><p>Next, I needed to find a tool to convert the .pyc file back into a .py file. So, I searched for tool online and discovered <a href="https://pylingual.io/">Pylingual.io</a>. Be careful while using such tools!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C9QmqOPojCYkxtceYFOopw.png" /><figcaption>screen after you try so hard and got so far in the end</figcaption></figure><p>After uploading the file, I finally got the Python code I was looking for! I could now understand the code and even find the hidden flag.</p><p>But there was more</p><h4>Brute Forcing with Script</h4><p>It was time to brute force! I asked ChatGPT to help write a script that:</p><ul><li>Inputs one character at a time.</li><li>Reads the output that the program gives.</li><li>Collects correct characters.</li><li>Inputs the correct character by character. After input incorrect character</li><li>Make sure the program can run until you get the flag</li></ul><p>The final code would pipe the input to the .exe program and run until the correct flag was obtained.</p><p>This is example code</p><pre>import subprocess<br><br># The path to your executable<br>program_path = &quot;path\to\your\executable.exe&quot;<br><br># The list of possible characters (1/33)<br>possible_chars = &quot; !\&quot;#$%&amp;&#39;()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~&quot;  # Modify this according to the characters allowed<br>max_length = 33  # Total characters expected<br><br># Function to run the program and interact with it<br>def run_program():<br>    # Run the executable using subprocess<br>    process = subprocess.Popen(program_path, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)<br><br>    return process<br><br>def communicate_program(process, input_char):<br>    # Send the input character to the program and get the output<br>    process.stdin.write(input_char + &#39;\n&#39;)<br>    process.stdin.flush()  # Ensure the input is sent<br>    output = process.stdout.readline()  # Read the program&#39;s response<br><br>    return output<br><br># Function to brute-force one character at a time<br>def brute_force():<br>    correct_input = &quot;&quot;<br>    incorrect_char = 0<br>    process = run_program()<br>    <br>    while len(correct_input) &lt; 33:<br>        <br>        for char in correct_input:<br>            <br>            response = communicate_program(process, char)<br>        <br>        for position in range(len(correct_input) + 1, max_length + 1):  # Iterate for each position (1/33)<br>            <br>            while True:<br>                char = possible_chars[incorrect_char]<br>                <br>                # Run the program with the current attempt<br>                response = communicate_program(process, char)<br>                <br>                # Check the program&#39;s response<br>                if &quot;correct!&quot; in response.lower():<br>                    print(f&quot;Correct character at position {position}: {char}&quot;)<br>                    correct_input += char  # Add correct char to our input<br>                    incorrect_char = 0<br>                    break<br>                <br>                # Adjust conditions as needed<br>                elif &quot;wrong character! try again.&quot; in response.lower():<br>                    incorrect_char += 1<br>                    break<br>                <br>            # Stop the loop<br>            if incorrect_char != 0:<br>                break<br>          <br>    process.terminate()  <br>    print(f&quot;Final Correct Sequence: {correct_input}&quot;)<br><br># Start the brute-forcing process<br>brute_force()</pre><p>Final Correct Sequence: fciaCTF{…}</p><p>Have a pink sky day!</p><p>Author:<a href="https://medium.com/u/7981cb3ea922">SystemCallBeam</a></p><p>Challenges:<a href="https://medium.com/u/29e16bfdf251">scriptpi01</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=779983158d15" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>