File: ssh.test

package info (click to toggle)
yasat 526-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 920 kB
  • sloc: sh: 4,723; makefile: 47
file content (163 lines) | stat: -rw-r--r-- 6,320 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/sh
################################################################################
#                                                                              #
#   Copyright (C) 2008-2012 LABBE Corentin <corentin.labbe@geomatys.fr>
#
#    YASAT is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    YASAT is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with YASAT.  If not, see <http://www.gnu.org/licenses/>.
#                                                                              #
################################################################################

SSH_CONF_REP="/etc/ssh/"

Title "Check ssh and sshd configurations"

if [ ! -e "$SSH_CONF_REP" ]; then
	echo "strange no ssh directory"
	return 1;
fi

#TODO not always /usr/sbin/sshd
check_file /usr/sbin/sshd 2 BINARY

#YASAT_TEST_SSH_1 PermitRootLogin must be set to no
FindValueOf ${SSH_CONF_REP}/sshd_config PermitRootLogin JUSTTEST
if [ ! -z "$RESULTAT" ] ; then
	if [ "$RESULTAT" = "yes" ] ;then
		Display --indent 2 --text "PermitRootLogin" --result "$RESULTAT" --color RED --advice SSH_ROOT_LOGIN
	else
		Display --indent 2 --text "PermitRootLogin" --result "$RESULTAT" --color GREEN
	fi
else
	Display --indent 2 --text "PermitRootLogin" --result NOTFOUND --color RED --advice SSH_ROOT_LOGIN
fi

#YASAT_TEST_SSH_2 PermitEmptyPassword must be set to no
FindValueOf ${SSH_CONF_REP}/sshd_config PermitEmptyPassword JUSTTEST
if [ ! -z "$RESULTAT" ] ; then
	if [ "$RESULTAT" = "no" ] ;then
		Display --indent 2 --text "PermitEmptyPassword" --result "$RESULTAT" --color RED
	else
		Display --indent 2 --text "PermitEmptyPassword" --result "$RESULTAT" --color GREEN
	fi
else
	Display --indent 2 --text "PermitEmptyPassword" --result NOTFOUND --color GREEN
fi

#YASAT_TEST_SSH_3 HostbasedAuthentication must be set to no
FindValueOf ${SSH_CONF_REP}/sshd_config HostbasedAuthentication JUSTTEST
if [ ! -z "$RESULTAT" ] ;then
	if [ "$RESULTAT" = "yes" ] ;then
		Display --indent 2 --text "HostbasedAuthentication" --result "$RESULTAT" --color RED
	else
		Display --indent 2 --text "HostbasedAuthentication" --result "$RESULTAT" --color GREEN
	fi
else
	Display --indent 2 --text "HostbasedAuthentication" --result NOTFOUND --color GREEN
fi

#YASAT_TEST_SSH_4 RhostsAuthentication must be set to no
FindValueOf ${SSH_CONF_REP}/sshd_config RhostsAuthentication JUSTTEST
if [ ! -z "$RESULTAT" ] ;then
	if [ "$RESULTAT" = "yes" ] ;then
		Display --indent 2 --text "RhostsAuthentication" --result "$RESULTAT" --color RED
	else
		Display --indent 2 --text "RhostsAuthentication" --result "$RESULTAT" --color GREEN
	fi
else
	Display --indent 2 --text "RhostsAuthentication" --result NOTFOUND --color GREEN
fi

#YASAT_TEST_SSH_5 Protocol must be set to 2
FindValueOf ${SSH_CONF_REP}/sshd_config Protocol JUSTTEST
if [ ! -z "$RESULTAT" ] ;then
	if [ "$RESULTAT" = "2" ] ;then
		Display --indent 2 --text "Protocol" --result "$RESULTAT" --color GREEN
	else
		Display --indent 2 --text "Protocol" --result "$RESULTAT" --color RED
	fi
else
	Display --indent 2 --text "Protocol" --result NOTFOUND --color GREEN
fi

