Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does include('php://input') not work?

Tags:

security

php

Imagine a toy PHP application vulnerable to absolute local file inclusion, e.g.

<?php include($_GET['action']);

I tried the following request to exploit it:

POST /?action=php://input HTTP/1.1
Host: XXXXXXXXXXXXXXXXX
Content-Length: 3

foo

This effectively executes include('php://input'); with request body foo, so I would expect it to print foo. However, I get the following error

<br />
<b>Warning</b>:  include(php://input): failed to open stream: operation failed in <b>XXXXXXXXXXXXXXXXX</b> on line <b>12</b><br />
<br />
<b>Warning</b>:  include(): Failed opening 'php://input' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in <b>XXXXXXXXXXXXXXXXXXX</b> on line <b>12</b><br />

What is the issue here? Is this a PHP security feature? If so, can somebody point to the responsible part of the PHP source code that mitigates this?

like image 952
Niklas B. Avatar asked Feb 22 '16 14:02

Niklas B.


1 Answers

I found the answer with the help of Gustek. Apparently php://input falls under the restrction of allow_url_include, while for example php://filter does not:

Restricted by allow_url_include: php://input, php://stdin, php://memory and php://temp only.

Source: Docs for php:// URL handler

like image 194
Niklas B. Avatar answered Nov 09 '22 22:11

Niklas B.