#!/bin/sh
/usr/local/bin/wget -nd -O /root/tables/emerging-block-ips http://www.emergingthreats.net/fwrules/emerging-Block-IPs.txt
/sbin/pfctl -Tl -f /etc/pf.conf
table <emerging-block-ips> persist file "/root/tables/emerging-block-ips"
block in log quick on $ext_if from <emerging-block-ips> } to any
block out log quick on $ext_if from any to <emerging-block-ips> #optional,paranoid-friendly
#!/bin/sh
fetch http://www.emergingthreats.net/fwrules/emerging-Block-IPs.txt -o /root/tables/emerging-block-ips
pfctl -t emerging-block-ips -Tr -f /root/tables/emerging-block-ips
# emerging threats list
table <emerging-block-ips> persist file "/root/tables/emerging-block-ips"
block in log quick on $int from <emerging-block-ips> to any
block out log quick on $int from any to <emerging-block-ips>
/usr/bin/fetch -i /root/tables/emerging-block-ips http://www.emergingthreats.net/fwrules/emerging-Block-IPs.txt
/usr/bin/fetch -m -o /root/tables/emerging-block-ips http://www.emergingthreats.net/fwrules/emerging-Block-IPs.txt
#!/bin/sh
old_time=`ls -lt /root/tables/emerging-Block-IPs.txt | awk '{print $6" "$7" "$8}'`
cd /root/tables
fetch -m http://www.emergingthreats.net/fwrules/emerging-Block-IPs.txt
new_time=`ls -lt /root/tables/emerging-Block-IPs.txt | awk '{print $6" "$7" "$8}'`
if [ "$old_time" != "$new_time" ]
then
pfctl -t emerging-block-ips -Tr -f /root/tables/emerging-Block-IPs.txt
fi
rbelk said:Ctaranotte, hope you don't mind but I modified your script.
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42a):
* <phk@FreeBSD.ORG> inspired this file. As long as you retain this notice, you don't try to fix this stuff as it is not broken and you keep your work based on this stuff sweet and simple, you
* can do whatever you want with this stuff. If we meet some day in this life or in an other, you think
* this stuff is worth it and you can afford it, you can buy me a beer or any other spirited beverage in return. In any case, I would be glad to buy you one.
* ----------------------------------------------------------------------------
*/
block out log quick on $ext_if from any to <emerging-block-ips> #optional,paranoid-friendly
#!/bin/sh
old_hash=$( /sbin/md5 -q /root/tables/emerging-Block-IPs.txt )
/usr/bin/fetch -i /root/tables/emerging-Block-IPs.txt http://www.emergingthreats.net/fwrules/emerging-Block-IPs.txt
new_hash=$( /sbin/md5 -q /root/tables/emerging-Block-IPs.txt )
if [ "$old_hash" != "$new_hash" ]
then
/sbin/pfctl -t emerging-block-ips -Tr -f /root/tables/emerging-Block-IPs.txt
fi
ctaranotte said:Let me know if my oinkmaster.conf is of interest.
ctaranotte said:Let me know if my oinkmaster.conf is of interest.
[color="Red"]url = http://www.emergingthreats.net/rules/emerging.rules.tar.gz[/color]
path = /bin:/usr/bin:/usr/local/bin
tmpdir = /tmp/oinkmaster/
update_files = \.rules$|\.config$|\.conf$|\.txt$|\.map$
use_path_checks = 1
skipfile local.rules
skipfile deleted.rules
skipfile snort.conf
skipfile sid-msg.map
#!/bin/sh
/usr/local/bin/oinkmaster -o /usr/local/etc/snort/rules/emerging-threads -C /usr/local/etc/oinkmaster.emerging.conf
/bin/rm /usr/local/etc/snort/sid-msg.map
/bin/cat /usr/local/etc/snort/sid-msg.map-sample /usr/local/etc/snort/rules/emerging-threads/emerging-sid-msg.map > /usr/local/etc/snort/sid-msg.map
/usr/local/etc/rc.d/snort restart
Prelude is a Universal "Security Information Management" (SIM) system. Prelude collects, normalizes, sorts, aggregates, correlates and reports all security-related events independently of the product brand or license giving rise to such events; Prelude is "agentless".
#!/bin/sh
#-------------------------------
#original written by DutchDaemon
#-------------------------------
old_hash=$( /sbin/md5 -q /usr/local/etc/emerging-Block-IPs.txt )
new_hash=$old_hash
/usr/bin/fetch -4 -A -i /usr/local/etc/emerging-Block-IPs.txt -o /tmp/pf_emerging_Block_IP.tmp http://www.emergingthreats.net/fwrules/emerging-Block-IPs.txt
if [ $? -eq 0 ] && [ -f /tmp/pf_emerging_Block_IP.tmp ]
then
mv /tmp/pf_emerging_Block_IP.tmp /usr/local/etc/emerging-Block-IPs.txt
new_hash=$( /sbin/md5 -q /usr/local/etc/pf_emerging_Block_IP.conf )
fi
if [ "$old_hash" != "$new_hash" ]
then
/sbin/pfctl -t emerging_block_ips -T replace -f /usr/local/etc/pf_emerging_Block_IP.conf
fi
#create empty table in memory
<et_block_ip> persist
# in filter section block all ip in <et_block_ip>
block in on $ext_if from <et_block_ip>
su root
pfctl -t et_block_ip -T replace -f /tmp/emerging-Block-IPs.txt
feralape said:Question.
How many ips can you block like this before you start having performance problems?
# Block IPs classed as threats by EmergingThreats.org
table <emerging-threats> persist file "/usr/local/etc/IPBlocks/EmergingThreats"
block in log quick on $ext_if from <emerging-threats> to any
block out log quick on $ext_if from any to <emerging-threats>
#!/usr/bin/perl
###############################################################################
# #
# Perl script to keep the a file on your system up to date with one from the #
# Internet. Originally written and intended to update the IP Block List from #
# EmergingThreats.org and refresh the pf table with the newest version. #
# #
# Transformed into a geneic utility on 2009-11-16 to work with any file on #
# the system and run a given command afterwards to refresh whatever daemon #
# needs to be. #
# #
# Usually run from cron, but no reason it can't be run interactively. #
# #
###############################################################################
# #
# Ruler's Common-Sense License: #
# #
# You may use this script however you want to, but I don't warrant it to #
# be good for anything in particular, though it happens to work well for #
# me. (I hate putting BS like this in, but I hate more being sued.) If #
# you use this script, you must keep this license and credit to me in it #
# in the form of this block, even if you modify it for your own use. If #
# you want to send me money for it, fantastic! Send me a private message #
# on the freebsd.org forums and I'll give you my PayPal address. :-) Even #
# just a simple 'thank you' would be nice. If not, that's fine too. All #
# hate mail/spam is sent directly to /dev/null #
# - Jim, AKA Ruler2112 #
# #
###############################################################################
# #
# History: #
# #
# 2009-08-26 by DutchDaemon Wrote a shell script that inspired this. #
# 2009-11-16 by Ruler2112 Wrote as a perl script as generic utility #
# to keep a file on the system synchronized #
# with one on the network. #
# 2009-11-18 by Ruler2112 Released on freebsd.org forums. #
# #
###############################################################################
use strict;
###############################################################################
# Variable Declaration Section #
# Set these variables to customize this script's behavior. #
###############################################################################
# Storage Directory
# Where to keep the file or files downloaded.
my $StorageDirectory = "/usr/local/etc/IPBlocks";
# FileName
# What file name to use for the file downloaded.
my $FileName = "EmergingThreats";
# HowManyBackups
# The system will rotate and keep this many of the most recent files.
# A setting of 0 will result in no old copies being kept.
my $HowManyBackups = 7;
# DebugMode
# If this value is not set to zero, all commands executed will be printed.
my $DebugMode = 0;
# FileURL
# The URL where the file to download exists.
my $FileURL = "http://www.emergingthreats.net/fwrules/emerging-Block-IPs.txt";
# TempFile
# Where the downloaded file is kept while being downloaded and compared to
# the most recent in StorageDirectory.
my $TempFile = "/tmp/Emerging-Threats-Block-IPs.txt";
# PreventRedownload
# If non-zero, the system will copy the file to the temporary location in
# order to try to prevent re-downloading the file needlessly. If a large
# file is used that you are fairly certain has changed since the last
# download, this option may be of use to you. Usually, a non-zero setting
# is best to save bandwidth at the cost of copying the last downloaded file.
my $PreventRedownload = 1;
# Location_*
# Where the * files are located on your system. Shouldn't change for BSD,
# but included for ease of porting.
my $Location_cp = "/bin/cp";
my $Location_fetch = "/usr/bin/fetch";
my $Location_md5 = "/sbin/md5";
my $Location_mkdir = "/bin/mkdir";
my $Location_mv = "/bin/mv";
my $Location_rm = "/bin/rm";
# PostCommand
# A command that will be executed after the file is updated.
# It is only executed if the file downloaded has changed from the previous
# version of the file downloaded. Use care when setting this!
my $PostCommand = "/sbin/pfctl -t emerging-threats -Tr -f '$StorageDirectory/$FileName'";
###############################################################################
# !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! #
###############################################################################
# This is the Beginning of the Script #
# #
# Do not change anything below this line unless you know what you're doing! #
###############################################################################
my ($existinghash, $downloadedhash, $fetchstatus);
my ($workstr, $counter);
# Disable output buffering if in debug mode
if($DebugMode)
{
$| = 1;
}
# Create the storage directory if it does not already exist
if(! -d "$StorageDirectory" )
{
Execute("$Location_mkdir '$StorageDirectory'");
}
# Remove temp file if it still exists
if(-e "$TempFile")
{
Execute("$Location_rm -f '$TempFile'");
}
# Perform the following only if we already have at least one copy of the file
$workstr = "";
if( -r "$StorageDirectory/$FileName")
{
# Calculate MD5 hash of the file we have
$existinghash = Execute("$Location_md5 -q '$StorageDirectory/$FileName'");
chomp($existinghash);
if($PreventRedownload)
{
# Copy the newest file we have to the temp file to prevent re-downloading
Execute("$Location_cp -p '$StorageDirectory/$FileName' '$TempFile'");
$workstr = "-m";
}
}
else
{
$existinghash = "blah";
}
# Download new file
$fetchstatus = Execute("$Location_fetch $workstr -q -o '$TempFile' $FileURL");
# If download failed, print error message and exit
if($fetchstatus > 0)
{
print "Download of new $FileName FAILED from $FileURL with error code $fetchstatus!\n";
exit;
}
# Calculate MD5 hash of the file just downloaded
$downloadedhash = Execute("$Location_md5 -q '$TempFile'");
chomp($downloadedhash);
# If hashes are different, we have a new file
if($downloadedhash ne $existinghash)
{
if($HowManyBackups > 0)
{
# Rotate files, keeping as many as configured in HowManyBackups
if(-e "$StorageDirectory/$FileName.$HowManyBackups")
{
Execute("$Location_rm -f '$StorageDirectory/$FileName.$HowManyBackups'");
}
for($counter = $HowManyBackups - 1; $counter > 0; $counter--)
{
$workstr = $counter + 1;
if(-e "$StorageDirectory/$FileName.$counter")
{
Execute("$Location_mv '$StorageDirectory/$FileName.$counter' '$StorageDirectory/$FileName.$workstr'");
}
}
if(-e "$StorageDirectory/$FileName")
{
Execute("$Location_mv '$StorageDirectory/$FileName' '$StorageDirectory/$FileName.1'");
}
}
else
{
# Just remove the old file - we don't need no stinking backups!
if(-e "$StorageDirectory/$FileName")
{
Execute("$Location_rm -f '$StorageDirectory/$FileName'");
}
}
# Move newly downloaded file into place and execute command after update
Execute("$Location_mv '$TempFile' '$StorageDirectory/$FileName'");
Execute("$PostCommand");
}
# Remove temp file if it still exists
if(-e "$TempFile")
{
Execute("$Location_rm -f '$TempFile'");
}
# Done
exit;
# Modularized command execution to allow for easy debugging
sub Execute()
{
my $command = shift;
my($retval);
if($DebugMode)
{
print "Running->$command<-\n";
}
$retval = `$command`;
return $retval;
}
#!/bin/sh
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42a):
# <phk@FreeBSD.ORG> inspired this file. As long as you retain this notice, you don't try to fix this stuff as it is not broken and you keep your work based on this stuff sweet and simple, you
# can do whatever you want with this stuff. If we meet some day in this life or in an other, you think
# this stuff is worth it and you can afford it, you can buy me a beer or any other spirited beverage in return. In any case, I would be glad to buy you one.
# ----------------------------------------------------------------------------
# -- Maximum time, in seconds, to wait before aborting an HTTP connection.
HTTP_TIMEOUT=60
cd /root/tables
old_hash=$( /sbin/md5 -q /root/tables/emerging-Block-IPs.txt )
/usr/bin/fetch -m /root/tables/emerging-Block-IPs.txt http://rules.emergingthreats.net/fwrules/emerging-Block-IPs.txt
# http://rules.emergingthreats.net/fwrules/emerging-Block-IPs.txt
new_hash=$( /sbin/md5 -q /root/tables/emerging-Block-IPs.txt )
if [ "$old_hash" != "$new_hash" ]
then
( /sbin/pfctl -t emerging-block-ips -Tr -f /root/tables/emerging-Block-IPs.txt ; \
echo ">>> emerging-Block-IPs.txt has been updated, and PF was restarted!" ) | mail -s "emerging-Block-IPs.txt report" root
else
echo ">>> emerging-Block-IPs.txt has not been updated, PF was not restarted!"
fi