From 1a515093cb28bfe8c2869c1ff97e55c00b452c9a Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Wed, 25 Sep 2013 16:46:54 -0500 Subject: [PATCH] Idiomatic Ruby Assuming this gets accepted, this should [FixRM #8240]. Take a look, and if you're good with it, I'll land on master. Everything seems to work out on this end. --- .../ui/console/command_dispatcher/core.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb index 608c84641b..6766ce7e7f 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb @@ -356,14 +356,13 @@ class Console::CommandDispatcher::Core # otherwise we'll end up with local listeners which aren't connected # to valid channels in the migrated meterpreter instance. existing_relays = [] - if service != nil - service.each_tcp_relay do |lhost, lport, rhost, rport, opts| - next if (opts['MeterpreterRelay'] == nil) - if existing_relays.length == 0 + if service + service.each_tcp_relay do |lhost, lport, rhost, rport, opts| + next unless opts['MeterpreterRelay'] + if existing_relays.empty? print_status("Removing existing TCP relays...") end - if (service.stop_tcp_relay(lport, lhost)) print_status("Successfully stopped TCP relay on #{lhost || '0.0.0.0'}:#{lport}") existing_relays << { @@ -375,8 +374,7 @@ class Console::CommandDispatcher::Core next end end - - if existing_relays.length > 0 + unless existing_relays.empty? print_status("#{existing_relays.length} TCP relay(s) removed.") end end @@ -388,13 +386,14 @@ class Console::CommandDispatcher::Core print_status("Migration completed successfully.") - if existing_relays.length > 0 + unless existing_relays.empty? print_status("Recreating TCP relay(s)...") existing_relays.each do |r| client.pfservice.start_tcp_relay(r[:lport], r[:opts]) print_status("Local TCP relay recreated: #{r[:opts]['LocalHost'] || '0.0.0.0'}:#{r[:lport]} <-> #{r[:opts]['PeerHost']}:#{r[:opts]['PeerPort']}") end end + end def cmd_load_help