From ef8601aa71de061c628fe3d8f8a32c63405bfaf0 Mon Sep 17 00:00:00 2001 From: Quentin Kaiser Date: Tue, 18 Dec 2018 19:42:26 +0100 Subject: [PATCH] Bail early if we receive an unexpected response. --- modules/exploits/multi/misc/consul_service_exec.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/exploits/multi/misc/consul_service_exec.rb b/modules/exploits/multi/misc/consul_service_exec.rb index 8ab4a71501..107cd7e0ae 100644 --- a/modules/exploits/multi/misc/consul_service_exec.rb +++ b/modules/exploits/multi/misc/consul_service_exec.rb @@ -78,7 +78,7 @@ class MetasploitModule < Msf::Exploit::Remote def execute_command(cmd, opts = {}) uri = target_uri.path - service_name = Rex::Text.rand_text_alpha(5) + service_name = Rex::Text.rand_text_alpha(5..10) print_status("Creating service '#{service_name}'") # NOTE: Timeout defines how much time the check script will run until @@ -102,9 +102,10 @@ class MetasploitModule < Msf::Exploit::Remote } }.to_json }) - if res and res.code == 200 - print_status("Service '#{service_name}' successfully created.") + unless res && res.code == 200 + fail_with(Failure::UnexpectedReply, 'An error occured when contacting the Consul API.') end + print_status("Service '#{service_name}' successfully created.") print_status("Waiting for service '#{service_name}' script to trigger") sleep(12) print_status("Removing service '#{service_name}'")