securing oracle linux 9 part 8 configuring command line warning banners

<p>In the previous part</p>
<h1><a href="/fa/os/os-infra/securing-oracle-linux-9-part-7-configuring-system-wide-crypto-policy-fa">Configuring the System-wide Crypto Policy</a></h1>
<p>was completed.</p>

<p><strong>1. CIS Benchmark Requirements (Section 1.7)</strong></p>
<p>This section focuses on implementing and properly configuring legal warning banners for system logins, and includes the following CIS controls:</p>
<ul>
<li>1.7.1 Ensure message of the day is configured properly (Automated)</li>
<li>1.7.2 Ensure local login warning banner is configured properly (Automated)</li>
<li>1.7.3 Ensure remote login warning banner is configured properly (Automated)</li>
<li>1.7.4 Ensure access to /etc/motd is configured (Automated)</li>
<li>1.7.5 Ensure access to /etc/issue is configured (Automated)</li>
<li>1.7.6 Ensure access to /etc/issue.net is configured (Automated)</li>
</ul>

<p><strong>2. Concept &amp; Rationale</strong></p>
<p>Displaying warning messages to users who connect to the system, whether locally or remotely, is a critical legal and security requirement. These banners inform users that the system is monitored and that unauthorized access is subject to legal action.</p>
<ul>
<li><strong>/etc/issue:</strong> The contents of this file are displayed before the login prompt on local terminals (Console/TTY).</li>
<li><strong>/etc/issue.net:</strong> The contents of this file are shown before login for remote connections such as SSH.</li>
<li><strong>/etc/motd (Message of the Day):</strong> The contents of this file are displayed after successful authentication.</li>
<li><strong>Information Leakage:</strong> It is important not to use control characters such as \m, \r, \s, and \v in these files, because they may reveal exact operating system and kernel information.</li>
<li><strong>Permissions:</strong> To prevent ordinary users or malware from modifying these messages, the files must be owned by root:root (UID 0 and GID 0) and their permissions must be set exactly to 0644.</li>
</ul>

<p><strong>3. Oracle Database Compatibility Check (RAC, ASM, Grid)</strong></p>
<p>Configuring warning banners is a security measure at the operating system's interactive access layer.</p>
<ul>
<li><strong>No Interference:</strong> Changing the contents of /etc/issue or /etc/motd does not interfere with Oracle Database, Grid Infrastructure services, inter-node communication, or installation and patching processes such as OUI and OPatch.</li>
<li><strong>Automated Scripts:</strong> Oracle tools running in the background in non-interactive shells are not affected by these messages. These changes are completely safe for Oracle RAC and standalone environments.</li>
</ul>

<p><strong>4. Checking the Current Status (Audit Script)</strong></p>
<p>This script verifies file presence and permissions, and also ensures that sensitive operating system information is not leaked through the banners.</p>
<p>GitHub link:</p>
<p><a href="https://github.com/vahiddb/ol9-cis-hardening/blob/main/modules/audit_08_Warning_Banners.sh">modules/audit_08_Warning_Banners.sh</a></p>
<p dir="rtl" lang="fa">If you are not familiar with bash scripts, you can refer to the training material I have published on the site for database administrators.</p>
<h1><a href="/fa/os/os-infra/bash-for-oracle-dbas-part-1-conditions-in-bash-if-test-fa">Bash for Oracle DBAs</a></h1>
<p>&nbsp;</p>

