downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Database Security> <Dosya Sistemi Güvenliği
Last updated: Fri, 13 Nov 2009

view this page in

Boş baytlı girdiler

PHP, dosya sistemi ile ilgili işlemler için kod seviyesinde C işlevlerini kullandığından boş baytlı (\0) dizgeler beklenmedik davranışlara yol açabilir. Boş bayt, C'de dizgeleri sonlandırmak için kullanıldığından boş bayt içeren dizgelerin tamamı değil, boş bayta kadar olan bölüm işleme sokulur. Aşağıdaki örnekte bunun sebep olduğu bir sorun ele alınmıştır:

Örnek 1 - Boş baytlardan olumsuz etkilenen bir betik

<?php
$dosya 
$_GET['dosya']; // "../../etc/passwd\0"
if (file_exists('/home/siteler/'.$dosya.'.php')) {
    
/* /home/siteler/../../etc/passwd mevcut olduğundan
       file_exists işlevi TRUE döndürür */
    
include '/home/siteler/'.$dosya.'.php';
    
// /etc/passwd dosyası betiğe dahil edildi
}
?>

Bu bakımdan, bir dosya sistemi işleminde kullanılan her dizge daima denetlenmelidir. Aşağıda, önceki örneğin iyileştirilmişi verilmiştir:

Örnek 2 - Girdiyi doğru şekilde ele almak

<?php
$dosya 
$_GET['dosya'];

// Kabul edilebilir değerlerin listesi
switch ($file) {
    case 
'main':
    case 
'foo':
    case 
'bar':
        include 
'/home/siteler/include/'.$dosya.'.php';
        break;
    default:
        include 
'/home/siteler/include/main.php';
}
?>


add a note add a note User Contributed Notes
Boş baytlı girdiler
kpobococ at gmail dot com
16-May-2009 07:25
Since problems with null bytes do not stretch to regular string functions, this should be enough to ensure no GET parameter contains them any more:

<?php
function getVar($name)
{
   
$value = isset($_GET[$name]) ? $_GET[$name] : null;
   
    if (
is_string($value)) {
       
$value = str_replace("\0", '', $value);
    }
}
?>

Modifying this to work with other superglobals should not be a problem, so I will leave it up to you.

Database Security> <Dosya Sistemi Güvenliği
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites