StuRa:Server/FreeBSD
Dokumentation für den FreeBSD-Server
Sicherheit
- ports aktuell halten:
- portsnap /var/db/portsnap/INDEX
- edit /etc/crontab:
0 13 * * * root portsnap -I cron fetch && portsnap update && pkg_version -vIL=
- tägliches Audit der (installierten) Ports:
- portaudit /var/db/portaudit/auditfile.tbz
- edit /etc/crontab:
0 14 * * * root portaudit -Fda
- VuXML abonnieren
- http://security.freebsd.org/ mal durchlesen
- National Vulnerability Database (NVD RSS) abonnieren
Paketfilter
- OpenBSD pf
- in /etc/rc.conf:
pf_enable="YES" pf_rules="/etc/pf.conf" pflog_enable="YES" # host system is gateway for jails gateway_enable="YES"
- syslogd an Hauptmaschine binden
- in /etc/rc.conf: (evtl. -ss flag?)
syslogd_flags="-b $MAIN_IP"
- Paketfilter starten:
/etc/rc.d/pf start
/etc/rc.d/pflog start
- pf.config: (check via
pfctl -vnf /etc/pf.conf
) (inzwischen veraltet)
### MAKROS thishost = "$MAIN_IP" # portsnap5 204.9.55.80 portsnap_freebsd = "{ 204.109.56.116 204.9.55.80 }" # auditfile.tbz is beeing fetched from portaudit.freebsd.org portaudit_freebsd = "69.147.83.36" # dnsserver from resolv.conf dnsserver = "{ 85.214.73.63 217.79.186.148 27.110.120.30 204.152.184.76 194.150$ ### RULES # default deny block in all block out all # lokales interface darf ohne einschränkungen pass in quick on lo0 all pass out quick on lo0 all ## HOST # allow ssh pass in on bce0 proto tcp from any to $thishost port $SSH_PORT pass out on bce0 proto tcp from $thishost port $SSH_PORT to any ## allow outbound icmp # echo request pass out inet proto icmp icmp-type 8 code 0 keep state # echo reply pass in inet proto icmp icmp-type 0 code 0 keep state # destination unreachable pass in inet proto icmp icmp-type 3 keep state # allow DNS lookups {also via tcp?} port 53 # what about traversal??? pass out on bce0 proto udp from $thishost to $dnsserver port 53 keep state # allow portsnap to fetch from freebsd.org (ports?) pass in on bce0 proto tcp from $portsnap_freebsd to $thishost pass out on bce0 proto tcp from $thishost to $portsnap_freebsd # allow portaudit to fetch auditfile.tbz via http pass in on bce0 proto tcp from $portaudit_freebsd port 80 to $thishost pass out on bce0 proto tcp from $thishost to $portaudit_freebsd port 80 ## JAIL Beispiel (uneingeschränkt -> dumme Idee, ports dienstabhänging freigeben pass in on bce0 proto { tcp udp icmp } from any to $jail_srs14 pass out on bce0 proto { tcp udp icmp } from $jail_srs14 to any
- regeln überprüfen:
pfctl -vnf /etc/pf.conf
Paketfilter bedienen
- anschalten:
pfctl -e
- ausschalten:
pfctl -d
- sanity check:
pfctl -vnf /etc/pf.conf
- alte Regeln ins Klo und neue in die Auslage:
pfctl -Fa -f /etc/pf.conf
Verweise
- PF: Der OpenBSD Packet Filter
- Jacek Artymiak - Building Firewalls with OpenBSD and PF, 2nd edition
- Peter N. M. Hansteen: The Book of PF, 2nd Edition - A No-Nonsense Guide to the OpenBSD Firewall
FreeBSD audit
- faschistoides Logging von Systemcalls
- präventiv wirkungslos, aber in der post-mortem Analyse extrem hilfreich
- FreeBSD Kapitel 17. Security Event Auditing
- in /etc/rc.conf:
auditd_enable="YES"
- start auditd:
/etc/rc.d/auditd start
- in /etc/security/audit_control:
flags:lo,aa,ex policy:cnt,argv synchronize config: audit -s
- cronjob für die logs: /etc/crontab
"0 */12 * * * root /usr/sbin/audit -n"
Jails
Jails dienen der Virtualisierung von Betriebssysteminstanzen. Näheres dazu im FreeBSD Handbuch Kapitel 15 - Jails.
Anlegen eines Jails
cd /usr/src
- evtl. erst Sourcen installieren: sysinstall-> configure -> distributions
- evtl.
# make buildworld
- Jails liegen unter /home/jails/$JAILNAME
- System für jail bauen:
# make installworld DESTDIR=/home/jails/$JAILNAME
# make distribution DESTDIR=/home/jails/$JAILNAME
- device nodes ins jail packen
# mount -t devfs devfs /home/jails/$JAILNAME/dev
- resolv.conf kopieren:
cp host /etc/resolv.conf to /home/jails/$JAILNAME/etc/resolv.conf
- rc.conf editieren:
jail_enable="YES" jail_list="$JAILNAME" ifconfig_bce0_alias0="$JAIL_IP netmask 255.255.255.0" jail_$JAILNAME_rootdir="/usr/home/jails/$JAILNAME" jail_$JAILNAME_hostname="$JAILNAME.stura.htw-dresden.de" jail_$JAILNAME_ip="$JAIL_IP" jail_$JAILNAME_devfs_enable="YES" jail_$JAILNAME_devfs_ruleset="devfs_rules_jail"
- jail starten:
/etc/rc.d/jail start
- Prozess im jail starten:
jexec $JAIL_ID tcsh
- $JAIL_ID aus
jls
ermittelbar - portscollection etc. installieren ...
portsnap fetch && portsnap extract && portsnap update
- evtl. ssh anschalten (in rc.conf):
sshd_enable="YES"
- $JAIL_ID aus
Löschen eines Jails
- ins jailroot wechseln (/home/jails/$JAILNAME)
chflags -R noschg * rm -rf * cd .. && rm -r $JAILNAME
Tricks, Probleme etc.
- sich evtl. ezjail mal anschauen (war damals kaputt)
- ping aus jails heraus erlauben
- host: allow_raw_socket=1 via
#sysctl security.jail.allow_raw_sockets=1
- bzw. in /etc/sysctl.conf setzen
- Quelle
- host: allow_raw_socket=1 via
- ssh:
- etc/ssh/sshd_config:
ListenAddress 0.0.0.0
- etc/ssh/sshd_config:
ssh
- openssh
- ssh auf anderen port legen
- Vorschläge für /etc/ssh/sshd_config:
VersionAddendum
Port $SSH_PORTNUMMER
ListenAddress $JAIL_IP
Protocol 2
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 1m
PermitRootLogin no
StrictModes yes
MaxAuthTries 4
MaxSessions 5
AllowUsers $DER_COOLE_LEUTE_CLUB
PermitEmptyPasswords no
X11Forwarding no
Banner none
- immer schön manpage lesen und mit dem Feinkamm durchgehen
- keys + passwörter zur Authentifizierung
- in jails:
ListenAddress 0.0.0.0
MTA: postfix
- in the email jail
# cd /usr/ports/mail/postfix
# make install clean
- postfix added to group mail -> y
- Would you like to activate Postfix in /etc/mail/mailer.conf -> y
- Einstellungen (Auszug + aliases)
- edit /usr/local/etc/postfix/main.cf:
local_recipient_maps = $alias_maps unknown_local_recipient_reject_code = 550 mynetworks = 127.0.0.0/8 myhostname = mail.stura.htw-dresden.de mydomain = stura.htw-dresden.de myorigin = $mydomain mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain inet_interfaces = all alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases home_mailbox = Maildir/ mail_spool_directory = /var/spool/mail relay_domains = stura.htw-dresden.de smtpd_recipient_restrictions = reject_invalid_hostname, reject_unknown_recipient_domain, reject_unauth_destination, reject_rbl_client sbl.spamhaus.org, permit smtpd_helo_restrictions = reject_invalid_helo_hostname, reject_non_fqdn_helo_hostname, reject_unknown_helo_hostname smtpd_client_restrictions = reject_rbl_client dnsbl.sorbs.net
MDA: dovecot
- optionen: kqueue, ssl, managesieve, mysql
#echo 'dovecot_enable="YES"' >> /etc/rc.conf
#cp /usr/local/share/examples/dovecot/dovecot.conf /usr/local/etc/dovecot.conf
#cp /usr/local/share/examples/dovecot/dovecot-sql.conf /usr/local/etc/dovecot-sql.conf
- in /usr/local/etc/dovecot.conf: (vorerst zum testen)
protocols = imap pop3
disable_plaintext_auth = no
ssl = no
mail_location = mbox:~/mail/:INBOX=/var/mail/%u
mail_privileged_group = mail
protocol imap {
imap_client_workarounds = delay-newmail outlook-idle netscape-eoh tb-extra-mailbox-sep
}
- Krypto drankleben (imap -> imaps, pop3 -> pop3s)
Tricks etc.
- alias-Adressen anlegen
- edit: /usr/local/etc/postfix/main.cf:
alias_maps = hash:/etc/aliases, hash:/etc/aliases.stura alias_database = hash:/etc/aliases,hash:/etc/aliases.stura
- edit /etc/aliases.stura:
newaliases
postfix reload
# usr/local/etc/rc.d/postfix restart
- SMTP testen:
nc $JAIL_IP 25
HELO microsoft.com
MAIL FROM:<bill@microsoft.com>
RCPT TO:<test@stura.htw-dresden.de>
DATA
From: <bill@microsoft.com>
To: <stest@stura.htw-dresden.de>
Subject: hui
das hätte nicht passieren sollen
.
QUIT
Plone
- JoSch damals gebaut, zwischenzeitlich grundsaniert
- Apache installiert
- apache 22 optionen:
- mod_ssl
- mod_rewrite
- mod_deflate
- ipv6
- apr ohne berkeley db und gnu db
- http://plone.org/documentation/kb/freebsdploneapache/preparefreebsd
- http://plone.org/documentation/kb/freebsdploneapache/preparefreebsd
DNS
- genutzt werden DNS Server des FoeBuD und des CCC
- zusätzlich (für OpenNIC)
- DE,NRW 217.79.186.148 ns1.nrw.de.dns.opennic.glue Günter Grodotzki yes (no logs kept)
- NZ 27.110.120.30 ns1.nz.dns.opennic.glue Dean Gardiner yes (24 hrs)
Tipps, Tricks etc.
- die Änderungen an Konfigurationsdateien (z.b. in /etc) via git tracken
- disk quotas für jails einrichten
- systemweite make.conf bauen
- rc.conf bzw. /etc/rc neu laden ohne reboot
- Achtung: über Konsole direkt am Gerät (single user mode verliert Netzwerkzugriff!)
# shutdown now (Note: without -r or -h) # return # exit