CrashX
В прошлом XSiteCMS
- Регистрация
 - 6 Июн 2008
 
- Сообщения
 - 681
 
- Реакции
 - 114
 
- Автор темы
 - #1
 
Тем было много, но предлагаюобсудить саму проблему не словами, а реальными примерами )
мне кажется что важно защита от
-XSS
-SQL инъекций
-shell
--------------
от
XSS
простой пример
	
	
	
		
вот у меня больше вопросы про защиту SQL, 
а именно как проверить валидный ли запрос не выполняя его или отфильтровать его так что бы все введенное воспринемалось как текст,
чем и как лучше фильтровать входящие данные,
наиболее часто применяемы методы для взлома...
	
		
			
		
		
	
				
			мне кажется что важно защита от
-XSS
-SQL инъекций
-shell
--------------
от
XSS
простой пример
		PHP:
	
	  function remove_xss($string) {
    // Remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed
    // This prevents some character re-spacing such as <java\0script>
    // Note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs
    $string = preg_replace('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/', '', $string);
    // Straight replacements, the user should never need these since they're normal characters
    // This prevents like <IMG SRC=@avascript:alert('XSS')>
    $search = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()~`";:?+/={}[]-_|\'\\';
    $search_count = count($search);
    for ($i = 0; $i < $search_count; $i++) {
      // ;? matches the ;, which is optional
      // 0{0,7} matches any padded zeros, which are optional and go up to 8 chars
      // @ @ search for the hex values
      $string = preg_replace('/(&#[xX]0{0,8}' . dechex(ord($search[$i])) . ';?)/i', $search[$i], $string); // with a ;
      // @ @ 0{0,7} matches '0' zero to seven times
      $string = preg_replace('/(�{0,8}' . ord($search[$i]) . ';?)/', $search[$i], $string); // with a ;
    }
    // Now the only remaining whitespace attacks are \t, \n, and \r
    $ra = array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'style',
        'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound',
        'title', 'link',
        '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');
    $ra_count = count($ra);
    $found = true; // Keep replacing as long as the previous round replaced something
    while ($found === true) {
      $string_before = $string;
      for ($i = 0; $i < $ra_count; $i++) {
        $pattern = '/';
        for ($j = 0; $j < strlen($ra[$i]); $j++) {
          if ($j > 0) {
            $pattern .= '((&#[xX]0{0,8}([9ab]);)||(�{0,8}([9|10|13]);))*';
          }
          $pattern .= $ra[$i][$j];
        }
        $pattern .= '/i';
        $replacement = ''; //substr($ra[$i], 0, 2).'<x>'.substr($ra[$i], 2); // add in <> to nerf the tag
        $string = preg_replace($pattern, $replacement, $string); // filter out the hex tags
        if ($string_before == $string) {
          // no replacements were made, so exit the loop
          $found = false;
        }
      }
    }
    return $string;
  }
	а именно как проверить валидный ли запрос не выполняя его или отфильтровать его так что бы все введенное воспринемалось как текст,
чем и как лучше фильтровать входящие данные,
наиболее часто применяемы методы для взлома...