Natas Level 33
Natas Level 33 — an upload checker and a file function combine so that a crafted archive triggers deserialisation; learn about PHP phar attacks.
Table of Contents
Source: This content is aggregated from overthewire (MIT). Visit the original repository for the latest version.
Username: natas33
URL: http://natas33.natas.labs.overthewire.org
Study guide
Level map: sign in as natas33 and find the password for natas34.
What this level teaches
How seemingly harmless file functions can trigger object deserialisation.
Key ideas
- Phar archives. PHP can read an archive format called phar, which stores serialised metadata.
- Stream wrappers. File functions accept URL-like paths such as
phar://...; opening one can cause the metadata to be unserialised automatically. - Gadget in the source. A class in the page code performs an unsafe action when it is destroyed.
- Building a phar. PHP’s
Pharclass lets you create one with your own metadata, if the build is allowed in your environment.
How to approach it
- Read the upload and checking code carefully, and find the class that does something interesting.
- Work out how to get your file to the server and make a file function open it as a phar.
How developers prevent it
Disallow phar:// for user-controlled paths, update PHP, and avoid dangerous classes that act on destruction.