Introduction

Website security is a critical aspect of server administration. Regular vulnerability assessments help identify potential security risks before they can be exploited. One of the most popular open-source tools for web server security auditing is Nikto, a powerful web server scanner that performs comprehensive tests against web servers to detect outdated software, insecure files, misconfigurations, and other common vulnerabilities.

For hosting providers and server administrators managing multiple cPanel accounts, manually scanning each domain can be time-consuming. In this guide, we will walk through the installation of Nikto and demonstrate how to automate vulnerability scanning for all cPanel-hosted domains using a simple shell script.

Installing Nikto

Download the Nikto package:

cd /usr/local/src
wget https://cirt.net/nikto/nikto-2.1.5.tar.gz

Extract the downloaded archive:

tar -xzf nikto-2.1.5.tar.gz

Navigate to the Nikto directory:

cd nikto-*

You can perform a vulnerability scan on a single domain using the following command:

/bin/perl /usr/local/src/nikto-2.1.5/nikto.pl -host <hostIPaddress> -vhost domain.tld -p 80

Shell Script to Scan All cPanel Domains

The following script automatically scans domains hosted on the same server and generates individual Nikto reports for each domain.

#!/bin/bash
for vhost in `cat /etc/trueuserdomains|cut -d : -f1`;
do
  echo "+++++++";
  echo $vhost;
  echo "+++++++";

  digip=`dig +short $vhost`
  check_serverip=$(/scripts/ipusage |grep $digip|awk '{print $1}')

  if [[ $digip == $check_serverip ]];
  then
    echo -e "Creating tmp directory for $vhost "
    mkdir -p /tmp/niktoscan/$vhost

    /bin/perl /usr/local/src/nikto-2.1.5/nikto.pl \
      -host $digip \
      -vhost $vhost \
      -p 80 > /tmp/niktoscan/$vhost/niktoscanreport.txt
  else
    echo "Both Result doesn't match"
  fi
done

How the Script Works

  1. Reads all domains from the /etc/trueuserdomains file.
  2. Resolves each domain to its IP address using dig.
  3. Verifies whether the domain points to the current server.
  4. Creates a dedicated directory for storing scan results.
  5. Executes a Nikto scan for each eligible domain.
  6. Saves the output to a separate report file for easier review and analysis.

Report Location

The generated scan reports will be stored in:

/tmp/niktoscan/domain.tld/niktoscanreport.txt

Each domain receives its own directory and report file, making it easier to review findings individually.

Benefits of Automated Nikto Scanning

  • Scan multiple hosted domains with a single command.
  • Save vulnerability reports separately for each website.
  • Quickly identify outdated software and insecure configurations.
  • Reduce manual effort for server administrators and hosting providers.
  • Improve overall server security through regular assessments.

Conclusion

Automating Nikto scans across cPanel accounts is an efficient way to maintain the security of multiple hosted websites. By combining Nikto’s powerful vulnerability detection capabilities with a simple shell script, administrators can perform regular security audits with minimal effort.

After the scans are completed, carefully review the generated reports and prioritize remediation of any critical or high-risk findings. Regular vulnerability scanning, timely patching, and proactive security monitoring are essential practices for maintaining a secure hosting environment and protecting customer websites from potential threats.

Leave a Reply