OpenSCAP (Security Content Automation Protocol) is the industry-standard framework for automated compliance scanning. You will install the OpenSCAP scanner, explore SCAP content (XCCDF/OVAL), run profile evaluations, generate HTML compliance reports, and produce automated remediation scripts. This lab covers the essential tools used in government, banking, and regulated-industry compliance workflows.
Step 1 — SCAP Architecture Overview
SCAP is a suite of interrelated standards:
Component
Purpose
File Type
XCCDF
Security checklists (benchmarks)
*.xml
OVAL
System state definitions
*oval*.xml
CVE
Vulnerability identifiers
—
CVSS
Vulnerability scoring
—
CPE
Platform naming
—
💡 Tip: XCCDF documents reference OVAL definitions. oscap evaluates the XCCDF checklist by running OVAL tests against the live system.
The SCAP Security Guide (SSG) provides pre-built XCCDF benchmarks for Ubuntu, RHEL, and more.
📸 Verified Output:
💡 Tip: The -ds.xml (DataStream) file is self-contained and preferred for automated scanning — it bundles XCCDF, OVAL, and CPE in one file.
Step 3 — Explore SCAP Content with oscap info
Before scanning, inspect available benchmarks and profiles:
📸 Verified Output:
Step 4 — Run an XCCDF Compliance Evaluation
📸 Verified Output:
💡 Tip: Exit code 2 = scan completed but some rules failed (not a tool error). Exit code 1 = tool error.
Step 5 — Parse Results & Generate Summary
📸 Verified Output:
Step 6 — Generate Remediation Script
OpenSCAP can automatically generate a remediation bash script:
📸 Verified Output:
💡 Tip: Review the remediation script before running! Some fixes may not be appropriate for your environment. Run --dry-run or test in a staging container first.
Title Verify that Interactive Boot is Disabled
Rule xccdf_org.ssgproject.content_rule_grub2_disable_interactive_boot
Ident CCE-85825-7
Result pass
Title Ensure /tmp Located On Separate Partition
Rule xccdf_org.ssgproject.content_rule_partition_for_tmp
Ident CCE-82069-4
Result fail
Title Ensure SSH PermitRootLogin is disabled
Rule xccdf_org.ssgproject.content_rule_sshd_disable_root_login
Ident CCE-82177-5
Result fail
Exit code: 2
-rw-r--r-- 1 root root 284K Mar 5 07:12 /tmp/scap-results.xml
-rw-r--r-- 1 root root 1.2M Mar 5 07:12 /tmp/scap-report.html
# Count pass/fail/error from results
oscap xccdf generate guide \
--profile xccdf_org.ssgproject.content_profile_standard \
/usr/share/xml/scap/ssg/content/ssg-ubuntu2204-ds.xml \
> /tmp/scap-guide.html 2>/dev/null
# Parse XML results for summary
python3 - << 'EOF'
import xml.etree.ElementTree as ET
tree = ET.parse('/tmp/scap-results.xml')
root = tree.getroot()
ns = {'xccdf': 'http://checklists.nist.gov/xccdf/1.2'}
results = {}
for rr in root.findall('.//xccdf:rule-result', ns):
result = rr.find('xccdf:result', ns)
if result is not None:
r = result.text.strip()
results[r] = results.get(r, 0) + 1
print("=== SCAP Compliance Summary ===")
for k, v in sorted(results.items()):
print(f" {k:20s}: {v:4d}")
total = sum(results.values())
passed = results.get('pass', 0)
print(f"\n Total rules : {total}")
print(f" Score : {passed}/{total} ({100*passed//total}%)")
EOF
312 /tmp/cis-remediation.sh
#!/bin/bash
###############################################################################
#
# Bash Remediation Script for Standard System Security Profile for Ubuntu 22.04
#
# Profile Description:
# This profile contains rules to ensure standard security baseline
# of a Ubuntu 22.04 system.
#
# Profile ID: xccdf_org.ssgproject.content_profile_standard
# Benchmark ID: xccdf_org.ssgproject.content_benchmark_Ubuntu_22-04
# Benchmark Version: 0.1.69
# XCCDF Version: 1.2
#
###############################################################################
set -e
###############################################################################
# BEGIN fix (urn:xccdf:fix:script:sh) for 'xccdf_org.ssgproject.content_rule_sshd_disable_root_login'
###############################################################################
# Remediation is applicable only in certain platforms
if rpm -q --quiet openssh-server 2>/dev/null || dpkg -l openssh-server &>/dev/null; then
# Download Ubuntu OVAL definitions (simulated — file would be from Ubuntu security)
# In production: wget https://security-metadata.canonical.com/oval/com.ubuntu.$(lsb_release -cs).usn.oval.xml.bz2
# Create minimal OVAL test to demonstrate the concept
cat > /tmp/demo.oval.xml << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<oval_definitions xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<generator>
<product_name>Demo OVAL</product_name>
<schema_version>5.11</schema_version>
<timestamp>2024-01-01T00:00:00</timestamp>
</generator>
<definitions/>
<tests/>
<objects/>
<states/>
</oval_definitions>
EOF
oscap oval eval /tmp/demo.oval.xml 2>&1 | head -5
echo "OVAL scanning capability confirmed"
# Show how to scan with real Ubuntu OVAL
echo ""
echo "=== Production CVE Scan Command ==="
echo "wget -q https://security-metadata.canonical.com/oval/com.ubuntu.jammy.usn.oval.xml.bz2"
echo "bunzip2 com.ubuntu.jammy.usn.oval.xml.bz2"
echo "oscap oval eval --report oval-report.html com.ubuntu.jammy.usn.oval.xml"