Lots of small changes, the big one is moving from sysread -> readpartial in the stream base class

git-svn-id: file:///home/svn/framework3/trunk@8764 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
HD Moore 2010-03-10 06:43:46 +00:00
parent e05921b297
commit 6bd2a954cf
6 changed files with 30 additions and 18 deletions

View File

@ -215,6 +215,15 @@ protected
include Rex::IO::StreamAbstraction
def peerinfo
@sock_inp.getpeername[1,2].map{|x| x.to_s}.join(":")
end
def localinfo
@sock_inp.getpeername[1,2].map{|x| x.to_s}.join(":")
end
def initialize(inp, out)
@sock_inp = inp
@sock_out = out
@ -273,3 +282,4 @@ end
end
end

View File

@ -42,7 +42,7 @@ class Session < Base
if(not s.rstream.has_read_data?(0))
{ "data" => "" }
else
data = s.shell_read
data = s.shell_read
if data.length > 0
@framework.events.on_session_output(s, data)
end

View File

@ -30,7 +30,7 @@ class SessionManager < Hash
next
end
if s.respond_to?('rstream') and s.rstream.eof
if s.respond_to?('rstream') and s.rstream.eof?
deregister(s, "Died")
dlog("Session #{s.sid} has died")
next

View File

@ -59,7 +59,7 @@ module FrameworkEventManager
Msf::Logging::stop_session_log(session)
msg = "#{session.desc} session #{session.name} closed."
if reason.length > 0
if reason and reason.length > 0
msg << " Reason: #{reason}"
end
output.print_status(msg)

View File

@ -60,7 +60,7 @@ module Stream
def read(length = nil, opts = {})
# XXX handle length being nil
begin
fd.sysread(length)
fd.readpartial(length)
rescue ::IOError, ::EOFError, ::Errno::EPIPE
return nil if (fd.abortive_close == true)
raise $!
@ -294,7 +294,7 @@ module Stream
# This flag indicates whether or not an abortive close has been issued.
#
attr_accessor :abortive_close
protected
end

View File

@ -24,8 +24,9 @@ module StreamAbstraction
#
# Initializes peer information.
#
def initinfo(peer)
def initinfo(peer,local)
@peer = peer
@local = local
end
#
@ -39,7 +40,7 @@ module StreamAbstraction
# Symbolic local information.
#
def localinfo
"Local Pipe"
(@local || "Local Pipe")
end
end
@ -51,9 +52,9 @@ module StreamAbstraction
self.lsock.extend(Rex::IO::Stream)
self.lsock.extend(Ext)
self.rsock.extend(Rex::IO::Stream)
self.monitor_rsock
end
#
@ -117,7 +118,7 @@ module StreamAbstraction
# The right side of the stream.
#
attr_reader :rsock
protected
def monitor_rsock
@ -125,7 +126,7 @@ protected
loop do
closed = false
buf = nil
begin
s = Rex::ThreadSafe.select( [ self.rsock ], nil, nil, 0.2 )
if( s == nil || s[0] == nil )
@ -134,7 +135,7 @@ protected
rescue Exception => e
closed = true
end
if( closed == false )
begin
buf = self.rsock.sysread( 32768 )
@ -143,7 +144,7 @@ protected
closed = true
end
end
if( closed == false )
total_sent = 0
total_length = buf.length
@ -153,7 +154,7 @@ protected
sent = self.write( data )
# sf: Only remove the data off the queue is syswrite was successfull.
# This way we naturally perform a resend if a failure occured.
# Catches an edge case with meterpreter TCP channels where remote send
# Catches an edge case with meterpreter TCP channels where remote send
# failes gracefully and a resend is required.
if( sent > 0 )
total_sent += sent
@ -165,7 +166,7 @@ protected
end
end
end
if( closed )
self.close_write
::Thread.exit
@ -173,12 +174,13 @@ protected
end
}
end
protected
attr_accessor :monitor_thread
attr_writer :lsock
attr_writer :rsock
end
end; end
end; end