reverb.twitter.com redirects to vulnerable reverb.guru
A Twitter subdomain redirected to an external site running a PHP application with an image upload feature that preserved file extensions and only resized images. An attacker could embed a web shell in a crafted JPEG that survived resizing, then upload it with a PHP extension to execute commands and alter the redirect target.
- Triaged in 5 days
- Fixed in 48 days
- Paid in 16 days
- Disclosed after 52 days
Hi!
http://reverb.twitter.com redirects requests to http://reverb.guru which hosts a vulnerable PHP application. I managed to get RCE there which allows to modify the contents of this site, so that reverb.twitter.com will redirect to a phishing page or force a malicious file download.
I was able to get RCE on reverb.guru the following way. By analyzing intercepted requests I discovered http://reverb.guru/api/actions/fileUpload.php. The script allows to upload images on the server (needs a valid Twitter auth):
POST /api/actions/fileUpload.php HTTP/1.1
Host: reverb.guru
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
X-NewRelic-ID: UwYFUF5WGwcCUlNVAgk=
X-Requested-With: XMLHttpRequest
Referer: http://reverb.guru/authoring/
Cookie: _ga=GA1.2.1164992843.1470821302; _gat=1; PHPSESSID=ckdlhrcaioq3mnp4n68asvb3i3
Connection: close
Content-Type: multipart/form-data; boundary=--------541639189
Content-Length: 121
----------541639189
Content-Disposition: form-data; name="image_file"; filename="test.jpg"
IMAGE_DATA
----------541639189--
HTTP/1.1 200 OK
Date: Wed, 10 Aug 2016 10:56:27 GMT
Server: Apache
X-NewRelic-App-Data: PxQAUVRSAAYTUFNUBQYCXkYdFGQHBDcQUQxLA1tMXV1dORY0QwhvTQVGXj1JAltHWQsPEWseUQ8IVGNDDgkCBh4SUBIaFAQcA1UJUQFNA0xUBgVTUU8VAhxGVwZWVAVfBQAPAwAEBQMDUxpOXllYQVY4
Content-Length: 57
Connection: close
Content-Type: application/json
{"image_path":"\/view\/data\/logos\/test_3922005924.jpg"}
The original extension is preserved, so to upload a web shell one needs just to use .php extension. However during the upload image is cropped to a 50x50 square, and the injected web shell is removed from the image. In order to deliver the web shell in the image, it is necessary to learn image quality after resizing. Luckily, uploaded image contains this information:

The next step is to generate a 50x50 jpeg image with 75% quality ratio and inject a web shell into it. There is a nice PoC that can generate such file for us: http://www.virtualabs.fr/Nasty-bulletproof-Jpegs-l
After our crafted jpeg has been uploaded, we can see that web shell survived resizing:

Now, switching to php extension it is possible execute arbitrary commands (http://reverb.guru/view/data/logos/test_4992504809.php?c=id ):

Suggested mitigation is to get rid of this redirect or the entire subdomain.
Thank you!
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
Impact
An attacker with a valid Twitter auth could run commands on the server and change the site content, so the Twitter subdomain could redirect to a phishing page or force a malicious download.
What the attacker needed
A valid Twitter auth; access to the upload endpoint
The fix
The reporter suggested removing the redirect or the entire subdomain.
How it was found
- Intercept requests to find the file upload endpoint on the external site.
- Upload an image and observe that the extension is kept and the image is cropped to 50x50.
- Note the image quality reported after resizing.
- Generate a 50x50 JPEG at that quality with a web shell embedded.
- Upload the crafted JPEG and confirm the shell survives resizing.
- Rename to a PHP extension and request it with a command parameter to execute commands.
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.
A Twitter-owned web address sent visitors to a separate site that ran a small PHP web app. That app let logged-in users upload pictures, but it kept whatever file extension the uploader chose and only shrank the image. By hiding code inside a picture that survived shrinking and naming it with a PHP extension, the uploader could run their own commands on the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.