Описание
Bref's Uploaded Files Not Deleted in Event-Driven Functions
Impacted Resources
bref/src/Event/Http/Psr7Bridge.php:94-125
Description
When Bref is used with the Event-Driven Function runtime and the handler is a RequestHandlerInterface, then the Lambda event is converted to a PSR7 object.
During the conversion process, if the request is a MultiPart, each part is parsed and for each which contains a file, it is extracted and saved in /tmp with a random filename starting with bref_upload_.
The function implementing the logic follows:
The flow mimics what plain PHP does but it does not delete the temporary files when the request has been processed.
Impact
An attacker could fill the Lambda instance disk by performing multiple MultiPart requests containing files. The attack has the following requirements and limitations:
- The Lambda should use the Event-Driven Function runtime.
- The Lambda should use the
RequestHandlerInterfacehandler. - The Lambda should implement at least an endpoint accepting POST requests.
- The attacker can send requests up to 6MB long, so multiple requests are required to fill the disk (the default Lambda disk size is 512MB, therefore with less than 100 requests the disk could be filled).
PoC
- Create a new Bref project.
- Create an
index.phpfile with the following content:
- Use the following
serverless.ymlto deploy the Lambda:
- Replay the following request multiple times after having replaced the
<HOST>placeholder with the deployed Lambda domain:
- Notice that each time the request is sent the number of the uploaded temporary files on the disk increases.
Suggested Remediation
Delete the temporary files after the request has been processed and the response have been generated.
References
Пакеты
bref/bref
< 2.1.13
2.1.13
Связанные уязвимости
Bref enable serverless PHP on AWS Lambda. When Bref is used with the Event-Driven Function runtime and the handler is a `RequestHandlerInterface`, then the Lambda event is converted to a PSR7 object. During the conversion process, if the request is a MultiPart, each part is parsed and for each which contains a file, it is extracted and saved in `/tmp` with a random filename starting with `bref_upload_`. The flow mimics what plain PHP does but it does not delete the temporary files when the request has been processed. An attacker could fill the Lambda instance disk by performing multiple MultiPart requests containing files. This vulnerability is patched in 2.1.13.