File: kernel.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 (269 lines) | stat: -rw-r--r-- 10,930 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/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/>.
#                                                                              #
################################################################################

Title "Check Kernel version and configuration"

#check securelevel
#TODO check also value in /etc/rc.securelevel
if [ "$OS_TYPE" = 'OpenBSD' ]
then
	SECURELEVEL="`$BSD_SYSCTL kern.securelevel | cut -d\= -f2`"
	if [ $SECURELEVEL -ge 0 ]
	then
		Display --indent 2 --text "Secure level" --result "$SECURELEVEL" --color BLUE
	else
		Display --indent 2 --text "Secure level" --result "$SECURELEVEL" --color RED --advice OPENBSD_SECURE_LEVEL_BELOW_ZERO
	fi
	return 1;
fi

#TODO Made some checks Under BSD 
if [ "$OS_TYPE" != 'Linux' ] ;then
	Display --indent 2 --text "Other OS than linux" --result TODO --color BLUE
	return 1;
fi

#Generaly on a server usb modules should not be loaded by default
#TODO check for monolithic addition of USB
#if /proc/modules dont exists, lsmod fail
if [ -e /proc/modules ] ; then
	USB_FOUND=0
	FIRE_FOUND=0
	USB_MODULES='uhci_hcd ohci_hcd ehci_hcd usb_storage usbnet'
	TMP_RESULT="${TEMPYASATDIR}/lsmod.out"
	lsmod > $TMP_RESULT 2> $ERROR_OUTPUT_FILE
	if [ $? -eq 0 ] ; then
		for usbmodule in $USB_MODULES
		do
			if [ ! -z "`grep ^$usbmodule[[:space:]] $TMP_RESULT`" ] ; then
				Display --indent 2 --text "USB module $usbmodule" --result FOUND --color ORANGE --advice KERNEL_USB_MODULES
				USB_FOUND=1
			fi
		done
		if [ $USB_FOUND -eq 0 ] ; then
			Display --indent 2 --text "Checking for unnecessary modules.. USB" --result NOTFOUND --color GREEN
		fi
	else
		if [ -e $TMP_RESULT ] ; then
			rm $TMP_RESULT
		fi
		Display --indent 2 --text "Checking modules with lsmod" --result FAILED --color ORANGE
	fi
	FIREWIRE_MODULES='firewire-sbp2 firewire-ohci firewire-core'
	TMP_RESULT="${TEMPYASATDIR}/lsmod.out"
	lsmod > $TMP_RESULT 2> $ERROR_OUTPUT_FILE
	if [ $? -eq 0 ] ; then
		for firemodule in $FIREWIRE_MODULES
		do
			if [ ! -z "`grep ^$firemodule[[:space:]] $TMP_RESULT`" ] ; then
				Display --indent 2 --text "Firewire module $firemodule" --result FOUND --color ORANGE --advice KERNEL_FIREWIRE_MODULES
			fi
		done
		if [ $FIRE_FOUND -eq 0 ] ; then
			Display --indent 2 --text "Checking for unnecessary modules.. Firewire" --result NOTFOUND --color GREEN
		fi
	else
		if [ -e $TMP_RESULT ] ; then
			rm $TMP_RESULT
		fi
		Display --indent 2 --text "Checking modules with lsmod" --result FAILED --color ORANGE
	fi
else
	Display --indent 2 --text "No /proc/modules, cannot check kernel modules" --result NOTFOUND --color BLUE
fi

#TODO FreeBSD security.bsd.see_other_uids
#TODO FreeBSD net.inet.ip.random_id

#kernel.panic = 60

#kernel to test 2.6.24 (vmsplice)
# 2.6.30 and 2.6.30.1 ( tun vulnerability)

#TODO check if we are under virtual machine

#/proc/sys/kernel/randomize_va_space
RANDOM_VA_SPACE="`sysctl kernel.randomize_va_space 2>> $ERROR_OUTPUT_FILE`"
if [ $? -eq 0 ] ; then
	RANDOM_VA_SPACE="`sysctl kernel.randomize_va_space | sed 's/^.*=[[:space:]]*//'`"
	if [ "$RANDOM_VA_SPACE" -eq 2 ] ; then
		Display --indent 2 --text "Randomized va space" --result YES --color GREEN
	else
		if [ $RANDOM_VA_SPACE -eq 1 ] ; then
			Display --indent 2 --text "Randomized va space at level 1 (want level 2)" --result PARTIAL --color ORANGE --advice KERNEL_RANDOM_VA_SPACE
		else
			Display --indent 2 --text "Randomized va space" --result NO --color RED --advice KERNEL_RANDOM_VA_SPACE
		fi
	fi
else
	Display --indent 2 --text "sysctl" --result FAILED --color ORANGE
fi


