2005-07-09 21:18:49 +00:00
|
|
|
require 'rex/socket'
|
2005-06-03 22:51:09 +00:00
|
|
|
|
|
|
|
###
|
|
|
|
#
|
2005-09-27 05:31:48 +00:00
|
|
|
# This class provides methods for interacting with an SSL TCP client
|
|
|
|
# connection.
|
2005-06-03 22:51:09 +00:00
|
|
|
#
|
|
|
|
###
|
2005-09-27 05:31:48 +00:00
|
|
|
module Rex::Socket::SslTcp
|
|
|
|
|
2005-11-03 04:43:19 +00:00
|
|
|
begin
|
|
|
|
require 'openssl'
|
|
|
|
|
2005-09-27 05:31:48 +00:00
|
|
|
include Rex::Socket::Tcp
|
2005-06-03 22:51:09 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Factory
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
2005-09-27 05:31:48 +00:00
|
|
|
def self.create(hash)
|
|
|
|
self.create_param(Rex::Socket::Parameters.from_hash(hash))
|
|
|
|
end
|
|
|
|
|
2005-06-03 22:51:09 +00:00
|
|
|
#
|
|
|
|
# Set the SSL flag to true and call the base class's create_param routine.
|
|
|
|
#
|
|
|
|
def self.create_param(param)
|
2005-09-27 05:31:48 +00:00
|
|
|
param.ssl = true
|
2005-06-03 22:51:09 +00:00
|
|
|
|
2005-09-27 05:31:48 +00:00
|
|
|
Rex::Socket::Tcp.create_param(param)
|
2005-06-03 22:51:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Class initialization
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
2005-09-27 05:31:48 +00:00
|
|
|
def initsock(params = nil)
|
2005-06-03 22:51:09 +00:00
|
|
|
super
|
|
|
|
|
|
|
|
# Build the SSL connection
|
|
|
|
self.sslctx = OpenSSL::SSL::SSLContext.new
|
2005-09-27 05:31:48 +00:00
|
|
|
self.sslsock = OpenSSL::SSL::SSLSocket.new(self, self.sslctx)
|
2005-06-03 22:51:09 +00:00
|
|
|
self.sslsock.sync_close = true
|
|
|
|
self.sslsock.connect
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Stream mixin implementations
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
def write(buf, opts = {})
|
|
|
|
return sslsock.write(buf)
|
|
|
|
end
|
|
|
|
|
|
|
|
def read(length = nil, opts = {})
|
|
|
|
length = 16384 unless length
|
|
|
|
|
|
|
|
begin
|
|
|
|
return sslsock.read(length)
|
|
|
|
rescue EOFError
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def close
|
|
|
|
sslsock.close
|
2005-09-27 05:31:48 +00:00
|
|
|
super
|
2005-06-03 22:51:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
attr_accessor :sslsock, :sslctx
|
|
|
|
|
2005-11-03 04:43:19 +00:00
|
|
|
rescue LoadError
|
|
|
|
end
|
|
|
|
|
2005-06-03 22:51:09 +00:00
|
|
|
end
|