add :closed? method to Meterpreter Channel

Implement a check for self.cid.nil? in Meterpreter's Channel class
in the :closed? method for compatibility with the Socket's :closed?

Touch up the Rex DNS server's stop method using this method on
pivot sockets.

Add SOL_SOCKET and SO_REUSEADDR options to the Rex UDP sockets
created by the DNS components - the server socket, as well as the
client abstraction socket.
MS-2855/keylogger-mettle-extension
RageLtMan 2016-03-01 02:06:55 -05:00
parent 570987aecd
commit e86ca56dd1
2 changed files with 10 additions and 1 deletions

View File

@ -250,6 +250,13 @@ class Channel
written.nil? ? 0 : written.value
end
#
# Wrapper around check for self.cid
#
def closed?
self.cid.nil?
end
#
# Wrapper around the low-level close.
#

View File

@ -190,6 +190,7 @@ class Server
if self.serve_udp
@udp_sock = Rex::Socket::Udp.create(self.sock_options)
udp_sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, 1)
self.listener_thread = Rex::ThreadFactory.spawn("UDPDNSServerListener", false) {
monitor_listener
}
@ -221,7 +222,7 @@ class Server
ensure
while csock = ensure_close.shift
csock.stop if csock.respond_to?(:stop)
csock.close unless csock.closed?
csock.close csock.respond_to?(:close) and !csock.closed?
end
end
self.cache.stop(flush_cache)
@ -299,6 +300,7 @@ protected
'LocalHost' => self.udp_sock.localhost,
'LocalPort' => self.udp_sock.localport
)
cli.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, 1)
dispatch_request(cli, buf)
end
end