2005-12-17 06:46:23 +00:00
|
|
|
#!/usr/bin/env ruby
|
2005-05-31 12:56:36 +00:00
|
|
|
|
|
|
|
require 'socket'
|
2006-01-07 18:59:04 +00:00
|
|
|
require 'fcntl'
|
2005-05-31 12:56:36 +00:00
|
|
|
|
|
|
|
module Rex
|
|
|
|
module IO
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This class provides an abstraction to a stream based
|
|
|
|
# connection through the use of a streaming socketpair.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
module StreamAbstraction
|
|
|
|
|
2006-01-07 10:04:30 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# Extension information for required Stream interface.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
module Ext
|
|
|
|
|
|
|
|
#
|
|
|
|
# Initializes peer information.
|
|
|
|
#
|
|
|
|
def initinfo(peer)
|
|
|
|
@peer = peer
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Symbolic peer information.
|
|
|
|
#
|
|
|
|
def peerinfo
|
2006-08-17 01:57:52 +00:00
|
|
|
(@peer || "Remote Pipe")
|
2006-01-07 10:04:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Symbolic local information.
|
|
|
|
#
|
|
|
|
def localinfo
|
2006-08-17 01:57:52 +00:00
|
|
|
"Local Pipe"
|
2006-01-07 10:04:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-07-19 04:21:15 +00:00
|
|
|
#
|
2005-11-15 05:22:13 +00:00
|
|
|
# This method creates a streaming socket pair and initializes it.
|
2005-07-19 04:21:15 +00:00
|
|
|
#
|
2005-05-31 12:56:36 +00:00
|
|
|
def initialize_abstraction
|
|
|
|
self.lsock, self.rsock = ::Socket.pair(::Socket::AF_UNIX,
|
|
|
|
::Socket::SOCK_STREAM, 0)
|
2005-09-27 05:31:48 +00:00
|
|
|
|
|
|
|
self.lsock.extend(Rex::IO::Stream)
|
2006-01-07 10:04:30 +00:00
|
|
|
self.lsock.extend(Ext)
|
2005-09-27 05:31:48 +00:00
|
|
|
self.rsock.extend(Rex::IO::Stream)
|
2005-05-31 12:56:36 +00:00
|
|
|
end
|
|
|
|
|
2005-07-26 04:08:01 +00:00
|
|
|
#
|
2005-11-15 05:22:13 +00:00
|
|
|
# This method cleans up the abstraction layer.
|
2005-07-26 04:08:01 +00:00
|
|
|
#
|
|
|
|
def cleanup_abstraction
|
|
|
|
self.lsock.close if (self.lsock)
|
|
|
|
self.rsock.close if (self.rsock)
|
|
|
|
|
|
|
|
self.lsock = nil
|
|
|
|
self.rsock = nil
|
|
|
|
end
|
|
|
|
|
2006-01-07 10:04:30 +00:00
|
|
|
#
|
|
|
|
# Writes to the local side.
|
|
|
|
#
|
|
|
|
def syswrite(buffer)
|
|
|
|
lsock.syswrite(buffer)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Reads from the local side.
|
|
|
|
#
|
|
|
|
def sysread(length)
|
|
|
|
lsock.sysread(length)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Shuts down the local side of the stream abstraction.
|
|
|
|
#
|
|
|
|
def shutdown(how)
|
|
|
|
lsock.shutdown(how)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Closes both sides of the stream abstraction.
|
|
|
|
#
|
|
|
|
def close
|
|
|
|
cleanup_abstraction
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Symbolic peer information.
|
|
|
|
#
|
|
|
|
def peerinfo
|
|
|
|
"Remote-side of Pipe"
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Symbolic local information.
|
|
|
|
#
|
|
|
|
def localinfo
|
|
|
|
"Local-side of Pipe"
|
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# The left side of the stream.
|
|
|
|
#
|
|
|
|
attr_reader :lsock
|
|
|
|
#
|
|
|
|
# The right side of the stream.
|
|
|
|
#
|
|
|
|
attr_reader :rsock
|
2005-05-31 12:56:36 +00:00
|
|
|
protected
|
2005-11-15 05:22:13 +00:00
|
|
|
attr_writer :lsock, :rsock # :nodoc:
|
2005-05-31 12:56:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end; end
|