KORTHVEILSecurity firewall
Guides

YARA rules: scan downloads and computers for malware

Download as PDF All guides

YARA rules describe malware by its patterns: the text, bytes and structure that a family of malware, or a disguised file, has in common. Korthveil uses the curated open rules of YARA-Forge in two places:

  • On the firewall: Gateway anti-virus checks every downloaded file that ClamAV finds clean against the YARA rules. A match is reported, or blocked.
  • On computers: the Korthveil agent checks new files on the computer against the same rules, wherever the computer is (see Korthveil agent).

At a glance:

Step Where What
1 Security › Malware protection › Gateway anti-virus Turn on the add-in. YARA comes with it
2 Same page, Scanning Choose the rule set (Core, Extended or Full) and, to start, Only report YARA matches, don't block
3 Same page, Plain-HTTP proxy, or Security › TLS inspection Choose which downloads the firewall sees: plain HTTP, and HTTPS through TLS inspection
4 Security › Malware protection Check that the YARA layer is on, with its rule count
5 Recent detections Look at what matched; then untick Only report to block
6 Optional: Security › Vulnerabilities › Agents Computers with the Korthveil agent check new files with the same rules

A video shows the same steps on a test firewall: YARA rules: scan downloads and computers for malware.

How the firewall checks a file

  1. ClamAV scans the file first. A file ClamAV calls malware is blocked by ClamAV.
  2. A file ClamAV finds clean goes to YARA. A match blocks it (or only reports it, if you choose so) and lists the rule's name.
  3. A file still clean goes to the Sandbox, if you set one up (see Malware protection).

YARA finds what signatures can miss: a known malware family in a new build, a packed or disguised file, or a test file hidden in a password-protected archive that ClamAV can't open (that is what the video and the test below use).

The firewall can only check a file it can read: plain HTTP downloads, HTTPS downloads through TLS inspection, and mail through the Email security add-in. FTP, POP3, IMAP and SMB are not scanned.

1. Turn on Gateway anti-virus with YARA

  1. Open Security › Malware protection, then the Gateway anti-virus tab.
  2. Under Scanning, Also check files with YARA rules (YARA-Forge) is ticked: YARA is on whenever the add-in is on, unless you untick it.
  3. Choose the Rule set:
