C 에서 NULL 바이트는 문자열의 끝을 나타내는데, 이것을 이용해 공격하는 기법입니다.

 \x00
 \0

아래 URL 의 값을 받는다고 가정해 보겠습니다.

habony.php?user_id=%27%3BSELECT+*+FROM+member_table

다음의 결과처럼 의도치 않게 문제가 발생하게 됩니다.

<?php 
 $_GET['user_id'] = '%27%3BSELECT+*+FROM+member_table'; 
 mysql_query("SELECT * FROM member_table WHERE uid='$_SESSION[memb]' 
                    AND md='$_GET[user_id]'");
 
 // 결과 : SELECT * FROM member_table WHERE uid='101' AND md='';
            SELECT * FROM member_table
 ?>

<?php 
 // file : "../../etc/passwd\0image.php" 
 $file = $_GET['file']; 

 // file_exists : TRUE 
 if(file_exists('/home/habony/'.$file.'.php')) 
 { 
    include '/home/habony/'.$file.'.php'; 
 } 
 // 결과 : include '../../etc/passwd'; 
 ?>

이 문제를 해결하기 위해 다음의 방법으로 해결할 수 있을 것입니다.

<?php 
 $clean = str_replace("\x00", '', $input); 
 // OR 

 $clean = str_replace("\0", '', $input); 
 // OR 
 $clean = str_replace(chr(0), '', $input); 
 ?>

0 댓글