當PHP.ini設置magic_quotes_Sybase為on時會覆蓋magic_quotes_gpc為on的處理,然而magic_quotes_Sybase僅僅是轉義了nullbyte和把'變成了'' :)
author: ryat#wolvez.org
team:http://www.80vul.com
date:2009-04-14
一 描敘
magic_quotes_gpc為on時,php在注冊變量時會調用addslashes()函數處理[既轉義單引號、雙引號、反斜線和nullbyte],但php.ini中還有另外一個選項影響著magic_quotes_gpc和addslashes()函數:當PHP.ini設置magic_quotes_sybase為on時會覆蓋magic_quotes_gpc為on的處理,然而magic_quotes_Sybase僅僅是轉義了nullbyte和把'變成了''
二 分析
先來看下addslashes的PHP源碼:
// string.c
PHPAPI char *php_addslashes(char *str, int length, int *new_length, int should_free TSRMLS_DC)
{
return php_addslashes_ex(str, length, new_length, should_free, 0 TSRMLS_CC);
}
...
PHPAPI char *PHP_addslashes_ex(char *str, int length, int *new_length, int should_free, int ignore_sybase TSRMLS_DC)
{
...
if (!ignore_sybase && PG(magic_quotes_sybase)) {
// 如果ignore_sybase=0[默認為0]且magic_quotes_Sybase為on就執行下面的代碼
while (source < end) {
switch (*source) {
case '\0':
*target++ = '\\';
*target++ = '0';
break;
case '\'':
*target++ = '\'';
*target++ = '\'';
break;
default:
*target++ = *source;
break;
}
source++;
// 從上面的代碼可以看到只是把null變成了\0,'變成了''
}
} else {
// 執行常規的轉義
...
由上面的代碼可以看到,如果magic_quotes_sybase為on就會覆蓋magic_quotes_gpc為on時的默認處理效果[而magic_quotes_Sybase僅僅是轉義了nullbyte和把'變成了'' :)]
然後我們看看關於magic_quotes_Sybase定義的部分:
// main.c
STD_PHP_INI_BOOLEAN("magic_quotes_sybase", "0", PHP_INI_ALL, OnUpdateBool, magic_quotes_Sybase, PHP_core_globals, core_globals)
可以看到,magic_quotes_Sybase在php.ini裡默認是關閉的,但是屬於PHP_INI_ALL類型的指令,那麼就可以在.htAccess或者httpd.conf裡來更改magic_quotes_Sybase的設置了. 如:
// .htAccess
PHP_flag magic_quotes_Sybase on
三 測試代碼
缺
四 實際應用
缺