Webmaster Forum
Go Back   Webmaster Forums UK SEO SEM Webmaster Community Forum - UKWW > Web Design and Website Development > Programming
Register FAQ Members List Downloads Calendar Today's Posts Webmaster Resources Webmaster Blogs

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-28-2007, 01:47 PM
Bagi Zoltán's Avatar
Boss Cart consultant
Recent Blog:
 
Join Date: Feb 2007
Location: Veszprém, Hungary
Posts: 1,584
iTrader: 9 / 100%
Thanks: 3
Thanked 15 Times in 10 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Bagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud of
Default Daily security, how to defend your site against sql injections

Today I have already released a security solution at iwt, but now i will post one for here as well. You need to know that it was developped in the last ten minutes, but very effective. The basic would be the same as it was posted at iwt with less modification.

The sql injection is very popular hacking method but there is one common thing in these type of attacks. According to this resource, the URL contains a string which cause a bad manipulation of the sql database, for instance the 'UNION SELECT', 'DROP TABLE', 'TRUNCATE TABLE' sql commands as the part of the requested url. For instance my directory was hacked requesting this string
Quote:
show_cat.php?cat_id=-1 union ALL SELECT login,password FROM dir_login /*
Since we know that the requested url will contain a certain string defending against this is quite easy, and funny.

1. Create a php file i would call this validator.php with the following content.
PHP Code:
<?php
$url 
$_SERVER['REQUEST_URI'];
$ip $_SERVER["REMOTE_ADDR"];
$target file(dirname(__FILE__). "/bannolnilog.txt");
foreach(
$target as $item){
$item trim($item);
if(
stristr($ip$item)){
header("HTTP/1.0 403 Forbidden");
exit;
}
}
if(
stristr($url'union') || stristr($url'drop') || stristr($url'truncate')){
include 
"message.php";
exit;
}
?>
The first part of the code will check if a certain browser is on our blacklist, and the second one will show him something special, can be found in the message.php file. At my site i use something very offensive text, but i don't want to influence you.

2. Create our logfile the blacklist which is called in my example bannolnilog.txt (to ban in Hungarian) chmod 644. Upload it to the root folder as you did it with the validator.php file.

3. We have the validator and the logfile so we need to create the message.php

I use this censored content as message
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta robots content="noindex, nofollow"/>
<title>F.... ..u!</title>
<style type="text/css">
<!--
.style1 {font-size: 24px}
-->
</style>
</head>

<body>
<br/><br/><br/><br/><br/><br/>
<p align="center" class="style1">Please be so kind and do me a favour</p>
<p align="center" class="style1"> F... ..U!! Poor b....d </p>
<p align="center" class="style1"> Your visit is now over </p>
<?php 
$ip 
$_SERVER["REMOTE_ADDR"];
$logfile 'bannolnilog.txt';
$fp fopen($logfile'a');
fputs($fp"$ip
"
);
fputs($fp" "); 
fclose($fp);
?>
</body>
</html>
This will take the IP adress of the attacker and put it into our log file, so using the same IP all we get is the 403 error.

4 We already have everything, the message the logfile and the validator, all we need to do is to place the invitation of the validator file to the very front of your script.
PHP Code:
<?php require "/you/need/to/insert/the/path/here/validator.php";?>
Now you may say good bye to those script kiddies.
__________________
Time may come when you will need a shopping cart
digitális mérleg keresőoptimalizálás

Last edited by Bagi Zoltán; 12-28-2007 at 02:05 PM. Reason: completed the code
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 12-28-2007, 01:52 PM
gkd_uk's Avatar
Super Moderator
Recent Blog:
 
Join Date: Mar 2007
Location: zeshaan.info
Posts: 3,676
iTrader: 3 / 100%
Thanks: 1
Thanked 4 Times in 3 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
gkd_uk has much to be proud ofgkd_uk has much to be proud ofgkd_uk has much to be proud ofgkd_uk has much to be proud ofgkd_uk has much to be proud ofgkd_uk has much to be proud ofgkd_uk has much to be proud ofgkd_uk has much to be proud ofgkd_uk has much to be proud of
Default

Great tutorial Bagi - rep added

I will be digging this post when I get home as I can no longer access digg from work

Last edited by gkd_uk; 12-28-2007 at 02:18 PM.
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 12-28-2007, 02:09 PM
Bagi Zoltán's Avatar
Boss Cart consultant
Recent Blog:
 
Join Date: Feb 2007
Location: Veszprém, Hungary
Posts: 1,584
iTrader: 9 / 100%
Thanks: 3
Thanked 15 Times in 10 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Bagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud of
Default

Thank iou Imran, meanwhile i completed the script with some other different malicious sql commands.
__________________
Time may come when you will need a shopping cart
digitális mérleg keresőoptimalizálás
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 12-29-2007, 12:10 AM
Meti's Avatar
Senior Member
Recent Blog:
 
Join Date: Mar 2007
Location: Sweden
Posts: 467
iTrader: 0 / 0%
Thanks: 0
Thanked 0 Times in 0 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Meti has a spectacular aura aboutMeti has a spectacular aura aboutMeti has a spectacular aura about
Default

That is great Bagi! Thank you very much, this may come to good use and I have added you rep for your efforts.

Thanks,
Meti
__________________
Computer Blogging - Gago Games
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 12-29-2007, 12:44 AM
espmartin's Avatar
Senior Member
Recent Blog:
 
Join Date: Jun 2007
Location: West Coast, USA (California)
Posts: 962
iTrader: 0 / 0%
Thanks: 0
Thanked 0 Times in 0 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
espmartin will become famous soon enough
Default

I can see how this works internally (the script and stopping injections), but how do you
implement it? I am a member of the WordPress Dev. email list, and a member just posted
that his WordPress was attacked with this type of hack.

His Host informed him of a few details, but not much else. He lost all data in the db!

So how do we use your script for protection?
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 12-29-2007, 08:40 AM
Bagi Zoltán's Avatar
Boss Cart consultant
Recent Blog:
 
Join Date: Feb 2007
Location: Veszprém, Hungary
Posts: 1,584
iTrader: 9 / 100%
Thanks: 3
Thanked 15 Times in 10 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Bagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud of
Default

Martin, you have a certain script. Before the connection would established to the database, in the case of wordpress this is the 1.st row of the given header.php in the template files you need to make the validator run using this
Quote:
<?php require "/you/need/to/insert/the/path/here/validator.php";?>
This will redirect the request to the specified file if the requested url contains a given string such as drop, delete, truncate. Martin i still gather some string that may be originated from sql attack, but you know i am not a programmer so need a bit more time to collect every form of it.
__________________
Time may come when you will need a shopping cart
digitális mérleg keresőoptimalizálás
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 12-29-2007, 02:34 PM
Resonate's Avatar
Internet Marketing Admin
 
Join Date: Sep 2007
Location: {{ A Remote Server }}
Posts: 626
iTrader: 0 / 0%
Thanks: 0
Thanked 0 Times in 0 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Resonate is a jewel in the roughResonate is a jewel in the roughResonate is a jewel in the rough
Send a message via ICQ to Resonate Send a message via AIM to Resonate Send a message via MSN to Resonate Send a message via Yahoo to Resonate Send a message via Skype™ to Resonate
Default

Excellent Bagi, You are a king of Kings
__________________
Currently taking my LEVEL 3 ADVANCED ELECTROTECHNICAL Certification exams.

Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #8 (permalink)  
Old 12-29-2007, 02:38 PM
Bagi Zoltán's Avatar
Boss Cart consultant
Recent Blog:
 
Join Date: Feb 2007
Location: Veszprém, Hungary
Posts: 1,584
iTrader: 9 / 100%
Thanks: 3
Thanked 15 Times in 10 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Bagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud ofBagi Zoltán has much to be proud of
Default

Don't think that Resonate, i only should have learned instead of script hacking
__________________
Time may come when you will need a shopping cart
digitális mérleg keresőoptimalizálás
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #9 (permalink)  
Old 12-29-2007, 02:39 PM
Resonate's Avatar
Internet Marketing Admin
 
Join Date: Sep 2007
Location: {{ A Remote Server }}
Posts: 626
iTrader: 0 / 0%
Thanks: 0
Thanked 0 Times in 0 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Resonate is a jewel in the roughResonate is a jewel in the roughResonate is a jewel in the rough
Send a message via ICQ to Resonate Send a message via AIM to Resonate Send a message via MSN to Resonate Send a message via Yahoo to Resonate Send a message via Skype™ to Resonate
Default

Quote:
Originally Posted by Bagi Zoltán View Post
Don't think that Resonate, i only should have learned instead of script hacking
Its good enough for me Bagi
__________________
Currently taking my LEVEL 3 ADVANCED ELECTROTECHNICAL Certification exams.

Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
  #10 (permalink)  
Old 12-29-2007, 07:26 PM
espmartin's Avatar
Senior Member
Recent Blog:
 
Join Date: Jun 2007
Location: West Coast, USA (California)
Posts: 962
iTrader: 0 / 0%
Thanks: 0
Thanked 0 Times in 0 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
espmartin will become famous soon enough
Default

Please post your finding Bagi! I'm going to use this on one or two of my blogs that get
allot of spam. Not that this is a spam deterrent, but those sites seem to be "targeted" -
and a hack attack would be the next avenue for those people!
Digg this Post!Add Post to del.icio.usStumble this Post!Wong this Post!
Reply With Quote
Reply

Bookmarks

Webmaster Resources
UK WW SEO Tools
Find UK Hosts
 
The Forum Rules
Forum Rules - MUST READ
 
Site Of the Month
BizzFace
Nominate site of the month
 
Tag Cloud
a75-s229 laptop ac adapter apple ipod nano 4gb brand new cellphone digital camera dj mixer domains drupal earphones ecommerce edible oil electronics estdomains events in india for webmasters free web space google analytical tool hosting hosting offer low cost iphone iphone 3g 16gb iphones laptops mdj's mobile phones motorola rokr e6 newbie new pioneercdj's nokia oil phones phpld plasma tv poineer prepaid phone card prepaid phone cards promo proxy renew social web hosting telecom links template design transfer usb cable web hosting

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