#TODO PAX PAGEEXEC SEGEXEC and check type of processor
NXbit=0
if [ -e /proc/cpuinfo ]
then
	if [ -z "`grep '^flags' /proc/cpuinfo | grep ' nx '`" ]
	then
		Display --indent 2 --text "No NX support" --result NOTFOUND --color ORANGE --advice KERNEL_NO_NX_BIT
	else
		Display --indent 2 --text "NX support" --result FOUND --color GREEN
		NXbit=1
	fi
else
	Display --indent 2 --text "No /proc/cpuinfo" --result NOTFOUND --color BLUE
fi

# http://www.redhat.com/docs/manuals/enterprise/RHEL-3-Manual/release-notes/as-x86/RELEASE-NOTES-U3-x86-en.html
#Exists only under Redhat and clone
if [ -e /proc/sys/kernel/exec-shield ]
then
	Display --indent 2 --text "/proc/sys/kernel/exec-shield" --result FOUND --color GREEN
	EXECSHIELD="`cat /proc/sys/kernel/exec-shield`"
	if [ $EXECSHIELD -ge 1 ]
	then
		Display --indent 4 --text "exec-shield value $EXECSHIELD" --result GOOD --color GREEN
	else
		Display --indent 4 --text "exec-shield value $EXECSHIELD" --result DISABLED --color RED --advice KERNEL_EXEC_SHIELD
	fi
else
	Display --indent 2 --text "/proc/sys/kernel/exec-shield" --result NOTFOUND --color BLUE
fi
#TODO /proc/sys/kernel/exec-shield-randomize


#if [ -e "${TEMPYASATDIR}/kernel_config" ] ;then
#	rm "${TEMPYASATDIR}/kernel_config"
#fi

#config can be found at /boot/config-`uname -r`
#if [ -e "/boot/config-`uname -r`" ] ;then
#	Display --indent 2 --text "/boot/config-`uname -r`" --result FOUND --color GREEN
#	cat "/boot/config-`uname -r`" > "${TEMPYASATDIR}/kernel_config"
#fi

# if user give me the path to a .config, i wont read /proc/config.gz
#if [ -z $YASAT_PATH_TO_KERNEL_CONFIG ] ;then
#	YASAT_PATH_TO_KERNEL_CONFIG='/usr/src/linux/.config'
#	if [ -e /proc/config.gz ] ;then
#		Display --indent 2 --text "/proc/config.gz" --result FOUND --color GREEN
#		zcat /proc/config.gz > ${TEMPYASATDIR}/kernel_config
#	else
#		if [ -e "${TEMPYASATDIR}/kernel_config" ] ;then
#			#we have already found .config elsewhere
#			Display --indent 2 --text "/proc/config.gz" --result NOTFOUND --color BLUE
#		else
#			Display --indent 2 --text "/proc/config.gz" --result NOTFOUND --color ORANGE --advice KERNEL_NO_CONFIG
#		fi
#	fi
#fi

#if [ ! -e "${TEMPYASATDIR}/kernel_config" ] ;then
#	if [ -e "$YASAT_PATH_TO_KERNEL_CONFIG" ] ;then
#		Display --indent 2 --text "$YASAT_PATH_TO_KERNEL_CONFIG" --result FOUND --color GREEN
#		cat "$YASAT_PATH_TO_KERNEL_CONFIG" > ${TEMPYASATDIR}/kernel_config
#	else
#		Display --indent 2 --text "$YASAT_PATH_TO_KERNEL_CONFIG" --result NOTFOUND --color ORANGE --advice KERNEL_NO_CONFIG
#	fi
#fi
prepare_kernel_config

