XSS :

Cross Site Scripting

 

웹사이트에

스크립트 태그를 집어넣어

웹 브라우저에서 실행시키는

해킹 방법

 


 

 

htmlspecialchars

 

 

XSS를 방지할 수 있는 

PHP 함수

 

사용자가 입력한

정보가 출력되는 부분을

모두 htmlspecialchars

감싼다

 

<?php
function print_title(){
  if(isset($_GET['id']))
    {echo htmlspecialchars($_GET['id']);}
  else
    {echo "Welcome";}
                      }

function print_description(){
  if(isset($_GET['id']))
  {echo htmlspecialchars(file_get_contents("data/".$_GET['id']));}
  else {echo "You did it!";}
                            }


function print_list(){
  $list = scandir('./data');
   $i = 0;
   while($i < count($list))
   {
    $title = htmlspecialchars($list[$i]);
    if($list[$i] != '.')
   {if($list[$i] != '..')
   {echo "<li>
          <a href=\"indexing.php?id=$title\">
          $title
          </a>
          </li>\n";}}
   $i = $i + 1;
   }
                        }
?>

 


 

 

URL을 이용한 해킹

기본 방지 함수

$basename

 

<?php
unlink('data/'.basename ($_POST['id']));
header('Location: indexing.php');
?>


-------------------------------




<?php
function print_title(){
  if(isset($_GET['id']))
    {echo htmlspecialchars($_GET['id']);}
  else
    {echo "Welcome";}
                      }

function print_description(){
  if(isset($_GET['id'])) {
    $basename = basename ($_GET['id']);
  echo htmlspecialchars(file_get_contents("data/".$basename));}
  else {echo "You did it!";}
                            }


function print_list(){
  $list = scandir('./data');
   $i = 0;
   while($i < count($list))
   {
    $title = htmlspecialchars($list[$i]);
    if($list[$i] != '.')
   {if($list[$i] != '..')
   {echo "<li>
          <a href=\"indexing.php?id=$title\">
          $title
          </a>
          </li>\n";}}
   $i = $i + 1;
   }
                        }
?>

 


 

 

728x90
반응형

+ Recent posts