Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
12-08-2006, 07:18 AM
|
#1
|
Member
Registered: Nov 2003
Posts: 810
Rep:
|
Importing List of Addresses into IP Tables
Hi there --
I have a list of addresses from a Shorewall blacklist file, and I would like to import them into my iptables list. Aside from manually entering in the addresses, is there a tool I can use to facilitate the process? Thanks.
|
|
|
12-08-2006, 07:29 AM
|
#2
|
Member
Registered: Sep 2002
Posts: 310
Rep: 
|
We can probably parse them out with perl or other core utils (grep, awk, sed). Can you post some lines (if not all) from the file?
|
|
|
12-08-2006, 07:39 AM
|
#3
|
Member
Registered: Nov 2003
Posts: 810
Original Poster
Rep:
|
Hi there --
Thanks for your reply. Listed below is a partial list of the addresses in questions:
61.0.0.0/8 tcp 22,25,53,6000
61.0.0.0/8 tcp
65.23.0.0/16 tcp
65.24.0.0/16 tcp
130.65.0.0/16 tcp
217.10.106.0/24 tcp
210.229.150.0/16 tcp
134.102.0.0/8 tcp
2.0.0.0/7 tcp
4.0.0.0/6 tcp
8.0.0.0/5 tcp
11.0.0.0/8 tcp
15.0.0.0/8 tcp
17.0.0.0/8 tcp #Apple
18.0.0.0/7 tcp #MIT
#43.0.0.0/8 tcp #Japan
41.0.0.0/8 tcp #AfriNIC
148.245.0.0/16 tcp #Mexico LACNIC
44.0.0.0/8 tcp #Amateur Radio
62.0.0.0/8 tcp #RIPE
|
|
|
12-08-2006, 08:25 AM
|
#4
|
Member
Registered: Sep 2002
Posts: 310
Rep: 
|
perl
Here is the perl script I created to parse and make rules:
Code:
#!/usr/bin/perl
# wall.pl by int0x80
# convert shorewall list to iptables
use strict;
my $config = shift or usage(); # find the config file
my $nic = "eth0"; # change this to your NIC
my @fields = (); # parts of each line
my $rule; # the iptables rule we build
open(CONF, $config); # open the config file for read
while(<CONF>){ # !EOF
@fields = split(/ /,$_); # parse each part
if($fields[0] !~ /^\s*#/){ # make sure this isn't commented
chomp($fields[1]); # clear newline if there
$rule = "iptables -I INPUT -i ". $nic ." -p ". $fields[1] ." -s ". $fields[0];
if(length $fields[2] && $fields[2] !~ /^\s*#/){
$rule = $rule . " -m mport --dports " . $fields[2];
}
chomp($rule); # clear newline if there
$rule = $rule . " -j DROP"; # finish the rule
print $rule ."\n"; # print rule
system($rule); # insert to filter
}
} # EOF
close CONF; # close the config file
sub usage {
die "Usage: wall.pl <config>\n";
}
Here is my usage:
Code:
int0x80:~/source/perl/shorewall-iptables$ ./wall.pl kaplan71.txt
iptables -I INPUT -i eth0 -p tcp -s 61.0.0.0/8 -m mport --dports 22,25,53,6000 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 61.0.0.0/8 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 65.23.0.0/16 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 65.24.0.0/16 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 130.65.0.0/16 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 217.10.106.0/24 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 210.229.150.0/16 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 134.102.0.0/8 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 2.0.0.0/7 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 4.0.0.0/6 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 8.0.0.0/5 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 11.0.0.0/8 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 15.0.0.0/8 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 17.0.0.0/8 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 18.0.0.0/7 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 41.0.0.0/8 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 148.245.0.0/16 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 44.0.0.0/8 -j DROP
iptables -I INPUT -i eth0 -p tcp -s 62.0.0.0/8 -j DROP
Here is the kaplan71.txt file:
Code:
int0x80:~/source/perl/shorewall-iptables$ cat kaplan71.txt
61.0.0.0/8 tcp 22,25,53,6000
61.0.0.0/8 tcp
65.23.0.0/16 tcp
65.24.0.0/16 tcp
130.65.0.0/16 tcp
217.10.106.0/24 tcp
210.229.150.0/16 tcp
134.102.0.0/8 tcp
2.0.0.0/7 tcp
4.0.0.0/6 tcp
8.0.0.0/5 tcp
11.0.0.0/8 tcp
15.0.0.0/8 tcp
17.0.0.0/8 tcp #Apple
18.0.0.0/7 tcp #MIT
#43.0.0.0/8 tcp #Japan
41.0.0.0/8 tcp #AfriNIC
148.245.0.0/16 tcp #Mexico LACNIC
44.0.0.0/8 tcp #Amateur Radio
62.0.0.0/8 tcp #RIPE
|
|
|
12-08-2006, 09:21 AM
|
#5
|
Member
Registered: Nov 2003
Posts: 810
Original Poster
Rep:
|
Hi there --
I ran the perl script as root and unfortunately the follow output appeared:
iptables -I INPUT -i eth0 -p -s 221.113.7.0/24 tcp 22,25,53,6000 -j DROP
iptables v1.3.5: unknown protocol `-s' specified
Try `iptables -h' or 'iptables --help' for more information.
iptables -I INPUT -i eth0 -p -s 61.0.0.0/8 tcp 22,25,53,6000 -j DROP
iptables v1.3.5: unknown protocol `-s' specified
I did run the script as a non-root user, via the sudo command, and I got output similar to what you saw, the only thing is, there were no changes to the iptables file after it was run.
What change(s) should I make to the script? Thanks in advance.
|
|
|
12-08-2006, 12:03 PM
|
#6
|
Member
Registered: Sep 2005
Location: New delhi
Distribution: RHEL 3.0/4.0
Posts: 777
Rep:
|
You got to specify the type of protocol in your iptables command.
|
|
|
12-08-2006, 01:27 PM
|
#7
|
Member
Registered: Sep 2002
Posts: 310
Rep: 
|
amitsharma is correct, your protocol has been misplaced in the command.
Be sure to check the script you are running is identical to what I posted.
|
|
|
12-08-2006, 01:55 PM
|
#8
|
Member
Registered: Nov 2003
Posts: 810
Original Poster
Rep:
|
Hi there --
I verified that the script was identical to what you had posted, and I ran it again, and while there was output onscreen, there was no change made to the /etc/sysconfig/iptables file. I also
deleted the existing wall.pl file and recreated it from scratch, without any success.
I ran the command as root and sudo user with the same results. When I ran an individual line as sudo or root user, I got the unknown protocol -s error. What am I missing here?
|
|
|
12-08-2006, 02:58 PM
|
#9
|
Member
Registered: Sep 2002
Posts: 310
Rep: 
|
First, it does not write anything to /etc/sysconfig/iptables, where do you see that in the code? If you want to see the rules, run iptables -nvL and pipe to less if necessary. Show me your usage here, copy and paste from your terminal. Use the CODE or QUOTE tags around it to preserve formatting. Include everything (source, usage, output).
|
|
|
12-08-2006, 03:48 PM
|
#10
|
Member
Registered: Nov 2003
Posts: 810
Original Poster
Rep:
|
Sorry about the confusion. I am entering the data now. Thanks for the help.
|
|
|
All times are GMT -5. The time now is 10:47 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|