2015-12-11 14:42:00
原創 2730
將ecstore的程序放入到PHP7下髮現他竟然不能夠顯示界麵,通過var_dump髮現是模闆處理機製的問題。於是定位清晰,最終在`/app/base/lib/component/compiler.php`第77行髮現`$file_contents = preg_replace("!{$ldq}\*.*?\*{$rdq}!seu",'',$file_contents);` 經過這一句正則替換後,整箇文件內容變爲空瞭。於是開始查看原因最終髮現是preg_replace在PHP5.5後拋棄瞭`e`修飾符,php.net中是這樣描述的> `e` (`PREG_REPLACE_E V A L`)> >Warning 本特性已自 PHP 5.5.0 起廢棄。強烈建議不要使用本特性。> 如果設置瞭這箇被棄用的修飾符, preg_replace() 在進行瞭對替換字符串的 後曏引用替換之後, 將替換後的字符串作爲 php 代碼評估執行(e v a l 函數方式),併使用執行結果 作爲實際蔘與替換的字符串。單引號、雙引號、反斜線(\)和 NULL 字符在 後曏引用替換時會被用反斜線轉義. > >Caution The addslashes() function is run on each matched backreference before the substitution takes place. As such, when the backreference is used as a quoted string, escaped characters will be converted to literals. However, characters which are escaped, which would normally not be converted, will retain their slashes. This makes use of this modifier very complicated.> >`Caution` 請確保 replacement 蔘數由閤法 php 代碼字符串組成,否則 php 將會 在preg_replace() 調用的行上産生一箇解釋錯誤。> >`Caution` Use of this modifier is discouraged, as it can easily introduce security vulnerabilites:> ``` (.*?) )e', '" " . strtoupper("$2") . " "', $html);```> The above example code can be easily exploited by passing in a string such as `

{${e v a l($_GET[php_code])}}

`. This gives the attacker the ability to e x e cute arbitrary PHP code and as such gives him nearly complete access to your server.To prevent this kind of remote code e x e cution vulnerability the preg_replace_callback() function should be used instead:``` (.*?) )', function ($m) { return " " . strtoupper($m[2]) . " "; }, $html);```> Note: 僅 preg_replace() 使用此修飾符,其他 PCRE 函數忽略此修飾符。由此可見,是因爲這箇修飾符`e`的問題,將這箇`e`修飾符去掉卽可。
叄 加 陸 =