-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSV-257802.rb
70 lines (52 loc) · 3 KB
/
SV-257802.rb
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
control 'SV-257802' do
title 'RHEL 9 must enable kernel parameters to enforce discretionary access control on symlinks.'
desc "By enabling the fs.protected_symlinks kernel parameter, symbolic links are permitted to be followed only when outside a sticky world-writable directory, or when the user identifier (UID) of the link and follower match, or when the directory owner matches the symlink's owner. Disallowing such symlinks helps mitigate vulnerabilities based on insecure file system accessed by privileged programs, avoiding an exploitation vector exploiting unsafe use of open() or creat()."
desc 'check', %q(Verify RHEL 9 is configured to enable DAC on symlinks.
Check the status of the fs.protected_symlinks kernel parameter with the following command:
$ sudo sysctl fs.protected_symlinks
fs.protected_symlinks = 1
If "fs.protected_symlinks " is not set to "1" or is missing, this is a finding.
Check that the configuration files are present to enable this kernel parameter.
$ sudo /usr/lib/systemd/systemd-sysctl --cat-config | egrep -v '^(#|;)' | grep -F fs.protected_symlinks | tail -1
fs.protected_symlinks = 1
If "fs.protected_symlinks" is not set to "1" or is missing, this is a finding.)
desc 'fix', 'Configure RHEL 9 to enable DAC on symlinks with the following:
Add or edit the following line in a system configuration file in the "/etc/sysctl.d/" directory:
fs.protected_symlinks = 1
Load settings from all system configuration files with the following command:
$ sudo sysctl --system'
impact 0.5
ref 'DPMS Target Red Hat Enterprise Linux 9'
tag severity: 'medium'
tag gtitle: 'SRG-OS-000312-GPOS-00123'
tag satisfies: ['SRG-OS-000312-GPOS-00122', 'SRG-OS-000312-GPOS-00123', 'SRG-OS-000312-GPOS-00124', 'SRG-OS-000324-GPOS-00125']
tag gid: 'V-257802'
tag rid: 'SV-257802r958702_rule'
tag stig_id: 'RHEL-09-213035'
tag fix_id: 'F-61467r925392_fix'
tag cci: ['CCI-002165', 'CCI-002235']
tag nist: ['AC-3 (4)', 'AC-6 (10)']
tag 'host'
only_if('Control not applicable within a container', impact: 0.0) {
!virtualization.system.eql?('docker')
}
parameter = 'fs.protected_symlinks'
value = 1
regexp = /^\s*#{parameter}\s*=\s*#{value}\s*$/
describe kernel_parameter(parameter) do
its('value') { should eq value }
end
search_results = command("/usr/lib/systemd/systemd-sysctl --cat-config | egrep -v '^(#|;)' | grep -F #{parameter}").stdout.strip.split("\n")
correct_result = search_results.any? { |line| line.match(regexp) }
incorrect_results = search_results.map(&:strip).reject { |line| line.match(regexp) }
describe 'Kernel config files' do
it "should configure '#{parameter}'" do
expect(correct_result).to eq(true), 'No config file was found that correctly sets this action'
end
unless incorrect_results.nil?
it 'should not have incorrect or conflicting setting(s) in the config files' do
expect(incorrect_results).to be_empty, "Incorrect or conflicting setting(s) found:\n\t- #{incorrect_results.join("\n\t- ")}"
end
end
end
end