Click here to Skip to main content
14,299,246 members

Antivirus Part--2

Rate this:
5.00 (2 votes)
Please Sign up or sign in to vote.
5.00 (2 votes)
19 Aug 2019CPOL
An opensource antivirus engine which uses Yara, Locality Sensitive Hashing to detect malware


I once wrote an opensource antivirus engine.

The above antivirus uses Message Digest 5 (MD5) algorithm to detect malware. The above antivirus is a great failure. In this article, I will explain how the antivirus failed and how the newer implementation has overcome its pitfall in detecting malware.

Drawbacks of MD5 as a Malware Signature

The previous antivirus used MD5 as its prime search engine for detecting malwares. The idea is to compare the md5 hash with the collection of known MD5 hashes of malware stored in a database. If the hash is matched, then the user will be notified. This approach is plain and simple but has major drawbacks which are explained further.

1. Replacing MD5 with TLSH

Since MD5 is a cryptographic hash function, even a small change to a file could generate you a completely randomized hash. So sample samples of malware will have different signatures. This will greatly flood the database with duplicate signatures and may also cause a failure in detection if the newer hash is not present in the database.

LSH, also known as Locality Sensitive Hashing, will produce similar hashes for similar files. TLSH is a Locality Sensitive Hashing developed by TrendMicro.

TLSH uses distance scores to calculate the distance between two hashes, a score of 0 represents the file is identical or highly identical. Increase in distance score is directly proportional to the difference between two files. We are using a Similarity distance of 20 which gives less false positives when comparing between hashes. The character length of TLSH is 70. The image below will show you that newer Antivirus is capable of removing the duplicates from its signature database.

Image 1

So we have now solved the data-duplication problem which is faced by the previous version of antivirus.

2. Using YARA Signatures

Yara is an opensource pattern matching engine developed by VirusTotal. A wide variety of malicious software can be detected using Yara rules. Yara rules for detecting most common malwares are readily available in various platforms like Github, etc., and the important feature is it is cross-platformed, i.e., it works on Linux, Windows and Mac OS X.

We have built the Yara library from their Github repository and used a wrapper made by Avast. Our antivirus has support for yara rules.

3. Antivirus Server

Our antivirus is a server and client model, i.e., the antivirus engine will run as an http server on and with port 5660, which means you could customize the frontend as you please.

Here are commonly used API calls for the server:

1. Requesting to Scan a File with YARA Signatures

You could request the server to scan a specific file for matching Yara signatures. Below is an example code of the request made using Python.

import requests
r ="", 
                   data={"file": "D:/test.eicar", "target": "windows"})

The above request will output the following JSON response.

  "detections": [
      "author": "Visweswaran",
      "description": "EICAR",
      "name": "bot"
      "author": "UNKNOWN AUTHOR",
      "description": "AV-TEST-FILE",
      "name": "example"
  "message": true

2. Scanning for TLSH in Our Database

def scan_for_tlsh(self, path):
    r ="", data={"file": path})
    tlsh_hash = r.json()["message"]
    if len(tlsh_hash) != 70:
        return None
        file_size = os.path.getsize(path)
        file_type = filetype.guess(path)
        mime = file_type.mime
        r = requests.get("{}7&
            tlsh_hash, file_size-10000, file_size+10000, mime
        if r.json()["message"] != -1:
            result = {
                "name": "Identified Threat",
                "author": "Undefined",
                "description": "This application matches known sample
                                collected from virussign.",
                "path": path
    except AttributeError:

4. Updating

An antivirus needs to be continuously updated to detect new malwares. Our antivirus downloads the signature from my opensource threat database.

The repository has two folders, ruleset and threat_db. The ruleset will contain rules for downloading the signatures.

Here is an example ruleset entry:

Our program will download all the signatures specified in the files from the specified URL key.

    "files": [
    "url": "

And the signature will look something like this:

    "tlsh": "8D63E1CA9195EDD4FC5BB839000275FAFB66044C7AEB7201F854ABDDE0D4780D2EC68A",
    "name": "VirusSign Sample",
    "size": 72704,
    "type": "application/x-msdownload"

5. Adding yara

You can add your own yara files in the yara folder and the antivirus engine comes with inbuilt error checker for yara.

You can check for compilation errors by going to this url: and the server will remove the files which has compilation errors. Running will remove duplicate TLSH hashes.

not found

Using the Antivirus

The antivirus ships with server mrida.exe and you should execute it first which will fireup the server. And you can execute mrida-gui.exe. This will run a basic User Interface to demonstrate the working of the antivirus. Here is how it looks:

No Image

no image

Points of Interest

I still have to admit that this is not a perfect antivirus implementation. It still has many drawbacks and any free commercial engine would outshine its detection. Yet it can be used for educational purposes and will serve the community. Windows only had one opensource antivirus which is clamwin but now we can add another one to the list however it works on other operating systems to.


  • 19th August, 2019: Initial version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Comments and Discussions

PraiseVote 5 Pin
EhabAhmed23-Aug-19 4:26
memberEhabAhmed23-Aug-19 4:26 
GeneralRe: Vote 5 Pin
VISWESWARAN199823-Aug-19 23:18
professionalVISWESWARAN199823-Aug-19 23:18 
QuestionCompilation errors Pin
Michael Haephrati19-Aug-19 5:05
mvpMichael Haephrati19-Aug-19 5:05 
AnswerRe: Compilation errors Pin
VISWESWARAN199819-Aug-19 5:19
professionalVISWESWARAN199819-Aug-19 5:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 19 Aug 2019


5 bookmarked