Challenge 3: The AI's "Smart" Sanitizer
Team Hack
Goal: Read the
config.php file using nested traversal.
The developer asked an AI to "write a function that blocks path traversal attacks". The AI suggested a simple str_replace. Can you fool it?
Copy
<?php
// --- SIMULATED INPUT ---
$page = "bio";
// -----------------------
// --- SANDBOX SETUP ---
$base = sys_get_temp_dir() . "/workshop_" . getmypid() . "/";
@mkdir($base); @mkdir($base . "pages");
file_put_contents($base . "pages/bio.php", "This is the bio page.");
file_put_contents($base . "config.php", "<?php \$flag = 'FLAG{AI_GENERATED_FILTER_BYPASS}'; echo \$flag;");
// AI SUGGESTION: "I'll remove ../ to make it secure!"
$page = str_replace("../", "", $page);
// VULNERABLE CODE
$requestedPage = "pages/" . $page . ".php";
echo "Loading: $requestedPage\n\n";
if (file_exists($base . $requestedPage)) {
include($base . $requestedPage);
} else {
echo "Page not found.";
}
Team Fix
Goal: Don't trust the AI's "hand-rolled" sanitizer.
AI often forgets that filters can be bypassed by "re-forming" the blacklisted string. Use robust native functions like basename().
Tip: basename($page) is much safer than trying to filter paths yourself.