Ne Kayıt Globals nedir?
A common security problem with PHP is the register_globals setting in PHP's configuration file ( php.ini ). PHP ile ortak bir güvenlik sorunu register_globals yapılandırma dosyası (php.ini) olarak php.ini This setting (which can be either On or Off ) tells whether or not to register the EGPCS (Environment, GET, POST, Cookie, Server) variables as global variables. Bu ayar, (ki olabilir veya kapalı) üzerinde olsa da olmasa da, küresel değişkenler olarak POST, Çerez, Sunucu) değişkenleri GET (Çevre ve EGPCS kayıt söyler. For example, if register_globals is on, the url
$ hiçbir kod gerekli bir $id değişken olarak kimlik ilan edecek açık. Similarly, $DOCUMENT_ROOT would also be defined, since it is part of the $_SERVER 'superglobal' array. Benzer şekilde, $DOCUMENT_ROOT de kullanılabilir olacaktır, çünkü $_SERVER 'süper' global dizi bir parçasıdır. These two examples are the equivalent of placing the following code at the beginning of a script: Bu iki örnek bir programın başında aşağıdaki kodu yerleştirmeye karşılığı vardır:
$id = $_GET [ 'id' ] ; $ Id = $ _GET [ 'ID'];
$DOCUMENT_ROOT = $_SERVER [ 'DOCUMENT_ROOT' ] ; $ DOCUMENT_ROOT = $ _SERVER [ 'DOCUMENT_ROOT'];
This feature is a great security risk, and you should ensure that register_globals is Off for all scripts (as of PHP 4.2.0 this is the default). Bu özellik, büyük bir güvenlik riski olduğunu ve sağlanması gereken register_globals kapalı tüm betikleri için (PHP 4.2.0 bu varsayılan olduğu gibi). It's preferred to go through PHP Predefined Variables instead, such as the superglobal $_REQUEST. Bu PHP Önceden tanımlı Değişkenleri yerine gibi süper küresel $ _REQUEST git tercih's. Even more secure is to further specify by using: $_ENV, $_GET, $_POST, $_COOKIE, or $_SERVER instead of using the more general superglobal $_REQUEST. Daha güvenli daha kullanarak: $ _ENV, $ _GET, $ _posts, $ _COOKIE veya $ _SERVER yerine daha genel küresel süper $ _REQUEST kullanarak belirtmek içindir.
[ edit ] Example [Düzenle] Örnek
Let's say that this PHP code is on the receiving end of a form. 's Bu PHP kodu formun alıcı son on varsayalım. The user has just entered an incorrect password. Kullanıcı sadece bir yanlış şifre girdi. The $_POST array variable handles it. Bu $ _posts dizi değişken bu işler. The code will describe that if the password is correct (correct password being, let's say, 12345), the variable $admin will be set to TRUE. Kod Eğer şifrenizi ( doğru şifre olmak, mesela, 12345 tir), değişken $ yönetici doğruysa TRUE olarak ayarlanmış olacak anlatacağız. The site's configuration says that if $admin is set to TRUE, that user will have administrative privileges. Sitenin yapılandırma eğer $ yönetici DOĞRU için bu kullanıcı yönetici haklarına sahip olacak ayarlamak olduğunu söylüyor. This code is PHP5 compatible. Bu kod php5 uyumludur.
if ( isset ( $_POST [ 'password' ] ) && $_POST [ 'password' ] == 12345 ) { (isset ($ _posts [ 'parola']) & & $ eğer _posts [ 'parola'] == 12345) (
$admin = TRUE ; $ Yönetici = TRUE;
} )
register_globals does not discriminate between $_POST variables and $_GET variables. register_globals $ _posts değişkenleri ve $ _GET değişkenleri arasında ayrımcılık değildir. So, suppose the user input the form and it took him or her to that above page. Böylece, kullanıcı girişi formu varsayalım ve ona bu yukarıdaki sayfa aldı. The user could decide that he or she deserves admin privileges even though they do not know the password. Kullanıcı bu onun rağmen şifrenizi bilmiyorsanız Admin hak karar verebilir. So, that user could append ?admin=1 to the URL of that page. Böylece bu kullanıcı ekleyin ki? Yönetici = 1 sayfa bir URL. What that would do, with register_globals On , would be to force the creation the variable $admin and automatically set the value to 1, making it equivalent to TRUE. Bu, Açık register_globals ile, değişken $ yönetici ve otomatik olarak 1 değeri set oluşturma gücü olacak, yapmak ne yapardınız True eşdeğerdir. So register_globals On allows the user to inject variables and values into the program! Yani register_globals Çarşamba kullanıcı programa değişkenleri ve değerleri enjekte sağlar! Here, whether or not they input the correct password, the user would now have administrative privileges just by doing something with the URL. Burada olsa da olmasa da onların girişini doğru şifre, kullanıcı artık sadece URL ile ilgili bir şeyler yaparak yönetici haklarına sahip olacak.
As you can see, this sort of situation can happen at anytime by someone who does enough thinking to figure out how the page was coded. Görüldüğü gibi, durum bu tür zaman kim yeterince sayfanın nasıl kodlu olduğunu anlamaya düşünme birine göre olabilir. It could happen in many other situations. Bir çok diğer durumlarda olabilir.
Another example is that of sessions. Bir başka örnek oturumları bu. When register_globals = on, we could also use $username in our example below but again you must realize that $username could also come from other means, such as GET (through the URL). Ne zaman = on register_globals, ayrıca aşağıdaki örnekte ama yine o $ username de diğer araçlarla, gibi URL () ulaşabilirsiniz gelebilir gerçekleştirmek gerekir kullanıcıadı $ kullanabilirsiniz.
<?php <? PHP
// We wouldn't know where $username came from but do know $_SESSION is / / Biz burada kullanıcıadı $ bilemeyiz geldi ama _SESSION $ biliyorum olduğunu
// for session data Oturumu veri / / için
if (isset($_SESSION['username'])) { (isset ($ eğer _SESSION [ 'Username'])) (
echo Hello {$_SESSION['username']} ; echo Merhaba ($ _SESSION [ 'kullanıcı adı']);
} else { ) Else (
echo Hello Guest echo Merhaba Konuk ; ;
echo Would you like to login?; echo giriş ister misiniz?;
} )
?> ?>
[ edit ] Best Practices [Düzenle] En İyi Uygulamalar
The best way to avoid it is to make sure that register_globals is set to Off in your php.ini. Bu register_globals için in php.ini Kapalı ayarlamak olduğundan emin olmaktır önlemek için en iyi yolu. But as a general coding recommendation, always initialize your variables. Ama genel bir kodlama tavsiyesi, her zaman olduğu gibi bir biçimde başlatılamadı. The following code makes a small addition to the previous code example, but first sets $admin to FALSE so that the user cannot get administrative privileges except via the conditional statement: Aşağıdaki kod, ama ilk set $ böylece kullanıcı koşullu beyanı üzerinden dışında idari yetkileri can't get YANLIŞ için yönetici önceki kod gibi küçük bir ek yapar: