Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kharissulistiyo/8f7bf05be5526bea3863024f873e1cf9 to your computer and use it in GitHub Desktop.
Save kharissulistiyo/8f7bf05be5526bea3863024f873e1cf9 to your computer and use it in GitHub Desktop.
Bad PHP code sample: Arbitrary File Download vulnerability
<?php
public function file_download() {
if ( !is_admin() || !is_user_logged_in() )
return;
if ( isset($_GET['page']) && isset($_GET['download']) ) {
if ( $_GET['page'] !== $this->menu_base )
return;
if ($this->wp_version_check('2.5') && function_exists('check_admin_referer'))
check_admin_referer('backup', self::NONCE_NAME);
$getdata = $this->get_real_get_data();
if (($file = realpath($getdata['download'])) !== FALSE) {
if( strtolower( substr( $file, -4 ) ) == ".log" ) {
header("Content-Type: text/plain;");
} else {
header("Content-Type: application/octet-stream;");
}
header("Content-Disposition: attachment; filename=".urlencode(basename($file)));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment