Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Block and keep tabs on people attempting XSS
Old 11-18-2007, 11:02 PM Block and keep tabs on people attempting XSS
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
Simply add the following before the area where you process the form. This supposes two things, the first is that you already have a session of mysql open and secondly, that your form is on the same page, just change the correct section as needed. SQL can be found beneath the PHP.
PHP Code:
$ip $_SERVER['REMOTE_ADDR']
$klb "select count from hax where ip = '$ip'";
$blk mysql_query($klb);
$bln mysql_num_rows($blk);
if(
$bln != ''){echo "<p>HAX! BLOCKED!</p>";
    
$cnt mysql_result($blk,0);
    
$cnt += 1;
    
$up "update hax set count = $cnt where ip = '$ip'";
    
$pu mysql_query($up);
    exit;
}
$ref $_SERVER['HTTP_REFERER'];
if(
$ref != "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']){
    
$ver "select count from hax where ip = '$ip'";
    
$rev mysql_query($ver);
    
$cnt mysql_result($rev0);
    if(
$cnt != ''){
        
$cnt += 1;
        
$up "update hax set count = $cnt where ip = '$ip'";
        
$pu mysql_query($up);
    }
    else{
        
$mk "insert into hax values('$ip','1')";
        
$km mysql_query($mk);
    }
    echo 
"<p>HAX! IP LOGGED!</p>";
    exit;

Code:
CREATE TABLE IF NOT EXISTS `hax` (
  `ip` varchar(15) NOT NULL,
  `count` int(11) unsigned NOT NULL default '0',
  PRIMARY KEY  (`ip`)
)
I'd like to note, the reason I have count is so you can report it better, if you check once and day and suddenly it jumped from none to 500 then their ISP should act quickly. Secondly, don't test this script unless you're sure of your IP so you can remove it.
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>

Last edited by Arenlor; 11-18-2007 at 11:08 PM.. Reason: Fixed a typo which wasn't there o.O
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
 
Register now for full access!
Old 11-19-2007, 02:39 PM Re: Block and keep tabs on people attempting XSS
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Useful script ^^ Thanks
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 11-19-2007, 05:33 PM Re: Block and keep tabs on people attempting XSS
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
Waste of time.

The $_SERVER['HTTP_REFERER'] superglobal ispretty unreliable and is under client control (might even be totally absent under IE - not sure). As for $_SERVER['REMOTE_ADDR']what about clients accessing through proxy servers like AOL.
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 11-19-2007, 08:12 PM Re: Block and keep tabs on people attempting XSS
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
True the referer CAN be changed. So can the user agent, IP etc. This is meant to first of block and stop attempts to use a form of XSS, and secondly to keep track of the people that do it, if I report to AOL that a user from 127.0.0.1 (I know that's not a real IP) attempted to perform the activity they will look into it, the same way they'd look into any hacking or spamming attempt.
__________________
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 11-19-2007, 09:21 PM Re: Block and keep tabs on people attempting XSS
Ultra Talker

Posts: 483
Trades: 0
Quote:
Originally Posted by Arenlor View Post
if I report to AOL that a user from 127.0.0.1 (I know that's not a real IP) attempted to perform the activity they will look into it
Attempted to perform WHAT activity, though?

You look at the referrer and you admit that it's easily changeable. So what will you report to AOL, exactly? The ONLY thing you CAN report, definitively, is that the user accessed your script WITHOUT sending a referrer value. Yeah, they'll look right into that...
__________________

Please login or register to view this content. Registration is FREE
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 11-24-2007, 07:04 PM Re: Block and keep tabs on people attempting XSS
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
The only thing I can report is the user attempted to access my site from another site.
__________________
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!
 
Reply     « Reply to Block and keep tabs on people attempting XSS
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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