|
Участник форума
Регистрация: 10.01.2006
Сообщений: 193
Провел на форуме: 553876
Репутация:
81
|
|
Я на своих проектах юзаю следующий алгоритм
1 Проверка расширения
2 Проверка Mime типа
3 Проверка типа вообще (через exif_imagetype)
4 Проба ширины и высоты - имеют ли числовые значения
Далее можно пере-рендерить картинку как уже написал Helios:
$im = imagecreatefromjpeg('image.jpg');
imagejpeg($im, 'newimage.jpg', 100);
Если рендерить и менять ширину/высоту по какой-то причине нельзя, то можно проверсти вот такую проверочку содержимого картинки
<meta http-equiv="content-type" content="text/html; charset=windows-1251">
<?php
$result_of_scan="";
$uploaded_img="resized.jpg";
$fh=fopen($uploaded_img, 'r');
$contents_of_uploaded_img=fread($fh, filesize($uploaded_img));
fclose($fh);
$list_of_potential_xss=array('javascript', 'vbscript', 'expression', 'applet', 'blink', 'link', 'style', 'script', 'embed',
'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base', 'onabort', 'onactivate',
'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate',
'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce',
'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable',
'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave',
'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin',
'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown',
'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove',
'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend',
'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange',
'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload', 'input', 'form', 'post','input', 'echo', 'background',
'alert', 'img src', 'table', 'Content-Type', 'charset', 'http-equiv', 'meta', 'body', 'document', 'style', 'cookie',
'false', 'true', 'delete', 'UTF-7', 'UTF-8', '.html', '.dhtml');
for($x = 0; $x < count($list_of_potential_xss); $x++)
{
preg_match("/".$list_of_potential_xss[$x]."/", $contents_of_uploaded_img, $matches);
if(count($matches) > 0)
{
$result_of_scan="true";
echo "$list_of_potential_xss[$x] - присутсвует<br><br>";
}
else
{
echo "$list_of_potential_xss[$x] - отсутсвует<br><br>";
}
}
if ($result_of_scan==="true")
{
echo ("<b><h1>XSS есть");
}
else
{
echo ("<b><h1>Все чисто");
}
?>
Последний раз редактировалось George767; 06.08.2007 в 10:23..
|