mirror of
https://github.com/rapid7/metasploit-framework
synced 2024-11-12 11:52:01 +01:00
Minor improvements and corner case bug fixes to session handling. This fixes issues that can come up when a stream is shut down
git-svn-id: file:///home/svn/framework3/trunk@11371 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
parent
c252d53c15
commit
c28ad8ea0c
@ -119,15 +119,15 @@ class CommandShell
|
||||
shell_write(cmd + "\n")
|
||||
|
||||
timeo = 5
|
||||
etime = Time.now.to_f + timeo
|
||||
etime = ::Time.now.to_f + timeo
|
||||
buff = ""
|
||||
|
||||
# Keep reading data until no more data is available or the timeout is
|
||||
# reached.
|
||||
while (Time.now.to_f < etime and ::IO.select([rstream], nil, nil, timeo))
|
||||
while (::Time.now.to_f < etime and ::IO.select([rstream], nil, nil, timeo))
|
||||
res = shell_read(-1, 0.01)
|
||||
buff << res if res
|
||||
timeo = etime - Time.now.to_f
|
||||
timeo = etime - ::Time.now.to_f
|
||||
end
|
||||
|
||||
buff
|
||||
@ -146,7 +146,7 @@ class CommandShell
|
||||
|
||||
# Read until we get the data between two tokens or absolute timeout.
|
||||
begin
|
||||
Timeout::timeout(timeout) do
|
||||
::Timeout.timeout(timeout) do
|
||||
buf = ''
|
||||
idx = nil
|
||||
loop do
|
||||
|
@ -152,7 +152,7 @@ module ReverseTcp
|
||||
client = self.listener_sock.accept
|
||||
rescue
|
||||
wlog("Exception raised during listener accept: #{$!}\n\n#{$@.join("\n")}")
|
||||
return nil
|
||||
break
|
||||
end
|
||||
|
||||
# Increment the has connection counter
|
||||
|
@ -126,21 +126,32 @@ protected
|
||||
closed = false
|
||||
buf = nil
|
||||
|
||||
if not self.rsock
|
||||
wlog("monitor_rsock: the remote socket is nil, exiting loop")
|
||||
break
|
||||
end
|
||||
|
||||
begin
|
||||
s = Rex::ThreadSafe.select( [ self.rsock ], nil, nil, 0.2 )
|
||||
if( s == nil || s[0] == nil )
|
||||
next
|
||||
end
|
||||
rescue Exception => e
|
||||
wlog("monitor_rsock: exception during select: #{e.class} #{e}")
|
||||
closed = true
|
||||
end
|
||||
|
||||
if( closed == false )
|
||||
begin
|
||||
buf = self.rsock.sysread( 32768 )
|
||||
closed = true if( buf == nil )
|
||||
rescue
|
||||
if buf == nil
|
||||
closed = true
|
||||
wlog("monitor_rsock: closed remote socket due to nil read")
|
||||
end
|
||||
|
||||
rescue ::Exception
|
||||
closed = true
|
||||
wlog("monitor_rsock: exception during read: #{e.class} #{e}")
|
||||
end
|
||||
end
|
||||
|
||||
@ -161,14 +172,15 @@ protected
|
||||
end
|
||||
rescue ::IOError => e
|
||||
closed = true
|
||||
wlog("monitor_rsock: exception during write: #{e.class} #{e}")
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if( closed )
|
||||
self.close_write
|
||||
::Thread.exit
|
||||
self.close_write if self.respond_to?('close_write')
|
||||
break
|
||||
end
|
||||
end
|
||||
}
|
||||
|
@ -72,4 +72,4 @@ end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user