2005-07-09 21:18:49 +00:00
|
|
|
require 'rex/socket'
|
|
|
|
require 'rex/socket/tcp'
|
|
|
|
require 'rex/io/stream_server'
|
2005-06-03 07:13:15 +00:00
|
|
|
|
2005-06-03 07:32:17 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# This class provides methods for interacting with a TCP server. It
|
|
|
|
# implements the StreamServer IO interface.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
###
|
2005-09-27 05:31:48 +00:00
|
|
|
module Rex::Socket::TcpServer
|
|
|
|
|
|
|
|
include Rex::Socket
|
2005-06-03 07:13:15 +00:00
|
|
|
include Rex::IO::StreamServer
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Factory
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
2005-07-16 07:32:11 +00:00
|
|
|
#
|
2005-11-15 05:22:13 +00:00
|
|
|
# Creates the server using the supplied hash.
|
2005-07-16 07:32:11 +00:00
|
|
|
#
|
|
|
|
def self.create(hash)
|
|
|
|
self.create_param(Rex::Socket::Parameters.from_hash(hash))
|
|
|
|
end
|
|
|
|
|
2005-06-03 07:13:15 +00:00
|
|
|
#
|
|
|
|
# Wrapper around the base class' creation method that automatically sets
|
2005-11-15 05:22:13 +00:00
|
|
|
# the parameter's protocol to TCP and sets the server flag to true.
|
2005-06-03 07:13:15 +00:00
|
|
|
#
|
|
|
|
def self.create_param(param)
|
|
|
|
param.proto = 'tcp'
|
|
|
|
param.server = true
|
|
|
|
|
2005-09-27 05:31:48 +00:00
|
|
|
Rex::Socket.create_param(param)
|
2005-06-03 07:13:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2005-11-15 05:22:13 +00:00
|
|
|
# Accepts a child connection.
|
2005-06-03 07:13:15 +00:00
|
|
|
#
|
|
|
|
def accept(opts = {})
|
2005-09-27 05:31:48 +00:00
|
|
|
t = super()[0]
|
2005-09-23 06:08:04 +00:00
|
|
|
|
|
|
|
if (t)
|
2005-09-27 05:31:48 +00:00
|
|
|
t.extend(Rex::Socket::Tcp)
|
2006-01-17 04:35:44 +00:00
|
|
|
t.context = self.context
|
|
|
|
|
2005-09-23 06:08:04 +00:00
|
|
|
pn = t.getpeername
|
|
|
|
|
|
|
|
t.peerhost = pn[1]
|
|
|
|
t.peerport = pn[2]
|
|
|
|
end
|
|
|
|
|
|
|
|
t
|
2005-06-03 07:13:15 +00:00
|
|
|
end
|
|
|
|
|
2008-10-19 21:03:39 +00:00
|
|
|
end
|