|
| 1 | +# encoding: utf-8 |
| 2 | +# |
| 3 | +# Copyright 2014, Deutsche Telekom AG |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +require 'spec_helper' |
| 19 | + |
| 20 | +RSpec.configure do |c| |
| 21 | + c.filter_run_excluding skipOn: backend(Serverspec::Commands::Base).check_os[:family] |
| 22 | +end |
| 23 | + |
| 24 | +# GIS: Req 3.21-4 |
| 25 | +describe command('find / -name \'.rhosts\' | wc -l ') do |
| 26 | + its(:stdout) { should match(/^0/) } |
| 27 | +end |
| 28 | + |
| 29 | +# GIS: Req 3.21-4 |
| 30 | +describe command('find / -name \'hosts.equiv\' | wc -l ') do |
| 31 | + its(:stdout) { should match(/^0/) } |
| 32 | +end |
| 33 | + |
| 34 | +# GIS: Req 3.21-7 |
| 35 | +describe file('/etc/shadow') do |
| 36 | + it { should be_owned_by 'root' } |
| 37 | +end |
| 38 | + |
| 39 | +# GIS: Req 3.21-7 |
| 40 | +describe file('/etc/shadow') do |
| 41 | + it { should be_mode 600 } |
| 42 | +end |
| 43 | + |
| 44 | +# GIS: Req 3.21-8 |
| 45 | +describe command('echo $PATH | grep -ci \'\.\'') do |
| 46 | + its(:stdout) { should match(/^0/) } |
| 47 | +end |
| 48 | + |
| 49 | +# GIS: Req 3.21-8 |
| 50 | +describe file('/etc/login.defs') do |
| 51 | + its(:content) { should match(%r{^ENV_SUPATH\s+PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin}) } |
| 52 | +end |
| 53 | + |
| 54 | +# GIS: Req 3.21-8 |
| 55 | +describe file('/etc/login.defs') do |
| 56 | + its(:content) { should match(%r{^ENV_PATH\s+PATH=/usr/local/bin:/usr/bin:/bin}) } |
| 57 | +end |
| 58 | + |
| 59 | +# GIS: Req 3.21-10 |
| 60 | +describe file('/etc/login.defs') do |
| 61 | + its(:content) { should match(/^UMASK +027/) } |
| 62 | +end |
| 63 | + |
| 64 | +# GIS: Req 3.21-12 |
| 65 | +describe 'SUID/ SGID whitelist check' do |
| 66 | + it 'found only whitelist suid/sgid' do |
| 67 | + whitelist = [ |
| 68 | + # whitelist as provided by NSA |
| 69 | + '/bin/mount', '/bin/ping', '/bin/su', '/bin/umount', '/sbin/pam_timestamp_check', |
| 70 | + '/sbin/unix_chkpwd', '/usr/bin/at', '/usr/bin/gpasswd', '/usr/bin/locate', |
| 71 | + '/usr/bin/newgrp', '/usr/bin/passwd', '/usr/bin/ssh-agent', '/usr/libexec/utempter/utempter', '/usr/sbin/lockdev', |
| 72 | + '/usr/sbin/sendmail.sendmail', '/usr/bin/expiry', |
| 73 | + # whitelist ipv6 |
| 74 | + '/bin/ping6', '/usr/bin/traceroute6.iputils', |
| 75 | + # whitelist nfs |
| 76 | + '/sbin/mount.nfs', '/sbin/umount.nfs', |
| 77 | + # whitelist nfs4 |
| 78 | + '/sbin/mount.nfs4', '/sbin/umount.nfs4', |
| 79 | + # whitelist cron |
| 80 | + '/usr/bin/crontab', |
| 81 | + # whitelist consolemssaging |
| 82 | + '/usr/bin/wall', '/usr/bin/write', |
| 83 | + # whitelist: only SGID with utmp group for multi-session access |
| 84 | + # impact is limited; installation/usage has some remaining risk |
| 85 | + '/usr/bin/screen', |
| 86 | + # whitelist locate |
| 87 | + '/usr/bin/mlocate', |
| 88 | + # whitelist usermanagement |
| 89 | + '/usr/bin/chage', '/usr/bin/chfn', '/usr/bin/chsh', |
| 90 | + # whitelist fuse |
| 91 | + '/bin/fusermount', |
| 92 | + # whitelist pkexec |
| 93 | + '/usr/bin/pkexec', |
| 94 | + # whitelist sudo |
| 95 | + '/usr/bin/sudo', '/usr/bin/sudoedit', |
| 96 | + # whitelist postfix |
| 97 | + '/usr/sbin/postdrop', '/usr/sbin/postqueue', |
| 98 | + # whitelist apache |
| 99 | + '/usr/sbin/suexec', |
| 100 | + # whitelist squid |
| 101 | + '/usr/lib/squid/ncsa_auth', '/usr/lib/squid/pam_auth', |
| 102 | + # whitelist kerberos |
| 103 | + '/usr/kerberos/bin/ksu', |
| 104 | + # whitelist pam_caching |
| 105 | + '/usr/sbin/ccreds_validate', |
| 106 | + # whitelist Xorg |
| 107 | + '/usr/bin/Xorg', # xorg |
| 108 | + '/usr/bin/X', # xorg |
| 109 | + '/usr/lib/dbus-1.0/dbus-daemon-launch-helper', # freedesktop ipc |
| 110 | + '/usr/lib/vte/gnome-pty-helper', # gnome |
| 111 | + '/usr/lib/libvte9/gnome-pty-helper', # gnome |
| 112 | + '/usr/lib/libvte-2.90-9/gnome-pty-helper' # gnome |
| 113 | + ] |
| 114 | + actual = command('find / -perm -4000 -o -perm -2000 -type f ! -path \'/proc/*\' -print 2>/dev/null | grep -v \'^find:\'').stdout.split(/\r?\n/) |
| 115 | + (actual - whitelist).count.should be 0 |
| 116 | + end |
| 117 | +end |
| 118 | + |
| 119 | +# GIS: Req 3.21-16 |
| 120 | +describe 'Unique uid' do |
| 121 | + it 'check for unique uids' do |
| 122 | + actual = command('cat /etc/passwd | cut -d \':\' -f 3').stdout.split(/\r?\n/) |
| 123 | + hm = actual.each_with_object(Hash.new(0)) { |d, counts| counts[d] += 1 } |
| 124 | + hm.each do |k, v| |
| 125 | + str = "User: UID #{k} instances: " |
| 126 | + ("#{str}#{v}").should eq("#{str}1") |
| 127 | + end |
| 128 | + end |
| 129 | +end |
0 commit comments