Add error handling around double-bind of ports
This commit is contained in:
@@ -236,6 +236,9 @@ class WindowsError
|
||||
PROCESS_MODE_NOT_BACKGROUND = 403
|
||||
INVALID_ADDRESS = 487
|
||||
|
||||
# Socket stuff
|
||||
ADDRESS_IN_USE = 10048
|
||||
|
||||
#
|
||||
# Return a string representation of the constant for a number
|
||||
#
|
||||
@@ -687,6 +690,8 @@ class WindowsError
|
||||
"The process is not in background processing mode."
|
||||
when INVALID_ADDRESS
|
||||
"Attempt to access invalid address."
|
||||
when ADDRESS_IN_USE
|
||||
"The address/port is already in use."
|
||||
else
|
||||
"#{code}"
|
||||
end
|
||||
|
||||
@@ -113,7 +113,9 @@ class Channel
|
||||
|
||||
# Transmit the request and wait for the response
|
||||
response = client.send_request(request)
|
||||
cid = response.get_tlv(TLV_TYPE_CHANNEL_ID).value
|
||||
cid = response.get_tlv_value(TLV_TYPE_CHANNEL_ID)
|
||||
|
||||
return nil unless cid
|
||||
|
||||
# Create the channel instance
|
||||
channel = klass.new(client, cid, type, flags)
|
||||
|
||||
+2
-8
@@ -79,14 +79,8 @@ class TcpServerChannel < Rex::Post::Meterpreter::Channel
|
||||
def self.open(client, params)
|
||||
c = Channel.create(client, 'stdapi_net_tcp_server', self, CHANNEL_FLAG_SYNCHRONOUS,
|
||||
[
|
||||
{
|
||||
'type' => TLV_TYPE_LOCAL_HOST,
|
||||
'value' => params.localhost
|
||||
},
|
||||
{
|
||||
'type' => TLV_TYPE_LOCAL_PORT,
|
||||
'value' => params.localport
|
||||
}
|
||||
{'type' => TLV_TYPE_LOCAL_HOST, 'value' => params.localhost},
|
||||
{'type' => TLV_TYPE_LOCAL_PORT, 'value' => params.localport}
|
||||
] )
|
||||
c.params = params
|
||||
c
|
||||
|
||||
@@ -454,20 +454,26 @@ class Console::CommandDispatcher::Stdapi::Net
|
||||
return
|
||||
end
|
||||
|
||||
channel = client.net.socket.create(
|
||||
Rex::Socket::Parameters.new(
|
||||
'LocalPort' => rport,
|
||||
'Proto' => 'tcp',
|
||||
'Server' => true
|
||||
begin
|
||||
channel = client.net.socket.create(
|
||||
Rex::Socket::Parameters.new(
|
||||
'LocalPort' => rport,
|
||||
'Proto' => 'tcp',
|
||||
'Server' => true
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
# Start the local TCP reverse relay in association with this stream
|
||||
service.start_reverse_tcp_relay(channel,
|
||||
'LocalPort' => rport,
|
||||
'PeerHost' => lhost,
|
||||
'PeerPort' => lport,
|
||||
'MeterpreterRelay' => true)
|
||||
# Start the local TCP reverse relay in association with this stream
|
||||
service.start_reverse_tcp_relay(channel,
|
||||
'LocalPort' => rport,
|
||||
'PeerHost' => lhost,
|
||||
'PeerPort' => lport,
|
||||
'MeterpreterRelay' => true)
|
||||
rescue Exception => e
|
||||
print_error("Failed to create relay: #{e.to_s}")
|
||||
return false
|
||||
end
|
||||
|
||||
else
|
||||
# Validate parameters
|
||||
unless lport && rhost && rport
|
||||
|
||||
Reference in New Issue
Block a user