Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $s = '<table width="300" border="0" cellspacing="0" cellpadding="0" calo="s" onlclick="alert(\'hack\');">
- <tr>
- <th scope="row"> </th>
- <td>а</td>
- <td>о</td>
- </tr>
- <tr>
- <th onClick="alert(\'fff\');" scope="row">а</th>
- <td> </td>
- <td>о</td>
- </tr>
- <tr>
- <th scope="row"> </th>
- <td>п</td>
- <td>р</td>
- </tr>
- </table>
- ddddddddddddd
- <a href=javascript: { {({}{}()())}alert(\'xss\') ) ) }>
- <div onload..;,;..\'alert(\"xss_attack\");\'>
- <a href=\'javascript:{ alert(\"xss_attack\"); otherxss();}\'
- onclick= \'alert(\"xss_attack\");\' onhover=\'alert
- (\"xss_attack\");\' onmouseout=alert(\"xss_attack\")
- class=\'thisclass\'> link</a>
- ';
- $s = remove_HTML(strip_javascript($s), 'table|td|th|tr|width|border|cellspacing|cellpadding|scope|row|align|center|right|left');
- print "<textarea>{$s}</textarea>";
- function strip_javascript($filter){
- // realign javascript href to onclick
- $filter = preg_replace("/href=(['\"]).*?javascript:(.*)?\\1/i", "onclick=' $2 '", $filter);
- //remove javascript from tags
- while( preg_match("/<(.*)?javascript.*?\(.*?((?>[^()]+)|(?R)).*?\)?\)(.*)?>/i", $filter))
- $filter = preg_replace("/<(.*)?javascript.*?\(.*?((?>[^()]+)|(?R)).*?\)?\)(.*)?>/i", "<$1$3$4$5>", $filter);
- // dump expressions from contibuted content
- if(0) $filter = preg_replace("/:expression\(.*?((?>[^(.*?)]+)|(?R)).*?\)\)/i", "", $filter);
- while( preg_match("/<(.*)?:expr.*?\(.*?((?>[^()]+)|(?R)).*?\)?\)(.*)?>/i", $filter))
- $filter = preg_replace("/<(.*)?:expr.*?\(.*?((?>[^()]+)|(?R)).*?\)?\)(.*)?>/i", "<$1$3$4$5>", $filter);
- // remove all on* events
- while( preg_match("/<(.*)?\s?on.+?=?\s?.+?(['\"]).*?\\2\s?(.*)?>/i", $filter) )
- $filter = preg_replace("/<(.*)?\s?on.+?=?\s?.+?(['\"]).*?\\2\s?(.*)?>/i", "<$1$3>", $filter);
- return $filter;
- }
- function remove_HTML($s , $keep = '' , $expand = 'script|style|noframes|select|option'){
- /**///prep the string
- $s = ' ' . $s;
- /**///initialize keep tag logic
- if(strlen($keep) > 0){
- $k = explode('|',$keep);
- for($i=0;$i<count($k);$i++){
- $s = str_replace('<' . $k[$i],'[{(' . $k[$i],$s);
- $s = str_replace('</' . $k[$i],'[{(/' . $k[$i],$s);
- }
- }
- //begin removal
- /**///remove comment blocks
- while(stripos($s,'<!--') > 0){
- $pos[1] = stripos($s,'<!--');
- $pos[2] = stripos($s,'-->', $pos[1]);
- $len[1] = $pos[2] - $pos[1] + 3;
- $x = substr($s,$pos[1],$len[1]);
- $s = str_replace($x,'',$s);
- }
- /**///remove tags with content between them
- if(strlen($expand) > 0){
- $e = explode('|',$expand);
- for($i=0;$i<count($e);$i++){
- while(stripos($s,'<' . $e[$i]) > 0){
- $len[1] = strlen('<' . $e[$i]);
- $pos[1] = stripos($s,'<' . $e[$i]);
- $pos[2] = stripos($s,$e[$i] . '>', $pos[1] + $len[1]);
- $len[2] = $pos[2] - $pos[1] + $len[1];
- $x = substr($s,$pos[1],$len[2]);
- $s = str_replace($x,'',$s);
- }
- }
- }
- /**///remove remaining tags
- while(stripos($s,'<') > 0){
- $pos[1] = stripos($s,'<');
- $pos[2] = stripos($s,'>', $pos[1]);
- $len[1] = $pos[2] - $pos[1] + 1;
- $x = substr($s,$pos[1],$len[1]);
- $s = str_replace($x,'',$s);
- }
- /**///finalize keep tag
- for($i=0;$i<count($k);$i++){
- $s = str_replace('[{(' . $k[$i],'<' . $k[$i],$s);
- $s = str_replace('[{(/' . $k[$i],'</' . $k[$i],$s);
- }
- return trim($s);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment