8, September 2008

Found a security vulnerability in the Access User Class. - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP  >  PHP classes @finalwebsites.com  >  Access_user Class (Moderator: Olaf)
Topic: Found a security vulnerability in the Access User Class.
« previous next »
Pages: [1] Print

Author Topic: Found a security vulnerability in the Access User Class.  (Read 1736 times)
Atari ST fan
*
Posts: 7
54 credits
Members referred : 0


« on: Oct 15, 2006, 03:36:06 AM »

After looking through your source code, I have found a vulnerability in the function access_page() (line 168 of access_user_class.php)

Code:
function access_page($refer = "", $qs = "", $level = DEFAULT_ACCESS_LEVEL) {
$refer_qs = $refer;
$refer_qs .= ($qs != "") ? "?".$qs : "";
if (isset($_SESSION['user']) && isset($_SESSION['pw'])) {
$this->user = $_SESSION['user'];
$this->user_pw = $_SESSION['pw'];
$this->get_access_level();
if (!$this->check_user()) {
$_SESSION['referer'] = $refer_qs;
header("Location: ".$this->login_page);
}
if ($this->access_level < $level) {
header("Location: ".$this->deny_access_page);
}
} else {
$_SESSION['referer'] = $refer_qs;
header("Location: ".$this->login_page);
}
}
The function merely uses header("Location: ".$this->deny_access_page); and does not exit() or die() after this redirect. This could allow an attacker to view a page that is supposed to be restricted, without even being logged in. This would be accomplished by using a browser that ignores the sent header. Then the rest of the script would execute, revealing the content of the page that is supposed to be invisible to attacker.

Here is what the code should be to be more secure:
Code:
function access_page($refer = "", $qs = "", $level = DEFAULT_ACCESS_LEVEL) {
$refer_qs = $refer;
$refer_qs .= ($qs != "") ? "?".$qs : "";
if (isset($_SESSION['user']) && isset($_SESSION['pw'])) {
$this->user = $_SESSION['user'];
$this->user_pw = $_SESSION['pw'];
$this->get_access_level();
if (!$this->check_user()) {
$_SESSION['referer'] = $refer_qs;
header("Location: ".$this->login_page);
exit();
}
if ($this->access_level < $level) {
header("Location: ".$this->deny_access_page);
exit();
}
} else {
$_SESSION['referer'] = $refer_qs;
header("Location: ".$this->login_page);
                        exit();
}
}

Let me know what you think.
Sean
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Oct 15, 2006, 10:00:22 AM »

Thank you Sean,

I remember that someone pointed me on this before, I will add the exit or die() commands to the script.

By the way there is only a problem if your protect script will be executed (a download script or something)

but anywhat there should be always a die or exit after the header location...

Quote
This would be accomplished by using a browser that ignores the sent header.
I didn't know that this is possible, do you have an example browser?
« Last Edit: Oct 15, 2006, 10:09:41 AM by olaf »


Last blog : Is your website is down? Know before your visitors do!
Atari ST fan
*
Posts: 7
54 credits
Members referred : 0


« Reply #2 on: Oct 15, 2006, 06:14:48 PM »

let me see if I can find an example browser

EDIT: I couldn't find any, but it seems that an attacker can modify a browser to ignore the sent headers.

Maybe it would be better to change the way access_page works to something like this:

{Protected Page}
Code:
include(filename);
$page = new Access;
if ($page->accesspage) {
PROTECTED HTML HERE
}

Then change the function to redirect and return false on authentication fail.
« Last Edit: Oct 15, 2006, 06:19:48 PM by sdat1333 »
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Oct 17, 2006, 10:18:24 AM »



Maybe it would be better to change the way access_page works to something like this:

{Protected Page}
Code:
include(filename);
$page = new Access;
if ($page->accesspage) {
PROTECTED HTML HERE
}

Then change the function to redirect and return false on authentication fail.

you can do that but I don't think that this is common with the most applications. If you need to fight back hackers you should do somthing more then protect pages with just a password...


Last blog : Is your website is down? Know before your visitors do!
OMG!I am geek
**
Gender: Male
Posts: 55
366 credits
Members referred : 0


my day will come..


« Reply #4 on: Oct 25, 2006, 09:14:50 AM »

But, isn't Header a merely PHP function that the server executes? I don't think there's any way to stop a header from being executed since it runs on the server itself..
I know Javascript and VB redirects can be prevented, but not PHP I believe.
My ears are open for reasons though.
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Oct 25, 2006, 10:24:42 AM »

But, isn't Header a merely PHP function that the server executes? I don't think there's any way to stop a header from being executed since it runs on the server itself..
I know Javascript and VB redirects can be prevented, but not PHP I believe.
My ears are open for reasons though.
yes right, that was the first time that a user is telling me these things (check the download count: more than 30000 incl. phpclasses.org)

that will say that a lot of applications a not safe (not only with AU)


Last blog : Is your website is down? Know before your visitors do!
Atari ST fan
*
Posts: 7
54 credits
Members referred : 0


« Reply #6 on: Oct 25, 2006, 01:36:40 PM »

But, isn't Header a merely PHP function that the server executes? I don't think there's any way to stop a header from being executed since it runs on the server itself..
I know Javascript and VB redirects can be prevented, but not PHP I believe.
My ears are open for reasons though.

Well think about it.

A hacker goes to protected page, and is not logged in.
PHP says "Go over here to login.php".
Hacked browser says OK, I went.
PHP execution still goes to completion
Page is shown to hacker.
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #7 on: Oct 25, 2006, 02:43:50 PM »


Well think about it.

A hacker goes to protected page, and is not logged in.
PHP says "Go over here to login.php".
Hacked browser says OK, I went.
PHP execution still goes to completion
Page is shown to hacker.

after this code is executed?

Code:
header("Location: page.php");
exit;


Last blog : Is your website is down? Know before your visitors do!
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8037
41179 credits
Members referred : 3



« Reply #8 on: Oct 25, 2006, 02:57:30 PM »

If the hacker opens this page with socket connection or with curl with FOLLOW_LOCATION = false he/she can get the results of the page.

Of course with the exit statement there is no problem.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : MIA - Where Nick and Tim
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #9 on: Oct 25, 2006, 08:07:26 PM »

If the hacker opens this page with socket connection or with curl with FOLLOW_LOCATION = false he/she can get the results of the page.

Of course with the exit statement there is no problem.
Ok the case is clear (thank you Nick)

the script was updated with the last version and this thread is closed Cheesy


Last blog : Is your website is down? Know before your visitors do!
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=4437
Tags : php javascript html curl vulnerability Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP  >  PHP classes @finalwebsites.com  >  Access_user Class (Moderator: Olaf)
Topic: Found a security vulnerability in the Access User Class.
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Sep 08, 2008, 06:31:00 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 36.302
Total Topics: 7.479
Total Members: 3.907
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: phpprofit

15 Guests, 4 Users online :

6 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.