SSRF in webhook testing functionality
This lab demonstrates an SSRF vulnerability in a webhook testing service. The application makes HTTP requests to user-supplied webhook URLs without proper validation, allowing access to internal services.
Objective: Use SSRF to access internal services, cloud metadata, or local files through webhook testing.
// Handle webhook test request
if (isset($_GET['webhook']) && !empty($_GET['webhook'])) {
$webhook_url = $_GET['webhook'];
// Vulnerable: No validation of webhook URL
try {
$context_options = [
'http' => [
'timeout' => 10,
'user_agent' => 'WebhookTester/1.0',
'follow_location' => true,
'max_redirects' => 5
]
];
if ($method === 'POST') {
$context_options['http']['method'] = 'POST';
$context_options['http']['header'] = 'Content-Type: application/json';
$context_options['http']['content'] = $payload;
}
$context = stream_context_create($context_options);
$response = file_get_contents($webhook_url, false, $context);
if ($response !== false) {
// Display response content
}
} catch (Exception $e) {
// Error handling
}
}
// Example vulnerable usage:
// ?webhook=https://example.com/webhook
// ?webhook=http://localhost:8080
// ?webhook=file:///etc/passwd
webhookTry these payloads in the webhook 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:
3.php?webhook=http://localhost:80803.php?webhook=file:///etc/passwdClick these links to test the vulnerability: