Audit Dell iDRAC (BMC) versions

Had a task today to audit our Dell iDRACs to determine what firmware they were running and if we had to update them.

With the help of Gitlab CoPilot I quickly whipped up this bash script:

#!/bin/bash
#
# Simple bash script to audit Dell iDRAC firmware versions using SNMP v2c
# CoPilot did 95% of the work, I just added some comments and error handling
#
# INPUT: A file containing a list of hostnames or IPs, one per line, and a valid SNMP public or private community string
# OUTPUT: The hostname and the firmware version of each iDRAC
#
# USAGE: ./dracScanner.sh <hostname_file> '<community_string>'
# EXAMPLE: ./dracScanner.sh hostnames.txt 'public'
#
# NOTE: This script requires snmpwalk be installed
#

# Dell OID for firmware version string
# Found it on Page 57 of this PDF: https://dl.dell.com/topicspdf/dell-opnmang-sw-v8.1_Connectivity%20Guide_en-us.pdf
# Tested on:
# - iDRAC 9 firmware 7.0.x and 7.20.x
# Should work on:
# - iDRAC 8
# - iDRAC 7
OID="1.3.6.1.4.1.674.10892.5.1.1.5.0"

# Check if smnpwalk is installed
if ! command -v snmpwalk &> /dev/null; then
    echo "snmpwalk could not be found. Please install it to use this script."
    exit 1
fi

# Check if the input file is provided
if [ -z "$1" ]; then
    echo "Usage: $0 <hostname_file> <community_string>"
    exit 1
fi

# Check if community string was provided
if [ -z "$2" ]; then
    echo "Usage: $0 <hostname_file> <community_string>"
    exit 1
fi

# Read the file containing hostnames
input_file="$1"

# Check if the file exists
if [ ! -f "$input_file" ]; then
    echo "File not found!"
    exit 1
fi

# Loop through each hostname or IP in the file
while IFS= read -r hostname || [ -n "$hostname" ]; do
    # Ping the host to check if it's alive
    if ping -c 1 "$hostname" &> /dev/null; then
        # Use snmpwalk to get the firmware version
        firmware_version=$(snmpwalk -v2c -c "$2" "$hostname" "$OID" | awk '{print $NF}')

        # Check if the firmware version is empty
        if [ -z "$firmware_version" ]; then
            echo "$hostname: SNMP query returned empty result"
            continue
        fi

        # Remove the quotes around the firmware version
        firmware_version=$(echo "$firmware_version" | tr -d '"')

        # Check if the firmware version is empty, if so, set it to "Unknown"
        if [ -z "$firmware_version" ]; then
            firmware_version="Unknown"
        fi
        
        # Check if the firmware version was retrieved successfully
        if [ -z "$firmware_version" ]; then
            echo "$hostname: Could not retrieve firmware version"
        else
            echo "$hostname: $firmware_version"
        fi
    else
        echo "$hostname is not reachable"
    fi
done < "$input_file"

Sample output:

┌──(kali㉿localhost)-[~/temp]
└─$ ./dracScanner.sh hostnames.txt '<SNMP COMMUNITY STRING>'
host1.mydomain.com: 7.00.00.174
host2.mydomain.com: 4.22.00.53
host3.mydomain.com: 7.00.00.181
host4.mydomain.com: 4.22.00.53
host5.mydomain.com: 4.40.00.00
host6.mydomain.com: 7.00.00.174
host7.mydomain.com: 7.20.10.05

If anyone ends up running this against some of the earlier iDRAC models, and it works, drop me a comment and I’ll update the script header.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.