<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">#!/bin/bash</span><br /><span style="font-family: 'courier new', courier, monospace;"># Script: audit_cis_1_7.sh</span><br /><span style="font-family: 'courier new', courier, monospace;"># Purpose: Audit Warning Banners Content and Permissions</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">echo -e "\n[+] Auditing CIS 1.7: Command Line Warning Banners..."</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">FILES=("/etc/motd" "/etc/issue" "/etc/issue.net")</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">for FILE in "${FILES[@]}"; do</span><br /><span style="font-family: 'courier new', courier, monospace;">    echo "[*] Checking $FILE..."</span><br /><span style="font-family: 'courier new', courier, monospace;">    if [ -e "$FILE" ]; then</span><br /><span style="font-family: 'courier new', courier, monospace;">        # Check permissions and ownership (CIS 1.7.4 - 1.7.6)</span><br /><span style="font-family: 'courier new', courier, monospace;">        STAT=$(stat -c "%a %U %G" "$FILE")</span><br /><span style="font-family: 'courier new', courier, monospace;">        if [ "$STAT" == "644 root root" ]; then</span><br /><span style="font-family: 'courier new', courier, monospace;">            echo "    [OK] Permissions and ownership are correct ($STAT)."</span><br /><span style="font-family: 'courier new', courier, monospace;">        else</span><br /><span style="font-family: 'courier new', courier, monospace;">            echo "    [!] WARNING: Incorrect permissions/ownership. Current: $STAT. Expected: 644 root root."</span><br /><span style="font-family: 'courier new', courier, monospace;">        fi</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">        # Check for OS information leaks (CIS 1.7.1 - 1.7.3</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">#!/bin/bash</span><br /><span style="font-family: 'courier new', courier, monospace;"># Script: audit8.sh</span><br /><span style="font-family: 'courier new', courier, monospace;"># Purpose: Audit Command Line Warning Banners (CIS 1.7)</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">echo "=========================================================================="</span><br /><span style="font-family: 'courier new', courier, monospace;">echo " CIS Requirement: 1.7 Command Line Warning Banners"</span><br /><span style="font-family: 'courier new', courier, monospace;">echo " - Ensure /etc/motd, /etc/issue, and /etc/issue.net are configured."</span><br /><span style="font-family: 'courier new', courier, monospace;">echo " - Ensure permissions are 644 and ownership is root:root."</span><br /><span style="font-family: 'courier new', courier, monospace;">echo " - Ensure no OS or kernel information is leaked."</span><br /><span style="font-family: 'courier new', courier, monospace;">echo " Oracle Context:"</span><br /><span style="font-family: 'courier new', courier, monospace;">echo " - Modifying warning banners has NO impact on Oracle Database/RAC."</span><br /><span style="font-family: 'courier new', courier, monospace;">echo " - Standard banners do not interfere with Oracle automated tasks."</span><br /><span style="font-family: 'courier new', courier, monospace;">echo "=========================================================================="</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">FAIL_COUNT=0</span><br /><span style="font-family: 'courier new', courier, monospace;">FILES=("/etc/motd" "/etc/issue" "/etc/issue.net")</span><br /><span style="font-family: 'courier new', courier, monospace;">OS_NAME=$(grep '^ID=' /etc/os-release | cut -d= -f2 | sed -e 's/"//g')</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">echo -e "\n[*] Auditing Warning Banners and Permissions..."</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">for FILE in "${FILES[@]}"; do</span><br /><span style="font-family: 'courier new', courier, monospace;">    echo "[*] Checking $FILE..."</span><br /><span style="font-family: 'courier new', courier, monospace;">    if [ -e "$FILE" ]; then</span><br /><span style="font-family: 'courier new', courier, monospace;">        # Check permissions and ownership</span><br /><span style="font-family: 'courier new', courier, monospace;">        STAT=$(stat -c "%a %U %G" "$FILE")</span><br /><span style="font-family: 'courier new', courier, monospace;">        if [ "$STAT" == "644 root root" ]; then</span><br /><span style="font-family: 'courier new', courier, monospace;">            echo -e "  \e[32m[PASS]\e[0m Permissions and ownership are correct ($STAT)."</span><br /><span style="font-family: 'courier new', courier, monospace;">        else</span><br /><span style="font-family: 'courier new', courier, monospace;">            echo -e "  \e[31m[FAIL]\e[0m Incorrect permissions/ownership. Current: $STAT (Expected: 644 root root)."</span><br /><span style="font-family: 'courier new', courier, monospace;">            FAIL_COUNT=$((FAIL_COUNT + 1))</span><br /><span style="font-family: 'courier new', courier, monospace;">        fi</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">        # Check for OS information leaks</span><br /><span style="font-family: 'courier new', courier, monospace;">        if grep -E -i "(\\\v|\\\r|\\\m|\\\s|$OS_NAME)" "$FILE" &gt; /dev/null 2&gt;&amp;1; then</span><br /><span style="font-family: 'courier new', courier, monospace;">            echo -e "  \e[31m[FAIL]\e[0m OS or Kernel information leakage detected."</span><br /><span style="font-family: 'courier new', courier, monospace;">            FAIL_COUNT=$((FAIL_COUNT + 1))</span><br /><span style="font-family: 'courier new', courier, monospace;">        else</span><br /><span style="font-family: 'courier new', courier, monospace;">            echo -e "  \e[32m[PASS]\e[0m No OS information leaks detected."</span><br /><span style="font-family: 'courier new', courier, monospace;">        fi</span><br /><span style="font-family: 'courier new', courier, monospace;">    else</span><br /><span style="font-family: 'courier new', courier, monospace;">        echo -e "  \e[31m[FAIL]\e[0m File $FILE does not exist."</span><br /><span style="font-family: 'courier new', courier, monospace;">        FAIL_COUNT=$((FAIL_COUNT + 1))</span><br /><span style="font-family: 'courier new', courier, monospace;">    fi</span><br /><span style="font-family: 'courier new', courier, monospace;">done</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">if [ "$FAIL_COUNT" -eq 0 ]; then</span><br /><span style="font-family: 'courier new', courier, monospace;">    echo -e "\n\e[32m[+] AUDIT RESULT: PASS\e[0m"</span><br /><span style="font-family: 'courier new', courier, monospace;">else</span><br /><span style="font-family: 'courier new', courier, monospace;">    echo -e "\n\e[31m[-] AUDIT RESULT: FAIL ($FAIL_COUNT issues found)\e[0m"</span><br /><span style="font-family: 'courier new', courier, monospace;">fi</span></p>

