10e3f233fSBartek Rutkowski#!/bin/sh 20e3f233fSBartek Rutkowski#- 30e3f233fSBartek Rutkowski# Copyright (c) 2016 Bartek Rutkowski 40e3f233fSBartek Rutkowski# All rights reserved. 50e3f233fSBartek Rutkowski# 60e3f233fSBartek Rutkowski# Redistribution and use in source and binary forms, with or without 70e3f233fSBartek Rutkowski# modification, are permitted provided that the following conditions 80e3f233fSBartek Rutkowski# are met: 90e3f233fSBartek Rutkowski# 1. Redistributions of source code must retain the above copyright 100e3f233fSBartek Rutkowski# notice, this list of conditions and the following disclaimer. 110e3f233fSBartek Rutkowski# 2. Redistributions in binary form must reproduce the above copyright 120e3f233fSBartek Rutkowski# notice, this list of conditions and the following disclaimer in the 130e3f233fSBartek Rutkowski# documentation and/or other materials provided with the distribution. 140e3f233fSBartek Rutkowski# 150e3f233fSBartek Rutkowski# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 160e3f233fSBartek Rutkowski# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 170e3f233fSBartek Rutkowski# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 180e3f233fSBartek Rutkowski# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 190e3f233fSBartek Rutkowski# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 200e3f233fSBartek Rutkowski# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 210e3f233fSBartek Rutkowski# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 220e3f233fSBartek Rutkowski# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 230e3f233fSBartek Rutkowski# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 240e3f233fSBartek Rutkowski# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 250e3f233fSBartek Rutkowski# SUCH DAMAGE. 260e3f233fSBartek Rutkowski# 270e3f233fSBartek Rutkowski# $FreeBSD$ 280e3f233fSBartek Rutkowski 29cc42ef53SBrad DavisBSDCFG_SHARE="/usr/share/bsdconfig" 30cc42ef53SBrad Davis. $BSDCFG_SHARE/common.subr || exit 1 31cc42ef53SBrad Davis 324d1ba6feSAlfonso S. Siciliano: ${BSDDIALOG_OK=0} 330e3f233fSBartek Rutkowski 3472121342SDimitry Andricecho -n > $BSDINSTALL_TMPETC/rc.conf.hardening 351d01cb0dSSteven Kreuzerecho -n > $BSDINSTALL_TMPETC/sysctl.conf.hardening 36c3afb29bSDag-Erling Smørgravecho -n > $BSDINSTALL_TMPBOOT/loader.conf.hardening 370e3f233fSBartek Rutkowski 380e3f233fSBartek Rutkowskiexec 3>&1 39cc42ef53SBrad DavisFEATURES=$( bsddialog --backtitle "$OSNAME Installer" \ 4095525572SBartek Rutkowski --title "System Hardening" --nocancel --separate-output \ 410e3f233fSBartek Rutkowski --checklist "Choose system security hardening options:" \ 420e3f233fSBartek Rutkowski 0 0 0 \ 432434a052SBartek Rutkowski "0 hide_uids" "Hide processes running as other users" ${hide_uids:-off} \ 442434a052SBartek Rutkowski "1 hide_gids" "Hide processes running as other groups" ${hide_gids:-off} \ 45d8061effSSteve Wills "2 hide_jail" "Hide processes running in jails" ${hide_jail:-off} \ 46d8061effSSteve Wills "3 read_msgbuf" "Disable reading kernel message buffer for unprivileged users" ${read_msgbuf:-off} \ 47d8061effSSteve Wills "4 proc_debug" "Disable process debugging facilities for unprivileged users" ${proc_debug:-off} \ 48d8061effSSteve Wills "5 random_pid" "Randomize the PID of newly created processes" ${random_pid:-off} \ 49391aafd7SBartek Rutkowski "6 clear_tmp" "Clean the /tmp filesystem on system startup" ${clear_tmp:-off} \ 50391aafd7SBartek Rutkowski "7 disable_syslogd" "Disable opening Syslogd network socket (disables remote logging)" ${disable_syslogd:-off} \ 51*fe06db18SBaptiste Daroussin "8 secure_console" "Enable console password prompt" ${secure_console:-off} \ 52*fe06db18SBaptiste Daroussin "9 disable_ddtrace" "Disallow DTrace destructive-mode" ${disable_ddtrace:-off} \ 530e3f233fSBartek Rutkowski2>&1 1>&3 ) 544d1ba6feSAlfonso S. Sicilianoretval=$? 550e3f233fSBartek Rutkowskiexec 3>&- 560e3f233fSBartek Rutkowski 574d1ba6feSAlfonso S. Sicilianoif [ $retval -ne $BSDDIALOG_OK ]; then 584d1ba6feSAlfonso S. Siciliano exit 1 594d1ba6feSAlfonso S. Sicilianofi 604d1ba6feSAlfonso S. Siciliano 610e3f233fSBartek Rutkowskifor feature in $FEATURES; do 62fbc57e2dSEd Maste case "$feature" in 63fbc57e2dSEd Maste hide_uids) 640e3f233fSBartek Rutkowski echo security.bsd.see_other_uids=0 >> $BSDINSTALL_TMPETC/sysctl.conf.hardening 65fbc57e2dSEd Maste ;; 66fbc57e2dSEd Maste hide_gids) 670e3f233fSBartek Rutkowski echo security.bsd.see_other_gids=0 >> $BSDINSTALL_TMPETC/sysctl.conf.hardening 68fbc57e2dSEd Maste ;; 69fbc57e2dSEd Maste hide_jail) 70d8061effSSteve Wills echo security.bsd.see_jail_proc=0 >> $BSDINSTALL_TMPETC/sysctl.conf.hardening 71fbc57e2dSEd Maste ;; 72fbc57e2dSEd Maste read_msgbuf) 730e3f233fSBartek Rutkowski echo security.bsd.unprivileged_read_msgbuf=0 >> $BSDINSTALL_TMPETC/sysctl.conf.hardening 74fbc57e2dSEd Maste ;; 75fbc57e2dSEd Maste proc_debug) 760e3f233fSBartek Rutkowski echo security.bsd.unprivileged_proc_debug=0 >> $BSDINSTALL_TMPETC/sysctl.conf.hardening 77fbc57e2dSEd Maste ;; 78fbc57e2dSEd Maste random_pid) 79f78bd12dSAllan Jude echo kern.randompid=1 >> $BSDINSTALL_TMPETC/sysctl.conf.hardening 80fbc57e2dSEd Maste ;; 81fbc57e2dSEd Maste clear_tmp) 820e3f233fSBartek Rutkowski echo 'clear_tmp_enable="YES"' >> $BSDINSTALL_TMPETC/rc.conf.hardening 83fbc57e2dSEd Maste ;; 84fbc57e2dSEd Maste disable_syslogd) 850e3f233fSBartek Rutkowski echo 'syslogd_flags="-ss"' >> $BSDINSTALL_TMPETC/rc.conf.hardening 86fbc57e2dSEd Maste ;; 87fbc57e2dSEd Maste secure_console) 8882ec242fSBartek Rutkowski sed "s/unknown off secure/unknown off insecure/g" $BSDINSTALL_CHROOT/etc/ttys > $BSDINSTALL_TMPETC/ttys.hardening 89fbc57e2dSEd Maste ;; 90fbc57e2dSEd Maste disable_ddtrace) 91c3afb29bSDag-Erling Smørgrav echo 'security.bsd.allow_destructive_dtrace=0' >> $BSDINSTALL_TMPBOOT/loader.conf.hardening 92fbc57e2dSEd Maste ;; 93fbc57e2dSEd Maste esac 940e3f233fSBartek Rutkowskidone 95