Re: [PHP] file_exists
- From: stuttle@xxxxxxxxx (Stut)
- Date: Thu, 15 Nov 2007 23:06:19 +0000
Instruct ICC wrote:
You clearly don't know what the realpath function does. Look it up.No, you've missed the point. $expecteddir is a fixed variable that you, the script author, specify. It does not contain anything coming from external veriables. You then compare the full path you build from the external variables to $expecteddir to verify that the file is in the right directory.I meant if $page evaluates to "/home/stut/phpstuff/inc/../../../../../../../../../../../../home/evil-user-home-dir/evil-payload.php"
I suggest you read the code I posted again.
-Stut
which it does not.
However I don't think your if (substr($page, 0, strlen($expecteddir)) != $expecteddir)
ever evaluates to TRUE. So you'll never get Access denied.
So how you set $page saved your ass. Good job.
-Stut
No I didn't. And I looked it up for the previous reply. And I said that's the only thing saving your ass.
Your IF never evaluates to true.
But it works to keep out the hacker. So I said "Good job".
My server is down right now so I can't do my usual example script.
The realpath function will reduce your definition of $page to "/home/evil-user-home-dir/evil-payload.php"
$expecteddir is set to "/home/stut/phpstuff/inc"
The if takes the first strlen($expecteddir) characters of the reduced $page and compares it to $expecteddir.
If they don't match then if means the requested file is outside your "safe" directory, hence access denied. If they do match then it's safe to include the file.
-Stut
--
http://stut.net/
.
- Follow-Ups:
- Re: [PHP] file_exists
- From: tedd
- RE: [PHP] file_exists
- From: Instruct ICC
- Re: [PHP] file_exists
- References:
- file_exists
- From: Ronald Wiplinger
- Re: [PHP] file_exists
- From: Chris
- Re: [PHP] file_exists
- From: Ronald Wiplinger
- Re: [PHP] file_exists
- From: Chris
- Re: [PHP] file_exists
- From: "Philip Thompson"
- Re: [PHP] file_exists
- From: Stut
- RE: [PHP] file_exists
- From: Instruct ICC
- Re: [PHP] file_exists
- From: Stut
- RE: [PHP] file_exists
- From: Instruct ICC
- Re: [PHP] file_exists
- From: Stut
- RE: [PHP] file_exists
- From: Instruct ICC
- Re: [PHP] file_exists
- From: Stut
- RE: [PHP] file_exists
- From: Instruct ICC
- file_exists
- Prev by Date: Foreach question
- Next by Date: Re: [PHP] Foreach question
- Previous by thread: RE: [PHP] file_exists
- Next by thread: RE: [PHP] file_exists
- Index(es):
Relevant Pages
|