#TODO CC_STACKPROTECTOR_ALL wait until it is "stable"
#TODO if PAX or GRSEC is enabled, check their suboptions
if [ -e "${TEMPYASATDIR}/kernel_config" ];then

	if [ ! -z "`grep 'CONFIG_COMPAT_BRK=y' ${TEMPYASATDIR}/kernel_config`" ];then
		Display --indent 2 --text "CONFIG_COMPAT_BRK" --result ENABLED --color ORANGE --advice KERNEL_CONFIG_COMPAT_BRK
	else
		Display --indent 2 --text "CONFIG_COMPAT_BRK" --result DISABLED --color GREEN
	fi

	if [ ! -z "`grep 'CONFIG_COMPAT_VDSO=y' ${TEMPYASATDIR}/kernel_config`" ];then
		Display --indent 2 --text "CONFIG_COMPAT_VDSO" --result ENABLED --color ORANGE --advice KERNEL_CONFIG_COMPAT_VDSO
	else
		Display --indent 2 --text "CONFIG_COMPAT_VDSO" --result DISABLED --color GREEN
	fi
	if [ ! -z "`grep 'CONFIG_DEVKMEM=y' ${TEMPYASATDIR}/kernel_config`" ];then
		Display --indent 2 --text "CONFIG_DEVKMEM" --result ENABLED --color ORANGE --advice KERNEL_CONFIG_DEVKMEM
	else
		Display --indent 2 --text "CONFIG_DEVKMEM" --result DISABLED --color GREEN
	fi
	if [ -z "`grep 'CONFIG_STRICT_DEVMEM=y' ${TEMPYASATDIR}/kernel_config`" ];then
		Display --indent 2 --text "CONFIG_STRICT_DEVMEM" --result DISABLED --color ORANGE --advice KERNEL_CONFIG_STRICT_DEVMEM
	else
		Display --indent 2 --text "CONFIG_STRICT_DEVMEM" --result ENABLED --color GREEN
	fi

	if [ -e /proc/sys/vm/mmap_min_addr ];then
		VALUE="`cat /proc/sys/vm/mmap_min_addr`"
		if [ $? -ne 0 ];then
			#under Redhat with a non root test this test is denied
			Display --indent 2 --text "/proc/sys/vm/mmap_min_addr" --result DENIED --color RED --advice YASAT_DENIED
		else
			if [ $VALUE -ge 1 ];then
				Display --indent 2 --text "/proc/sys/vm/mmap_min_addr" --result "$VALUE" --color GREEN
			else
				Display --indent 2 --text "/proc/sys/vm/mmap_min_addr" --result "$VALUE" --color RED --advice KERNEL_MMAP_MIN_ADDR
			fi
		fi
	fi

	if [ ! -z "`grep 'CONFIG_X86_MCE=y' ${TEMPYASATDIR}/kernel_config`" ];then
		Display --indent 2 --text "CONFIG_X86_MCE" --result ENABLED --color GREEN
		#TODO check the presence of mcelog
	else
		Display --indent 2 --text "CONFIG_X86_MCE" --result DISABLED --color ORANGE --advice KERNEL_CONFIG_MCE
	fi
	if [ ! -z "`grep 'CONFIG_PAX=y' ${TEMPYASATDIR}/kernel_config`" ];then
		Display --indent 2 --text "CONFIG_PAX" --result ENABLED --color GREEN
	else
		Display --indent 2 --text "CONFIG_PAX" --result DISABLED --color ORANGE --advice KERNEL_CONFIG_PAX
	fi
	if [ ! -z "`grep 'CONFIG_GRKERNSEC=y' ${TEMPYASATDIR}/kernel_config`" ];then
		Display --indent 2 --text "CONFIG_GRKERNSEC" --result ENABLED --color GREEN
	else
		Display --indent 2 --text "CONFIG_GRKERNSEC" --result DISABLED --color ORANGE --advice KERNEL_CONFIG_GRSEC
	fi
	if [ ! -z "`grep 'CONFIG_SECURITY_SELINUX=y' ${TEMPYASATDIR}/kernel_config`" ];then
		Display --indent 2 --text "CONFIG_SECURITY_SELINUX" --result ENABLED --color GREEN
	else
		Display --indent 2 --text "CONFIG_SECURITY_SELINUX" --result DISABLED --color ORANGE --advice KERNEL_CONFIG_SECURITY_SELINUX
	fi
	if [ ! -z "`grep 'CONFIG_DEBUG_SET_MODULE_RONX=y' ${TEMPYASATDIR}/kernel_config`" ] ;then
		Display --indent 2 --text "CONFIG_DEBUG_SET_MODULE_RONX" --result ENABLED --color GREEN
	else
		Display --indent 2 --text "CONFIG_DEBUG_SET_MODULE_RONX" --result DISABLED --color ORANGE --advice KERNEL_CONFIG_DEBUG_SET_MODULE_RONX
	fi
	if [ ! -z "`grep 'CONFIG_DEBUG_RODATA=y' ${TEMPYASATDIR}/kernel_config`" ] ;then
		Display --indent 2 --text "CONFIG_DEBUG_RODATA" --result ENABLED --color GREEN
	else
		Display --indent 2 --text "CONFIG_DEBUG_RODATA" --result DISABLED --color ORANGE --advice KERNEL_CONFIG_DEBUG_RODATA
	fi
	if [ ! -z "`grep 'CONFIG_DEBUG_STRICT_USER_COPY_CHECKS=y' ${TEMPYASATDIR}/kernel_config`" ] ;then
		Display --indent 2 --text "CONFIG_DEBUG_STRICT_USER_COPY_CHECKS" --result ENABLED --color GREEN
	else
		Display --indent 2 --text "CONFIG_DEBUG_STRICT_USER_COPY_CHECKS" --result DISABLED --color ORANGE --advice KERNEL_CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
	fi
fi
#end of -e "${TEMPYASATDIR}/kernel_config