Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If <code>allow_url_include</code> is off, you can't execute remote code. But you can find other pages, for example a content management dashboard, to upload your code as "image", then find the actual path and <code>include</code> it.</p> <p>And, there are still ways to exploit.</p> <p>Let's look inside your code. You may notice that it automatically add an extension <code>.php</code> at the end of path. So you should remove <code>php</code> in GET param. But what if the file you want to include does not have PHP extension? Then use <code>%00</code> to terminate string, such as</p> <pre><code>http://localhost/include.php?page=../uploads/your_uploaded_fake_image.jpg%00 </code></pre> <p>There's a special protocol in PHP, powerful and dangerous. It's <code>php://</code>. You can check out the <a href="http://php.net/manual/en/wrappers.php.php" rel="noreferrer">offcial manual</a> for detailed information, and here I'll show you some cases to make a file inclusion vulnerability become source disclosure and even remote code execution vulnerabilities.</p> <p>Before your test, I suggest you use <strong>Firefox</strong> with <strong><a href="https://addons.mozilla.org/en-US/firefox/addon/hackbar/" rel="noreferrer">HackBar</a></strong> plugin. It's a powerful penetration testing suite.</p> <ol> <li>Source disclosure</li> </ol> <p>This feature doesn't need url inclusion allowed.</p> <p><code>php://filter</code> is a kind of meta-wrapper designed to permit the application of filters to a stream at the time of opening. This is useful with all-in-one file functions such as readfile(), file(), and file_get_contents() where there is otherwise no opportunity to apply a filter to the stream prior the contents being read. (<a href="http://www.php.net/manual/en/filters.string.php" rel="noreferrer">Reference</a>)</p> <p>Then you can see the source <code>secret.inc.php</code> in the same directory via following request.</p> <pre><code>http://localhost/include.php?page=php://filter/read=convert.base64-encode/resource=secret.inc </code></pre> <p><img src="https://i.stack.imgur.com/iLLq2.png" alt="demo"></p> <p>File content will be encoded in base64, so it does support binary file.</p> <p>It's <strong>powerful</strong> to get sensitive information, such as database passwords or a encryption key! If privilege is not proper configurated, it can even jump out of cage and extract data from files in outter directories, like <code>/etc/passwd</code>!</p> <ol start="2"> <li>Remote code execution</li> </ol> <p><strong>Actually you can't exploit this way, because <code>allow_url_include</code> is Off in this case.</strong></p> <p>But I must point it out because it's <strong>magical</strong>!</p> <p>It's completly different from local include. It doesn't need to upload any file to a remote server or so. All you need is one single request.</p> <p><code>php://input</code> can access the raw HTTP request body, so what does <code>include("php://input")</code> do? Just visit <code>http://localhost/include.php?page=php://input</code>, with valid PHP code in request body, then you can execute any (allowed) function in remote server!</p> <p><img src="https://i.stack.imgur.com/74gnc.png" alt="enter image description here"></p> <p>Don't forget the <code>%00</code> to drop <code>.php</code> tail.</p> <p>Besides, PHP supports <code>data://</code> URL scheme. You can directly put code in GET param! The following test doesn't need any special tool, just a normal browser can execute an attack. </p> <pre><code>http://localhost/include.php?page=data:text/plaintext,&lt;?php phpinfo();?&gt; </code></pre> <p>Some Web Application Firewalls may detect suspected string in URL and block evil request, they won't leave the <code>phpinfo</code> alone. Is there a way to encrypt? Of course. <code>data://</code> URL supports at least base64 encoding...</p> <pre><code>http://localhost/include.php?page=data:text/plain;base64, PD9waHAgcGhwaW5mbygpOyA/Pg== </code></pre> <p>And you will get familiar phpinfo once again!</p> <p><img src="https://i.stack.imgur.com/ehlst.png" alt="with base64 encoding"></p> <h2>Note</h2> <p>The null byte trick (<code>%00</code>) does not work anymore for PHP >= 5.3.4: <a href="http://blog.benjaminwalters.net/?p=22139" rel="noreferrer">http://blog.benjaminwalters.net/?p=22139</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload