امن‌سازی Oracle Linux 9 (مقاله بیست و هفتم): مدیریت دسترسی فایل‌های حسابرسی (Auditd File Access)

در قسمت قبل

پیکربندی قوانین حسابرسی

انجام شد.

۱. الزامات CIS Benchmark (بخش 6.3.4)

این مقاله به بررسی و پیاده‌سازی بندهای مربوط به امنیت فایل‌ها و ابزارهای Audit بر اساس استاندارد CIS می‌پردازد:

  • 6.3.4.1 Ensure the audit log file directory mode is configured (Automated)
  • 6.3.4.2 Ensure audit log files mode is configured (Automated)
  • 6.3.4.3 Ensure audit log files owner is configured (Automated)
  • 6.3.4.4 Ensure audit log files group owner is configured (Automated)
  • 6.3.4.5 Ensure audit configuration files mode is configured (Automated)
  • 6.3.4.6 Ensure audit configuration files owner is configured (Automated)
  • 6.3.4.7 Ensure audit configuration files group owner is configured (Automated)
  • 6.3.4.8 Ensure audit tools mode is configured (Automated)
  • 6.3.4.9 Ensure audit tools owner is configured (Automated)
  • 6.3.4.10 Ensure audit tools group owner is configured (Automated)

۲. مفهوم و دلیل (Concept & Rationale)

لاگ‌های حسابرسی (Audit Logs)، فایل‌های پیکربندی آن و ابزارهای مرتبط با auditd حاوی اطلاعات بسیار حساسی از رویدادهای سیستم، فرآیندها و تلاش‌های ورود به سیستم هستند. اگر یک مهاجم یا کاربر غیرمجاز بتواند این فایل‌ها را بخواند، ممکن است به اطلاعات مفیدی برای نفوذ دست یابد. همچنین، اگر بتواند آن‌ها را تغییر داده یا پاک کند، می‌تواند ردپای خود را مخفی کند. بنابراین، محدود کردن دقیق مالکیت (Owner/Group) به root و محدود کردن سطح دسترسی (Permissions) برای این فایل‌ها و ابزارها یک الزام قطعی است.

۳. بررسی سازگاری با پایگاه داده Oracle (RAC & Grid)

اعمال این محدودیت‌ها روی دایرکتوری /var/log/audit، فایل‌های /etc/audit/ و ابزارهای سیستمی (مثل auditctl) هیچ‌گونه تداخلی با عملکرد Oracle Database و Oracle Grid Infrastructure ندارد. اوراکل لاگ‌های حسابرسی مخصوص به خود را در مسیرهای مجزا (مانند adump در ساختار $ORACLE_BASE) ذخیره می‌کند و فرآیندهای دیتابیس (با مالکیت کاربر oracle یا grid) نیازی به خواندن یا تغییر لاگ‌ها و ابزارهای حسابرسی سیستم‌عامل ندارند.

۴. نحوه بررسی وضعیت فعلی (Audit Script)

اسکریپت زیر وضعیت مالکیت و سطح دسترسی دایرکتوری لاگ‌ها، فایل‌های لاگ، فایل‌های پیکربندی و ابزارهای audit را بررسی می‌کند:

لینک این اسکریپت در github:

modules/audit_27_Auditd_File_Access.sh

در صورتی که با bash script  آشنا نیستید، می توانید به آموزشی که برای دیتابیس ادمین ها در سایت گذاشته ام مراجعه کنید.

Bash for Oracle DBAs

#!/bin/bash
# Script: audit27.sh
# Purpose: Audit permissions and ownership of auditd files and tools (CIS 6.3.4)

echo "=========================================================================="
echo " CIS Requirement: Auditd File Access (CIS 6.3.4)"
echo " - Ensure /var/log/audit is 0750 or 0700"
echo " - Ensure log files and config files are 0640 or 0600, owned by root"
echo " - Ensure audit tools are securely configured"
echo "=========================================================================="

AUDIT_STATUS="PASS"

check_perms() {
    local desc="$1"
    local result="$2"
    if [ -z "$result" ]; then
        echo "[PASS] $desc"
    else
        echo "[FAIL] $desc"
        echo "$result" | sed 's/^/       -> /'
        AUDIT_STATUS="FAIL"
    fi
}

# 1. Directory Mode
RES=$(stat -c "%n - %a" /var/log/audit 2>/dev/null | grep -vE "(750|700)")
check_perms "/var/log/audit directory mode" "$RES"

# 2. Log Files
RES=$(find /var/log/audit -type f \( ! -perm 0600 -a ! -perm 0640 \) 2>/dev/null)
check_perms "/var/log/audit files mode (0600/0640)" "$RES"

RES=$(find /var/log/audit -type f ! -user root -o ! -group root 2>/dev/null)
check_perms "/var/log/audit files ownership (root:root)" "$RES"

# 3. Config Files
RES=$(find /etc/audit -type f \( ! -perm 0640 -a ! -perm 0600 \) 2>/dev/null)
check_perms "/etc/audit config files mode (0640/0600)" "$RES"

RES=$(find /etc/audit -type f ! -user root -o ! -group root 2>/dev/null)
check_perms "/etc/audit config files ownership (root:root)" "$RES"

# 4. Tools
TOOLS=("/sbin/auditctl" "/sbin/aureport" "/sbin/ausearch" "/sbin/autrace" "/sbin/auditd" "/sbin/augenrules")
TOOL_FAIL=""
for tool in "${TOOLS[@]}"; do
    if [ -e "$tool" ]; then
        MODE=$(stat -c "%a" "$tool")
        OWNER=$(stat -c "%U:%G" "$tool")
        if [[ ! "$MODE" =~ ^(755|750)$ ]] || [[ "$OWNER" != "root:root" ]]; then
            TOOL_FAIL="$TOOL_FAIL$tool (Mode:$MODE, Owner:$OWNER)\n"
        fi
    fi
done
check_perms "Audit tools permissions and ownership" "$(echo -e "$TOOL_FAIL" | sed '/^$/d')"

echo "--------------------------------------------------------------------------"
if [ "$AUDIT_STATUS" = "PASS" ]; then
    echo " Final Audit Status: PASS"
else
    echo " Final Audit Status: FAIL"
fi
echo "=========================================================================="

۵. نحوه اعمال تنظیمات (Remediation Bash Script)

اسکریپت زیر تمامی مجوزها و مالکیت‌ها را بر اساس الزامات CIS تصحیح می‌کند:

لینک این اسکریپت در github:

modules/remediate_27_Auditd_File_Access.sh

#!/bin/bash
# Script: remediate_cis_6_3_4.sh
# Purpose: Fix permissions and ownership for auditd files and tools

if [ "$EUID" -ne 0 ]; then echo "Please run as root"; exit 1; fi

echo -e "\n[+] Remediating CIS 6.3.4..."

# 6.3.4.1 - 6.3.4.4: Log files and directory
echo "[*] Securing /var/log/audit and log files..."
chown root:root /var/log/audit
chmod 0750 /var/log/audit
find /var/log/audit -type f -exec chmod 0640 {} \;
find /var/log/audit -type f -exec chown root:root {} \;

# 6.3.4.5 - 6.3.4.7: Config files
echo "[*] Securing /etc/audit/ configuration files..."
find /etc/audit -type f -exec chown root:root {} \;
find /etc/audit -type f -exec chmod 0640 {} \;
chown root:root /etc/audit/auditd.conf 2>/dev/null
chmod 0640 /etc/audit/auditd.conf 2>/dev/null

# 6.3.4.8 - 6.3.4.10: Audit tools
echo "[*] Securing audit tools..."
TOOLS=("/sbin/auditctl" "/sbin/aureport" "/sbin/ausearch" "/sbin/autrace" "/sbin/auditd" "/sbin/augenrules")
for tool in "${TOOLS[@]}"; do
    if [ -e "$tool" ]; then
        chown root:root "$tool"
        chmod 0755 "$tool"
    fi
done

echo "[+] Remediation applied successfully."

در قسمت بعد به سراغ:

مدیریت دسترسی فایل‌های سیستم

می رویم.