Rule set What it has
Core: fewest false alarms (recommended) YARA-Forge's core rules: the highest quality and the fewest false alarms
Extended: more families More rules, for more malware families
Full: everything, more false alarms Every rule YARA-Forge publishes. Expect files that are not malware to match
  1. To start, tick Only report YARA matches, don't block. Matches are listed under Recent detections and the file is still delivered. When you have seen what the rules find on your network, untick it to block.
  2. Press Save to pending changes, then Review and commit. Saving the settings switches the add-in on. (If the add-in was on before and has been switched off, saving keeps it off in 1.7.6: switch it on with the add-in's own on/off control at the top of the page.)
Gateway anti-virus, Scanning: YARA rules on, the Core rule set and Only report YARA matches ticked
Gateway anti-virus, Scanning: YARA rules on, the Core rule set and Only report YARA matches ticked

Plain HTTP downloads. If you don't use TLS inspection, tick Scan plain HTTP (port 80) downloads from these zones under Plain-HTTP proxy and choose your zones (here the office network, lan). With TLS inspection on and Also proxy plain HTTP (port 80) for scanning ticked there, leave this off. It works for IPv4 and IPv6.

Plain-HTTP proxy: plain HTTP downloads from the office network are scanned
Plain-HTTP proxy: plain HTTP downloads from the office network are scanned

2. The rules download by themselves

The firewall downloads the chosen rule set from YARA-Forge's own releases on GitHub (github.com/YARAHQ/yara-forge), compiles it, and checks for a new release once a day. If a download fails, the last rules stay in use. Nothing else is needed: there is no key and no account.

  • The first download starts at once. From 1.7.7 on, turning YARA on, choosing another rule set or restarting the add-in downloads the rules right away; they are ready within a minute or two. (In 1.7.6 the first download waited for the add-in's hourly check, up to an hour.) ClamAV keeps scanning in the meantime.
  • Where to see them: Security › Malware protection shows the YARA layer as On and current with the number of rules, for example 5,081 rules for the Core set of YARA-Forge release 20261129 used for this guide. On, needs attention means YARA is on but no rules are loaded yet.
  • Security › Malware protection › Gateway anti-virus shows a YARA rules box with the number of rules, the YARA-Forge release and the set (from 1.7.8), and Update signatures and rules now downloads the newest ClamAV signatures and YARA rules on demand.
Security › Malware protection: Malware families and disguised files (YARA-Forge), on and current, with the number of rules
Security › Malware protection: Malware families and disguised files (YARA-Forge), on and current, with the number of rules

The Engine panel of Gateway anti-virus shows ClamAV, its signatures, how many files were scanned and blocked, and how many of them by YARA.

Gateway anti-virus, Engine: ClamAV running, its signatures, files scanned and blocked, by YARA
Gateway anti-virus, Engine: ClamAV running, its signatures, files scanned and blocked, by YARA

The daily malware protection self-test raises the warning YARA rules are not loaded when YARA is on but has no rules (see Malware protection). In 1.7.6 the first self-test runs 30 minutes after the firewall starts, before the first rules arrive on a newly enabled add-in, so this warning can appear once and stay until the next day's test, although the rules are there by then. Check the YARA layer on Security › Malware protection: when it says On and current with a rule count, YARA works.

3. HTTPS downloads need TLS inspection

Most downloads use HTTPS. The firewall can scan a file inside an encrypted download only when it decrypts it, with TLS inspection:

  1. Open Security › TLS inspection (if you chose More add-ins under Appearance › Menu, it is there while the add-in is off).
  2. Read and confirm the privacy and legal notice, and choose the zones whose HTTPS is inspected.
  3. Under What is inspected, Scan downloads with Gateway anti-virus is ticked by default: decrypted downloads go to ClamAV and then to the YARA rules.
  4. Under Which devices are decrypted, choose Decrypt: Only devices that trust the certificate. A device that can't trust the inspection certificate is then never decrypted, so its HTTPS keeps working. With the default, Every device, a device that refuses the certificate passes uninspected for 6 hours.
  5. Save and commit.
TLS inspection, What is inspected: Scan downloads with Gateway anti-virus
TLS inspection, What is inspected: Scan downloads with Gateway anti-virus
TLS inspection, Which devices are decrypted: Only devices that trust the certificate
TLS inspection, Which devices are decrypted: Only devices that trust the certificate
  • TVs, consoles, speakers, cameras, smart-home devices and printers are recognised and never decrypted. Banks, card payments and Verifying you are human checks are never decrypted either (see TLS inspection).
  • Devices that are not decrypted still have DNS filtering, the web filter by name, intrusion prevention and fingerprint blocking. Their HTTPS downloads are not scanned by ClamAV or YARA.

4. Test it with a harmless file

A YARA-Forge Core rule, ELCEEF_EICAR_Encrypted_ZIP, recognises the standard EICAR anti-virus test file inside a password-protected ZIP archive by the archive's own header (the file's size and checksum), without the password. EICAR is a 68-byte text every anti-virus treats as a test, and it is not malware. Because ClamAV can't open the encrypted archive, ClamAV finds it clean and YARA is what finds it.

  1. Make the test file on any computer: save the EICAR text exactly, 68 bytes with no line ending, as eicar.com, and put it in a password-protected ZIP with the classic ZIP encryption, for example zip -P test eicar-encrypted.zip eicar.com. (AES-encrypted ZIP files leave the checksum out, so the rule can't recognise them.)
  2. Put it on a web server your test computer reaches through the firewall over plain HTTP (or HTTPS with TLS inspection), and download it.
  3. With Only report YARA matches ticked, the download arrives. Recent detections lists it: the device, the download's address, the result infected, the rule ELCEEF_EICAR_Encrypted_ZIP and the action allow. On our test firewall the computer downloaded over IPv6 (2001:db8:10::10); IPv4 downloads are scanned the same way.

  4. Untick Only report YARA matches, save and commit, and download again. The download is stopped and the browser gets Korthveil's block page. Recent detections lists it with the action block.

Recent detections: the test file reported (allow), then blocked (block) by the YARA rule ELCEEF_EICAR_Encrypted_ZIP
Recent detections: the test file reported (allow), then blocked (block) by the YARA rule ELCEEF_EICAR_Encrypted_ZIP

The button Scan the EICAR test file under Engine tests ClamAV with the plain EICAR file, not YARA.

What a detection does

  • It is listed under Recent detections on the Gateway anti-virus page, with its time, device, address, rule and action.
  • The device is listed under Security › Malware protection › Infected devices, Watched devices: a sign seen in the last 30 minutes that is not enough on its own to quarantine it (a download is not an infection).
  • There is no notification for a single detection: look at Recent detections. Alerts come from the daily self-test (below) and from Infected devices when a device shows stronger signs.
Infected devices, Watched devices: the lab computer's address with the YARA match
Infected devices, Watched devices: the lab computer's address with the YARA match
  • A blocked download gets Korthveil's block page. Set a contact and a message for it under Plain-HTTP proxy (Block page contact, Block page message).

5. Computers: the Korthveil agent uses the same rules

With the Korthveil agent on your computers, the firewall gives them the Gateway anti-virus YARA rules:

  1. Open Security › Vulnerabilities, the Agents tab, and press Settings.
  2. Under Malware and scripts on the computers, tick Check new files on the computers (or give a computer group its own settings), and commit.
  3. The Agents tab then says how many YARA rules the computers get, for example 4,720 YARA rules (361 of 5,081 need what computers can't evaluate).
Security › Vulnerabilities › Agents: the YARA rules computers get, and how many they can't evaluate
Security › Vulnerabilities › Agents: the YARA rules computers get, and how many they can't evaluate
  • The agent checks new and changed files in Downloads, the desktop, mail attachments, temporary folders and removable drives, wherever the computer is.
  • A YARA match on a computer is suspicious: it is reported with the rule's name. It is quarantined only if you tick Quarantine suspicious files too. When Gateway anti-virus is set to Only report YARA matches, computers never quarantine for a YARA match either.
  • The agent evaluates YARA itself, without extra software on the computer. Rules that need a YARA module (such as pe or math) or a for loop are left out on computers, and counted on the Agents tab. The test rule above uses a for loop, so computers don't use it: test the agent with the firewall's own test files described in Korthveil agent.
  • The agent reads the first 32 MB of a large file.

The agent's own pages and settings are in Korthveil agent.

Not possible yet

  • Your own YARA rules. Korthveil uses YARA-Forge's rule sets only; there is no place yet to add rules of your own or to turn single rules off. (The Extra signature files field under Signature updates takes ClamAV signature files, not YARA rules for this engine.)

Good to know

  • YARA checks a file for at most 15 seconds, and only files up to the scan size limit (Largest file scanned, 25 MiB by default).
  • YARA-Forge collects rules from many open projects and tests them for quality; each rule keeps its author and licence. Korthveil downloads them only from YARA-Forge's own GitHub releases.
  • YARA rules match patterns, so a rule can match a file that is not malware, more often with Extended and Full. Start with Core and Only report.
  • Korthveil never runs a downloaded file on the firewall.

Download as PDF All guides