Skip to content

Commit

Permalink
Make all kernel parameter checks related to net.ipv6 conditional
Browse files Browse the repository at this point in the history
There are various validations where we check the net.ipv6 kernel
parameters. However, if ipv6 is disabled, then these checks will
fail.

Signed-off-by: Ivo van Doorn <[email protected]>
  • Loading branch information
IvDoorn committed Nov 15, 2023
1 parent 975fd37 commit 5c7d5c0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
12 changes: 8 additions & 4 deletions controls/3_1_network_parameters_host_only.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

title '3.1 Network Parameters (Host Only)'

ipv6 = command('test -f /proc/net/if_inet6').exit_status

control 'cis-dil-benchmark-3.1.1' do
title 'Ensure IP forwarding is disabled'
desc "The net.ipv4.ip_forward flag is used to tell the system whether it can forward packets or not.\n\nRationale: Setting the flag to 0 ensures that a system with multiple interfaces (for example, a hard proxy), will never be able to forward packets, and therefore, never serve as a router."
Expand All @@ -27,10 +29,12 @@
tag cis: 'distribution-independent-linux:3.1.1'
tag level: 1

%w(
net.ipv4.ip_forward
net.ipv6.conf.all.forwarding
).each do |kp|
parameters = ['net.ipv4.ip_forward']
if ipv6.zero?
parameters += ['net.ipv6.conf.all.forwarding']
end

parameters.each do |kp|
describe kernel_parameter(kp) do
its('value') { should_not be_nil }
its('value') { should cmp 0 }
Expand Down
40 changes: 28 additions & 12 deletions controls/3_2_network_parameters_host_and_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

title '3.2 Network Parameters (Host and Router)'

ipv6 = command('test -f /proc/net/if_inet6').exit_status

control 'cis-dil-benchmark-3.2.1' do
title 'Ensure source routed packets are not accepted'
desc "In networking, source routing allows a sender to partially or fully specify the route packets take through a network. In contrast, non-source routed packets travel a path determined by routers in the network. In some cases, systems may not be routable or reachable from some locations (e.g. private addresses vs. Internet routable), and so source routed packets would need to be used.\n\nRationale: Setting net.ipv4.conf.all.accept_source_route and net.ipv4.conf.default.accept_source_route to 0 disables the system from accepting source routed packets. Assume this system was capable of routing packets to Internet routable addresses on one interface and private addresses on another interface. Assume that the private addresses were not routable to the Internet routable addresses and vice versa. Under normal routing circumstances, an attacker from the Internet routable addresses could not use the system as a way to reach the private address systems. If, however, source routed packets were allowed, they could be used to gain access to the private address systems as the route could be specified, rather than rely on routing protocols that did not allow this routing."
Expand All @@ -27,12 +29,18 @@
tag cis: 'distribution-independent-linux:3.2.1'
tag level: 1

%w(
net.ipv4.conf.all.accept_source_route
net.ipv4.conf.default.accept_source_route
net.ipv6.conf.all.accept_source_route
net.ipv6.conf.default.accept_source_route
).each do |kp|
parameters = [
'net.ipv4.conf.all.accept_source_route',
'net.ipv4.conf.default.accept_source_route',
]
if ipv6.zero?
parameters += [
'net.ipv6.conf.all.accept_source_route',
'net.ipv6.conf.default.accept_source_route',
]
end

parameters.each do |kp|
describe kernel_parameter(kp) do
its(:value) { should_not be_nil }
its(:value) { should eq 0 }
Expand All @@ -48,12 +56,18 @@
tag cis: 'distribution-independent-linux:3.2.2'
tag level: 1

%w(
net.ipv4.conf.all.accept_redirects
net.ipv4.conf.default.accept_redirects
net.ipv6.conf.all.accept_redirects
net.ipv6.conf.default.accept_redirects
).each do |kp|
parameters = [
'net.ipv4.conf.all.accept_redirects',
'net.ipv4.conf.default.accept_redirects',
]
if ipv6.zero?
parameters += [
'net.ipv6.conf.all.accept_redirects',
'net.ipv6.conf.default.accept_redirects',
]
end

parameters.each do |kp|
describe kernel_parameter(kp) do
its(:value) { should_not be_nil }
its(:value) { should eq 0 }
Expand Down Expand Up @@ -165,4 +179,6 @@
its(:value) { should eq 0 }
end
end

only_if { ipv6.zero? }
end

0 comments on commit 5c7d5c0

Please sign in to comment.