PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rating: Thread Rating: 28 votes, 4.54 average. Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #256  
Old May 15th, 2008, 12:16 AM
kicken's Avatar
kicken kicken is offline
Wiser? Not exactly.
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: May 2001
Location: Ft Myers, FL
Posts: 4,097 kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)kicken User rank is Colonel (50000 - 60000 Reputation Level)  Folding Points: 115670 Folding Title: Super Ultimate Folder - Level 1Folding Points: 115670 Folding Title: Super Ultimate Folder - Level 1Folding Points: 115670 Folding Title: Super Ultimate Folder - Level 1Folding Points: 115670 Folding Title: Super Ultimate Folder - Level 1Folding Points: 115670 Folding Title: Super Ultimate Folder - Level 1Folding Points: 115670 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Month 2 Weeks 5 Days 22 h 47 m 32 sec
Reputation Power: 532
Send a message via ICQ to kicken Send a message via AIM to kicken Send a message via MSN to kicken
A lot of scripts handle access by including a 'secure.php' file which validates the user by session/posted username/passwords, and in the case of a login failure redirects to the login page.

Remember to always do this redirect in such a way that the rest of the script is not executed after the redirect. The easiest way to do this is using exit; after the redirect.

Example:
I've been recently looking over code for a company to identify security holes and they were doing this for their authentication. they had code which boils down to something like this:

Code:
secure.php
<?php

if (isset($_COOKIE['username']) && isset($_COOKIE['userpass'])){
   $rs = mysql_query('SELECT  password FROM users WHERE username="'.$_COOKIE['username'].'"');
   if (mysql_num_rows($rs) == 0){
     header('Location: login.php');
   }
   else {
       $securepass=mysql_result($rs, 0, 0);
       if (base64_decode($_COOKIE['userpass']) != $securepass){
           header('location: login.php');
       }
  }
}


That file is used in an admin file as so:
Code:
edit.php
<?php

//Validate login, redirect to login page if incorrect.
include('secure.php');


$action = $_GET['action'];
if ($action == 'delete'){
   mysql_query('DELETE FROM entries WHERE entry_id='.$_GET['id']);
   echo 'Entry deleted';
}
?>


Now. Aside from the glaring SQL Injection problems, it is also possible for a completely unauthenticated user to delete stuff because they do not prevent the rest of the script from running.

A request to the URL http://www.site.com/admin/edit.php?action=delete&id=1

will generate a response like so:
Code:
HTTP/1.1 200 Ok
Location: login.php

Entry Deleted


The browser will happily redirect you to login.php and it looks like your code works, but if you look at the DB you'll be quick to notice entry_id #1 is no longer there because the delete was executed when the script finished up. The fix? Just exit after a redirect.

Code:
header('Location: login.php');
exit;
__________________
Spidermonkey Tutorial

http://wiser.aoeex.com/ - Long term project (offline due to evil crawlers and lack of content)
http://www.aoeex.com/gmap.php - Put yourself on the map

Reply With Quote
  #257  
Old June 22nd, 2008, 06:28 PM
GH4 GH4 is offline
Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Posts: 75 GH4 User rank is Corporal (100 - 500 Reputation Level)GH4 User rank is Corporal (100 - 500 Reputation Level)GH4 User rank is Corporal (100 - 500 Reputation Level)GH4 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 18 h 29 m 33 sec
Reputation Power: 0
Send a message via AIM to GH4
MySpace
What are you asking? Are you asking us to try and identify any security holes that you missed?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > [Everyone] Must read Security Notes


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway