-5

i have a problem with my website many hackers came to me and stealing members cookies and redirecting to their website . I searched a little bit and i found a script that blocks xss exploiting but i am new to php and i don't know how to use it. I tried to use include and the name of the php file. This script:

/* 

* XSS filter 
* 
* This was built from numerous sources 
* (thanks all, sorry I didn't track to credit you) 
* 
* It was tested against *most* exploits here: http://ha.ckers.org/xss.html 
* WARNING: Some weren't tested!!! 
* Those include the Actionscript and SSI samples, or any newer than Jan 2011 
* 
* 
* TO-DO: compare to SymphonyCMS filter: 
* https://github.com/symphonycms/xssfilter/blob/master/extension.driver.php 
* (Symphony's is probably faster than my hack) 
*/ 

function xss_clean($data) 
{ 
    // Fix &entity\n; 
    $data = str_replace(array('&','<','>'), array('&','<','>'), $data); 
    $data = preg_replace('/(&#*\w+)[\x00-\x20]+;/u', '$1;', $data); 
    $data = preg_replace('/(&#x*[0-9A-F]+);*/iu', '$1;', $data); 
    $data = html_entity_decode($data, ENT_COMPAT, 'UTF-8'); 

// Remove any attribute starting with "on" or xmlns 
    $data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $data); 

// Remove javascript: and vbscript: protocols 
    $data = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`\'"]*)[\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2nojavascript...', $data); 
    $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2novbscript...', $data); 
    $data = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#u', '$1=$2nomozbinding...', $data); 

// Only works in IE: <span style="width: expression(alert('Ping!'));"></span> 
    $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i', '$1>', $data); 
    $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i', '$1>', $data); 
    $data = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*+>#iu', '$1>', $data); 

// Remove namespaced elements (we do not need them) 
    $data = preg_replace('#</*\w+:\w[^>]*+>#i', '', $data); 
    do 
    { 
    // Remove really unwanted tags 
        $old_data = $data; 
        $data = preg_replace('#</*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i', '', $data); 
    } 
    while ($old_data !== $data); 

// we are done... 

return $data; 

}

How to use it ? Please explain where to put it ?

kolin
  • 2,326
  • 1
  • 28
  • 46

1 Answers1

1

You need to include this file, then wherever you read anything from the client (or to be more precise: where you output your client's input) you need to replace $_GET['something'] with xss_clean($_GET['something']) and $_POST['sth'] with xss_clean($_POST['sth'])

Adassko
  • 5,201
  • 20
  • 37
  • Before replacing the $_GET with xss_clean ($_GET) i need to include the xss_clean.php at the top of the page , right? – Westel Gamers Feb 24 '15 at 08:05
  • Ok i will try what you've said and after come back with reply . Thanks – Westel Gamers Feb 24 '15 at 08:07
  • When i do include("xss_clean.php"); i save the specific php file , and i do a page reload. The code from xss_clean is showing over the header and the footer , why ? – Westel Gamers Feb 24 '15 at 12:32
  • You are supposed to use it like that `` If you did this, and it doesnt work, follow [this link](http://stackoverflow.com/a/5121589/4583548) – Eda190 Mar 02 '15 at 17:55