Skip to content

Commit 4fb5820

Browse files
committed
Land rapid7#3529 - Handle Rex::AddressInUse exception
2 parents 5fa639c + 4098979 commit 4fb5820

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/rex/post/meterpreter/ui/console.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ def run_command(dispatcher, method, arguments)
106106
log_error("Operation timed out.")
107107
rescue RequestError => info
108108
log_error(info.to_s)
109+
rescue Rex::AddressInUse => e
110+
log_error(e.message)
109111
rescue ::Errno::EPIPE, ::OpenSSL::SSL::SSLError, ::IOError
110112
self.client.kill
111113
rescue ::Exception => e
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding:binary -*-
2+
require 'spec_helper'
3+
4+
require 'rex/post/meterpreter/ui/console'
5+
6+
describe Rex::Post::Meterpreter::Ui::Console do
7+
8+
subject(:console) do
9+
Rex::Post::Meterpreter::Ui::Console.new(nil)
10+
end
11+
12+
describe "#run_command" do
13+
let(:dispatcher) do
14+
double
15+
end
16+
17+
it "logs error when Rex::AddressInUse is raised" do
18+
allow(dispatcher).to receive(:cmd_address_in_use) do
19+
raise Rex::AddressInUse, "0.0.0.0:80"
20+
end
21+
22+
expect(subject).to receive(:log_error).with("The address is already in use (0.0.0.0:80).")
23+
subject.run_command(dispatcher, "address_in_use", nil)
24+
end
25+
end
26+
27+
end

0 commit comments

Comments
 (0)