Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 07-21-2006, 12:53 AM Security Faults
portkey's Avatar
Skilled Talker

Posts: 55
Name: Erica Dion
Trades: 0
I use a VERY basic script to make content load easier into my layout so that everypage does not need to be edited each time i change layouts. The code (seen below) is very faulty though as it allows external sources to be included, making it very easy to hack into my server, due to how its link:
http://www.mydomain.com/index.php?site=homepage

PHP Code:
<?php
if(!$site || $site == ""){
  
$site "news";
}

include(
"$site.php"); 
?>
I know i could just include a header and footer on each page, but i had hoped to try and avoid that at all costs. What is there a way to keep the current system but increase security?
portkey is offline
Reply With Quote
View Public Profile Visit portkey's homepage!
 
 
Register now for full access!
Old 07-21-2006, 03:13 AM Re: Security Faults
Mad182's Avatar
Skilled Talker

Posts: 54
Name: Madars
Location: Latvia
Trades: 0
I'm not good at this, but maybe you can read all include file names in array, and than chech if its in array. If it's not, show news page.
__________________
There's no place like 127.0.0.1

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Mad182 is offline
Reply With Quote
View Public Profile Visit Mad182's homepage!
 
Old 07-21-2006, 09:15 AM Re: Security Faults
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
You can use $_SERVER['HTTP_REFERER'] to check where its called from.

So

if( $_SERVER['HTTP_REFERER'] == "www.mydomain.com"){

if(!empty($_GET['site'])){
$site = $_GET['site'];
$site = "news";
}

include($site.".php");
}

Also you are going about it in the old style by assuming $site has mapped directly to site which is depreciated these days and considered bad practice. Use $_GET['site'] to grab your variables from the URL and $_POST['var'] when dealing with forms.

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 07-21-2006, 09:26 AM Re: Security Faults
AliKat's Avatar
Extreme Talker

Latest Blog Post:
Save the Children
Posts: 176
Location: MS
Trades: 0
You could use a switch statement for each of your pages.

PHP Code:
switch($_GET['site'])
{
 case 
"homepage": include("homepage.php"); break;
 case 
"X": include("X.php"); break;
 default: include(
"news.php");

Though I wouldn't use words I would use numbers 1, 2, 3, etc.

The domain script is easy but you could screw up your site if someone put in a file that was exiting on your server that wasn't meant to be displayed. It's not a secruity risk as most of what you put on there you'd know what is.
AliKat is offline
Reply With Quote
View Public Profile Visit AliKat's homepage!
 
Old 07-21-2006, 11:50 AM Re: Security Faults
Ultra Talker

Posts: 256
Location: Auckland, New Zealand
Trades: 0
AliKat's method is probably the better option, by making sure that you limit what pages can be included.

PHP Code:
<?php
if(isset($_GET['site']) && $_GET['site'] === || !empty($_GET['site']))
{
  switch(
$_GET['site'])
  {
    case 
0:
      include_once(
'page1.php');
      break;
    case 
1:
      include_once(
'page2.php');
      break;
    default:
      include_once(
'news.php');
      break;
  }
}
?>
At least this way they can't include any other sites that you don't allow, however for a number of different sites, a better management way would be required, storing it in an array, flatfile/xml, database etc.

Cheers,

MC
__________________
#------------------------------signature---------------------------------------------------------------------------------#
Quote:
I am well recognised for what I don't do than what I do. Chores are just one of those things.
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
Old 07-24-2006, 09:05 AM Re: Security Faults
Junior Talker

Posts: 3
Name: Josh
Trades: 0
Do what one of the others said with the cases..

That code is easy to break, you simply make a script on your server that echos BAD CODE, that gets executed by your server and the user can do anything...
Acecool is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Security Faults
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29693 seconds with 12 queries