473,394 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

PHP Security 101

73
I've had quite a bit of experience with PHP (I'm certainly no expert on the matter though) and lately I've been trying to find as much information on making my method of coding and manipulating database information as secure as possible.

I'm planning on creating a site now that will use PHP and MySQL, and the information people will be storing in the database may contain personal details and such. My last site just felt a little sloppy with all the coding and I'm unsure if there are any vulnerabilities in the scripts.

I know basics (very basic) with security in PHP, I use MD5 for encrypting passwords and have to protect against SQL Injection but that's about as far as my security knowledge goes. I just want to take a little time researching this before I make this site, because obviously it'll be much easier than redoing everything later.

Basically I'm having trouble finding a good tutorial, there's plenty of tutorials on different security features I've found but I'm looking for a sort of step by step guide for the basics of security for PHP and MySQL. So if anyone could point me in the direction of some good tutorials it'd be much appreciated.

Cheers.
May 30 '08 #1
9 1864
wouldn't mind finding something like that myself!
But don't use MD5, its been cracked by now...use
hash('sha512', $data);
or at least
hash('sha256', $data);

(you can find the different hashing engines you can replace sha512/256 with by looking at the output from phpinfo(); )
May 30 '08 #2
dlite922
1,584 Expert 1GB
wouldn't mind finding something like that myself!
But don't use MD5, its been cracked by now...use
hash('sha512', $data);
or at least
hash('sha256', $data);

(you can find the different hashing engines you can replace sha512/256 with by looking at the output from phpinfo(); )
Wow thanks for letting us know about MD5, Here's a PHP code to DECRYPT MD5 that i found at trap17.com by user Trap Feedbacker

