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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-24-2008, 02:54 PM
Bagi Zoltán's Avatar
Boss Cart Support
 
Join Date: Feb 2007
Location: Veszprém, Hungary
Posts: 1,421
iTrader: 0 / 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 Hacker trap script

I would like to declare that this is not a genuine post, so i already posted it on an other forum as well, but now i know that i should have post it here firstly.

This script arsenal will help to fight against hacker, won't make your script more secure so if it is open for a certain attack this won't solve the programing bug, but will make the entrance more difficoult.

Let's see what are the functions:
  • validate the Googlebot, the msnbot and the Yahoo! Slurp so when someone proxify the the site it won't cause content duplication,
  • make possible to ban certain user agents, IPs as well,
  • inspect the requested URL string so when someone would like to manipulate the mysql database via injection method the trap will reward it with a very elegant IP ban (this function must be modify in accordance of the website and the needs) ,

This is the core code called security.php

PHP Code:
  <?php
$ua
= $_SERVER['HTTP_USER_AGENT'];
$webadress = $_SERVER['REQUEST_URI'];
$ip = $_SERVER['REMOTE_ADDR'];
$target = file(dirname(__FILE__)."/ip-logfile.txt");
$sqltarget = file(dirname(__FILE__)."/sql-injection.txt");
$ualist = file(dirname(__FILE__)."/banned-ua.txt");
$loc = dirname(__FILE__);

//if the visitor said to be a robot
if(strstr($ua, 'msnbot') || stristr($ua, 'Googlebot') || stristr($ua, 'Yahoo! Slurp')){
//we must validate it
require "$loc/security-proxy-checker.php";
}
else{

//visitors with banned user agents are not allowed to access
foreach($ualist as $item){
$item = trim($item);
if(
stristr($ua, $item)){
require
"$loc/message.php";
exit;}}
//visitors with banned IPs are not allowed to access
foreach($target as $item){
$item = trim($item);
if(
stristr($ip, $item)){
require
"$loc/message.php";
exit;
}}

//let's inspect the requested URL string
foreach($sqltarget as $sqlitem){
$sqlitem = trim($sqlitem);
if(
stristr($webadress, $sqlitem)){
require
"$loc/index.php";
exit;}}}
?>
As you may recognise the script uses txt files which stores the banned user agents / IPs and typical string particulars which might be used during the sql injection attack.

Very important part of the solution is the index.php file with the following code
PHP Code:
  <?php
$ip
= $_SERVER["REMOTE_ADDR"];
$webadress = $_SERVER['REQUEST_URI'];
$loc = dirname(__FILE__);
$logfile = "$loc/ip-logfile.txt";
$urllogfile = "$loc/requested-string.txt";
$time = date("F j, Y, g:i a");
require
"$loc/message.php";
//Let's start the statistic module
//store the IP as first step
$fp = fopen($logfile, 'a');
fputs($fp, "$ip
"
);
fclose($fp);
$fpstring = fopen($urllogfile, 'a');
//Put the string and some very importent parameter into a control logfile so if somebody was banned without any reason we will have the chance to fix that
fputs($fpstring, "$ip requested this string $webadress this time $time
"
);
fclose($fpstring);
exit;
?>
My favourite part of the whole thing is the message.php which stores my greetings to the attackers, very nice one so nothing rough.

Attaching you may find the whole archived folder (with Hungarian comments in the files). In order to implement the trap all you need to do is to upload the files into an optional folder let's name it core for instance and place this code to the very front of the files you would like to protect.

PHP Code:
PHP Code:
<?php require "/thisisthepathof/core/security.php"; ?>
And one more thing. Don't forget to restict the crawl of the optional core folder where the files are stored in the robots.txt file, this may catch some extra bad guy.

I warrant nothing but this works very well at my site. I regularly check the requested-string.txt to see if somebody had been banned accidentally. But i regularly smile on the catchings.
Thanks

