File: ssh.test

package info (click to toggle)
yasat 755-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,020 kB
  • ctags: 9
  • sloc: sh: 5,780; makefile: 47
file content (188 lines) | stat: -rw-r--r-- 8,182 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/sh
################################################################################
#                                                                              #
#   Copyright (C) 2008-2014 LABBE Corentin <clabbe.montjoie@gmail.com>
#
#    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="${SCAN_ROOT}/etc/ssh/"

Title "Check ssh and sshd configurations"

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

TESTNAME='YASAT_TEST_SSH Disable and Remove OpenSSH Software'
Compliance --result 'NOTTESTED' --plugin ssh --nsag 3.5.1.1 --cce 4268-9 --cce 4272-1
TESTNAME='YASAT_TEST_SSH Remove SSH Server iptables Firewall Exception'
Compliance --result 'NOTTESTED' --plugin ssh --nsag 3.5.1.2 --cce 4295-2
TESTNAME='YASAT_TEST_SSH Limit Users SSH Access'
Compliance --result 'NOTTESTED' --plugin ssh --nsag 3.5.2.2
TESTNAME='YASAT_TEST_SSH Set Idle Timeout Interval for User Logins'
Compliance --result 'NOTTESTED' --plugin ssh --nsag 3.5.2.3 --cce 14061-6
TESTNAME='YASAT_TEST_SSH Enable a Warning Banner'
Compliance --result 'NOTIMPL' --plugin ssh --nsag 3.5.2.8 --cce 4431-3
TESTNAME='YASAT_TEST_SSH Do Not Allow Users to Set Environment Options'
Compliance --result 'NOTIMPL' --plugin ssh --nsag 3.5.2.9 --cce 14716-5
TESTNAME='YASAT_TEST_SSH Use Only Approved Ciphers in Counter Mode'
Compliance --result 'NOTIMPL' --plugin ssh --nsag 3.5.2.10 --cce 14491-5
TESTNAME='YASAT_TEST_SSH Strengthen Firewall Configuration if Possible'
Compliance --result 'NOTIMPL' --plugin ssh --nsag 3.5.2.11

#TODO not always /usr/sbin/sshd
check_file "${SCAN_ROOT}/usr/sbin/sshd" 2 BINARY

TESTNAME='YASAT_TEST_SSH_1 NSAG=3.5.2.6 CCEID=4387-7 PermitRootLogin must be set to no'
FindValueOf ${SSH_CONF_REP}/sshd_config PermitRootLogin JUSTTEST 
check_value "$RESULTAT" 'no' 'false' 'PermitRootLogin' 'RED' 'SSH_ROOT_LOGIN' 3.5.2.6 4387-7
#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

TESTNAME='YASAT_TEST_SSH_2 NSAG=3.5.2.7 CCEID=3660-8 PermitEmptyPassword must be set to no'
FindValueOf ${SSH_CONF_REP}/sshd_config PermitEmptyPassword JUSTTEST
check_value "$RESULTAT" 'no' 'false' 'PermitEmptyPassword' 'RED' 'TODO' 3.5.2.7 3660-8
#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

TESTNAME='YASAT_TEST_SSH_3 NSAG=3.5.2.5 CCEID=4370-3 HostbasedAuthentication must be set to no'
FindValueOf ${SSH_CONF_REP}/sshd_config HostbasedAuthentication JUSTTEST
check_value "$RESULTAT" 'no' 'false' 'HostbasedAuthentication' 'RED' 'TODO' 3.5.2.5 4370-3
#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

TESTNAME='YASAT_TEST_SSH_5 NSAG=3.5.2.1 CCEID=4325-7 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
		Compliance --result OK --plugin ssh --nsag 3.5.2.1 --cce 4325-7
	else
		Display --indent 2 --text "Protocol" --result "$RESULTAT" --color RED
		Compliance --result NOK --plugin ssh --nsag 3.5.2.1 --cce 4325-7
	fi
else
	Display --indent 2 --text "Protocol" --result NOTFOUND --color GREEN
	Compliance --result OK --plugin ssh --nsag 3.5.2.1 --cce 4325-7
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'

TESTNAME='YASAT_TEST_SSH_9 NSAG=3.5.2.4 CCEID=4475-0 IgnoreRhosts must be set to yes'
FindValueOf ${SSH_CONF_REP}/sshd_config IgnoreRhosts JUSTTEST
check_value "$RESULTAT" 'yes' 'false' 'IgnoreRhosts' 'RED' 'SSH_IGNORERHOSTS' 3.5.2.4 4475-0

#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.pub 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
	check_private_key "${SSH_CONF_REP}"/ssh_host_key 2 sshd
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;