Introducing Wrapwrap: Using PHP Filters To Wrap A File With A Prefix And Suffix
The article describes a technique to add an arbitrary suffix to a resource using PHP filters, enabling the wrapping of file contents into any structure. This allows an attacker to read local files or internal services when an application uses file_get_contents and parses the result, even if it only displays a specific field.
Published on ambionics.io
wrapwrap marks another improvement to the PHP filter exploitation saga. Adding arbitrary prefixes to resources using php://filter is nice, but you can now add an arbitrary suffix as well, allowing you to wrap PHP resources into any structure.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, the application reads a user-controlled URL with file_get_contents and then parses the result without proper validation, allowing PHP filter chains to manipulate the data.
Impact
An attacker could read local files or access internal services that would otherwise be blind, by wrapping the contents in a format the application displays.
What the attacker needed
Application uses file_get_contents on user input; application parses and displays part of the response
How it was found
- Identify an endpoint that reads a user-supplied URL and parses the response.
- Use the wrapwrap tool to generate a filter chain that adds a prefix and suffix to the target file.
- Send the filter chain as the URL parameter to retrieve the file contents wrapped in the expected structure.
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 write-up has not been written yet. The Original tab links to the source.
PHP filters are a feature that can transform data as it is read. The article shows how to chain many filters to add extra characters before and after a file's contents, so that a program that expects a certain format will still display the file. This can let an attacker read files 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.