[PATCH 07/13] OVAL + remediation for sshd_disable_root_login

Shawn Wells shawn.d.wells at gmail.com
Sat Sep 7 19:23:10 UTC 2013


-------------- next part --------------
>From 57658ac62cc809a9d65115c4e35c1020d1ef663e Mon Sep 17 00:00:00 2001
From: Shawn Wells <shawn at redhat.com>
Date: Sat, 7 Sep 2013 12:05:39 -0400
Subject: [PATCH 07/13] OVAL + remediation for sshd_disable_root_login
 - Updated OVAL file & id to match XCCDF
 - filename --> filepath
 - Added remediation

Remediation testing:
[root at rhel6 checks]# grep PermitRootLogin /etc/ssh/sshd_config
PermitRootLogin yes
[root at rhel6 checks]# ./testcheck.py sshd_disable_root_login.xml
Evaluating with OVAL tempfile : /tmp/sshd_disable_root_loginFVOkWd.xml
Writing results to : /tmp/sshd_disable_root_loginFVOkWd.xml-results
Definition oval:scap-security-guide.testing:def:159: false
Definition oval:scap-security-guide.testing:def:127: false
Definition oval:scap-security-guide.testing:def:125: false
Evaluation done.
[root at rhel6 checks]# bash ../fixes/bash/sshd_disable_root_login.sh
[root at rhel6 checks]# ./testcheck.py sshd_disable_root_login.xml
Evaluating with OVAL tempfile : /tmp/sshd_disable_root_login383Dnq.xml
Writing results to : /tmp/sshd_disable_root_login383Dnq.xml-results
Definition oval:scap-security-guide.testing:def:159: true
Definition oval:scap-security-guide.testing:def:127: false
Definition oval:scap-security-guide.testing:def:125: false
Evaluation done.
---
 RHEL6/input/checks/sshd_disable_root_login.xml    |   30 ++++++++++++++++++++
 RHEL6/input/checks/sshd_permitrootlogin_no.xml    |   31 ---------------------
 RHEL6/input/fixes/bash/sshd_disable_root_login.sh |    5 +++
 RHEL6/input/services/ssh.xml                      |    2 +-
 4 files changed, 36 insertions(+), 32 deletions(-)
 create mode 100644 RHEL6/input/checks/sshd_disable_root_login.xml
 delete mode 100644 RHEL6/input/checks/sshd_permitrootlogin_no.xml
 create mode 100644 RHEL6/input/fixes/bash/sshd_disable_root_login.sh

