@@ -29,6 +29,7 @@ def initialize(info={})
29
29
OptAddress . new ( 'CADDRESS' , [ true , 'IPv4/IPv6 address to which to connect.' ] ) ,
30
30
OptInt . new ( 'CPORT' , [ true , 'Port number to which to connect.' ] ) ,
31
31
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 ] ) ,
32
33
OptEnum . new ( 'TYPE' , [ true , 'Type of forwarding' , 'v4tov4' , [ 'v4tov4' , 'v6tov6' , 'v6tov4' , 'v4tov6' ] ] )
33
34
] , self . class )
34
35
end
@@ -42,19 +43,26 @@ def run
42
43
type = datastore [ 'TYPE' ]
43
44
lport = datastore [ 'LPORT' ]
44
45
cport = datastore [ 'CPORT' ]
46
+ ipv6_xp = datastore [ 'IPV6_XP' ]
45
47
laddress = datastore [ 'LADDRESS' ]
46
48
caddress = datastore [ 'CADDRESS' ]
47
49
48
- return if not enable_portproxy ( lport , cport , laddress , caddress , type )
50
+ return if not enable_portproxy ( lport , cport , laddress , caddress , type , ipv6_xp )
49
51
fw_enable_ports ( lport )
50
52
51
53
end
52
54
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
55
63
# http://support.microsoft.com/kb/555744/en-us
56
64
if sysinfo [ "OS" ] =~ /XP/
57
- return false if not enable_ipv6 ( )
65
+ return false if not check_ipv6 ( ipv6_xp )
58
66
end
59
67
60
68
print_status ( "Setting PortProxy ..." )
@@ -67,26 +75,43 @@ def enable_portproxy(lport,cport,laddress,caddress,type)
67
75
end
68
76
69
77
output = cmd_exec ( "netsh" , "interface portproxy show all" )
70
- print_status ( "Local IP\t Local Port\t Remote IP\t Remote Port" )
71
78
output . each_line do |l |
72
- print_status ( " #{ l . chomp } ") if l . strip =~ /^[0-9]|\* /
79
+ rtable << l . split ( " ") if l . strip =~ /^[0-9]|\* /
73
80
end
81
+ print_status ( rtable . to_s )
74
82
return true
75
83
end
76
84
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
83
88
return true
84
89
else
85
- print_error ( "IPv6 was not successfully installed. Run it again." )
86
90
return false
87
91
end
88
92
end
89
93
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
+
90
115
def fw_enable_ports ( port )
91
116
print_status ( "Setting port #{ port } in Windows Firewall ..." )
92
117
begin
@@ -102,8 +127,8 @@ def fw_enable_ports(port)
102
127
else
103
128
print_error ( "There was an error enabling the port." )
104
129
end
105
- rescue ::Exception => e
130
+ rescue ::Exception => e
106
131
print_status ( "The following Error was encountered: #{ e . class } #{ e } " )
107
132
end
108
133
end
109
- end
134
+ end
0 commit comments