المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : احمي موقعك من الهكرز



bahattab
20-01-2008, 11:18 PM
احمي موقعك من الهكرز


هناك العديد من الهكرز المبتدئين يحاولون اختراق الموقع عن طريق ارسال كود html او كود جافا سكربت غير مرغوب فيه ولحذفه قمت بعمل كود صغير يتم وضعه في اعلى الصفحة ليقوم بعملي فلترة للمتغيرات المرسلة للموقع وهذا هو الكود
لا اعرف لماذا يظهر الكود بطريقة يصعب فيها فهم الكود
ولكن وعلى اي حال هذا هو الكود



<?
/*
This function programmed by Rami Yacoub \"pooi@maktoob.com\"
it\'s to make your page safe from xss attack,
HTML tages
to remove it let $accept HTMl=0;
to Convert special characters to HTML entities let accept HTMl=2
to accepet some char let $accept HTMl=1 and in $HTML Accepted Tages=\'<h1><br> <img....\'; // your accepted char here
the special chars
to delete it let $deleteOrAddSlash=2
to addslash let $deleteOrAddSlash=1
note it change all get, post and cookies variables
how 2 use: easy just include it in ur pages
plz test it before using , and send back

*/

function removeEvilAttributes($tagSource)
{
$stripAttrib = \"\' (style|class)=\\\"(.*?)\\\"\'i\";
$tagSource = stripslashes($tagSource);
$tagSource = preg_replace($stripAttrib, \'\', $tagSource);
return $tagSource;
}
function removeEvilTags($source,$allowedTags){
$source = strip_tags($source, $allowedTags);
return preg_replace(\'/<(.*?)>/ie\', \"\'<\'.removeEvilAttributes(\'\\\\1\').\'>\'\", $source);
}
//------------This Function To Delete The HTML Char(NOT Convert)----------
function showtextintags($text){
$text = preg_replace(\"/(\\<script)(.*?)(script>)/si\", \"dada\", \"$text\");
$text = strip_tags($text);
$text = str_replace(\"<!--\", \"&lt;!--\", $text);
$text = preg_replace(\"/(\\<)(.*?)(--\\>)/mi\", \"\".nl2br(\"\\\\2\").\"\", $text);
return $text;
}
//-------------------Strip Xss----
function checkXSS($arr,$acceptHTMl,$HTMLAcceptedTages,$dele teOrAddSlash){
foreach ($arr as $k => $v){
if (is_array($v)){
$arr[$k] = checkXSS($v);
}else{
if(!$acceptHTMl){
$v= showtextintags($v);
}elseif( ($acceptHTMl==1) && $HTMLAcceptedTages ){
$v=removeEvilTags($v,$HTMLAcceptedTages);
}elseif($acceptHTMl==2){
$v=htmlspecialchars($v);
}
//else the html will stay as is

if($deleteOrAddSlash==1){
$v=addslashes($v);
}else{
$v=str_replace(\"\'\",\'\',$v);
$v=str_replace(\'\"\',\'\',$v);
$v=str_replace(\";\",\'\',$v);
$v=str_replace(\"\\\\\",\'\',$v);
}

$arr[$k] =$v;
}
}
return $arr;
}

$acceptHTMl=2;
$HTMLAcceptedTages=0;//\'<H1><H2><H3><H4><H5><H6><br>\';
$deleteOrAddSlash=2;
if (!empty($_GET)) { $_GET = checkXSS($_GET,$acceptHTMl,$HTMLAcceptedTages,$del eteOrAddSlash); }
if (!empty($_POST)) { $_POST = checkXSS($_POST,$acceptHTMl,$HTMLAcceptedTages,$de leteOrAddSlash); }
if (!empty($_COOKIE)) { $_COOKIE = checkXSS($_COOKIE,$acceptHTMl,$HTMLAcceptedTages,$ deleteOrAddSlash); }
?>




http://www.c4arab.com/forums/archive/index.php/t-31030.html