@@ -41,19 +41,12 @@ def run
41
41
return
42
42
end
43
43
44
- type = datastore [ 'TYPE' ]
45
- lport = datastore [ 'LPORT' ]
46
- cport = datastore [ 'CPORT' ]
47
- ipv6_xp = datastore [ 'IPV6_XP' ]
48
- laddress = datastore [ 'LADDRESS' ]
49
- caddress = datastore [ 'CADDRESS' ]
50
-
51
- return unless enable_portproxy ( lport , cport , laddress , caddress , type , ipv6_xp )
52
- fw_enable_ports ( lport )
44
+ return unless enable_portproxy
45
+ fw_enable_ports
53
46
54
47
end
55
48
56
- def enable_portproxy ( lport , cport , laddress , caddress , type , ipv6_xp )
49
+ def enable_portproxy
57
50
rtable = Rex ::Ui ::Text ::Table . new (
58
51
'Header' => 'Port Forwarding Table' ,
59
52
'Indent' => 3 ,
@@ -63,11 +56,17 @@ def enable_portproxy(lport,cport,laddress,caddress,type,ipv6_xp)
63
56
# Due to a bug in Windows XP you need to install IPv6
64
57
# http://support.microsoft.com/kb/555744/en-us
65
58
if sysinfo [ "OS" ] =~ /XP/
66
- return false if not check_ipv6 ( ipv6_xp )
59
+ return false if not check_ipv6
67
60
end
68
61
69
62
print_status ( "Setting PortProxy ..." )
70
- output = cmd_exec ( "netsh" , "interface portproxy add #{ type } listenport=#{ lport } listenaddress=#{ laddress } connectport=#{ cport } connectaddress=#{ caddress } " )
63
+ netsh_args = "interface portproxy "
64
+ netsh_args << "add #{ datastore [ 'TYPE' ] } "
65
+ netsh_args << "listenport=#{ datastore [ 'LPORT' ] } "
66
+ netsh_args << "listenaddress=#{ datastore [ 'LADDRESS' ] } "
67
+ netsh_args << "connectport=#{ datastore [ 'CPORT' ] } "
68
+ netsh_args << "connectaddress=#{ datastore [ 'CADDRESS' ] } "
69
+ output = cmd_exec ( "netsh" , netsh_args )
71
70
if output . size > 2
72
71
print_error ( "Setup error. Verify parameters and syntax." )
73
72
return false
@@ -92,12 +91,12 @@ def ipv6_installed()
92
91
end
93
92
end
94
93
95
- def check_ipv6 ( ipv6_xp )
94
+ def check_ipv6
96
95
if ipv6_installed ( )
97
96
print_status ( "IPv6 is already installed." )
98
97
return true
99
98
else
100
- if not ipv6_xp
99
+ if not datastore [ 'IPV6_XP' ]
101
100
print_error ( "IPv6 is not installed. You need IPv6 to use portproxy." )
102
101
return false
103
102
else
@@ -113,17 +112,17 @@ def check_ipv6(ipv6_xp)
113
112
end
114
113
end
115
114
116
- def fw_enable_ports ( port )
117
- print_status ( "Setting port #{ port } in Windows Firewall ..." )
115
+ def fw_enable_ports
116
+ print_status ( "Setting port #{ datastore [ 'LPORT' ] } in Windows Firewall ..." )
118
117
begin
119
118
if sysinfo [ "OS" ] =~ /Windows 7|Vista|2008|2012/
120
- cmd_exec ( "netsh" , "advfirewall firewall add rule name=\" Windows Service\" dir=in protocol=TCP action=allow localport=\" #{ port } \" " )
119
+ cmd_exec ( "netsh" , "advfirewall firewall add rule name=\" Windows Service\" dir=in protocol=TCP action=allow localport=\" #{ datastore [ 'LPORT' ] } \" " )
121
120
else
122
- cmd_exec ( "netsh" , "firewall set portopening protocol=TCP port=\" #{ port } \" " )
121
+ cmd_exec ( "netsh" , "firewall set portopening protocol=TCP port=\" #{ datastore [ 'LPORT' ] } \" " )
123
122
end
124
123
output = cmd_exec ( "netsh" , "firewall show state" )
125
124
126
- if output =~ /^#{ port } /
125
+ if output =~ /^#{ datastore [ 'LPORT' ] } /
127
126
print_good ( "Port opened in Windows Firewall." )
128
127
else
129
128
print_error ( "There was an error enabling the port." )
0 commit comments