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:
  #136  
Old March 12th, 2003, 11:25 PM
wizards wizards is offline
The Wizard
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 128 wizards User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
use php-cgiwrap to run php scripts in your username...
__________________
Stand out for justice as witnesses to God

Reply With Quote
  #137  
Old March 13th, 2003, 09:52 AM
Morrigan's Avatar
Morrigan Morrigan is offline
Midnight Rider
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: Quebec, Canada
Posts: 58 Morrigan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
I want to point out something I found out about cookie forging. On a site I developed, different users have different kind of access, and their user_id and access_id is stored in a session variables, and for those who want the site to remember their login, also in a cookie. We figured someone might try to edit their cookie and change the access rank to one higher than their legitimate one, and tested it, and it was just ignored. Also, if the browser was closed, and then re-opened to the page, the edited cookie would simply be deleted.

Has this happened to anyone else? I tested it on different machines and the same behavior re-occured.

Reply With Quote
  #138  
Old March 13th, 2003, 10:05 AM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Afghanistan
Posts: 14,385 Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 72870 Folding Title: Intermediate FolderFolding Points: 72870 Folding Title: Intermediate FolderFolding Points: 72870 Folding Title: Intermediate FolderFolding Points: 72870 Folding Title: Intermediate Folder
Time spent in forums: 2 Months 4 Weeks 20 h 19 m 49 sec
Reputation Power: 1784
Send a message via ICQ to Sepodati Send a message via Yahoo to Sepodati
I think the browser tries to protect the cookie and ignore any changes you make directly to the file. but that doesn't stop someone from connecting directly through telnet or with a socket in PHP and sending their own cookie data by creating their own headers. They will know the format needed from the cookie you've already supplied them.

The vulnerability is there, even if you can't directly edit the cookie file. I think that ability is system dependent.

---John Holmes...

Reply With Quote
  #139  
Old April 14th, 2003, 06:54 PM
nintendong's Avatar
nintendong nintendong is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 13 nintendong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I found this as a little extra for CMS security



PHP Code:
 $crypt_pass crypt($this->passCRYPT_MD5); 

Reply With Quote
  #140  
Old April 14th, 2003, 07:02 PM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Afghanistan
Posts: 14,385 Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 72870 Folding Title: Intermediate FolderFolding Points: 72870 Folding Title: Intermediate FolderFolding Points: 72870 Folding Title: Intermediate FolderFolding Points: 72870 Folding Title: Intermediate Folder
Time spent in forums: 2 Months 4 Weeks 20 h 19 m 49 sec
Reputation Power: 1784
Send a message via ICQ to Sepodati Send a message via Yahoo to Sepodati
Wow, you're right. I put that line in my code and now I can't hack into my program at all. It's amazing...

Anyhow... Thanks for the tip, but you may want to describe what it does and how someone should use it. That's the whole purpose of this thread.

---John Holmes...

Reply With Quote
  #141  
Old April 14th, 2003, 07:37 PM
nintendong's Avatar
nintendong nintendong is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 13 nintendong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
http://www.etronicscomputers.com/do...orbeginners.htm

Is this a secure way for using sessions? This is an easy example for me to understand, but I wont use it if it's not a secure one. It looks secure though. Check it out. Thanks!

Reply With Quote
  #142  
Old April 16th, 2003, 03:08 AM
Dieter's Avatar
Dieter Dieter is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: SA, Centurion
Posts: 305 Dieter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 5 h 16 m 26 sec
Reputation Power: 6
thanks for this great post - will surely help alot !!!
__________________
:P

Reply With Quote
  #143  
Old April 19th, 2003, 12:01 PM
nintendong's Avatar
nintendong nintendong is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 13 nintendong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
HELP!

I'm extremely confused now. I'm almost finished creating my Content system and the one of the things I need to finish is the login/validating part. This example below, is it for logging in or validating after logging in on every page? It also seems that everyone has a different example and a different opinion and I'm trying to make my CMS as secure as possible but with all these opinions, different examples, and some that don't work, is there one example we can all agree on, or is any good examples you can recommend? About the below example, I tried it, didn’t work, still don’t know if its for logging in or validating after logging in. Someone please help me? Thank you.

Quote:
Originally posted by iamtgo3
Another thing I have seen is to set 2+ cookies and/or sessionID. This way you can use the cookie data to query a database to see if they are valid users before giving them access to certain pages.
PHP Code:
//Set Cookies and sessionID when the users logs in.
setcookie("registered""Yes"time()+ "2592000""/"""0);
setcookie("username"$nametime()+ "2592000""/"""0);
setcookie("userid"$useridtime()+ "2592000""/"""0);
setcookie("password"$passwordtime()+ "2592000""/"""0);
$session session_id();

