I was trying to learn file I/O and related function in C, and thus tried to create a baby-version of a virus. Following is the exact code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *mod_host, *fin_host;
mod_host = fopen("host.txt", "r+");
fin_host = fopen("final.txt", "w+");
if (mod_host == NULL)
{
printf("Lucky you!\n");
return 0;
}
int c;
while ((c = fgetc(mod_host)) != EOF)
{
fputc(((c^2) % 94) + 32, fin_host);
}
fclose(mod_host);
remove("host.txt");
fclose(fin_host);
rename("final.txt", "host.infected");
printf("Sorry, you are now infected!\n");
}
What the above code exactly does, can be understood by the following pseudo-code:
open the file "host.txt"
create and open another file "final.txt"
transfer the contents of "host.txt" to "final.txt" and modify them in the latter file
delete "host.txt"
rename "file.txt" to "host.infected"
Now the program's actions and consequences are definitely malicious, and thus I expected my anti-virus (I use Kaspersky AV) to not let me run the executable created after compiling the above code. But turns out, the executable ran completely fine, did it's job, and returned 0 without Kaspersky AV giving any warnings. So, I explicitly tried to scan the executable for viruses. Again, Kaspersky AV finished the scan and reported that no malicious objects were detected, and the executable was safe to open.
Of course, the above program is not even a proper virus, and I have hard-coded a lot of things, from file names to the character modification logic, but still, it is malicious in the sense that it removes/deletes an existing file, and creates a new one (which in this case, is just full of gibberish, but it could potentially be another virus as well). Moreover, I cannot restore that deleted file even from my "Recycle Bin", since it is not present there. This does sound enough damage to me, still why doesn't Kaspersky AV consider this executable harmful? In case it matters, I am running this code on Windows 10.