Reply
Login System Using PHP Session, Safe?
Old 05-23-2008, 07:03 PM Login System Using PHP Session, Safe?
Experienced Talker

Posts: 35
Name: Gjore Sazdovski
Now, I'm looking for an expert, explained advice on building PHP login systems.

Is using the built-in "session_register" safe enought? what are the vulns/holes?

I want to build a REALLY strong login system, closed-source...

Should I be using these built-in functions or make my own system with custom cookies? And if I must do that, any advice on what-to and what-not-to do?

Thanks in advance.
Gjore.S is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 05-23-2008, 07:38 PM Re: Login System Using PHP Session, Safe?
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 984
Name: Jeremy Miller
Location: Reno, NV
I'd say the following:

1) Use database-based sessions. This makes hacking the session harder.
2) Require cookies. This will minimize session hacking.
3) Might want to just define session variables with the $_SESSION array since it's not 100% compatible with session_register-related functions.
4) Do not store passwords in plain-text form. Look at the hash() function. I usually use SHA512.
5) Protect against multiple attempts. There are 2 ways you can do this:
I) Only allow X number of attempts, or
II) For each failed attempt, make the user wait Y seconds between attempts. This doesn't protect you as much, but it slows down brute force scripts.
6) Do NOT use IP-based tracking. On large hosts, the IP can change from page to page which can be a real pain. I did this once and had quite a few AO-Hell members *****ing at me.
7) I suggest a username-based system instead of a login-based system where the username is used only for logging in. Why? Doing so makes it harder to guess 1/2 the equation (i.e. a hacker must guess both username and password instead of just password when provided the email [or it's easy to find]).

That should get you started. Good luck!
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-24-2008, 03:37 AM Re: Login System Using PHP Session, Safe?
Arenlor's Avatar
Ultra Talker

Posts: 463
Name: Jerod Lycett
Location: /home/arenlor
Sessions are the most secure thing. Use them instead of cookies.
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 05-24-2008, 10:46 AM Re: Login System Using PHP Session, Safe?
rogem002's Avatar
Webmaster Talker

Posts: 611
Name: Mike
Location: United Kingdom
Sessions are stored server side, not client side. This makes them much more secure. Though, it's a good idea to have a confirmation server-side based on browser and IP address just encase the cookie what holds the session ID leaks.
__________________
PHP Code:
Add_Talkupation('rogem002'); // Because sharing is awesome! 
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 05-24-2008, 12:57 PM Re: Login System Using PHP Session, Safe?
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 984
Name: Jeremy Miller
Location: Reno, NV
Sessions are maintained in 2 ways: A cookie or by rewriting URLs. I was recommending cookie's only.

Confirmation of browser sounds good, but only go into the world of IP validation if you're ready for headaches (read my original reply above for why).
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-24-2008, 02:40 PM Re: Login System Using PHP Session, Safe?
Experienced Talker

Posts: 35
Name: Gjore Sazdovski
Quote:
Originally Posted by JeremyMiller View Post
I'd say the following:

1) Use database-based sessions. This makes hacking the session harder.
2) Require cookies. This will minimize session hacking.
3) Might want to just define session variables with the $_SESSION array since it's not 100% compatible with session_register-related functions.
4) Do not store passwords in plain-text form. Look at the hash() function. I usually use SHA512.
5) Protect against multiple attempts. There are 2 ways you can do this:
I) Only allow X number of attempts, or
II) For each failed attempt, make the user wait Y seconds between attempts. This doesn't protect you as much, but it slows down brute force scripts.
6) Do NOT use IP-based tracking. On large hosts, the IP can change from page to page which can be a real pain. I did this once and had quite a few AO-Hell members *****ing at me.
7) I suggest a username-based system instead of a login-based system where the username is used only for logging in. Why? Doing so makes it harder to guess 1/2 the equation (i.e. a hacker must guess both username and password instead of just password when provided the email [or it's easy to find]).

That should get you started. Good luck!
1) you talk about storing permanent session data in DB or something else?
2) cookies are a must, parsing the session UID by url is a no-f*-way
3) yeah I will do that if I use the build-in session system, for temporary stuff I need parsed along the pages.
4) SHA512 + salt + SHA512 + salt2 + SHA512 + salt3 + SHA512 + MD5 (yeah, this is closed source so I can make any combination I want.. and using MD5 in the end, confuses the hackers, 99% of them will think that the encryption is "pass + MD5".. and even If they do know that behind the MD5 there is a SHA512 hash... when are they gonna crack it? year 2150? )
5) I'm still thinking about a way to make this as good as possible so that brute-force is slowed down and made hard, and DoS & DDoS are hard to pull off (for example they try to login into multiple accounts a few times and make allot of accounts frozen or temporary-locked)
6) I my country the dynamic-ip users get a new IP only when they reconnect. ip changing from page to page will not be allowed, if there are users that will need this, there will be special proxies available for them, but NOT those free-public ones as all of them will be banned.
7) I will be using username + password authentication, the username privacy will be the same as the passwords. so it's like 2 passwords to get in