diff --git a/RHEL6/input/checks/sshd_disable_root_login.xml b/RHEL6/input/checks/sshd_disable_root_login.xml
new file mode 100644
index 0000000..58e52a3
--- /dev/null
+++ b/RHEL6/input/checks/sshd_disable_root_login.xml
@@ -0,0 +1,30 @@
+<def-group>
+  <definition class="compliance" id="sshd_disable_root_login" version="1">
+    <metadata>
+      <title>Disable root Login via SSH</title>
+      <affected family="unix">
+        <platform>Red Hat Enterprise Linux 6</platform>
+      </affected>
+      <description>Root login via SSH should be disabled (and dependencies are
+      met)</description>
+      <reference source="MED" ref_id="20130813" ref_url="test_attestation" />
+    </metadata>
+    <criteria comment="SSH is not being used or conditions are met"
+    operator="OR">
+      <extend_definition comment="sshd service is disabled"
+      definition_ref="service_sshd_disabled" />
+      <criterion comment="Check PermitRootLogin in /etc/ssh/sshd_config"
+      test_ref="test_sshd_permitrootlogin_no" />
+    </criteria>
+  </definition>
+  <ind:textfilecontent54_test check="all" check_existence="none_exist"
+  comment="Tests the value of the PermitRootLogin[\s]*(&lt;:nocomment:&gt;*) setting in the /etc/ssh/sshd_config file"
+  id="test_sshd_permitrootlogin_no" version="1">
+    <ind:object object_ref="obj_sshd_permitrootlogin_no" />
+  </ind:textfilecontent54_test>
+  <ind:textfilecontent54_object id="obj_sshd_permitrootlogin_no" version="1">
+    <ind:filepath>/etc/ssh/sshd_config</ind:filepath>
+    <ind:pattern operation="pattern match">^[\s]*(?i)PermitRootLogin[\s]+yes[\s]*$</ind:pattern>
+    <ind:instance datatype="int">1</ind:instance>
+  </ind:textfilecontent54_object>
+</def-group>
diff --git a/RHEL6/input/checks/sshd_permitrootlogin_no.xml b/RHEL6/input/checks/sshd_permitrootlogin_no.xml
deleted file mode 100644
index 37f255f..0000000
--- a/RHEL6/input/checks/sshd_permitrootlogin_no.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<def-group>
-  <definition class="compliance" id="sshd_permitrootlogin_no" version="1">
-    <metadata>
-      <title>Disable root Login via SSH</title>
-      <affected family="unix">
-        <platform>Red Hat Enterprise Linux 6</platform>
-      </affected>
-      <description>Root login via SSH should be disabled (and dependencies are
-      met)</description>
-      <reference source="MED" ref_id="20130813" ref_url="test_attestation" />
-    </metadata>
-    <criteria comment="SSH is not being used or conditions are met"
-    operator="OR">
-      <extend_definition comment="sshd service is disabled"
-      definition_ref="service_sshd_disabled" />
-      <criterion comment="Check PermitRootLogin in /etc/ssh/sshd_config"
-      test_ref="test_sshd_permitrootlogin_no" />
-    </criteria>
-  </definition>
-  <ind:textfilecontent54_test check="all" check_existence="none_exist"
-  comment="Tests the value of the PermitRootLogin[\s]*(&lt;:nocomment:&gt;*) setting in the /etc/ssh/sshd_config file"
-  id="test_sshd_permitrootlogin_no" version="1">
-    <ind:object object_ref="obj_sshd_permitrootlogin_no" />
-  </ind:textfilecontent54_test>
-  <ind:textfilecontent54_object id="obj_sshd_permitrootlogin_no" version="1">
-    <ind:path>/etc/ssh</ind:path>
-    <ind:filename>sshd_config</ind:filename>
-    <ind:pattern operation="pattern match">^[\s]*(?i)PermitRootLogin[\s]+yes[\s]*$</ind:pattern>
-    <ind:instance datatype="int">1</ind:instance>
-  </ind:textfilecontent54_object>
-</def-group>
diff --git a/RHEL6/input/fixes/bash/sshd_disable_root_login.sh b/RHEL6/input/fixes/bash/sshd_disable_root_login.sh
new file mode 100644
index 0000000..ffd8262
--- /dev/null
+++ b/RHEL6/input/fixes/bash/sshd_disable_root_login.sh
@@ -0,0 +1,5 @@
+grep -q ^PermitRootLogin /etc/ssh/sshd_config && \
+  sed -i "s/PermitRootLogin.*/PermitRootLogin no/g" /etc/ssh/sshd_config
+if ! [ $? -eq 0 ]; then
+    echo "PermitRootLogin "no >> /etc/ssh/sshd_config
+fi
diff --git a/RHEL6/input/services/ssh.xml b/RHEL6/input/services/ssh.xml
index c4a5ffc..a67ddd1 100644
--- a/RHEL6/input/services/ssh.xml
+++ b/RHEL6/input/services/ssh.xml
@@ -263,7 +263,7 @@ privileged commands on the system
 and also allows direct attack attempts on root's password.
 </rationale>
 <ident cce="27100-7" />
-<oval id="sshd_permitrootlogin_no" />
+<oval id="sshd_disable_root_login" />
 <ref nist="AC-6(2),IA-2(1)" disa="770" />
 <tested by="DS" on="20121024"/>
 </Rule>
-- 
1.7.1



More information about the scap-security-guide mailing list