Web Hosting Deals Holiday Logo Design Website Header Templates Register domain Search Engine Optimisation Web Hosting
Go Back   Talk Mania Forum > Talk-Mania Forum News and Suggestions > Articles > Internet Security

Internet Security Internet Security Articles

 Image

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-23-2007, 08:50 PM
Junior Member
 
Join Date: Feb 2007
Posts: 10
codingplade is on a distinguished road
Lightbulb Protect your site

Well, most hacker's attacks we can divide to following types:

1. SQL-injection
2. CSS (Cross site scripting)
3. PHP - including
4. Local file including

It's main types of attack, then i can remember at end of work day.
Remember one simple rule "Always check coming data!". Also, register_globals, but it another history...

1. SQL - injection.

If we have businnes with numeric values:

$sql = "SELECT something FROM somewhere WHERE id = $GET['id']";

You need just check it to number:

if(!is_numeric($GET['id'])) die('Good job. Try again.');

If we have business with string values, you must check it for managing simbols and escape it, and don,t forget about magic_quotes (PHP by default escape get, post, cookies values).

if (!get_magic_quotes_gpc)
foreach ($_REQUEST as $val)
$val = mysql_real_escape_string($val);

It's escaped managing simbols and any string like ' UNION SELECT * FROM admin will be send to MySQL as string, not as command.

And for insurance we will be join blowfish to md5('myverysecretpassword');

When you insert new user to database good practice is:

$blowfish = 'MORE MORE MORE... simbols... any...';

$sql = "INSERT INTO table SET password=\"".md5($_GET['password'].$blowfish)."\"";

Now if even hacker take database dump without blowfish he never can decrypt password.

All this you can into single file, for examle 'security.php':

<?php
if(isset($_GET['id']) && !is_numeric($GET['id'])) die('Good job. Try again.');
if (!get_magic_quotes_gpc)
foreach ($_REQUEST as $val)
$val = mysql_real_escape_string($val);
$blowfish = 'MORE MORE MORE... simbols... any...';
?>

...and including this file from other scripts.

2. CSS (Cross site scripting)
It simple, just always when you using user data check it for html-tags:

$str = strip_tags($str);

And for more secure when you draw it to browser:

echo htmlspecialchars($val);

Unfortunatelly it all what i khow... Next...

3. PHP - including
When you include your files into script, strongly not recommended do it from another site.

include('http://somewhereininternet.com');

Do it only if you haven't another.

And never use user's data as is. I will shortly because, they told me write faster .

4. Local file including

If you read local file, for example 'file.txt' always create array of allowed values:

$files = array('file.txt',
'anotherfile.txt');

if(!in_array($GET['file'], $files)) die('Good attempt. Try again.');
else file($_GET['file']);

That's all, Sorry for my English.

Reply With Quote
  #2 (permalink)  
Old 03-03-2007, 01:14 AM
xTr xTr is offline
Junior Member
 
Join Date: Mar 2007
Posts: 9
xTr is on a distinguished road
i would add:

if you using vars from inputs for later sql queries

like u use: $sql = "INSERT INTO `table` VALUES (1, ". $_GET['input_var'] .")

you should use mysql_real_escape_string($_GET['input_var']) instead of alone $_GET['input_var']

this should make your inputs more safe for sql injections
Reply With Quote
  #3 (permalink)  
Old 12-26-2008, 01:06 AM
Member
 
Join Date: Dec 2008
Posts: 43
softerfoud is on a distinguished road
thank you.

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +2. The time now is 08:08 AM.



Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC8
Forums Copyright © Talk-Mania.com