1997-02-09 22:50:16 +00:00
|
|
|
#!/usr/local/bin/perl
|
|
|
|
# for best results, bring up all your interfaces before running this
|
1999-11-08 20:51:23 +00:00
|
|
|
|
|
|
|
if ($^O =~ m/^irix/i)
|
|
|
|
{
|
|
|
|
&irix_mkfilters || regular_mkfilters || die $!;
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
®ular_mkfilters || irix_mkfilters || die $!;
|
|
|
|
}
|
|
|
|
|
1997-02-09 22:50:16 +00:00
|
|
|
foreach $i (keys %ifaces) {
|
|
|
|
$net{$i} = $inet{$i}."/".$netmask{$i} if (defined($inet{$i}));
|
|
|
|
}
|
|
|
|
#
|
|
|
|
# print out route suggestions
|
|
|
|
#
|
|
|
|
print "#\n";
|
|
|
|
print "# The following routes should be configured, if not already:\n";
|
|
|
|
print "#\n";
|
|
|
|
foreach $i (keys %ifaces) {
|
|
|
|
next if (($i =~ /lo/) || !defined($net{$i}) || defined($ppp{$i}));
|
|
|
|
print "# route add $inet{$i} localhost 0\n";
|
|
|
|
}
|
|
|
|
print "#\n";
|
|
|
|
|
|
|
|
#
|
|
|
|
# print out some generic filters which people should use somewhere near the top
|
|
|
|
#
|
|
|
|
print "block in log quick from any to any with ipopts\n";
|
|
|
|
print "block in log quick proto tcp from any to any with short\n";
|
|
|
|
|
1997-11-16 04:52:19 +00:00
|
|
|
$grpi = 0;
|
|
|
|
|
1997-02-09 22:50:16 +00:00
|
|
|
foreach $i (keys %ifaces) {
|
|
|
|
if (!defined($inet{$i})) {
|
|
|
|
next;
|
|
|
|
}
|
1997-11-16 04:52:19 +00:00
|
|
|
|
|
|
|
$grpi += 100;
|
|
|
|
$grpo = $grpi + 50;
|
|
|
|
|
1997-02-09 22:50:16 +00:00
|
|
|
if ($i !~ /lo/) {
|
1997-11-16 04:52:19 +00:00
|
|
|
print "pass out on $i all head $grpo\n";
|
|
|
|
print "block out from 127.0.0.0/8 to any group $grpo\n";
|
|
|
|
print "block out from any to 127.0.0.0/8 group $grpo\n";
|
|
|
|
print "block out from any to $inet{$i}/32 group $grpo\n";
|
|
|
|
print "pass in on $i all head $grpi\n";
|
|
|
|
print "block in from 127.0.0.0/8 to any group $grpi\n";
|
|
|
|
print "block in from $inet{$i}/32 to any group $grpi\n";
|
1997-02-09 22:50:16 +00:00
|
|
|
foreach $j (keys %ifaces) {
|
|
|
|
if ($i ne $j && $j !~ /^lo/ && defined($net{$j})) {
|
1997-11-16 04:52:19 +00:00
|
|
|
print "block in from $net{$j} to any group $grpi\n";
|
1997-02-09 22:50:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-11-08 20:51:23 +00:00
|
|
|
|
|
|
|
sub irix_mkfilters
|
|
|
|
{
|
|
|
|
open(NETSTAT, "/usr/etc/netstat -i|") || return 0;
|
2013-08-11 14:28:45 +00:00
|
|
|
|
1999-11-08 20:51:23 +00:00
|
|
|
while (defined($line = <NETSTAT>))
|
|
|
|
{
|
|
|
|
if ($line =~ m/^Name/)
|
|
|
|
{
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
elsif ($line =~ m/^(\S+)/)
|
|
|
|
{
|
|
|
|
open(I, "/usr/etc/ifconfig $1|") || return 0;
|
|
|
|
&scan_ifconfig;
|
|
|
|
close I; # being neat... - Allen
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close NETSTAT; # again, being neat... - Allen
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub regular_mkfilters
|
|
|
|
{
|
|
|
|
open(I, "ifconfig -a|") || return 0;
|
|
|
|
&scan_ifconfig;
|
|
|
|
close I; # being neat... - Allen
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub scan_ifconfig
|
|
|
|
{
|
|
|
|
while (<I>) {
|
|
|
|
chop;
|
|
|
|
if (/^[a-zA-Z]+\d+:/) {
|
|
|
|
($iface = $_) =~ s/^([a-zA-Z]+\d+).*/$1/;
|
|
|
|
$ifaces{$iface} = $iface;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if (/inet/) {
|
|
|
|
if (/\-\-\>/) { # PPP, (SLIP?)
|
|
|
|
($inet{$iface} = $_) =~ s/.*inet ([^ ]+) \-\-\> ([^ ]+).*/$1/;
|
|
|
|
($ppp{$iface} = $_) =~ s/.*inet ([^ ]+) \-\-\> ([^ ]+).*/$2/;
|
|
|
|
} else {
|
|
|
|
($inet{$iface} = $_) =~ s/.*inet ([^ ]+).*/$1/;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (/netmask/) {
|
|
|
|
($mask = $_) =~ s/.*netmask ([^ ]+).*/$1/;
|
|
|
|
$mask =~ s/^/0x/ if ($mask =~ /^[0-9a-f]*$/);
|
|
|
|
$netmask{$iface} = $mask;
|
|
|
|
}
|
|
|
|
if (/broadcast/) {
|
|
|
|
($bcast{$iface} = $_) =~ s/.*broadcast ([^ ]+).*/$1/;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-11 14:28:45 +00:00
|
|
|
|