taint
1.0.0
用於檢測XSS代碼(污染的字符串)的PHP擴展名,也可用於發現SQL注入漏洞,外殼注入等。
這個想法來自https://wiki.php.net/rfc/taint,我以PHP擴展為實現,這使補丁不需要。
請注意,由於它將減慢您的應用程序,因此不能在產品ENV中啟用此擴展名。
由於PHP8.0實施的並發症,Taint不會與PHP8.0+兼容。
Taint是PECL擴展名,因此您可以通過以下方式安裝它。
pecl install taint
$/path/to/phpize
$./configure --with-php-config=/path/to/php-config/
$make && make install
當啟用Taint時,如果您將污染的字符串(來自$ _get,$ _post或$ _cookie)傳遞給某些功能,Taint會警告您。
<?php
$ a = trim ( $ _GET [ ' a ' ]);
$ file_name = ' /tmp ' . $ a ;
$ output = " Welcome, { $ a } !!! " ;
$ var = " output " ;
$ sql = " Select * from " . $ a ;
$ sql .= " ooxx " ;
echo $ output ;
print $ $ var ;
include ( $ file_name );
mysql_query ( $ sql );以上示例將輸出類似的內容:
Warning: main() [function.echo]: Attempt to echo a string that might be tainted
Warning: main() [function.echo]: Attempt to print a string that might be tainted
Warning: include() [function.include]: File path contains data that might be tainted
Warning: mysql_query() [function.mysql-query]: SQL statement contains data that might be tainted
如果您需要隱藏特定腳本的錯誤,則可以:
ini_set('taint.error_level', 0);