#YASAT_TEST_SSH_6 StrictModes must be set to yes
FindValueOf ${SSH_CONF_REP}/sshd_config StrictModes JUSTTEST
if [ ! -z "$RESULTAT" ] ; then
	if [ "$RESULTAT" = "no" ] ; then
		Display --indent 2 --text "StrictModes" --result "$RESULTAT" --color RED
	else
		Display --indent 2 --text "StrictModes" --result "$RESULTAT" --color GREEN
	fi
else
	Display --indent 2 --text "StrictModes" --result NOTFOUND --color GREEN
fi

#YASAT_TEST_SSH_7 UsePrivilegeSeparation must be set to yes
FindValueOf ${SSH_CONF_REP}/sshd_config UsePrivilegeSeparation JUSTTEST
if [ ! -z "$RESULTAT" ] ; then
	if [ "$RESULTAT" = "no" ] ; then
		Display --indent 2 --text "UsePrivilegeSeparation" --result "$RESULTAT" --color RED
	else
		Display --indent 2 --text "UsePrivilegeSeparation" --result "$RESULTAT" --color GREEN
	fi
else
	Display --indent 2 --text "UsePrivilegeSeparation" --result NOTFOUND --color GREEN
fi

#YASAT_TEST_SSH_8 X11Forwarding must be set to no
FindValueOf ${SSH_CONF_REP}/sshd_config X11Forwarding JUSTTEST
check_value "$RESULTAT" 'no' 'false' 'X11Forwarding' 'ORANGE' 'SSH_X11FORWARDING'

#YASAT_TEST_SSH_9 IgnoreRhosts must be set to yes
FindValueOf ${SSH_CONF_REP}/sshd_config IgnoreRhosts JUSTTEST
check_value "$RESULTAT" 'yes' 'false' 'IgnoreRhosts' 'RED' 'SSH_IGNORERHOSTS'

#check HostKey
#grep ^HostKey "${SSH_CONF_REP}/sshd_config"
#YASAT_TEST_SSH_10 Check ssh_host_dsa_key permissions
if [ -e "${SSH_CONF_REP}"/ssh_host_dsa_key ] ; then
	check_private_key "${SSH_CONF_REP}"/ssh_host_dsa_key 2 sshd
fi
#YASAT_TEST_SSH_11 Check ssh_host_dsa_key.pub permissions
if [ -e "${SSH_CONF_REP}"/ssh_host_dsa_key ] ; then
	check_a_file "${SSH_CONF_REP}"/ssh_host_dsa_key.pub 2 root "$ROOTGROUP" 644
fi

#YASAT_TEST_SSH_12 Check ssh_host_rsa_key permissions and keysize
if [ -e "${SSH_CONF_REP}"/ssh_host_rsa_key ] ; then
	check_private_key "${SSH_CONF_REP}"/ssh_host_rsa_key 2 sshd
fi
#YASAT_TEST_SSH_13 Check ssh_host_rsa_key.pub permissions
if [ -e "${SSH_CONF_REP}"/ssh_host_rsa_key ] ; then
	check_a_file "${SSH_CONF_REP}"/ssh_host_rsa_key 2 root "$ROOTGROUP" 644
fi

#YASAT_TEST_SSH_14 Check ssh_host_key permissions
if [ -e "${SSH_CONF_REP}"/ssh_host_key ] ; then
	check_a_file "${SSH_CONF_REP}"/ssh_host_key 2 root "$ROOTGROUP" 600
fi
#YASAT_TEST_SSH_15 Check ssh_host_key.pub permissions
if [ -e "${SSH_CONF_REP}"/ssh_host_key ] ; then
	check_a_file "${SSH_CONF_REP}"/ssh_host_key.pub 2 root "$ROOTGROUP" 644
fi

#YASAT_TEST_SSH_16 Check sshd_config_key permissions
if [ -e "${SSH_CONF_REP}"/sshd_config ] ; then
	check_a_file "${SSH_CONF_REP}"/sshd_config 2 root "$ROOTGROUP" 600
fi
#YASAT_TEST_SSH_17 Check sshd_config_key permissions
if [ -e "${SSH_CONF_REP}"/ssh_config ] ; then
	check_a_file "${SSH_CONF_REP}"/ssh_config 2 root "$ROOTGROUP" 644
fi

return 0;