1302897Srobak#!/bin/sh
2302897Srobak#-
3302897Srobak# Copyright (c) 2016 Bartek Rutkowski
4302897Srobak# All rights reserved.
5302897Srobak#
6302897Srobak# Redistribution and use in source and binary forms, with or without
7302897Srobak# modification, are permitted provided that the following conditions
8302897Srobak# are met:
9302897Srobak# 1. Redistributions of source code must retain the above copyright
10302897Srobak#    notice, this list of conditions and the following disclaimer.
11302897Srobak# 2. Redistributions in binary form must reproduce the above copyright
12302897Srobak#    notice, this list of conditions and the following disclaimer in the
13302897Srobak#    documentation and/or other materials provided with the distribution.
14302897Srobak#
15302897Srobak# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16302897Srobak# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17302897Srobak# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18302897Srobak# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19302897Srobak# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20302897Srobak# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21302897Srobak# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22302897Srobak# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23302897Srobak# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24302897Srobak# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25302897Srobak# SUCH DAMAGE.
26302897Srobak#
27302897Srobak# $FreeBSD: releng/11.0/usr.sbin/bsdinstall/scripts/hardening 303749 2016-08-04 17:26:32Z dim $
28302897Srobak
29302897Srobak: ${DIALOG_OK=0}
30302897Srobak
31303749Sdimecho -n > $BSDINSTALL_TMPETC/rc.conf.hardening
32302897Srobak
33302897Srobakexec 3>&1
34302897SrobakFEATURES=$( dialog --backtitle "FreeBSD Installer" \
35302897Srobak    --title "System Hardening" --nocancel --notags --separate-output \
36302897Srobak    --checklist "Choose system security hardening options:" \
37302897Srobak    0 0 0 \
38302897Srobak	"hide_uids" "Hide processes running as other users" ${hide_uids:-off} \
39302897Srobak	"hide_gids" "Hide processes running as other groups" ${hide_gids:-off} \
40302897Srobak	"read_msgbuf" "Disable reading kernel message buffer for unprivileged users" ${read_msgbuf:-off} \
41302897Srobak	"proc_debug" "Disable process debugging facilities for unprivileged users" ${proc_debug:-off} \
42302897Srobak	"random_pid" "Randomize the PID of newly created processes" ${random_id:-off} \
43302897Srobak	"stack_guard" "Insert stack guard page ahead of the growable segments" ${stack_guard:-off} \
44302897Srobak	"clear_tmp" "Clean the /tmp filesystem on system startup" ${clear_tmp:-off} \
45302897Srobak	"disable_syslogd" "Disable opening Syslogd network socket (disables remote logging)" ${disable_syslogd:-off} \
46302897Srobak	"disable_sendmail" "Disable Sendmail service" ${disable_sendmail:-off} \
47302897Srobak2>&1 1>&3 )
48302897Srobakexec 3>&-
49302897Srobak
50302897Srobakfor feature in $FEATURES; do
51302897Srobak	if [ "$feature" = "hide_uids" ]; then
52302897Srobak		echo security.bsd.see_other_uids=0 >> $BSDINSTALL_TMPETC/sysctl.conf.hardening
53302897Srobak	fi
54302897Srobak	if [ "$feature" = "hide_gids" ]; then
55302897Srobak		echo security.bsd.see_other_gids=0 >> $BSDINSTALL_TMPETC/sysctl.conf.hardening
56302897Srobak	fi
57302897Srobak	if [ "$feature" = "read_msgbuf" ]; then
58302897Srobak		echo security.bsd.unprivileged_read_msgbuf=0 >> $BSDINSTALL_TMPETC/sysctl.conf.hardening
59302897Srobak	fi
60302897Srobak	if [ "$feature" = "proc_debug" ]; then
61302897Srobak		echo security.bsd.unprivileged_proc_debug=0 >> $BSDINSTALL_TMPETC/sysctl.conf.hardening
62302897Srobak	fi
63302897Srobak	if [ "$feature" = "random_id" ]; then
64302897Srobak		echo kern.randompid=$(jot -r 1 9999) >> $BSDINSTALL_TMPETC/sysctl.conf.hardening
65302897Srobak	fi
66302897Srobak	if [ "$feature" = "stack_guard" ]; then
67302897Srobak		echo security.bsd.stack_guard_page=1 >> $BSDINSTALL_TMPETC/sysctl.conf.hardening
68302897Srobak	fi
69302897Srobak	if [ "$feature" = "clear_tmp" ]; then
70302897Srobak		echo 'clear_tmp_enable="YES"' >> $BSDINSTALL_TMPETC/rc.conf.hardening
71302897Srobak	fi
72302897Srobak	if [ "$feature" = "disable_syslogd" ]; then
73302897Srobak		echo 'syslogd_flags="-ss"' >> $BSDINSTALL_TMPETC/rc.conf.hardening
74302897Srobak	fi
75302897Srobak	if [ "$feature" = "disable_sendmail" ]; then
76302897Srobak		echo 'sendmail_enable="NONE"' >> $BSDINSTALL_TMPETC/rc.conf.hardening
77302897Srobak	fi
78302897Srobakdone
79302897Srobak
80