Skip to content

Commit f2f8d29

Browse files
committed
Merge pull request #18 from atomic111/master
split sysctl_spec.rb, added suid whitliste and uid unique search
2 parents e3bdd66 + 0138222 commit f2f8d29

2 files changed

Lines changed: 114 additions & 40 deletions

File tree

default/serverspec/os_spec.rb

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
RSpec.configure do |c|
6+
c.filter_run_excluding skipOn: backend(Serverspec::Commands::Base).check_os[:family]
7+
end
8+
9+
# GIS: Req 3.21-4
10+
describe command('find / -name \'.rhosts\' | wc -l ') do
11+
its(:stdout) { should match(/^0/) }
12+
end
13+
14+
# GIS: Req 3.21-4
15+
describe command('find / -name \'hosts.equiv\' | wc -l ') do
16+
its(:stdout) { should match(/^0/) }
17+
end
18+
19+
# GIS: Req 3.21-7
20+
describe file('/etc/shadow') do
21+
it { should be_owned_by 'root' }
22+
end
23+
24+
# GIS: Req 3.21-7
25+
describe file('/etc/shadow') do
26+
it { should be_mode 600 }
27+
end
28+
29+
# GIS: Req 3.21-8
30+
describe command('echo $PATH | grep -ci \'\.\'') do
31+
its(:stdout) { should match(/^0/) }
32+
end
33+
34+
# GIS: Req 3.21-8
35+
describe file('/etc/login.defs') do
36+
its(:content) { should match(%r{^ENV_SUPATH\s+PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin}) }
37+
end
38+
39+
# GIS: Req 3.21-8
40+
describe file('/etc/login.defs') do
41+
its(:content) { should match(%r{^ENV_PATH\s+PATH=/usr/local/bin:/usr/bin:/bin}) }
42+
end
43+
44+
# GIS: Req 3.21-10
45+
describe file('/etc/login.defs') do
46+
its(:content) { should match(/^UMASK +027/) }
47+
end
48+
49+
# GIS: Req 3.21-12
50+
describe 'SUID/ SGID whitelist check' do
51+
it 'found only whitelist suid/sgid' do
52+
whitelist = [
53+
# whitelist as provided by NSA
54+
'/bin/mount', '/bin/ping', '/bin/su', '/bin/umount', '/sbin/pam_timestamp_check',
55+
'/sbin/unix_chkpwd', '/usr/bin/at', '/usr/bin/gpasswd', '/usr/bin/locate',
56+
'/usr/bin/newgrp', '/usr/bin/passwd', '/usr/bin/ssh-agent', '/usr/libexec/utempter/utempter', '/usr/sbin/lockdev',
57+
'/usr/sbin/sendmail.sendmail', '/usr/bin/expiry',
58+
# whitelist ipv6
59+
'/bin/ping6', '/usr/bin/traceroute6.iputils',
60+
# whitelist nfs
61+
'/sbin/mount.nfs', '/sbin/umount.nfs',
62+
# whitelist nfs4
63+
'/sbin/mount.nfs4', '/sbin/umount.nfs4',
64+
# whitelist cron
65+
'/usr/bin/crontab',
66+
# whitelist consolemssaging
67+
'/usr/bin/wall', '/usr/bin/write',
68+
# whitelist: only SGID with utmp group for multi-session access
69+
# impact is limited; installation/usage has some remaining risk
70+
'/usr/bin/screen',
71+
# whitelist locate
72+
'/usr/bin/mlocate',
73+
# whitelist usermanagement
74+
'/usr/bin/chage', '/usr/bin/chfn', '/usr/bin/chsh',
75+
# whitelist fuse
76+
'/bin/fusermount',
77+
# whitelist pkexec
78+
'/usr/bin/pkexec',
79+
# whitelist sudo
80+
'/usr/bin/sudo', '/usr/bin/sudoedit',
81+
# whitelist postfix
82+
'/usr/sbin/postdrop', '/usr/sbin/postqueue',
83+
# whitelist apache
84+
'/usr/sbin/suexec',
85+
# whitelist squid
86+
'/usr/lib/squid/ncsa_auth', '/usr/lib/squid/pam_auth',
87+
# whitelist kerberos
88+
'/usr/kerberos/bin/ksu',
89+
# whitelist pam_caching
90+
'/usr/sbin/ccreds_validate',
91+
# whitelist Xorg
92+
'/usr/bin/Xorg', # xorg
93+
'/usr/bin/X', # xorg
94+
'/usr/lib/dbus-1.0/dbus-daemon-launch-helper', # freedesktop ipc
95+
'/usr/lib/vte/gnome-pty-helper', # gnome
96+
'/usr/lib/libvte9/gnome-pty-helper', # gnome
97+
'/usr/lib/libvte-2.90-9/gnome-pty-helper' # gnome
98+
]
99+
actual = command('find / -perm -4000 -o -perm -2000 -type f ! -path \'/proc/*\' -print 2>/dev/null | grep -v \'^find:\'').stdout.split(/\r?\n/)
100+
(actual - whitelist).count.should be 0
101+
end
102+
end
103+
104+
# GIS: Req 3.21-16
105+
describe 'Unique uid' do
106+
it 'check for unique uids' do
107+
actual = command('cat /etc/passwd | cut -d \':\' -f 3').stdout.split(/\r?\n/)
108+
hm = actual.each_with_object(Hash.new(0)) { |d, counts| counts[d] += 1 }
109+
hm.each do |k, v|
110+
str = "User: UID #{k} instances: "
111+
("#{str}#{v}").should eq("#{str}1")
112+
end
113+
end
114+
end

default/serverspec/sysctl_spec.rb

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -207,43 +207,3 @@
207207
its(:value) { should eq 2 }
208208
end
209209
end
210-
211-
# GIS: Req 3.21-4
212-
describe command('find / -name \'.rhosts\' | wc -l ') do
213-
its(:stdout) { should match(/^0/) }
214-
end
215-
216-
# GIS: Req 3.21-4
217-
describe command('find / -name \'hosts.equiv\' | wc -l ') do
218-
its(:stdout) { should match(/^0/) }
219-
end
220-
221-
# GIS: Req 3.21-7
222-
describe file('/etc/shadow') do
223-
it { should be_owned_by 'root' }
224-
end
225-
226-
# GIS: Req 3.21-7
227-
describe file('/etc/shadow') do
228-
it { should be_mode 600 }
229-
end
230-
231-
# GIS: Req 3.21-8
232-
describe command('echo $PATH | grep -ci \'\.\'') do
233-
its(:stdout) { should match(/^0/) }
234-
end
235-
236-
# GIS: Req 3.21-8
237-
describe file('/etc/login.defs') do
238-
its(:content) { should match(%r{^ENV_SUPATH\s+PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin}) }
239-
end
240-
241-
# GIS: Req 3.21-8
242-
describe file('/etc/login.defs') do
243-
its(:content) { should match(%r{^ENV_PATH\s+PATH=/usr/local/bin:/usr/bin:/bin}) }
244-
end
245-
246-
# GIS: Req 3.21-10
247-
describe file('/etc/login.defs') do
248-
its(:content) { should match(/^UMASK +027/) }
249-
end

0 commit comments

Comments
 (0)