/
test_eicar.cpp
70 lines (53 loc) · 1.79 KB
/
test_eicar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <string>
#include <fstream>
#include <iostream>
/*
Application Details:
Executable: test_eicar.exe
Created Date: December 5, 2010
Author: Joe Kraxner <joe[\@/]kraxner.net>
Written and compiled in Microsoft Visual Studio 2010
Background:
This application was written by Joe Kraxner as a tool
to test anti-virus software that has the ability to detect
the EICAR Test Virus (http://www.eicar.org/anti_virus_test_file.htm).
The primary purpose of the application is to use test_eicar.exe in
a script that can be manually executed to generate a plain-text file
named "EICAR_VIRUS_TEST.txt". The anti-virus software should detect
the text file and delete.
Usage:
A single word such as "RUN" or "TEST" must be given as an
argument for the application to run. This is a safeguard to keep
the application from accidentally executing by double-clicking.
Example:
test_eicar.exe RUN
*/
using namespace std;
void outputFileCheck(ofstream &fout, string filename);
int main()
{
//Declare output file for EICAR test string
ofstream eicar_out;
//check the output file
outputFileCheck(eicar_out, "eicar_test.txt");
//Declare the eicarTestString variable
string eicarTestString = "X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*";
//print the eicarTestString to a file
eicar_out << eicarTestString << endl;
//finished with the output, close the file handle
eicar_out.close();
//exit safely
return 0;
}
void outputFileCheck(ofstream &fout, string filename)
{
//Declare and open output file
fout.open(filename.c_str());
//Print an error if that failed
if(fout.fail())
{
cerr << "Unable to open " << filename << endl;
//Exit with errors
exit(2);
}
}