now, I like you guys to take a look at the two systems below, and tell me possible exploits/holes and problems on both of them:

System 1:
------------------
> When the user registers, we generate a random 256 or 512 bit string, and store it in DB with his other info. These strings are unique for every username.

> When the user logs in with his username and password, we generate a custom UID based on:
--> The random string for that user (a.k.a the third password that nobody knows )
--> His current IP-adress
--> The time he logged in
--> Some info about his browser

> The UID is encrypted like the passwords with custom combinations and salts, and is stored in DB.

> The custom random string, and the time the user logged in, are stored encrypted using a custom two-way encryption in a cookie, in clients browser Also, the cookie names are "wtf" like "0xA1" no-one has a single clue what-is-stored-where and how-its-scrambled

> On every page load, the info from the cookies is decrypted and combined with the rest of the stuff, the UID is re-generated and re-encrypted, and if it matches a UID in DB, the user is confirmed as logged in

> Every time the session is successfull, the last page visit time is stored with the UID, encrypted ofcourse.

> Exe service, checks for session UIDs that are not used for more than an hour, and deletes them. checks are done every minute.

> An option available to users, to make their sessions idle time last longer, at their own risk ofcourse.
--------------------------

System 2:
--------------------------
session_start
session_register()
session_isregistered()
session_unset()
session_destroy()
--------------------------

End

Last edited by Gjore.S : 05-24-2008 at 02:42 PM.
Gjore.S is offline
Reply With Quote
View Public Profile
 
Old 05-24-2008, 07:12 PM Re: Login System Using PHP Session, Safe?
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 984
Name: Jeremy Miller
Location: Reno, NV
First, let me comment regarding the multiple hashing usage. Your end result is only as secure as md5 since it is the last one used. Security should not be based off of the secrecy of the method. All which is required to hack is to find any input which results in the same md5 hash. That is called a collision -- finding a value does not mean you have found the value. http://en.wikipedia.org/wiki/MD5#Vulnerability comments on a method other than the "rainbow table" for hacking md5 and http://www.mscs.dal.ca/~selinger/md5collision/ goes in a bit more depth. Storing the password SHA512 with a seed is probably the best you'll be able to do at this time.

Second, I do not mean permanent sessions. Part of the security of a session is its short time frame.

Third, a custom encryption algorithm is a bad idea. Unless you're on par with Rivest, Shamir, and Adleman, you're likely to create something no where near the rigour of RSA. Stick with those encryption algos which are public (i.e. have faced peer review by highly skilled mathematicians) and considered the best. If you can think of a reliable way to deploy the one-time encryption pad, then you could beat them, but otherwise don't hold your breath and don't risk the security of your system.

If you want to encrypt communications between the server and browser, use a SSL cert of the max current bit length -- it already successfully deploys the best public-key encryption.

If you want to re-invent the code for security reasons, then study the RSA site where the mathematics is explained in sufficient detail (or at least it was when I last went there a couple years ago).

When I do login systems, I generate a unique salt (this could be per user, but I usually do per site -- per user is more secure), store passwords in SHA512(password.unique_salt). No information is stored via cookies except the PHPSESSID. All information about the user is stored in $_SESSION variables (which are stored in the database instead of the sometimes-public session storage). Database sessions are valid only for 20 minutes at most.

When it comes to persistent logins, see my post at http://www.webmaster-talk.com/php-fo...tml#post537594

You mentioned, also, that you name your cookies odd names. This is fine, but security through obfuscation is not very strong; though it is better than nothing.

Good luck!
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-25-2008, 05:12 AM Re: Login System Using PHP Session, Safe?
Experienced Talker

Posts: 35
Name: Gjore Sazdovski
Quote:
Originally Posted by JeremyMiller View Post
First, let me comment regarding the multiple hashing usage. Your end result is only as secure as md5 since it is the last one used. Security should not be based off of the secrecy of the method. All which is required to hack is to find any input which results in the same md5 hash. That is called a collision -- finding a value does not mean you have found the value. http://en.wikipedia.org/wiki/MD5#Vulnerability comments on a method other than the "rainbow table" for hacking md5 and http://www.mscs.dal.ca/~selinger/md5collision/ goes in a bit more depth. Storing the password SHA512 with a seed is probably the best you'll be able to do at this time.
You got me confused a little bit
You say that all which is required to hack is to find any input which results in same md5 hash... I'm aware about the MD5 vulns, and I written "MD5" above just as an example, not that I'm really going to use it, but this got me confused a little bit so I'll write a little example:

PaSsW0rD -> PaSsW0rD + SaLt1 -> SHA512 ->
b9ae399ff01efa461460958f6b7301a6044693f3ac66d5b487 ddb6d10bb0f46626541c75f347ab1bbc0c8588d46523cb7dd4 5b47eba25eca0e5757fe876c59a0
-> SaLt2 + the_hash_above -> SHA512 ->
fb0cb7b22a8afc7d4d98333a02583526089bf0d5a99c9b2192 0b86c1729a11efd6d36d5d7d15d505e6bdd9c58a7e5a21a25d 8565a6eb8b825ccb4bc7924af74f
-> first_64_chars_of_the_hash + SaLt3 + second_64_chars -> SHA512 ->
6976cc1f2a9eec8f23fd6f39ae32289221a19178e9db59b8c4 9cc434c0801278f9616594d8b7434536808d375da04a56a8b4 5ecd52e63d68547bb400ce854743
-> MD5 ->
6944c201e95e3527a74e05bd8b7d374b

Now, let's say the hacker finds an input that results in the same MD5 hash, he inputs it in the "password" box, and this

hacker_input -> hacker_input+salt1 -> hash -> salt2+hash -> hash -> ha+salt3+sh -> hash -> MD5

will give the same result ?

Finding a value that will produce the same MD5 does not mean that value will produce the same MD5 if it's put through the multiple hash procedure.

That's just my opinion, correct me where I'm wrong.

Let's say the hacker makes an SQL-injection, he get's the MD5 hash, he finds a value that produces that MD5, how is he going to use it?

Quote:
Originally Posted by JeremyMiller View Post
Third, a custom encryption algorithm is a bad idea. Unless you're on par with Rivest, Shamir, and Adleman, you're likely to create something no where near the rigour of RSA. Stick with those encryption algos which are public (i.e. have faced peer review by highly skilled mathematicians) and considered the best. If you can think of a reliable way to deploy the one-time encryption pad, then you could beat them, but otherwise don't hold your breath and don't risk the security of your system.
Can you please suggest me the most secure 2-way encryption in your opinion?

Quote:
Originally Posted by JeremyMiller View Post
When I do login systems, I generate a unique salt (this could be per user, but I usually do per site -- per user is more secure), store passwords in SHA512(password.unique_salt). No information is stored via cookies except the PHPSESSID. All information about the user is stored in $_SESSION variables (which are stored in the database instead of the sometimes-public session storage). Database sessions are valid only for 20 minutes at most.

When it comes to persistent logins, see my post at http://www.webmaster-talk.com/php-fo...tml#post537594
so, I store users IP and browser info in $_SESSION, and check them everytime the user opens a page, just in case the cookie got stolen. Is this secure enought?

Quote:
Originally Posted by JeremyMiller View Post
You mentioned, also, that you name your cookies odd names. This is fine, but security through obfuscation is not very strong; though it is better than nothing.
I totaly agree, obfuscation is never really strong, but makes a good "cherry on top" on high-security sites

Thanks allot for your time on this
Gjore.S is offline
Reply With Quote
View Public Profile
 
Old 05-25-2008, 02:53 PM Re: Login System Using PHP Session, Safe?
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 984
Name: Jeremy Miller
Location: Reno, NV
Dude, you're missing the point. I have explained this ad nauseam and you're still dedicated to your initial concept. At this point, I'm exiting this conversation with the admonition to read what I have written, get off of the over complication of things, learn 3rd year mathematics at a college (at least if you're writing your own implementation of encryption), and see what others will do. Now, amongst those items, all you really need to do is "read what I have written" and get over trying to make the method complicated as a mask to tell yourself that it's more secure.

Remember this: You are not going to come up with a login system better than those already recommended above. You just don't have the skills -- no offense. As a side note, I wouldn't make anything better either. I probably have the skills, but there's no need to when it works and is simple. "KISS" works for encryption.


Good luck.
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 05-25-2008, 03:46 PM Re: Login System Using PHP Session, Safe?
Experienced Talker

Posts: 35
Name: Gjore Sazdovski
You are right, I don't have those extreme PHP skills, but I have the creative and inspired mind that is not satisfied with "keeping it simple" and just copy-paste simple two-line code from the net.

Anyway, thanks for the tips, got the info I needed. I'm halfway through my concept and would love to have you on the initial security testing, maybe you will prove that "KISS" works better

Best Regards
Gjore.S is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Login System Using PHP Session, Safe?
 

Thread Tools

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
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.18140 seconds with 12 queries