fix portfwd command not functioning properly

git-svn-id: file:///home/svn/framework3/trunk@5075 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Matt Miller 2007-08-10 23:54:26 +00:00
parent b698d99209
commit 89d0e200f6
2 changed files with 56 additions and 46 deletions

View File

@ -23,6 +23,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "metsrv", "metsrv\metsrv.vcp
{9E4DE963-873F-4525-A7D0-CE34EDBBDCCA} = {9E4DE963-873F-4525-A7D0-CE34EDBBDCCA}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ext_server_remoterub", "ext_server_remoterub\ext_server_remoterub.vcproj", "{6BEB2977-82CB-4783-A1A0-CBDD536CDC91}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@ -49,6 +51,10 @@ Global
{37E24F8F-1BD9-490B-8CD2-4768B89E5EAB}.Debug|Win32.Build.0 = Debug|Win32
{37E24F8F-1BD9-490B-8CD2-4768B89E5EAB}.Release|Win32.ActiveCfg = Release|Win32
{37E24F8F-1BD9-490B-8CD2-4768B89E5EAB}.Release|Win32.Build.0 = Release|Win32
{6BEB2977-82CB-4783-A1A0-CBDD536CDC91}.Debug|Win32.ActiveCfg = Debug|Win32
{6BEB2977-82CB-4783-A1A0-CBDD536CDC91}.Debug|Win32.Build.0 = Debug|Win32
{6BEB2977-82CB-4783-A1A0-CBDD536CDC91}.Release|Win32.ActiveCfg = Release|Win32
{6BEB2977-82CB-4783-A1A0-CBDD536CDC91}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -17,6 +17,23 @@ class Console::CommandDispatcher::Stdapi::Net
include Console::CommandDispatcher
#
# This module is used to extend the meterpreter session
# so that local port forwards can be tracked and cleaned
# up when the meterpreter session goes away
#
module PortForwardTracker
def cleanup
super
if pfservice
pfservice.deref
end
end
attr_accessor :pfservice
end
#
# Options for the route command.
#
@ -159,15 +176,20 @@ class Console::CommandDispatcher::Stdapi::Net
end
}
# If we haven't extended the session, then do it now since we'll
# need to track port forwards
if client.kind_of?(PortForwardTracker) == false
client.extend(PortForwardTracker)
client.pfservice = Rex::ServiceManager.start(Rex::Services::LocalRelay)
end
# Build a local port forward in association with the channel
service = client.pfservice
# Process the command
case args.shift
when "list"
# Get the service context
service = Rex::ServiceManager.start(Rex::Services::LocalRelay)
begin
cnt = 0
# Enumerate each TCP relay
@ -182,9 +204,6 @@ class Console::CommandDispatcher::Stdapi::Net
print_line
print_line("#{cnt} total local port forwards.")
ensure
service.deref
end
when "add"
@ -194,10 +213,6 @@ class Console::CommandDispatcher::Stdapi::Net
return
end
# Build a local port forward in association with the channel
service = Rex::ServiceManager.start(Rex::Services::LocalRelay)
begin
# Start the local TCP relay in association with this stream
service.start_tcp_relay(lport,
'LocalHost' => lhost,
@ -210,11 +225,6 @@ class Console::CommandDispatcher::Stdapi::Net
print_status("Local TCP relay created: #{lhost || '0.0.0.0'}:#{lport} <-> #{rhost}:#{rport}")
ensure
# Lost our reference to the service now that we're done with it
service.deref
end
# Delete local port forwards
when "delete"
@ -224,18 +234,12 @@ class Console::CommandDispatcher::Stdapi::Net
return
end
service = Rex::ServiceManager.start(Rex::Services::LocalRelay)
# Stop the service
begin
if (service.stop_tcp_relay(lport, lhost))
print_status("Successfully stopped TCP relay on #{lhost || '0.0.0.0'}:#{lport}")
else
print_error("Failed to stop TCP relay on #{lhost || '0.0.0.0'}:#{lport}")
end
ensure
service.deref
end
end
end