<h2 dir="rtl" lang="fa">5. Applying the Configuration (Remediation Bash Script)</h2>
<p dir="rtl" lang="fa">The following script configures the standard banner content in a consistent way and restricts file permissions.</p>
<p dir="rtl" lang="fa">GitHub link:</p>
<p dir="rtl" lang="fa"><a href="https://github.com/vahiddb/ol9-cis-hardening/blob/main/modules/remediate_08_Warning_Banners.sh">modules/remediate_08_Warning_Banners.sh</a></p>
<p dir="rtl" lang="fa">&nbsp;</p>

<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">#!/bin/bash</span><br /><span style="font-family: 'courier new', courier, monospace;"># Script: remediation8.sh</span><br /><span style="font-family: 'courier new', courier, monospace;"># Purpose: Configure Warning Banners and Permissions (CIS 1.7)</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">if [ "$EUID" -ne 0 ]; then </span><br /><span style="font-family: 'courier new', courier, monospace;">    echo "Please run as root"</span><br /><span style="font-family: 'courier new', courier, monospace;">    exit 1</span><br /><span style="font-family: 'courier new', courier, monospace;">fi</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">echo "=========================================================================="</span><br /><span style="font-family: 'courier new', courier, monospace;">echo " Applying Remediation for CIS 1.7 (Command Line Warning Banners)"</span><br /><span style="font-family: 'courier new', courier, monospace;">echo " Oracle Context: Safe to apply. No impact on DB/RAC operations."</span><br /><span style="font-family: 'courier new', courier, monospace;">echo "=========================================================================="</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">BANNER_TEXT="Authorized uses only. All activity may be monitored and reported.</span><br /><span style="font-family: 'courier new', courier, monospace;">Individuals using this computer system without authority, or in excess of their authority, are subject to having all of their activities on this system monitored and recorded by system personnel.</span><br /><span style="font-family: 'courier new', courier, monospace;">Anyone using this system expressly consents to such monitoring and is advised that if such monitoring reveals possible evidence of criminal activity, system personnel may provide the evidence of such monitoring to law enforcement officials."</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">FILES=("/etc/motd" "/etc/issue" "/etc/issue.net")</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">for FILE in "${FILES[@]}"; do</span><br /><span style="font-family: 'courier new', courier, monospace;">    # 1. Update Content</span><br /><span style="font-family: 'courier new', courier, monospace;">    echo "$BANNER_TEXT" &gt; "$FILE"</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">    # 2. Set Ownership and Permissions</span><br /><span style="font-family: 'courier new', courier, monospace;">    chown root:root "$FILE"</span><br /><span style="font-family: 'courier new', courier, monospace;">    chmod 0644 "$FILE"</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">    echo -e "  \e[32m[OK]\e[0m Configured content and permissions for $FILE."</span><br /><span style="font-family: 'courier new', courier, monospace;">done</span></p>
<p dir="ltr" style="text-align: left;"><span style="font-family: 'courier new', courier, monospace;">echo -e "\n\e[32m[+] REMEDIATION APPLIED SUCCESSFULLY\e[0m"</span></p>

<p>In the next part</p>
<h1><a href="/fa/os/os-infra/securing-oracle-linux-9-part-9-configuring-and-managing-gnome-display-manager-gdm-fa">Configuring and Managing GNOME Display Manager (GDM)</a></h1>
<p>we will continue.</p>
<p>&nbsp;</p>