Detecting and removing malware using VirusTotal integration

Wazuh is capable of connecting to external APIs and alerting tools such as VirusTotal. In this PoC, you scan a directory for changes and make the wazuh-integratord component query VirusTotal for threat results using the VirusTotal API. Once VirusTotal identifies a file as a threat, Wazuh is configured to trigger an active response to remove the file from the system.

For more information on this service, check the VirusTotal integration section of the documentation.


Configure your environment as follows to test the PoC.

  1. Enable File Integrity Monitoring in /var/ossec/etc/ossec.conf at the Ubuntu 20 endpoint to monitor /root in real time.

        <directories whodata="yes">/root</directories>
  2. Add the following rules to /var/ossec/etc/rules/local_rules.xml at the Wazuh manager. These rules are to alert about changes in /root directories detected by FIM scans.

    <group name="syscheck,pci_dss_11.5,nist_800_53_SI.7,">
        <!-- Rules for Linux systems -->
        <rule id="100200" level="7">
            <field name="file">/root</field>
            <description>File modified in /root directory.</description>
        <rule id="100201" level="7">
            <field name="file">/root</field>
            <description>File added to /root directory.</description>
  3. Add the following configuration to the /var/ossec/etc/ossec.conf file at the Wazuh manager, replacing YOUR_VIRUS_TOTAL_API_KEY with your own VirusTotal API key. This enables the Virustotal integration, triggering a VirusTotal query whenever any of rules ID 100200 and 100201 are tripped.

        <api_key>YOUR_VIRUS_TOTAL_API_KEY</api_key> <!-- Replace with your VirusTotal API key -->

    If you have a premium VirusTotal API key, with high frequency of queries allowed, you can add more rules besides these two. You could also add to your rules more directories to monitor besides /root.

  4. Create the /var/ossec/active-response/bin/ active response script at the Ubuntu 20 endpoint for the removal of a file from the system.

    LOCAL=`dirname $0`;
    cd $LOCAL
    cd ../
    read INPUT_JSON
    FILENAME=$(echo $INPUT_JSON | jq -r
    COMMAND=$(echo $INPUT_JSON | jq -r .command)
    #------------------------ Analyze command -------------------------#
    if [ ${COMMAND} = "add" ]
     # Send control message to execd
     printf '{"version":1,"origin":{"name":"remove-threat","module":"active-response"},"command":"check_keys", "parameters":{"keys":[]}}\n'
     read RESPONSE
     COMMAND2=$(echo $RESPONSE | jq -r .command)
     if [ ${COMMAND2} != "continue" ]
      echo "`date '+%Y/%m/%d %H:%M:%S'` $0: $INPUT_JSON Remove threat active response aborted" >> ${LOG_FILE}
      exit 0;
    # Removing file
    rm -f $FILENAME
    if [ $? -eq 0 ]; then
     echo "`date '+%Y/%m/%d %H:%M:%S'` $0: $INPUT_JSON Successfully removed threat" >> ${LOG_FILE}
     echo "`date '+%Y/%m/%d %H:%M:%S'` $0: $INPUT_JSON Error removing threat" >> ${LOG_FILE}
    exit 0;
  5. Change /var/ossec/active-response/bin/ owner and file permissions.

    # chmod 750 /var/ossec/active-response/bin/
    # chown root:wazuh /var/ossec/active-response/bin/
  6. Run apt-get install jq -y if jq is missing. This allows the script to process the JSON input.

  7. Append the following blocks to /var/ossec/etc/ossec.conf at the Wazuh manager. This enables an active response and call when VirusTotal query results for threats are positive matches.

  8. Edit /var/ossec/etc/decoders/local_decoder.xml at the Wazuh manager and add the following active response decoder configuration.

    <decoder name="ar_log_fields">
        <regex offset="after_parent">^(\S+) Removed threat located at (\S+)</regex>
        <order>script_name, path</order>
  9. Add rules to the /var/ossec/etc/rules/local_rules.xml file at the Wazuh manager to alert about the active response results.

    <group name="virustotal,">
      <rule id="100092" level="12">
          <match>Successfully removed threat</match>
          <description>$(parameters.program) removed threat located at $(</description>
      <rule id="100093" level="12">
          <match>Error removing threat</match>
          <description>Error removing threat located at $(</description>
  10. Restart the Wazuh agent to apply local configuration changes.

    # systemctl restart wazuh-agent
  11. Restart the Wazuh manager to apply the configuration changes.

    # systemctl restart wazuh-manager

Steps to generate the alerts

  1. Download a malicious file to /root directory in the Ubuntu 20 endpoint. This triggers a VirusTotal query and generates an alert. In addition, the file will be automatically removed by the active response to this threat.

    # cd /root
    # curl -LO && ls -lah

Query the alerts

You can visualize the alert data in the Wazuh dashboard. To do this, go to the Security events module and add the filters in the search bar to query the alerts.

  • **