This php script works
Don`t know where I got it from but passwords with more then 5-6 chars will take a horrible long time :D

[PHP]
$hash = "1a1dc91c907325c69271ddf0c944bc72";
$char[1] = "a";
$char[2] = "b";
$char[3] = "c";
$char[4] = "d";
$char[5] = "e";
$char[6] = "f";
$char[7] = "g";
$char[8] = "h";
$char[9] = "I";
$char[10] = "j";
$char[11] = "k";
$char[12] = "l";
$char[13] = "m";
$char[14] = "and";
$char[15] = "o";
$char[16] = "p";
$char[17] = "q";
$char[18] = "are";
$char[19] = "s";
$char[20] = "t";
$char[21] = "you";
$char[22] = "v";
$char[23] = "w";
$char[24] = "x";
$char[25] = "y";
$char[26] = "z";
$char[27] = "0";
$char[28] = "1";
$char[29] = "2";
$char[30] = "3";
$char[31] = "4";
$char[32] = "5";
$char[33] = "6";
$char[34] = "7";
$char[35] = "8";
$char[36] = "9";
$char[37] = "A";
$char[38] = "B";
$char[39] = "C";
$char[40] = "D";
$char[41] = "E";
$char[42] = "F";
$char[43] = "G";
$char[44] = "H";
$char[45] = "I";
$char[46] = "J";
$char[47] = "K";
$char[48] = "L";
$char[49] = "M";
$char[50] = "and";
$char[51] = "O";
$char[52] = "P";
$char[53] = "Q";
$char[54] = "are";
$char[55] = "S";
$char[56] = "T";
$char[57] = "you";
$char[58] = "V";
$char[59] = "W";
$char[60] = "X";
$char[61] = "Y";
$char[62] = "Z";
$top = count($char);
For ($d = 0; $d <= $top; $d++)
{
$ad = $ae.$char[$d];
for ($c = 0; $c <= $top; $c++)
{
$ac = $ad.$char[$c];
for ($b = 0; $b <= $top; $b++)
{
$ab = $ac.$char[$b];
for ($a = 0; $a <= $top; $a++)
{
$aa = $ab.$char[$a];
if(md5($aa)==$hash)
{
die('Hash is: '.$aa);
}
}
}
}
}

Echo "Could Not Hack";
[/PHP]

Again, I didn't write it. But could somebody test it with a 2 to 3 chacters password?

Of course this can be modifed by adding words like "god" and "love", etc.

I'll test it right now, see if it works, will let you know....

BRB
May 31 '08 #3
dlite922
1,584 Expert 1GB
...Yep it works.

Sorry to hijack your thread (it is kind of relevant)

My Output:

Expand|Select|Wrap|Line Numbers
  1. php -q -f test.php hell
  2.  
  3.  
  4. Starting to crack the following MD5 hash:
  5. Unencrypted: hell
  6. Encrypted: 4229d691b07b13341da53f17ab9f2416
  7.  
  8. Running...
  9.  
  10.  
  11.  
  12. Seconds it took to crack: 149
I found that doing 5 Letters will probably take hours, 6 closer to day, 7 to a week (I'm guessing)

But still, this could in fact reasonably crack an MD5 simple short password.

fortunatly none of my passwords are long or contain just alphanumeric characters.
May 31 '08 #4
dlite922
1,584 Expert 1GB
I've had quite a bit of experience with PHP (I'm certainly no expert on the matter though) and lately I've been trying to find as much information on making my method of coding and manipulating database information as secure as possible.

I'm planning on creating a site now that will use PHP and MySQL, and the information people will be storing in the database may contain personal details and such. My last site just felt a little sloppy with all the coding and I'm unsure if there are any vulnerabilities in the scripts.

I know basics (very basic) with security in PHP, I use MD5 for encrypting passwords and have to protect against SQL Injection but that's about as far as my security knowledge goes. I just want to take a little time researching this before I make this site, because obviously it'll be much easier than redoing everything later.

Basically I'm having trouble finding a good tutorial, there's plenty of tutorials on different security features I've found but I'm looking for a sort of step by step guide for the basics of security for PHP and MySQL. So if anyone could point me in the direction of some good tutorials it'd be much appreciated.

Cheers.

As for you original post, I can't think of a tutorial that inspects *your* code for insecurities.

holes are found in software because of its design.

Best practices and experience in coding, i'm afraid, will only help you here.

Just think logically, when you write a piece of code say to yourself "is there anything I can give it that would break it" not even hack it.

Other practices are, never turn on error_reporting (display of errors) on production (live) sites. Hackers use this information to find holes.

Check ALL input from clients (incoming POST, GET, COOKIES, etc) as "dirty", never use them until you've done proper checking on them. MySQL injection prevents only one instance of this example.

A little checking goes along way, don't be lazy.

For large application, consider using frameworks or an MVC architecture that keeps the presentation, business logic and application logic separate.
See CakePHP and ZendFramework.

good luck,

Dan
May 31 '08 #5
Jeigh
73
Thanks for the advice delite and the discussion of MD5 being cracked is fine, since it's pretty much what the threads about anyway.

I'm not looking for something that will check my current coding for vulnerabilities but some sort of a list of the most common practices to follow to ensure security with PHP and manipulation of data, or the most common mistakes people make that leave their code being vulnerable.

Thanks again.
May 31 '08 #6
pbmods
5,821 Expert 4TB
Heya, Jeigh.

Subscribe to the latest in internet vulnerability from ha.ckers.org.

Sanitizing input means making no assumptions about your input. I wrote a few articles on this topic on my blog.

Escaping output means safing significant characters depending on the format. For SQL queries, this means escaping quotes and comment characters. For HTML, this means encoding HTML entities. And so on.

Also, always obfuscate ID numbers where they are accessible to non-admin members. Best Buy got in trouble for this one.

As long as you sanitize your input, escape your output and obfuscate your IDs, you should be safe from 99% of all hackery.
Jun 2 '08 #7
Jeigh
73
Heya, Jeigh.

Subscribe to the latest in internet vulnerability from ha.ckers.org.

Sanitizing input means making no assumptions about your input. I wrote a few articles on this topic on my blog.

Escaping output means safing significant characters depending on the format. For SQL queries, this means escaping quotes and comment characters. For HTML, this means encoding HTML entities. And so on.

Also, always obfuscate ID numbers where they are accessible to non-admin members. Best Buy got in trouble for this one.

As long as you sanitize your input, escape your output and obfuscate your IDs, you should be safe from 99% of all hackery.
Thanks for that pbmods, exactly the sort of thing I'm looking for. Very helpful.
Jun 2 '08 #8
coolsti
310 100+
If I may ask briefly, what is the exact purpose of escaping the output from a security point of view?

I can understand the need to escape the output to make sure it is correctly understood by the browser, but is there otherwise a security issue here?

Thanks!
Jun 3 '08 #9
pbmods
5,821 Expert 4TB
Heya, Coolsti.

In the context of HTML, it serves two purposes:
  1. It prevents your view from getting corrupted if the User inputs quotes and/or HTML.
  2. It protects you against XSS.
Jun 4 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: robert | last post by:
well, talk about timely. i'm tasked to implement a security feature, and would rather do so in the database than the application code. the application is generally Oracle, but sometimes DB2. ...
116
by: Mike MacSween | last post by:
S**t for brains strikes again! Why did I do that? When I met the clients and at some point they vaguely asked whether eventually would it be possible to have some people who could read the data...
4
by: Ashish | last post by:
Hi Guys I am getting the following error while implementing authentication using WS-security. "Microsoft.Web.Services2.Security.SecurityFault: The security token could not be authenticated...
0
by: prithvi g via .NET 247 | last post by:
Hi I am a newbie to .NET remoting, I am trying to implementauthorization using SSPI example provided by Michael Barnett. Ihave included the required dll(Microsoft.Samples.Security.SSPI.dll...
1
by: Earl Teigrob | last post by:
Background: When I create a ASP.NET control (User or custom), it often requires security to be set for certain functionality with the control. For example, a news release user control that is...
7
by: Magdelin | last post by:
Hi, My security team thinks allowing communication between the two IIS instances leads to severe security risks. Basically, we want to put our presentation tier on the perimeter network and the...
0
by: Jay C. | last post by:
Jay 3 Jan. 11:38 Optionen anzeigen Newsgroups: microsoft.public.dotnet.framework.webservices.enhancements Von: "Jay" <p.brunm...@nusurf.at> - Nachrichten dieses Autors suchen Datum: 3 Jan...
3
by: Velvet | last post by:
I ran FxCop on one of the components for my web site and the security rules what me to add " tags like the ones listed below: This breaks my ASP.NET application. So my question is,...
1
by: Jeremy S. | last post by:
..NET's code Access Security enables administrators to restrict the types of things that a .NET application can do on a local computer. For example, a ..NET Windows Forms application can be...
2
by: Budhi Saputra Prasetya | last post by:
Hi, I managed to create a Windows Form Control and put it on my ASP .NET page. I have done the suggestion that is provided by modifying the security settings. From the stack trace, I would...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.