<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Al Amrikasir</title>
    <description>The latest articles on DEV Community by Al Amrikasir (@amrikasir).</description>
    <link>https://dev.to/amrikasir</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F286952%2F5bf1e4c5-4425-4631-bd48-a39431de866c.jpg</url>
      <title>DEV Community: Al Amrikasir</title>
      <link>https://dev.to/amrikasir</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amrikasir"/>
    <language>en</language>
    <item>
      <title>CTF Write-Up: 2024 Haunted Brewery - Brew4u Challenge</title>
      <dc:creator>Al Amrikasir</dc:creator>
      <pubDate>Wed, 06 Nov 2024 04:22:42 +0000</pubDate>
      <link>https://dev.to/amrikasir/ctf-write-up-2024-haunted-brewery-brew4u-challenge-4nne</link>
      <guid>https://dev.to/amrikasir/ctf-write-up-2024-haunted-brewery-brew4u-challenge-4nne</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;After tackling the “Raise the Dead” challenge, I was ready for the next spooky adventure. This time, I found myself diving into the mysterious Brew4u challenge. With the Haunted Brewery’s annual contest in full swing, this challenge hinted at secrets hidden within the brewery’s system. The goal? Submit a custom brew description while staying alert for any clues that might lead to the legendary BrewMaster’s secret recipe. Let’s see what mysteries lie behind this web exploit!&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenge Description and Clues:
&lt;/h2&gt;

&lt;p&gt;The Haunted Brewery Brew4u Contest is open to patrons who can design the best custom brew! Participants submit descriptions of their dream beer to the BrewMaster for a chance to have it featured in the taproom.&lt;/p&gt;

&lt;p&gt;However, this year, something feels off. Rumors suggest the brewery's submission system is hiding a secret. Some say the legendary BrewMaster's secret-ingredient recipe is buried within the system, accessible only to those with a keen eye for detail.&lt;/p&gt;

&lt;p&gt;Your mission: Submit a description for your custom brew, but be on the lookout—hidden within the system’s responses could be the clues you need to uncover the BrewMaster's secret recipe. The right approach might reveal more than just a drinkable masterpiece.&lt;/p&gt;

&lt;p&gt;Connect to the challenge: &lt;a href="https://hackersnhops-stop-changing-the-flag.chals.io/" rel="noopener noreferrer"&gt;https://hackersnhops-stop-changing-the-flag.chals.io/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6g3ikdwo912e9sqaju24.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6g3ikdwo912e9sqaju24.png" alt="Front page Brew4u" width="800" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Investigating
&lt;/h2&gt;

&lt;p&gt;First, I started by investigating where the “secret ingredients” could be hiding. It turns out there’s a flag text file located within the app or brewery files, holding the information we need.&lt;/p&gt;

&lt;p&gt;Next, I decided to test the example brew submission. After entering it, the page redirected me to:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hackersnhops-stop-changing-the-flag.chals.io/ssti" rel="noopener noreferrer"&gt;https://hackersnhops-stop-changing-the-flag.chals.io/ssti&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This endpoint responded by returning the description of the recipe I had just submitted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding SSTI (Server-Side Template Injection)
&lt;/h2&gt;

&lt;p&gt;The URL endpoint I was redirected to, &lt;code&gt;/ssti&lt;/code&gt;, gave me a clear hint that the challenge involves a &lt;strong&gt;Server-Side Template Injection&lt;/strong&gt; (SSTI). SSTI occurs when user input is improperly handled by a template engine on the server side. This allows attackers to inject malicious code into the template, which can then be executed by the server.&lt;/p&gt;

&lt;p&gt;In this case, the page was returning the description I submitted, but there’s a possibility that we can manipulate the input field to execute code on the server and extract sensitive data, like the hidden flag. By exploiting SSTI, attackers could potentially access environment variables, files, or even execute arbitrary code if the template engine is vulnerable.&lt;/p&gt;

&lt;p&gt;Knowing this, I decided to test different payloads to see if I could inject something that would reveal more than just the description.&lt;/p&gt;

&lt;h2&gt;
  
  
  Investigating the Response Header
&lt;/h2&gt;

&lt;p&gt;Next, I focused on analyzing the response headers received after submitting my brew recipe. One detail that caught my attention was the Server header:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Server: Werkzeug/2.0.3 Python/3.9.19&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This indicated that the application was running on Werkzeug, a WSGI utility library for Python, and specifically, version 2.0.3 with Python 3.9.19.&lt;/p&gt;

&lt;p&gt;Werkzeug is often used in web frameworks like Flask, which could give me an insight into the underlying framework and help me identify potential weaknesses or misconfigurations. Knowing the server version could also help me in finding specific exploits related to this software.&lt;/p&gt;

&lt;h2&gt;
  
  
  Template Injection Attempt with &lt;code&gt;{{ config }}&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;I decided to try injecting a simple payload into the template engine to see if I could access any useful server-side information. I used the &lt;code&gt;{{ config }}&lt;/code&gt; payload, which is commonly used in Flask (since it’s powered by Werkzeug) to access the application’s configuration settings.&lt;/p&gt;

