Toon posts:

[PfSense] Spamhause en/of Dshield gebruiken

Pagina: 1
Acties:
  • 209 views sinds 30-01-2008
  • Reageer

Verwijderd

Topicstarter
Onder het mom van 'there's no day like today', besloot ik om m'n gesneuvelde Smoothwall te vervangen met Pfsense.

Een ding wat mij wel aantrok aan Smoothwall is dat het dmv een paar handmatige tweaks op de fora, het mogelijk is om de blacklists/blocklists van resp. Spamhaus en Dshield dmv scripted Cron-jobs in de firewall (iptables) te zetten. Dit gebeurt overigens door een aparte chain die door de scripts worden aangemaakt.

Omdat Pfsense op BSD is gebasseerd en dus gebruikt maakt van de pfilter van openbsd. Lijkt het mij onverstandig als noob om de Smoothwall scripts klakkeloos over te nemen in Pfsense.

Pfsense kan worden uitgebreid met add-on door middel van zogenoemde packages, helaas heeft niemand er nog eentje geschreven om gebruikt te kunnen maken voor Spamhaus en/of Dshield.

Concreet is mijn vraag: wie weet hoe ik, zonder Pfsense kapot te maken, de blacklists in de firewall kan zetten, wat elk uur (of dag) word bijgewerkt. Bij voorkeur het liefst door middel van zo'n pfsense package. Wie voelt zich geroepen? _/-\o_


PfSense is het jonger groter broertje van Monowall. Alle twee zijn ze gebaseerd op (free)BSD en bieden zeer interessante mogelijkheden, welke je veelal anders pas tegenkomt op dure commerciële pakketten. Lees: betaalde versie van smoothwall en andere. Zo wil ik bijv. graag m'n broers mbv vpn toegang verschaffen tot m'n lan. (moet ik nog allemaal precies uitzoeken).

Verwijderd

Euh, als je daar niet een expliciet script voor vind dan zul je dit zelf moeten kloppen. Het bestaat uit 2 delen, de cronjob die de lijst met ip's ophaalt en de wijzigingen aan je PF configuratie. De cronjob om de lijst op te halen mag je zelf bedenken, en voor pf zou je iets van de volgende regels kunnen gebruiken (waarbij /etc/blocked-hosts.conf de lijst met ip's is):

table <blocked_hosts> persist file "/etc/blocked-hosts.conf"

block quick on $ext_if from <blocked_hosts> to any

[ Voor 5% gewijzigd door Verwijderd op 08-05-2007 10:42 ]


Verwijderd

Topicstarter
Tja, ik weet gewoonweg té weinig om dat zelf te kunnen. (Wil mezelf eigenlijk geen programmeer-capaciteiten toedichten). Los daarvan weet ik de basis dingen van iptables, van pfilter nada. :'( Dank voor het stukje code; de context ervan ontgaat me.

Verwijderd

Dan is dit toch een uitgelezen moment om dat te leren? Als eerste moet je de lijst met ip's hebben (bv voor spamhaus) en dit in de config file voor pf zetten (incl pfctl commando voor het herladen van je ruleset):

wget -qO - http://www.spamhaus.org/drop/drop.lasso \
    | awk '{print $1}' \
    | grep -v "\;" > /etc/blocked-hosts.conf


Hierna pas je /etc/pf.conf aan, en voeg je de twee regels toe die ik in mn 1e post gezet had (wel op de juiste plek; de table regel moet helemaal bovenin, en de block regel na je nat regels).

pfctl -f /etc/pf.conf


Iedere keer dat je die lijst opnieuw download en /etc/blocked-hosts.conf opnieuw aanmaakt moet je mbv bovenstaand commando je ruleset herladen.

  • GraveR
  • Registratie: Januari 2000
  • Laatst online: 22-08-2025