// Run this validation when a user comes to restricted area
if ($HTTP_COOKIE_VARS["registered"] != "Yes") {
  echo 
"You do not have access";
  exit;
}

$username$HTTP_COOKIE_VARS['username'];
$userid $HTTP_COOKIE_VARS['userid'];
$password$HTTP_COOKIE_VARS['password'];

$db_name "Database";

$link mysql_connect("localhost""username""password") or die("Could not connect to server!");
$query "SELECT * FROM Users WHERE userid = '$userid' AND password = password('$password') AND userid = '$userid'";
$result mysql_db_query($db_name$query$link) or die("Could not complete database query");
$num mysql_num_rows($result);

if (
$num != 0) {
  echo 
"Your In";
} else {
  echo 
"You are not in";


Reply With Quote
  #144  
Old April 19th, 2003, 02:45 PM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Afghanistan
Posts: 14,385 Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 72870 Folding Title: Intermediate FolderFolding Points: 72870 Folding Title: Intermediate FolderFolding Points: 72870 Folding Title: Intermediate FolderFolding Points: 72870 Folding Title: Intermediate Folder
Time spent in forums: 2 Months 4 Weeks 20 h 19 m 49 sec
Reputation Power: 1784
Send a message via ICQ to Sepodati Send a message via Yahoo to Sepodati
If you have questions, please start a new thread. This thread is for security notes, a place to post remarks related to PHP security. This isn't the best place to ask new questions. The only people reading this thread are (hopefully) newbies here and those of us that have contributed and get the notice through email that someone posted here.

Anyhow, that code you posted here is not a good method to use at all. It's setting the user's password in a cookie, which is a bad idea and the query is messed up (repeated $user check).

There are better methods and it's been discussed around here a lot. Either search or start a new thread with your questions.

---John Holmes...

Reply With Quote
  #145  
Old May 19th, 2003, 07:32 AM
BigJB-Work BigJB-Work is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 1 BigJB-Work User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by DiPesa
You named this vulnerability:


That is an obvious bug. But only if you use

include($page);

in you code. As Keiichi suggested to use
include("$DOCUMENT_ROOT/director/blah_$page.php");

You effectively execute
include("$DOCUMENT_ROOT/director/blah_../../../../../etc/passwd.php");

which results in an illegal filename. The trick suggested by Keiichi limits the pages you can use to the pages mentioned: bla_*.php.


Personally i prefer to check the $page for punctuation and simply deny it and return an error page if any exsists. It means a bit extra thought into how directory structures are going to be layed out. Alternatively you might simply check for a "../" or "://".

Reply With Quote
  #146  
Old May 20th, 2003, 04:12 AM
Jeb.'s Avatar
Jeb. Jeb. is offline
Gogo Google.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Adelaide, Australia
Posts: 226 Jeb. User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to Jeb.
I like to predefine all my pages that will be accessed. However, I don't just load the page names into the array: I load key=>value pairs into the array. I pass the KEY in the url, so the user never knows what file they're getting.

I know which pages will be permissible, and which will not.

I load these accepted pages into an array, and perform a check on them.

If the page exists in the array, I include it. Otherwise, I don't. Pretty common method nowadays.

Two fold advantage: Secure, and shadowed, meaning the user doesn't really know what they're looking at. All they see is "index.php?code=00".

It's not very extensible (well, it could be with some tricks), but it's just my preferred method.

Reply With Quote
  #147  
Old May 25th, 2003, 05:20 PM
9902468 9902468 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 1 9902468 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Keiichi
Morisato's

method is my choice for this .inc mess,


PHP Code:
if (file_exists(blah_$page.php)) {
  include(
"$DOCUMENT_ROOT/director/blah_$page.php");
}
else { echo 
"does not exist"; } 


But I only accept letters a-z in $page; everything else gets ripped away.

About cookies/username/password, I use two cookies. One contains data for timeout, (name=session_time, value=time_of_creation, updated every request), one contains no information (name and value are generated randomly at login, this is only to annoy hackers)

All I do is that I compare that current_time - session_time < 10minutes and randomly_generated_cookie_name value = randomly_generated_cookie_value, if all this adds up, then I trust my session and I can check user_level, used_id etc from session.

example randomly_generated_cookie_name = 2434b2cc4c148f68de4ecbaf549710e7

These ofcourse are addition to php's own session id cookie. If you wan't to make it a bit harder to hack you can change the values to random number cookie every request.

Any thoughts?

-9902468

Reply With Quote
  #148  
Old May 25th, 2003, 05:34 PM
dwh dwh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2000
Posts: 180 dwh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 9 m 32 sec
Reputation Power: 8