&lt;p&gt;To my surprise, the response returned a detailed dictionary of the app’s configuration, which included various settings like:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;Config {'ENV': 'production', 'DEBUG': False, 'TESTING': False, 'PROPAGATE_EXCEPTIONS': None, 'SECRET_KEY': None, 'PERMANENT_SESSION_LIFETIME': datetime.timedelta(days=31), 'SESSION_COOKIE_NAME': 'session', ...}&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This exposed a range of useful information about the server environment, including the environment mode (production), session settings, and more. Notably, the SECRET_KEY field was None, which could be a potential weak spot for further exploitation.&lt;/p&gt;

&lt;p&gt;At this point, I realized that the app might not be handling user input properly, making it vulnerable to further SSTI attacks.&lt;/p&gt;

&lt;h2&gt;
  
  
  More Exploit
&lt;/h2&gt;

&lt;p&gt;Encouraged by the results of injecting &lt;code&gt;{{ config }}&lt;/code&gt;, I decided to push further by trying additional payloads to see what else I could uncover. I started by injecting &lt;code&gt;{{ request }}&lt;/code&gt; to check for any information about the current HTTP request. This returned useful details about the request object.&lt;/p&gt;

&lt;p&gt;Next, I attempted &lt;code&gt;{{ request.application }}&lt;/code&gt;, which is another common payload used in Flask applications to access more specific server-side details. The result was:&lt;br&gt;
&lt;code&gt;&amp;lt;bound method Request.application of &amp;lt;class 'flask.wrappers.Request'&amp;gt;&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This output indicated that the request.application method was exposed. Although it wasn’t directly revealing any immediate sensitive data, it did show that the Flask request object had exposed server-side methods that could potentially be leveraged in further attacks.&lt;/p&gt;

&lt;p&gt;At this point, it was clear that the app was highly vulnerable to Server-Side Template Injection (SSTI), and it was possible to continue exploring for ways to extract more critical information or trigger further vulnerabilities.&lt;/p&gt;

&lt;p&gt;As I was looking for ways to access more sensitive information, I realized that I might be able to view the contents of the current working directory. To achieve this, I injected the following payload:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__globals__&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__builtins__&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;__import__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;os&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;listdir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;.&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This payload exploited the os module (which is part of Python’s standard library) by accessing it through the &lt;strong&gt;import&lt;/strong&gt; function. The result was an array containing the names of files and directories in the current working directory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fynqfv6orfnrqfkz7qbj6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fynqfv6orfnrqfkz7qbj6.png" alt="Image description" width="800" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This allowed me to see what files were present on the server, which could be useful for further exploration. This step confirmed that the server’s security was severely compromised, as I had full access to potentially sensitive directories and files on the system.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;['flag.txt', 'app.py', 'requirements.txt', 'Dockerfile', 'static', 'templates']&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Among these files, &lt;em&gt;flag.txt&lt;/em&gt; immediately stood out as a potential candidate for containing the flag. This was a crucial find, as it directly pointed to a file that likely held the secret flag we were hunting for.&lt;/p&gt;

&lt;p&gt;With this discovery, my next step was clear: investigate the &lt;em&gt;flag.txt&lt;/em&gt; file to uncover the hidden flag and complete the challenge.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finisher
&lt;/h2&gt;

&lt;p&gt;Since I had already located &lt;em&gt;flag.txt&lt;/em&gt; in the directory, I decided to take the next step and try to read its contents. Using another injection, I attempted to open and read the file directly from the server by injecting the following payload:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__globals__&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__builtins__&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;flag.txt&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This payload used Python’s built-in open() function to access the file and read() to get its content. The result returned the contents of flag.txt, revealing the hidden flag:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;HnH{j1njA2_t3mpl4t3_1nj3cT}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;With this, I had successfully retrieved the flag and completed the challenge.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this challenge, I was able to exploit a &lt;strong&gt;Server-Side Template Injection&lt;/strong&gt; (SSTI) vulnerability to access sensitive server-side information, ultimately leading to the discovery of the hidden flag. By systematically exploring the application’s configuration, performing directory listing, and reading the contents of the &lt;em&gt;flag.txt&lt;/em&gt; file, I was able to complete the challenge successfully. This exercise reinforced the importance of carefully handling user input and the potential risks of exposing internal application components in web applications.&lt;/p&gt;

&lt;p&gt;A big thank you to my colleague &lt;a class="mentioned-user" href="https://dev.to/sulthanullah_haqqihidaya"&gt;@sulthanullah_haqqihidaya&lt;/a&gt; for the valuable explanation about SSTI, which greatly helped in solving this challenge.&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>ctf</category>
      <category>writeup</category>
      <category>web</category>
    </item>
    <item>
      <title>CTF Write-Up: 2024 Haunted Brewery - Raise the Dead Challenge</title>
      <dc:creator>Al Amrikasir</dc:creator>
      <pubDate>Mon, 04 Nov 2024 11:22:49 +0000</pubDate>
      <link>https://dev.to/amrikasir/ctf-write-up-raise-the-dead-the-haunted-brewery-challenge-1jl4</link>
      <guid>https://dev.to/amrikasir/ctf-write-up-raise-the-dead-the-haunted-brewery-challenge-1jl4</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I recently joined my first CTF event, “The Haunted Brewery,” hosted by Hackers N’ Hops and sponsored by &lt;a href="https://tac9security.com/" rel="noopener noreferrer"&gt;Tac 9 Security&lt;/a&gt; and &lt;a href="https://cyber-center.org/" rel="noopener noreferrer"&gt;the National Cybersecurity Center&lt;/a&gt;. This event has been an exciting way to dive into the world of cybersecurity, especially with spooky challenges like “Raise the Dead”&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenge Description and Clues:
&lt;/h2&gt;

&lt;p&gt;When I entered the crypt, I could barely see anything. The only light came from a small flame near a large steel coffin. Suddenly, a ghostly voice whispered, “Release me… and I will help chase off these amateur ghosts ruining your beer… release meeee.” This immediately set the scene for an interesting (and creepy) puzzle.&lt;br&gt;
I was given a file called &lt;em&gt;coffin.txt&lt;/em&gt; that I suspected held the key to solving this spooky puzzle.&lt;/p&gt;

&lt;p&gt;On the coffin, there was a sign that read:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Within we have buried the count. We are sure he will never get out. Do not make the mistake of releasing him!&lt;/p&gt;

&lt;p&gt;Should you encounter another vampire, do as we did! We put a giant STAKE into the heart of him... rolled him facedown and then put him in the coffin backwards!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Investigating the &lt;em&gt;coffin.txt&lt;/em&gt; File:
&lt;/h2&gt;

&lt;p&gt;The file contents were strange at first glance. Here’s what I found:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Hexadecimal Pattern&lt;/strong&gt;: The file mainly consisted of hexadecimal-looking sequences, but something was off. The first line appeared incomplete, as if missing a chunk, which raised my curiosity about hidden information.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;00000000000000000000000000000010000000000000000000000000
000010c20000000000006644000000000000000000000000000000000000
003000000011000000000000000000000000000000100000000000000000
000000000000e045000000000000750f0000000000000000000000000000
000000000030000000900000000000000081000000000000008000000051
000000e1000000000000700b000000000000050400000000000000000000
000000000000000000200000001000000000000000100000000000000010
000000000000000000000000000000620000000000000581000000000000
000000000000000000030000001000001032000000000000000000000000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;“EKATS” Pattern&lt;/strong&gt;: Scrolling down, I encountered repeated sequences of “EKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATS.” This sequence seemed unusual until I realized that “EKATS” was simply “STAKE” spelled backward, aligning with the clue about the vampire being “staked” in reverse.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;EKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATS
EKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATS
EKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATS
EKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATS
EKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATSEKATS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;ELF Header at the End&lt;/strong&gt;: Near the end of the file, I found a hexadecimal sequence resembling an ELF header, 64C454F7. When reversed, it read 7F454C46, which is the standard ELF file magic number (\x7FELF). This hinted that the file might contain a hidden ELF executable embedded in reverse.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;000400d00083000400000000000000000000760700000000000000040000
00000000220c0000001000e3003000000000000000000010102064c454f7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Solution Steps:
&lt;/h2&gt;

&lt;p&gt;After recognizing the hints, I realized that the entire file was likely encoded backward. Here’s how I approached the solution:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Reversing the File Content&lt;/strong&gt;: I used a command-line tool to reverse the contents of coffin.txt from end to start. This allowed me to see if any coherent data appeared when the file was read in reverse order.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;➜ &lt;span class="nb"&gt;tac &lt;/span&gt;coffin.txt | rev &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; reversed_coffin.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Remove STAKE from Count Heart&lt;/strong&gt;: I edited reversed_coffin.txt manualy to remove STAKE. This left me with a cleaner hexadecimal sequence that appeared to be the hex representation of a binary file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Converting Hexadecimal to Binary&lt;/strong&gt;:&lt;br&gt;
I took the remaining hexadecimal data and converted it into binary format. Here’s the command I used:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;➜ xxd &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; reversed_coffin.txt &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; opened_coffin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Identifying the Binary&lt;/strong&gt; as an ELF File:
After converting, I checked the file type:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;➜ file opened_coffin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;after execute the ELF file, I got the flag &lt;code&gt;HnH{BackFromTheDead}&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;This challenge was a fantastic exercise in recognizing patterns, reversing data, and converting hex to binary to reveal a hidden executable file. Removing the “STAKE” pattern was key to extracting the ELF file and ultimately finding the flag. This experience not only improved my technical skills but also reminded me to pay close attention to story-based hints in CTFs.&lt;/p&gt;

&lt;p&gt;A big thank you to Hackers N’ Hops, Tac 9 Security, and the National Cybersecurity Center for organizing this event. It’s been a great learning experience and a fun way to practice Forensic (or RE ????)&lt;/p&gt;

&lt;p&gt;nah, I just hate RE.&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>ctf</category>
      <category>writeup</category>
      <category>forensic</category>
    </item>
  </channel>
</rss>