Hier dat script voor FreeBSD met ipfw:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/perl
#-----------------------------------------------------------------------------------#
#   Group: Front Matter
#
#       Script: spamhaus.pl
#       ___________________________________________________________________________
#
#       Version 0.02
#
#       About: Author
#
#           Kurt Kincaid
#           Email: perl -e "($_='tjgvlvsuAzbipp/dpn')=~s/(.)/chr(ord($1)-1)/ge;print"
#
#       Copyright (C) 2005 Kurt Kincaid
#
#       About: License
#
#          This script is licensed under the GPL license.
#
#          This script may be modified and/or redistributed under the same
#          conditions as SmoothWall Express itself.
#
#      Note:
#
#          This script is based on the original script and concept by *compgeek1221*
#          on the SmoothWall forums. <http://community.smoothwall.org/forum/viewtopic.php?t=10562>
#          In the original version by compgeek1221, a box other than the SmoothWall box downloaded
#          the IP list and then used *scp* to copy it over. At that point, a perl script on
#          the SmoothWall box imported that list and exported a properly formatted shell script
#          which actually added the rules to iptables. I wanted to streamline this process and to
#          avoid having to involve a second box.
#
#      Topic: Description
#
#          Block IPs of spam proliferators.
#
#      Topic: Dates
#
#          Creation and modification dates
#
#          Date Written:
#
#             27-Oct-2005 12:45:19 PM
#
#          Last Modified:
#
#             27-Oct-2005 02:04:22 PM
#
#      Topic: Required Modules
#
#          - strict
#          - Getopt::Long
#          - IO::Socket
#
#   Group: Installation, Configuration, and Usage
#
#       Topic: Installation
#
#          Installation is fairly straight-forward. First, you need to add the following lines
#          to your /etc/rc.d/rc.firewall.up file:
#
#          (code)
#          # SBL Drop List
#          /sbin/iptables -N sbl-drop
#          /sbin/iptables -A ipblock -j sbl-drop
#          (end)
#
#          If you wish to make use of this without having to reboot, you will need to execute
#          the iptables lines shown above by hand.
#
#          Once you've setup the iptables chain, you will need to put this script in a directory
#          of your choosing. I put it in the /var/smoothwall/mods/ directory, but in theory, it
#          can reside anywhere. Make sure the permissions on the script are set to 0700.
#
#          Finally, add an entry to /etc/crontab to run the script at specified intervals. Personally,
#          I'm currently running the script at the top of each hour. This may be overkill, though.
#          Here is the entry I added to the /etc/crontab file:
#
#>         0 * * * * root /var/smoothwall/mods/spamhaus.pl > /dev/null
#
#       Topic: Configuration
#
#          The script comes preconfigured, so there should be no configuration necessary. Once you've
#          run the script at least once, you can view the virus-drop chain like so:
#
#>         # iptables -L sbl-drop -n
#
#       Topic: Usage
#
#          The script may be run by hand, as a cron job, or both. Each time the script it run, it flushes
#          the virus-block chain and repopulates it with the current list.
#
#          The script may also be run in debug mode by passing the "--debug" flag to the script at runtime.
#          If running in debug mode, the script prints the iptables commands to STDOUT, rather than
#          executing them.
#-----------------------------------------------------------------------------------#

use strict;
use Getopt::Long;
use IO::Socket;

our( $n, $m, $debug, $host, $port, $sock, $list );
GetOptions( 'debug' => \$debug );

$host = "www.spamhaus.org";
$port = 80;
unless ( $sock = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port, Proto => 'tcp', Timeout => 5 ) ) {
    print( "Error: Could not connect to $host. Aborting.\n" );
   exit;
}

print $sock "GET /drop/drop.lasso HTTP/1.1\r\nHost: $host\r\nConnection: close\r\n\r\n";
$list .= $_ while <$sock>;
close( $sock );
my @lines = split( /\n/, $list );

if ( $debug ) {
    print( "ipfw delete 2000\n" );
} else {
    if ( scalar @lines ) {
        system( "/sbin/ipfw delete 2000" );
   } else {
       print( "Error: Unable to retrieve drop list from Spamhaus.org. Aborting.\n" );
      exit;
   }
}

foreach my $line ( @lines ) {
   next unless $line =~ /^\d/;
   next if $line =~ /^127\./;
   $line =~ m/(\d+\.\d+\.\d+\.\d+)\/(\d+)/;
   $n = $1;
   $m = $2;
   if ( $n && $m ) {
      if ( $debug ) {
         print( "ipfw add 2000 deny log ip from $n/$m to me\n" );
      } else {
          system( "/sbin/ipfw add 2000 deny log ip from $n/$m to me" );
      }
   } else {
       print( "Warning - Entry in unexpected format: $line\n" );
   }
}