NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page php inclusion flaw (I could get hacked, please help)

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 11-14-2004, 06:21 PM THREAD STARTER               #1 (permalink)
NamePros Regular
Join Date: Oct 2004
Location: IL
Posts: 657
Unknown will become famous soon enoughUnknown will become famous soon enough
 



Dynamic Page Inclusion Fix


One of my sites includes files depending on the variable definded in the URL address. Someone told me that is a secruity flaw, could anyone tell me what I can do to fix it?
Here is an exmaple:

mysite.com/?page=somehaxsite.com/haxscript.php

It will include haxscript.php, any one know hte fix?
Last edited by Unknown; 11-14-2004 at 06:43 PM.
Unknown is offline  
Old 11-14-2004, 07:28 PM THREAD STARTER               #2 (permalink)
NamePros Regular
Join Date: Oct 2004
Location: IL
Posts: 657
Unknown will become famous soon enoughUnknown will become famous soon enough
 



Bump
Unknown is offline  
Old 11-14-2004, 08:30 PM   #3 (permalink)
New Member
 
wcolby's Avatar
Join Date: Nov 2004
Posts: 13
wcolby is an unknown quantity at this point
 



you need to edit the files so the filename's it looks for are prefixed with a let's say a letter or word..

mysite.com/?page=sale.php would pulldown inc_sale.php

If you need help post the snippet of code that does your includes or email it to me at wcolby@NOSPAMranking.ws (remove the nospam) and I'll edit it and mail it back to you with instructions.
__________________
SEO News | Free Link Popularity Checker
wcolby is offline  
Old 11-14-2004, 10:27 PM THREAD STARTER               #4 (permalink)
NamePros Regular
Join Date: Oct 2004
Location: IL
Posts: 657
Unknown will become famous soon enoughUnknown will become famous soon enough
 



So I just create a prefix for all file names and in the script ask for the $page var and add the prefix to it then include it?

This is simple, but I was wondering if there is an easier way.
Unknown is offline  
Old 11-21-2004, 04:11 PM   #5 (permalink)
NamePros Regular
 
DuffMan's Avatar
Join Date: Jul 2003
Location: Maryland, USA
Posts: 603
DuffMan has a spectacular aura aboutDuffMan has a spectacular aura about
 



I actually had my site hacked like this. I ended up just creating header and footer files and including them in every page instead of using the index.php?page=bla method. I know it takes a lot of work, but you're almost guaranteed to be safe. Alternatively, you could probably make sure the include statement is like this:

include("http://www.mysite.com/".$_HTTP_GET_VARS["page"]);

I'm not completely sure that's safe, however, so I would just go with the first method.
__________________
Eric AKA DuffMan
[HG Interactive]
[ ShoutPro]
DuffMan is offline  
Old 11-21-2004, 08:37 PM   #6 (permalink)
Account Closed
 
axilant's Avatar
Join Date: May 2004
Location: /etc/passwd
Posts: 2,178
axilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to behold
 

Member of the Month
July 2005

or,

you can have an array of allowed files that can be included, and use a if statement to make sure its allowed to be used. Could be a hassle if ur not fimiliar with arrays.
axilant is offline  
Old 11-21-2004, 09:20 PM   #7 (permalink)
québécois libre
 
peaudecastor's Avatar
Join Date: Oct 2003
Location: Trois-Rivieres, Québec
Posts: 558
peaudecastor is just really nicepeaudecastor is just really nicepeaudecastor is just really nicepeaudecastor is just really nicepeaudecastor is just really nicepeaudecastor is just really nicepeaudecastor is just really nicepeaudecastor is just really nice
 



Just be sure that there isnt an http:// tag in the url you get..
peaudecastor is offline  
Old 11-22-2004, 12:12 AM   #8 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
Originally Posted by DuffMan
Alternatively, you could probably make sure the include statement is like this:
????: NamePros.com http://www.namepros.com/programming/55553-php-inclusion-flaw-i-could-get.html

include("http://www.mysite.com/".$_HTTP_GET_VARS["page"]);

I'm not completely sure that's safe, however, so I would just go with the first method.
if you do that then the person has access to any file that is on that domain,

what is to stop someone going to a url for say http://www.mysite.com/script.php?pag...des/config.inc
__________________
Manage your portfolio using my new Domain Portfolio Management script.
Securing Your Domain Name From Theft
Peter is offline  
Old 11-24-2004, 02:58 PM   #9 (permalink)
NamePros Regular
 
DuffMan's Avatar
Join Date: Jul 2003
Location: Maryland, USA
Posts: 603
DuffMan has a spectacular aura aboutDuffMan has a spectacular aura about
 



Originally Posted by filth
if you do that then the person has access to any file that is on that domain,

what is to stop someone going to a url for say http://www.mysite.com/script.php?pag...des/config.inc
True, didn't think of that. That's why I said I wasn't sure it was safe.
????: NamePros.com http://www.namepros.com/showthread.php?t=55553

However, most include files are .inc.php and the values are within <?php and ?> tags, meaning they won't be shown anyway.

I'd just go with the header and footer files methods. It's a minor inconvenience to switch over, but makes you safer in the long run.
__________________
Eric AKA DuffMan
[HG Interactive]
[ ShoutPro]
DuffMan is offline  
Old 11-25-2004, 12:31 AM   #10 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
then why this discussion in the first place, the person wishes to secure a php file. Also even if it is a .php file the possible error message could convey information in itself.
__________________
Manage your portfolio using my new Domain Portfolio Management script.
Securing Your Domain Name From Theft
Peter is offline  
Old 11-25-2004, 12:39 AM   #11 (permalink)
Senior Member
Join Date: May 2003
Posts: 2,187
adam_uk is a jewel in the roughadam_uk is a jewel in the roughadam_uk is a jewel in the rough
 


Breast Cancer
use a switch statement

<?

switch($_GET['page'])
{
case 'page1':
include("page1.php");
break;
case 'page2':
include("page1.php");
????: NamePros.com http://www.namepros.com/showthread.php?t=55553
break;
case 'page3':
include("page1.php");
break;
case 'page4':
include("page1.php");
break;
case default:
include("error.php");
}
?>

then change the links to http://yoursite.com/index.php?page=page1

etc

and if they give something like http://yourside.com/index.php?page=hakscript.php

that will send them to the default case and show them an error
adam_uk is offline  
Old 11-25-2004, 05:23 PM   #12 (permalink)
NamePros Regular
Join Date: Apr 2004
Location: Near Albany NY
Posts: 261
NineASpades is on a distinguished road
 



Why not just have your link look like
http://www.yoursite.com?page=blah
not
http://www.yoursite.com?page=blah.php

Then in the index file have
include($_GET[page].php);

I think that would work....
__________________
CoverageArea.com & CoverageAreas.com - TAKING OFFERS
Discuss Business | PC Gaming Talk | Travel Safety Tips
NineASpades is offline  
Old 11-25-2004, 07:22 PM   #13 (permalink)
Account Closed
 
Sergio965's Avatar
Join Date: Apr 2004
Location: ~root
Posts: 1,091
Sergio965 is a splendid one to beholdSergio965 is a splendid one to beholdSergio965 is a splendid one to beholdSergio965 is a splendid one to beholdSergio965 is a splendid one to beholdSergio965 is a splendid one to beholdSergio965 is a splendid one to behold
 



Originally Posted by NineASpades
Why not just have your link look like
http://www.yoursite.com?page=blah
not
http://www.yoursite.com?page=blah.php

Then in the index file have
include($_GET[page].php);

I think that would work....
Yea, but wouldn't they still be able to access the file?

Using:
http://www.yoursite.com?page=hacksite
Sergio965 is offline  
Old 11-25-2004, 07:33 PM   #14 (permalink)
NamePros Regular
Join Date: Apr 2004
Location: Near Albany NY
Posts: 261
NineASpades is on a distinguished road
 



Well along with what I said I usually have an index file which will have something like

if ($_GET[page] == "blah") {
include("blah.php");
}

or like said before use a switch structure.

Also, is there a reason the user should not be allowed to visit
http://www.yoursite.com?page=whatever

I do not understnad how that would lead them to hacking the site...Can you explain please?
__________________
CoverageArea.com & CoverageAreas.com - TAKING OFFERS
Discuss Business | PC Gaming Talk | Travel Safety Tips
NineASpades is offline  
Old 11-25-2004, 08:12 PM   #15 (permalink)
Account Closed
 
Sergio965's Avatar
Join Date: Apr 2004
Location: ~root
Posts: 1,091
Sergio965 is a splendid one to beholdSergio965 is a splendid one to beholdSergio965 is a splendid one to beholdSergio965 is a splendid one to beholdSergio965 is a splendid one to beholdSergio965 is a splendid one to beholdSergio965 is a splendid one to behold
 



Originally Posted by NineASpades
Well along with what I said I usually have an index file which will have something like

if ($_GET[page] == "blah") {
include("blah.php");
}

or like said before use a switch structure.

Also, is there a reason the user should not be allowed to visit
http://www.yoursite.com?page=whatever

I do not understnad how that would lead them to hacking the site...Can you explain please?
Wouldn't that make an error?

Maybe:

if ($_GET[page] == "blah") {
include("blah.php");
}
else
{
include ("error.php");
}

or

if ($_GET[page] == "blah")
include("blah.php");
else
include ("error.php");

Maybe? That should work..
Sergio965 is offline  
Old 11-25-2004, 08:17 PM   #16 (permalink)
NamePros Regular
Join Date: Apr 2004
Location: Near Albany NY
Posts: 261
NineASpades is on a distinguished road
 



Yes, thats what I meant...The code I posted was a quicky, I didnt expand on the else.
__________________
CoverageArea.com & CoverageAreas.com - TAKING OFFERS
Discuss Business | PC Gaming Talk | Travel Safety Tips
NineASpades is offline  
Old 11-25-2004, 08:22 PM   #17 (permalink)
Account Closed
 
Sergio965's Avatar
Join Date: Apr 2004
Location: ~root
Posts: 1,091
Sergio965 is a splendid one to beholdSergio965 is a splendid one to beholdSergio965 is a splendid one to beholdSergio965 is a splendid one to beholdSergio965 is a splendid one to beholdSergio965 is a splendid one to beholdSergio965 is a splendid one to behold
 



oh allright,

So yea..the code I posts would work, you just would need tomake the error.php, either make or just not make it and let it go to a dns error. You can also use the switch, it's almost the same thing..

So, yea...
Sergio965 is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 05:10 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger