ports/57365: New port: mail/spamd - Trapit in cooperation with security/pf
Max Laier
max at love2party.net
Mon Sep 29 15:00:38 UTC 2003
>Number: 57365
>Category: ports
>Synopsis: New port: mail/spamd - Trapit in cooperation with security/pf
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: freebsd-ports-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Mon Sep 29 08:00:33 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator: Max Laier
>Release: FreeBSD 5.1-RELEASE i386
>Organization:
>Environment:
System: FreeBSD router.laiers.local 5.1-RELEASE FreeBSD 5.1-RELEASE #1: Tue Aug 5 13:21:55 CEST 2003 mlaier at router.laiers.local:/usr/local/pfsys/freebsd/src/sys/i386/compile/SMP i386
>Description:
A Trapit is a fake SMTP server that tries to waste as much resources
of a spam-relay as possible - without delivering any mail.
Implemented for pf, but might work with other ip filters as well.
mail/relaydb is a fine tool to utilize spamd.
>How-To-Repeat:
>Fix:
--- spamd.shar begins here ---
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# spamd/Makefile
# spamd/distinfo
# spamd/files
# spamd/files/spamd.sh.sample
# spamd/files/local-patch.sed
# spamd/pkg-descr
# spamd/pkg-install
# spamd/pkg-plist
#
echo x - spamd/Makefile
sed 's/^X//' >spamd/Makefile << 'END-of-spamd/Makefile'
X# New ports collection makefile for: spamd
X# Date created: 23 June 2003
X# Whom: Max Laier <max at love2party.net>
X#
X# $FreeBSD$
X#
X
XPORTNAME= spamd
XPORTVERSION= 3.4
XCATEGORIES= mail
XMASTER_SITES= http://pf4freebsd.love2party.net/
XDISTNAME= ${PORTNAME}_${PORTVERSION}
X
XMAINTAINER= max at love2party.net
XCOMMENT= Traps spammers with a very slow smtp-login and return 4xx error
X
XRUN_DEPENDS= ${LOCALBASE}/sbin/pfctl:${PORTSDIR}/security/pf
X
X.if !defined(BATCH) && !defined(PACKAGE_BUILDING)
XIS_INTERACTIVE= yes
X.endif
X
XMAN5= spamd.conf.5
XMAN8= spamd.8 spamd-setup.8
X
XMANCOMPRESSED= maybe
X
XMAKE_ARGS= MANDIR="${PREFIX}/man/man"
X
XSAMPLE_SPAMD_CONF= ${PREFIX}/etc/spamd.conf.sample
XSAMPLE_SPAMD_RC= ${PREFIX}/etc/rc.d/spamd.sh
X
X.include <bsd.port.pre.mk>
X
X.if ${OSVERSION} < 500000
XIGNORE= "Only for 5.0 and above"
X.endif
X
Xpost-patch:
X ${SED} -e 's!%%LOCALBASE%%!${LOCALBASE}!' \
X ${PATCHDIR}/local-patch.sed | ${PATCH} \
X ${WRKSRC}/spamd-setup/spamd-setup.c
X
Xpre-su-install:
X.if !defined(BATCH) && !defined(PACKAGE_BUILDING)
X @${SETENV} PKG_PREFIX=${PREFIX} ${SH} ${PKGINSTALL} ${PKGNAME} PRE-INSTALL
X.endif
X
Xpost-install:
X @if [ ! -f ${SAMPLE_SPAMD_RC} ]; then \
X ${ECHO_MSG} "Installing ${SAMPLE_SPAMD_RC} startup file."; \
X ${INSTALL_SCRIPT} ${FILESDIR}/spamd.sh.sample \
X ${SAMPLE_SPAMD_RC}; \
X fi
X @if [ ! -f ${SAMPLE_SPAMD_CONF} ]; then \
X ${ECHO_MSG} "Installing ${SAMPLE_SPAMD_CONF} file."; \
X ${INSTALL_DATA} ${WRKSRC}/spamd/spamd.conf \
X ${SAMPLE_SPAMD_CONF}; \
X fi
X
X.include <bsd.port.post.mk>
END-of-spamd/Makefile
echo x - spamd/distinfo
sed 's/^X//' >spamd/distinfo << 'END-of-spamd/distinfo'
XMD5 (spamd_3.4.tar.gz) = 628d0e0672b7bebb7bf6c562958480a6
END-of-spamd/distinfo
echo c - spamd/files
mkdir -p spamd/files > /dev/null 2>&1
echo x - spamd/files/spamd.sh.sample
sed 's/^X//' >spamd/files/spamd.sh.sample << 'END-of-spamd/files/spamd.sh.sample'
X#!/bin/sh
X#
X# $FreeBSD: ports/security/pf/files/pf.sh.sample,v 1.1 2003/06/13 01:09:29 foxfair Exp $
X
Xif ! PREFIX=$(expr $0 : "\(/.*\)/etc/rc\.d/$(basename $0)\$"); then
X echo "$0: Cannot determine the PREFIX" >&2
X echo "Please use the complete pathname." >&2
X exit 1
Xfi
X
Xif [ -z "${source_rc_confs_defined}" ]; then
X if [ -r /etc/defaults/rc.conf ]; then
X . /etc/defaults/rc.conf
X source_rc_confs
X elif [ -r /etc/rc.conf ]; then
X . /etc/rc.conf
X fi
Xfi
X
Xcase "$1" in
Xstart)
X case "${spamd_enable}" in
X [Yy][Ee][Ss])
X echo -n ' spamd'
X ${PREFIX}/libexec/spamd ${spamd_flags}
X if [ -x ${PREFIX}/sbin/spamd-setup ]; then
X ${PREFIX}/sbin/spamd-setup
X fi
X ;;
X esac
X ;;
Xstop)
X killall spamd
X ;;
X*)
X echo "Usage: `basename $0` {start|stop}" >&2
X ;;
Xesac
X
Xexit 0
END-of-spamd/files/spamd.sh.sample
echo x - spamd/files/local-patch.sed
sed 's/^X//' >spamd/files/local-patch.sed << 'END-of-spamd/files/local-patch.sed'
X--- spamd-setup/spamd-setup.c.orig Mon Sep 29 14:15:19 2003
X+++ spamd-setup/spamd-setup.c Mon Sep 29 14:16:37 2003
X@@ -47,8 +47,8 @@
X #endif
X
X #define PATH_FTP "/usr/bin/ftp"
X-#define PATH_PFCTL "/sbin/pfctl"
X-#define PATH_SPAMD_CONF "/etc/spamd.conf"
X+#define PATH_PFCTL "%%LOCALBASE%%/sbin/pfctl"
X+#define PATH_SPAMD_CONF "%%LOCALBASE%%/etc/spamd.conf"
X #define SPAMD_ARG_MAX 256 /* max # of args to an exec */
X
X struct cidr {
END-of-spamd/files/local-patch.sed
echo x - spamd/pkg-descr
sed 's/^X//' >spamd/pkg-descr << 'END-of-spamd/pkg-descr'
XTarpits like spamd are fake SMTP servers, which accept connections but don't
Xdeliver mail. Instead, they keep the connections open and reply very slowly.
XIf the peer is patient enough to actually complete the SMTP dialogue (which
Xwill take ten minutes or more), the tarpit returns a 'temporary error' code
X(4xx), which indicates that the mail could not be delivered successfully and
Xthat the sender should keep the mail in his queue and retry again later. If
Xhe does, the same procedure repeats. Until, after several attempts, wasting
Xboth his queue space and socket handles for several days, he gives up. The
Xresources I have to waste to do this are minimal.
X
XIf the sender is badly configured, an uncooperative recipient might actually
Xdelay his entire queue handling for several minutes each time he connects to
Xthe tarpit. And many spammers use badly configured open relays
X
XWWW: http://www.benzedrine.cx/relaydb.html
X
X-Max <max at love2party.net>
END-of-spamd/pkg-descr
echo x - spamd/pkg-install
sed 's/^X//' >spamd/pkg-install << 'END-of-spamd/pkg-install'
X#!/bin/sh
X# an installation script for spamd copied from pf_freebsd
X
Xask() {
X local question default answer
X
X question=$1
X default=$2
X if [ -z "${PACKAGE_BUILDING}" ]; then
X read -p "${question} (y/n) [${default}]? " answer
X fi
X if [ x${answer} = x ]; then
X answer=${default}
X fi
X echo ${answer}
X}
X
Xyesno() {
X local dflt question answer
X
X question=$1
X dflt=$2
X while :; do
X answer=$(ask "${question}" "${dflt}")
X case "${answer}" in
X [Yy]*) return 0;;
X [Nn]*) return 1;;
X esac
X echo "Please answer yes or no."
X done
X}
X
Xcheck_service() {
X local name number type comment
X
X name=$1
X number=$2
X type=$3
X comment=$4
X
X FILE="/etc/services"
X # check
X OK=no
X HAS_SERVICE=no
X COUNT=1
X for i in `grep $name $FILE `; do
X if [ $COUNT = 1 ] && [ X"$i" = X"$name" ]; then
X HAS_SERVICE=yes
X elif [ $COUNT = 2 ] && [ $HAS_SERVICE = yes ] && \
X [ X"$i" = X"$number/$type" ]; then
X OK=yes
X break
X fi
X COUNT=`expr ${COUNT} + 1`
X done
X # add an entry for SERVICE to /etc/services
X if [ $OK = no ]; then
X echo "This system has no entry for $name in ${FILE}"
X if yesno "Would you like to add it automatically?" y; then
X mv ${FILE} ${FILE}.bak
X (grep -v $name ${FILE}.bak ; \
X echo "$name $number/$type # $comment") \
X >> ${FILE}
X rm ${FILE}.bak
X else
X echo "Please add '$name $number/$type' into ${FILE}, and try again."
X return 1
X fi
X fi
X return 0
X}
X
Xcase $2 in
XPRE-INSTALL)
X
X if ! check_service spamd 8025 tcp "# spamd(8)"; then
X exit 1
X fi
X if ! check_service spamd-cfg 8026 tcp "# spamd(8) configuration"; then
X exit 1
X fi
X ;;
X
Xesac
END-of-spamd/pkg-install
echo x - spamd/pkg-plist
sed 's/^X//' >spamd/pkg-plist << 'END-of-spamd/pkg-plist'
Xlibexec/spamd
Xsbin/spamd-setup
Xetc/rc.d/spamd.sh
Xetc/spamd.conf.sample
END-of-spamd/pkg-plist
exit
--- spamd.shar ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-ports-bugs
mailing list