Skip to content

Commit c31a233

Browse files
committed
Juan changes applied
1 parent 2b57755 commit c31a233

File tree

1 file changed

+40
-15
lines changed

1 file changed

+40
-15
lines changed

modules/post/windows/manage/portproxy.rb

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def initialize(info={})
2929
OptAddress.new('CADDRESS', [ true, 'IPv4/IPv6 address to which to connect.']),
3030
OptInt.new( 'CPORT', [ true, 'Port number to which to connect.']),
3131
OptInt.new( 'LPORT', [ true, 'Port number to which to listen.']),
32+
OptBool.new( 'IPV6_XP', [ true, 'Install IPv6 on Windows XP (needed for v4tov4).', true]),
3233
OptEnum.new( 'TYPE', [ true, 'Type of forwarding', 'v4tov4', ['v4tov4','v6tov6','v6tov4','v4tov6']])
3334
], self.class)
3435
end
@@ -42,19 +43,26 @@ def run
4243
type = datastore['TYPE']
4344
lport = datastore['LPORT']
4445
cport = datastore['CPORT']
46+
ipv6_xp = datastore['IPV6_XP']
4547
laddress = datastore['LADDRESS']
4648
caddress = datastore['CADDRESS']
4749

48-
return if not enable_portproxy(lport,cport,laddress,caddress,type)
50+
return if not enable_portproxy(lport,cport,laddress,caddress,type,ipv6_xp)
4951
fw_enable_ports(lport)
5052

5153
end
5254

53-
def enable_portproxy(lport,cport,laddress,caddress,type)
54-
# Due to a bug in Windows XP you need to install ipv6
55+
def enable_portproxy(lport,cport,laddress,caddress,type,ipv6_xp)
56+
rtable = Rex::Ui::Text::Table.new(
57+
'Header' => 'Port Forwarding Table',
58+
'Indent' => 3,
59+
'Columns' => ['LOCAL IP', 'LOCAL PORT', 'REMOTE IP', 'REMOTE PORT']
60+
)
61+
62+
# Due to a bug in Windows XP you need to install IPv6
5563
# http://support.microsoft.com/kb/555744/en-us
5664
if sysinfo["OS"] =~ /XP/
57-
return false if not enable_ipv6()
65+
return false if not check_ipv6(ipv6_xp)
5866
end
5967

6068
print_status("Setting PortProxy ...")
@@ -67,26 +75,43 @@ def enable_portproxy(lport,cport,laddress,caddress,type)
6775
end
6876

6977
output = cmd_exec("netsh","interface portproxy show all")
70-
print_status("Local IP\tLocal Port\tRemote IP\tRemote Port")
7178
output.each_line do |l|
72-
print_status("#{l.chomp}") if l.strip =~ /^[0-9]|\*/
79+
rtable << l.split(" ") if l.strip =~ /^[0-9]|\*/
7380
end
81+
print_status(rtable.to_s)
7482
return true
7583
end
7684

77-
def enable_ipv6()
78-
print_status("Checking IPv6. This could take a while ...")
79-
cmd_exec("netsh","interface ipv6 install",120)
80-
output = cmd_exec("netsh","interface ipv6 show global")
81-
if output =~ /-----/
82-
print_good("IPV6 installed.")
85+
def ipv6_installed()
86+
output = cmd_exec("netsh","interface ipv6 show interface")
87+
if output.lines.count > 2
8388
return true
8489
else
85-
print_error("IPv6 was not successfully installed. Run it again.")
8690
return false
8791
end
8892
end
8993

94+
def check_ipv6(ipv6_xp)
95+
if ipv6_installed()
96+
print_status("IPv6 is already installed.")
97+
return true
98+
else
99+
if not ipv6_xp
100+
print_error("IPv6 is not installed. You need IPv6 to use portproxy.")
101+
return false
102+
else
103+
print_status("Installing IPv6 ...")
104+
cmd_exec("netsh","interface ipv6 install",120)
105+
if not ipv6_installed
106+
print_error("IPv6 was not successfully installed. Run it again.")
107+
return false
108+
end
109+
print_good("IPv6 was successfully installed.")
110+
return true
111+
end
112+
end
113+
end
114+
90115
def fw_enable_ports(port)
91116
print_status ("Setting port #{port} in Windows Firewall ...")
92117
begin
@@ -102,8 +127,8 @@ def fw_enable_ports(port)
102127
else
103128
print_error("There was an error enabling the port.")
104129
end
105-
rescue::Exception => e
130+
rescue ::Exception => e
106131
print_status("The following Error was encountered: #{e.class} #{e}")
107132
end
108133
end
109-
end
134+
end

0 commit comments

Comments
 (0)