ps. today i realized that at my Hungarian blog some very strange URLs has been restricted for instance /Databases/vicndatadata.mdb or /Reg/User_Reg.asp. I though that is something that i don't need it and since i know that WP is written in php and i use permalinks i completed my sql-injection.txt file with this two lines:
Quote:
.asp
.mdb
restricting the access of these certain file extensions, and my security logs become very busy since then
I'm going to ask Cyrus to help me extend the protection covering leeching and xss attacks as well, but don't tell him, he knows nothing about my purpose
Attached Files
File Type: zip hacker-trap.zip (2.4 KB, 10 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble this Post!
Reply With Quote
  #2 (permalink)  
Old 01-24-2008, 03:19 PM
gkd_uk's Avatar
Super Moderator
 
Join Date: Mar 2007
Location: zeshaan.info
Posts: 3,539
iTrader: 2 / 100%
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 post Bagi - rep added
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble this Post!
Reply With Quote
  #3 (permalink)  
Old 01-24-2008, 03:20 PM
temi's Avatar
Facilitator
 
Join Date: Jun 2003
Location: London, England.
Posts: 10,902
iTrader: 13 / 100%
temi is just really nicetemi is just really nicetemi is just really nicetemi is just really nicetemi is just really nice
Send a message via ICQ to temi
Default

Thanks for sharing Bagi
__________________

Add Eco sites to The Green Directory free of charge
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble this Post!
Reply With Quote
  #4 (permalink)  
Old 01-25-2008, 09:11 AM
deluxdon's Avatar
Senior Member
 
Join Date: Mar 2007
Location: www.WebIindex.com
Posts: 788
iTrader: 1 / 100%
deluxdon has a spectacular aura aboutdeluxdon has a spectacular aura aboutdeluxdon has a spectacular aura about
Default

Useful post bagi. Thanks for sharing it with us.

DON.
__________________
Web Hosting Rating | Websites For Sale | Web Hosting Reviews
Start a directory and start making money with PHP Link Directory
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble this Post!
Reply With Quote
  #5 (permalink)  
Old 01-25-2008, 09:26 AM
Bagi Zoltán's Avatar
Boss Cart Support
 
Join Date: Feb 2007
Location: Veszprém, Hungary
Posts: 1,421
iTrader: 0 / 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

It is my pleasure to read your responses.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble this Post!
Reply With Quote
  #6 (permalink)  
Old 01-25-2008, 02:26 PM
UK WW Staff
 
Join Date: Mar 2007
Posts: 301
iTrader: 0 / 0%
Lovely is on a distinguished road
Send a message via ICQ to Lovely Send a message via Yahoo to Lovely
Default

It is a nice script Bagi Zoltán, thanks for sharing it. I wonder if there is any hacker and anti virus script that can work with server?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble this Post!
Reply With Quote
  #7 (permalink)  
Old 01-25-2008, 07:10 PM
espmartin's Avatar
Senior Member
 
Join Date: Jun 2007
Location: West Coast, USA (California)
Posts: 962
iTrader: 0 / 0%
espmartin will become famous soon enough
Default

Bagi, you should begin a security consulting service! Serious!!!!

I'll be your first client. PM me bro!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble this Post!
Reply With Quote
  #8 (permalink)  
Old 01-27-2008, 12:07 PM
Bagi Zoltán's Avatar
Boss Cart Support
 
Join Date: Feb 2007
Location: Veszprém, Hungary
Posts: 1,421
iTrader: 0 / 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

Lovely, sadly i don't know as much about how to identify viruses with php but sadly my toolkit is limited only on server side scripts. As far as i know viruses are not really able to catch via script, but secure gateways such as zorp, which identify the unnatural package transmissions.

Martin, thank you for your kind words i am thinking on this, but i need to learn hacking as first. Of course i am thinking on ethical hacking, but you must know how to attack a script/server to know how to defend it, so it will be a long way and i am only at the startline at the monent. My sister work for an information security company called Kurt, i guess you have never heard about it, but there works one of the biggest hackers on the whole planet. He was disqualified from the hacker world champion because he used some tool which was not allowed I want him to be my mentor. Sweet dreams

I would like to release only FREE defending scripts in the future which cover wider area of web based attacks that might be installaed easily for everyone.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble this Post!
Reply With Quote
  #9 (permalink)  
Old 01-27-2008, 10:48 PM
Banned
 
Join Date: Jan 2008
Posts: 8
iTrader: 0 / 0%
magyar is on a distinguished road
Default

Very nice. Thank you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble this Post!
Reply With Quote
  #10 (permalink)  
Old 01-28-2008, 07:57 AM
Bagi Zoltán's Avatar
Boss Cart Support
 
Join Date: Feb 2007
Location: Veszprém, Hungary
Posts: 1,421
iTrader: 0 / 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

This is a schame that you use our nation as user member and got banned. Next time you should choose something else when you go spammming.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Stumble this Post!
Reply With Quote
Reply


Useful Resources & Sites
Search Engine Marketing Company
UK Web Hosting
Build One Way Links
 
 
 
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



All times are GMT. The time now is 01:47 PM.

UK Webmaster World Forums - Internet marketing, web development, domain names, SEO contest and discussuons.
Subscribe to our feeds   Subscribe to our feeds

Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0