|
1 |
| -# encoding: utf-8 |
2 | 1 | #
|
3 | 2 | # Copyright 2015, Patrick Muench
|
4 | 3 | #
|
|
18 | 17 | # author: Dominik Richter
|
19 | 18 | # author: Patrick Muench
|
20 | 19 |
|
| 20 | +login_defs_umask = attribute('login_defs_umask', default: '027', description: 'Default umask to set in login.defs') |
| 21 | +login_defs_passmaxdays = attribute('login_defs_passmaxdays', default: '60', description: 'Default password maxdays to set in login.defs') |
| 22 | +login_defs_passmindays = attribute('login_defs_passmindays', default: '7', description: 'Default password mindays to set in login.defs') |
| 23 | +login_defs_passwarnage = attribute('login_defs_passwarnage', default: '7', description: 'Default password warnage (days) to set in login.defs') |
| 24 | +if os.redhat? |
| 25 | + shadow_group = 'root' |
| 26 | +elsif os.debian? |
| 27 | + shadow_group = 'shadow' |
| 28 | +end |
| 29 | +blacklist = attribute( |
| 30 | + 'blacklist', |
| 31 | + default: [ |
| 32 | + # blacklist as provided by NSA |
| 33 | + '/usr/bin/rcp', '/usr/bin/rlogin', '/usr/bin/rsh', |
| 34 | + # sshd must not use host-based authentication (see ssh cookbook) |
| 35 | + '/usr/libexec/openssh/ssh-keysign', |
| 36 | + '/usr/lib/openssh/ssh-keysign', |
| 37 | + # misc others |
| 38 | + '/sbin/netreport', # not normally required for user |
| 39 | + '/usr/sbin/usernetctl', # modify interfaces via functional accounts |
| 40 | + # connecting to ... |
| 41 | + '/usr/sbin/userisdnctl', # no isdn... |
| 42 | + '/usr/sbin/pppd', # no ppp / dsl ... |
| 43 | + # lockfile |
| 44 | + '/usr/bin/lockfile', |
| 45 | + '/usr/bin/mail-lock', |
| 46 | + '/usr/bin/mail-unlock', |
| 47 | + '/usr/bin/mail-touchlock', |
| 48 | + '/usr/bin/dotlockfile', |
| 49 | + # need more investigation, blacklist for now |
| 50 | + '/usr/bin/arping', |
| 51 | + '/usr/sbin/arping', |
| 52 | + '/usr/sbin/uuidd', |
| 53 | + '/usr/bin/mtr', # investigate current state... |
| 54 | + '/usr/lib/evolution/camel-lock-helper-1.2', # investigate current state... |
| 55 | + '/usr/lib/pt_chown', # pseudo-tty, needed? |
| 56 | + '/usr/lib/eject/dmcrypt-get-device', |
| 57 | + '/usr/lib/mc/cons.saver' # midnight commander screensaver |
| 58 | + # from Ubuntu xenial, need to investigate |
| 59 | + # '/sbin/unix_chkpwd', |
| 60 | + # '/sbin/pam_extrausers_chkpwd', |
| 61 | + # '/usr/lib/x86_64-linux-gnu/utempter/utempter', |
| 62 | + # '/usr/sbin/postdrop', |
| 63 | + # '/usr/sbin/postqueue', |
| 64 | + # '/usr/bin/ssh-agent', |
| 65 | + # '/usr/bin/mlocate', |
| 66 | + # '/usr/bin/crontab', |
| 67 | + # '/usr/bin/screen', |
| 68 | + # '/usr/bin/expiry', |
| 69 | + # '/usr/bin/wall', |
| 70 | + # '/usr/bin/chage', |
| 71 | + # '/usr/bin/bsd-write' |
| 72 | + ], |
| 73 | + description: 'blacklist of suid/sgid program on system' |
| 74 | +) |
| 75 | + |
21 | 76 | control 'os-01' do
|
22 | 77 | impact 1.0
|
23 | 78 | title 'Trusted hosts login'
|
|
38 | 93 | it { should exist }
|
39 | 94 | it { should be_file }
|
40 | 95 | it { should be_owned_by 'root' }
|
41 |
| - its('group') { should eq 'root' } |
| 96 | + its('group') { should eq shadow_group } |
42 | 97 | it { should_not be_executable }
|
43 | 98 | it { should be_writable.by('owner') }
|
44 | 99 | it { should be_readable.by('owner') }
|
45 |
| - it { should_not be_readable.by('group') } |
46 | 100 | it { should_not be_readable.by('other') }
|
47 | 101 | end
|
| 102 | + if os.redhat? |
| 103 | + describe file('/etc/shadow') do |
| 104 | + it { should_not be_readable.by('group') } |
| 105 | + end |
| 106 | + elsif os.debian? |
| 107 | + describe file('/etc/shadow') do |
| 108 | + it { should be_readable.by('group') } |
| 109 | + end |
| 110 | + end |
48 | 111 | end
|
49 | 112 |
|
50 | 113 | control 'os-03' do
|
|
86 | 149 | it { should be_owned_by 'root' }
|
87 | 150 | its('group') { should eq 'root' }
|
88 | 151 | it { should_not be_executable }
|
89 |
| - it { should_not be_writable } |
90 | 152 | it { should be_readable.by('owner') }
|
91 | 153 | it { should be_readable.by('group') }
|
92 | 154 | it { should be_readable.by('other') }
|
93 | 155 | end
|
94 | 156 | describe login_defs do
|
95 | 157 | its('ENV_SUPATH') { should include('/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin') }
|
96 | 158 | its('ENV_PATH') { should include('/usr/local/bin:/usr/bin:/bin') }
|
97 |
| - its('UMASK') { should include('027') } |
98 |
| - its('PASS_MAX_DAYS') { should eq '60' } |
99 |
| - its('PASS_MIN_DAYS') { should eq '7' } |
100 |
| - its('PASS_WARN_AGE') { should eq '7' } |
| 159 | + its('UMASK') { should include(login_defs_umask) } |
| 160 | + its('PASS_MAX_DAYS') { should eq login_defs_passmaxdays } |
| 161 | + its('PASS_MIN_DAYS') { should eq login_defs_passmindays } |
| 162 | + its('PASS_WARN_AGE') { should eq login_defs_passwarnage } |
101 | 163 | its('LOGIN_RETRIES') { should eq '5' }
|
102 | 164 | its('LOGIN_TIMEOUT') { should eq '60' }
|
103 | 165 | its('UID_MIN') { should eq '1000' }
|
104 | 166 | its('GID_MIN') { should eq '1000' }
|
105 |
| - its('SYS_UID_MIN') { should eq '100' } |
106 |
| - its('SYS_UID_MAX') { should eq '999' } |
107 |
| - its('SYS_GID_MIN') { should eq '100' } |
108 |
| - its('SYS_GID_MAX') { should eq '999' } |
109 |
| - its('ENCRYPT_METHOD') { should eq 'SHA512' } |
| 167 | + end |
| 168 | +end |
| 169 | + |
| 170 | +control 'os-05b' do |
| 171 | + impact 1.0 |
| 172 | + title 'Check login.defs - RedHat specific' |
| 173 | + desc 'Check owner and permissions for login.defs. Also check the configured PATH variable and umask in login.defs' |
| 174 | + if os.redhat? |
| 175 | + describe file('/etc/login.defs') do |
| 176 | + it { should_not be_writable } |
| 177 | + end |
| 178 | + describe login_defs do |
| 179 | + its('SYS_UID_MIN') { should eq '100' } |
| 180 | + its('SYS_UID_MAX') { should eq '999' } |
| 181 | + its('SYS_GID_MIN') { should eq '100' } |
| 182 | + its('SYS_GID_MAX') { should eq '999' } |
| 183 | + end |
110 | 184 | end
|
111 | 185 | end
|
112 | 186 |
|
|
115 | 189 | title 'Check for SUID/ SGID blacklist'
|
116 | 190 | desc 'Find blacklisted SUID and SGID files to ensure that no rogue SUID and SGID files have been introduced into the system'
|
117 | 191 |
|
118 |
| - blacklist = [ |
119 |
| - # blacklist as provided by NSA |
120 |
| - '/usr/bin/rcp', '/usr/bin/rlogin', '/usr/bin/rsh', |
121 |
| - # sshd must not use host-based authentication (see ssh cookbook) |
122 |
| - '/usr/libexec/openssh/ssh-keysign', |
123 |
| - '/usr/lib/openssh/ssh-keysign', |
124 |
| - # misc others |
125 |
| - '/sbin/netreport', # not normally required for user |
126 |
| - '/usr/sbin/usernetctl', # modify interfaces via functional accounts |
127 |
| - # connecting to ... |
128 |
| - '/usr/sbin/userisdnctl', # no isdn... |
129 |
| - '/usr/sbin/pppd', # no ppp / dsl ... |
130 |
| - # lockfile |
131 |
| - '/usr/bin/lockfile', |
132 |
| - '/usr/bin/mail-lock', |
133 |
| - '/usr/bin/mail-unlock', |
134 |
| - '/usr/bin/mail-touchlock', |
135 |
| - '/usr/bin/dotlockfile', |
136 |
| - # need more investigation, blacklist for now |
137 |
| - '/usr/bin/arping', |
138 |
| - '/usr/sbin/arping', |
139 |
| - '/usr/sbin/uuidd', |
140 |
| - '/usr/bin/mtr', # investigate current state... |
141 |
| - '/usr/lib/evolution/camel-lock-helper-1.2', # investigate current state... |
142 |
| - '/usr/lib/pt_chown', # pseudo-tty, needed? |
143 |
| - '/usr/lib/eject/dmcrypt-get-device', |
144 |
| - '/usr/lib/mc/cons.saver' # midnight commander screensaver |
145 |
| - ] |
146 |
| - |
147 |
| - output = command('find / -perm -4000 -o -perm -2000 -type f ! -path \'/proc/*\' -print 2>/dev/null | grep -v \'^find:\'') |
| 192 | + output = command('find / -perm -4000 -o -perm -2000 -type f ! -path \'/proc/*\' ! -path \'/var/lib/lxd/containers/*\' -print 2>/dev/null | grep -v \'^find:\'') |
148 | 193 | diff = output.stdout.split(/\r?\n/) & blacklist
|
149 | 194 | describe diff do
|
150 | 195 | it { should be_empty }
|
|
162 | 207 | its('gids') { should_not contain_duplicates }
|
163 | 208 | end
|
164 | 209 | end
|
| 210 | + |
| 211 | +control 'os-08' do |
| 212 | + impact 1.0 |
| 213 | + title 'Entropy' |
| 214 | + desc 'Check system has enough entropy - greater than 1000' |
| 215 | + describe file('/proc/sys/kernel/random/entropy_avail').content.to_i do |
| 216 | + it { should >= 1000 } |
| 217 | + end |
| 218 | +end |
| 219 | + |
| 220 | +control 'os-09' do |
| 221 | + impact 1.0 |
| 222 | + title 'Check for .rhosts and .netrc file' |
| 223 | + desc 'Find .rhosts and .netrc files - CIS Benchmark 9.2.9-10' |
| 224 | + |
| 225 | + output = command('find / \( -iname .rhosts -o -iname .netrc \) -print 2>/dev/null | grep -v \'^find:\'') |
| 226 | + out = output.stdout.split(/\r?\n/) |
| 227 | + describe out do |
| 228 | + it { should be_empty } |
| 229 | + end |
| 230 | +end |
0 commit comments