|
|
b5e178 |
diff --git a/controls/anssi.yml b/controls/anssi.yml
|
|
|
b5e178 |
index 851993512..515a4a172 100644
|
|
|
b5e178 |
--- a/controls/anssi.yml
|
|
|
b5e178 |
+++ b/controls/anssi.yml
|
|
|
b5e178 |
@@ -850,7 +850,8 @@ controls:
|
|
|
b5e178 |
- id: R63
|
|
|
b5e178 |
level: intermediary
|
|
|
b5e178 |
title: Explicit arguments in sudo specifications
|
|
|
b5e178 |
- # rules: TBD
|
|
|
b5e178 |
+ rules:
|
|
|
b5e178 |
+ - sudoers_explicit_command_args
|
|
|
b5e178 |
|
|
|
b5e178 |
- id: R64
|
|
|
b5e178 |
level: intermediary
|
|
|
b5e178 |
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/oval/shared.xml b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/oval/shared.xml
|
|
|
b5e178 |
new file mode 100644
|
|
|
b5e178 |
index 000000000..94a0cb421
|
|
|
b5e178 |
--- /dev/null
|
|
|
b5e178 |
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/oval/shared.xml
|
|
|
b5e178 |
@@ -0,0 +1,25 @@
|
|
|
b5e178 |
+<def-group>
|
|
|
b5e178 |
+ <definition class="compliance" id="{{{ rule_id }}}" version="1">
|
|
|
b5e178 |
+ {{{ oval_metadata("Check that sudoers doesn't contain commands without arguments specified") }}}
|
|
|
b5e178 |
+ <criteria operator="AND">
|
|
|
b5e178 |
+ <criterion comment="Make sure that no commands are without arguments" test_ref="test_{{{ rule_id }}}" />
|
|
|
b5e178 |
+ </criteria>
|
|
|
b5e178 |
+ </definition>
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+ comment="Make sure that no command in user spec is without any argument"
|
|
|
b5e178 |
+ id="test_{{{ rule_id }}}" version="1">
|
|
|
b5e178 |
+ <ind:object object_ref="object_{{{ rule_id }}}" />
|
|
|
b5e178 |
+ </ind:textfilecontent54_test>
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+ <ind:textfilecontent54_object id="object_{{{ rule_id }}}" version="1">
|
|
|
b5e178 |
+ <ind:filepath operation="pattern match">^/etc/sudoers(\.d/.*)?$</ind:filepath>
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+ where a command is <runas spec>?<anything except ,>+,
|
|
|
b5e178 |
+ - ',' is a command delimiter, while
|
|
|
b5e178 |
+ The last capturing group holds the offending command without args.
|
|
|
b5e178 |
+ -->
|
|
|
b5e178 |
+ <ind:pattern operation="pattern match">^(?:\s*[^#=]+)=(?:\s*(?:\([^\)]+\))?\s*(?!\s*\()[^,\s]+(?:[ \t]+[^,\s]+)+[ \t]*,)*(\s*(?:\([^\)]+\))?\s*(?!\s*\()[^,\s]+[ \t]*(?:,|$))</ind:pattern>
|
|
|
b5e178 |
+ <ind:instance datatype="int">1</ind:instance>
|
|
|
b5e178 |
+ </ind:textfilecontent54_object>
|
|
|
b5e178 |
+</def-group>
|
|
|
b5e178 |
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/rule.yml b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/rule.yml
|
|
|
b5e178 |
new file mode 100644
|
|
|
b5e178 |
index 000000000..a0590c8b0
|
|
|
b5e178 |
--- /dev/null
|
|
|
b5e178 |
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/rule.yml
|
|
|
b5e178 |
@@ -0,0 +1,46 @@
|
|
|
b5e178 |
+documentation_complete: true
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+title: "Explicit arguments in sudo specifications"
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+description: |-
|
|
|
b5e178 |
+ All commands in the sudoers file must strictly specify the arguments allowed to be used for a given user.
|
|
|
b5e178 |
+ If the command is supposed to be executed only without arguments, pass "" as an argument in the corresponding user specification.
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+rationale: |-
|
|
|
b5e178 |
+ Any argument can modify quite significantly the behavior of a program, whether regarding the
|
|
|
b5e178 |
+ realized operation (read, write, delete, etc.) or accessed resources (path in a file system tree). To
|
|
|
b5e178 |
+ avoid any possibility of misuse of a command by a user, the ambiguities must be removed at the
|
|
|
b5e178 |
+ level of its specification.
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+ For example, on some systems, the kernel messages are only accessible by root.
|
|
|
b5e178 |
+ If a user nevertheless must have the privileges to read them, the argument of the dmesg command has to be restricted
|
|
|
b5e178 |
+ in order to prevent the user from flushing the buffer through the -c option:
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+ user ALL = dmesg ""
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+severity: medium
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+identifiers:
|
|
|
b5e178 |
+ cce@rhel7: CCE-83631-2
|
|
|
b5e178 |
+ cce@rhel8: CCE-83632-0
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+references:
|
|
|
b5e178 |
+ anssi: BP28(R63)
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+ocil_clause: '/etc/sudoers file contains user specifications that allow execution of commands with any arguments'
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+ocil: |-
|
|
|
b5e178 |
+ To determine if arguments that commands can be executed with are restricted, run the following command:
|
|
|
b5e178 |
+ $ sudo grep -PR '^(?:\s*[^#=]+)=(?:\s*(?:\([^\)]+\))?\s*(?!\s*\()[^,\s]+(?:[ \t]+[^,\s]+)+[ \t]*,)*(\s*(?:\([^\)]+\))?\s*(?!\s*\()[^,\s]+[ \t]*(?:,|$))' /etc/sudoers /etc/sudoers.d/
|
|
|
b5e178 |
+ The command should return no output.
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+platform: sudo
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+warnings:
|
|
|
b5e178 |
+ - general:
|
|
|
b5e178 |
+ This rule doesn't come with a remediation, as absence of arguments in the user spec doesn't mean that the command is intended to be executed with no arguments.
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+ - general:
|
|
|
b5e178 |
+ The rule can produce false findings when an argument contains a comma - sudoers syntax allows comma escaping using backslash, but the check doesn't support that.
|
|
|
b5e178 |
+ For example, root ALL=(ALL) echo 1\,2 allows root to execute echo 1,2 , but the check would interpret it as two commands echo 1\ and 2 .
|
|
|
b5e178 |
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/commented.pass.sh b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/commented.pass.sh
|
|
|
b5e178 |
new file mode 100644
|
|
|
b5e178 |
index 000000000..b0d05b2a5
|
|
|
b5e178 |
--- /dev/null
|
|
|
b5e178 |
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/commented.pass.sh
|
|
|
b5e178 |
@@ -0,0 +1,5 @@
|
|
|
b5e178 |
+# platform = multi_platform_all
|
|
|
b5e178 |
+# packages = sudo
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+echo '#jen,!fred ALL, !SERVERS = !/bin/sh' > /etc/sudoers
|
|
|
b5e178 |
+echo '# somebody ALL=/bin/ls, (!bob,alice) !/bin/cat, /bin/dog' > /etc/sudoers.d/foo
|
|
|
b5e178 |
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/complex-1.fail.sh b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/complex-1.fail.sh
|
|
|
b5e178 |
new file mode 100644
|
|
|
b5e178 |
index 000000000..c6f885f9f
|
|
|
b5e178 |
--- /dev/null
|
|
|
b5e178 |
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/complex-1.fail.sh
|
|
|
b5e178 |
@@ -0,0 +1,5 @@
|
|
|
b5e178 |
+# platform = multi_platform_all
|
|
|
b5e178 |
+# packages = sudo
|
|
|
b5e178 |
+# remediation = none
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+echo 'somebody ALL=/bin/ls, (!bob,alice) /bin/cat arg, /bin/dog' > /etc/sudoers
|
|
|
b5e178 |
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/complex-2.fail.sh b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/complex-2.fail.sh
|
|
|
b5e178 |
new file mode 100644
|
|
|
b5e178 |
index 000000000..fce851f55
|
|
|
b5e178 |
--- /dev/null
|
|
|
b5e178 |
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/complex-2.fail.sh
|
|
|
b5e178 |
@@ -0,0 +1,5 @@
|
|
|
b5e178 |
+# platform = multi_platform_all
|
|
|
b5e178 |
+# packages = sudo
|
|
|
b5e178 |
+# remediation = none
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+echo 'nobody ALL=/bin/ls, (!bob,alice) /bin/dog, /bin/cat arg' > /etc/sudoers
|
|
|
b5e178 |
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/false_positive.fail.sh b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/false_positive.fail.sh
|
|
|
b5e178 |
new file mode 100644
|
|
|
b5e178 |
index 000000000..baf66468d
|
|
|
b5e178 |
--- /dev/null
|
|
|
b5e178 |
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/false_positive.fail.sh
|
|
|
b5e178 |
@@ -0,0 +1,9 @@
|
|
|
b5e178 |
+# platform = multi_platform_all
|
|
|
b5e178 |
+# remediation = none
|
|
|
b5e178 |
+# packages = sudo
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+# The val1\,val2 is the first argument of the /bin/dog command that contains a comma.
|
|
|
b5e178 |
+# Our check tends to interpret the comma as commad delimiter, so the dog arg is val1\
|
|
|
b5e178 |
+# and val2 is another command in the user spec.
|
|
|
b5e178 |
+echo 'nobody ALL=/bin/ls "", (!bob,alice) /bin/dog val1\,val2, /bin/cat ""' > /etc/sudoers
|
|
|
b5e178 |
+
|
|
|
b5e178 |
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/simple.fail.sh b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/simple.fail.sh
|
|
|
b5e178 |
new file mode 100644
|
|
|
b5e178 |
index 000000000..9a04a205a
|
|
|
b5e178 |
--- /dev/null
|
|
|
b5e178 |
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/simple.fail.sh
|
|
|
b5e178 |
@@ -0,0 +1,5 @@
|
|
|
b5e178 |
+# platform = multi_platform_all
|
|
|
b5e178 |
+# packages = sudo
|
|
|
b5e178 |
+# remediation = none
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+echo 'jen,!fred ALL,SERVERS = /bin/sh ' > /etc/sudoers
|
|
|
b5e178 |
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/simple.pass.sh b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/simple.pass.sh
|
|
|
b5e178 |
new file mode 100644
|
|
|
b5e178 |
index 000000000..4a3a7c94b
|
|
|
b5e178 |
--- /dev/null
|
|
|
b5e178 |
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/simple.pass.sh
|
|
|
b5e178 |
@@ -0,0 +1,6 @@
|
|
|
b5e178 |
+# platform = multi_platform_all
|
|
|
b5e178 |
+# packages = sudo
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+echo 'nobody ALL=/bin/ls "", (!bob,alice) /bin/dog arg, /bin/cat ""' > /etc/sudoers
|
|
|
b5e178 |
+echo 'jen,!fred ALL,!SERVERS = /bin/sh arg' >> /etc/sudoers
|
|
|
b5e178 |
+echo 'nobody ALL=/bin/ls arg arg, (bob,!alice) /bin/dog arg, /bin/cat arg' > /etc/sudoers.d/foo
|
|
|
b5e178 |
diff --git a/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/sudoers_d.fail.sh b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/sudoers_d.fail.sh
|
|
|
b5e178 |
new file mode 100644
|
|
|
b5e178 |
index 000000000..9643a3337
|
|
|
b5e178 |
--- /dev/null
|
|
|
b5e178 |
+++ b/linux_os/guide/system/software/sudo/sudoers_explicit_command_args/tests/sudoers_d.fail.sh
|
|
|
b5e178 |
@@ -0,0 +1,9 @@
|
|
|
b5e178 |
+# platform = multi_platform_all
|
|
|
b5e178 |
+# packages = sudo
|
|
|
b5e178 |
+# remediation = none
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+echo 'nobody ALL=/bin/ls, (!bob,alice) /bin/dog arg, /bin/cat ""' > /etc/sudoers
|
|
|
b5e178 |
+echo 'jen,!fred ALL,!SERVERS = /bin/sh arg' >> /etc/sudoers
|
|
|
b5e178 |
+echo 'nobody ALL=/bin/ls, (bob,!alice) /bin/dog arg, /bin/cat arg' > /etc/sudoers.d/foo
|
|
|
b5e178 |
+
|
|
|
b5e178 |
+echo 'user ALL = ALL' > /etc/sudoers.d/bar
|
|
|
b5e178 |
diff --git a/shared/references/cce-redhat-avail.txt b/shared/references/cce-redhat-avail.txt
|
|
|
b5e178 |
index 4dbec8255..94a116b59 100644
|
|
|
b5e178 |
--- a/shared/references/cce-redhat-avail.txt
|
|
|
b5e178 |
+++ b/shared/references/cce-redhat-avail.txt
|
|
|
b5e178 |
@@ -140,8 +140,6 @@ CCE-83626-2
|
|
|
b5e178 |
CCE-83627-0
|
|
|
b5e178 |
CCE-83628-8
|
|
|
b5e178 |
CCE-83629-6
|
|
|
b5e178 |
-CCE-83631-2
|
|
|
b5e178 |
-CCE-83632-0
|
|
|
b5e178 |
CCE-83633-8
|
|
|
b5e178 |
CCE-83634-6
|
|
|
b5e178 |
CCE-83635-3
|