Re: [Full-disclosure] Data Type Conversion Attack



Since I couldn't see any mention of a fix, here you go my tiny rant.

The example vulnerable code is faulty on multiple levels. One shouldn't rely
on automated typecasting, but explicitly mark which kind of typecasting.
The main priciple here is NOT typecasting, but "making bad code look bad".
Here, you go:

$vuln=(int)$_GET["var"]+1;

Or, if you prefer a more pro approach;

$vuln=intval($_GET["var"])+1;

Regards,
Christian Sciberras.


On Mon, Dec 21, 2009 at 1:39 PM, Manu <sourvivor@xxxxxxxxx> wrote:

*Introduction*



This test allows attackers to discover local installation paths in websites
using PHP in which the error messages hasn´t been completely blocked. The
idea is to use the http parameters to perform an explicit data type
conversion to generate a non-managed exception which shows the local
installation path on the web server.



*Local Path disclosure*



Let´s suppose a PHP code running on a web server like following:



*Dca.php*

*<?php ***

*$vuln= $_GET["var"] +1;***

*?>***



As can be seen, this program receives a numeric parameter which is used to
perform a mathematical function. The normal way to call this program is
something like:



- *http://www.testserver.com/dca.php?var=1<https://owa.informatica64.com/owa/redir.aspx?C=03bb620597674e25acf80fef5ea71825&URL=http%3a%2f%2fwww.testserver.com%2fdca.php%3fvar%3d1>
*



In order to force an implicit data type conversion the following syntax in
the calling http parameters can be used:



- *http://www.testserver.com/dca.php?var[]=1<https://owa.informatica64.com/owa/redir.aspx?C=03bb620597674e25acf80fef5ea71825&URL=http%3a%2f%2fwww.testserver.com%2fdca.php%3fvar%255b%255d%3d1>
*



This syntax will force the PHP engine to convert the parameter into an
array structure. If the *display_errors* parameter in the *php.ini*configuration file is enabled then an error message like the following will
be showed up:



*Unsupported operand types in C:\server\htdocs\dca\dca.php on line 2*



This behavior is due to the fact that there are not an implicit transform
for adding operation in array structures. In my personal research I found
out that there are a lot of PHP functions which usually applied to http
parameters that causes the same behavior dumping the error messages as shown
giving to the attacker more information that strictly necessary.



Manuel Fernández

Security Consultor

Informática64

_______________________________________________
Full-Disclosure - We believe in it.
Charter: http://lists.grok.org.uk/full-disclosure-charter.html
Hosted and sponsored by Secunia - http://secunia.com/

_______________________________________________
Full-Disclosure - We believe in it.
Charter: http://lists.grok.org.uk/full-disclosure-charter.html
Hosted and sponsored by Secunia - http://secunia.com/

Relevant Pages

  • [Full-disclosure] Data Type Conversion Attack
    ... This test allows attackers to discover local installation paths in websites ... using PHP in which the error messages hasn´t been completely blocked. ... parameters that causes the same behavior dumping the error messages as shown ...
    (Full-Disclosure)
  • Re: loose thinking
    ... php> var_dump; ... There is no difference between an empty string and null in array indexing. ... Having arrays where keys can be any arbitrary data type looks like an ...
    (comp.lang.php)
  • Re: Error messages
    ... removing the useless *catchable* FATAL error:( ... Php let you indicate the data type to be used and then considers it as a syntax error??? ...
    (comp.lang.php)
  • PHP+MSSQL
    ... Lately I try to use MSSQL and PHP, the problem arise when PHP try to ... I try to used normal working file that store BLOB as file type in MSSQL ... Is it because the image data type in MSSQL can ...
    (comp.lang.php)
  • Best Organization of PHP Include Files?
    ... In my PHP code, I typically break my functions into groups (usually based on ... the data type they operate on), and then include the files, i.e.: ... the PHP interpreter requires some time to parse each include file. ... b)What is the best paradigm for managing include files? ...
    (comp.lang.php)