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,32 +176,34 @@ 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)
cnt = 0
begin
# Enumerate each TCP relay
service.each_tcp_relay { |lhost, lport, rhost, rport, opts|
next if (opts['MeterpreterRelay'] == nil)
cnt = 0
print_line("#{cnt}: #{lhost}:#{lport} -> #{rhost}:#{rport}")
# Enumerate each TCP relay
service.each_tcp_relay { |lhost, lport, rhost, rport, opts|
next if (opts['MeterpreterRelay'] == nil)
cnt += 1
}
print_line("#{cnt}: #{lhost}:#{lport} -> #{rhost}:#{rport}")
print_line
print_line("#{cnt} total local port forwards.")
cnt += 1
}
print_line
print_line("#{cnt} total local port forwards.")
ensure
service.deref
end
when "add"
@ -194,26 +213,17 @@ class Console::CommandDispatcher::Stdapi::Net
return
end
# Build a local port forward in association with the channel
service = Rex::ServiceManager.start(Rex::Services::LocalRelay)
# Start the local TCP relay in association with this stream
service.start_tcp_relay(lport,
'LocalHost' => lhost,
'PeerHost' => rhost,
'PeerPort' => rport,
'MeterpreterRelay' => true,
'OnLocalConnection' => Proc.new { |relay, lfd|
create_tcp_channel(relay)
})
begin
# Start the local TCP relay in association with this stream
service.start_tcp_relay(lport,
'LocalHost' => lhost,
'PeerHost' => rhost,
'PeerPort' => rport,
'MeterpreterRelay' => true,
'OnLocalConnection' => Proc.new { |relay, lfd|
create_tcp_channel(relay)
})
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
print_status("Local TCP relay created: #{lhost || '0.0.0.0'}:#{lport} <-> #{rhost}:#{rport}")
# Delete local port forwards
when "delete"
@ -224,17 +234,11 @@ 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
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
end