Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this trivial C program detected as a Virus?

Tags:

c

antivirus

I'm a bit rusty in C, but I've come across this strange problem:

I wrote this program:

#include <stdio.h>

main()
{
  int n;
  n=1;
  while (n>0)
  {
    puts("Write a number: ");
    scanf(" %d",&n);
    printf("This is the number you wrote: %d\n", n);
  }

}

Apparently there are absolutely no syntax errors, and for what I could understand, neither was any compiling error. It compiled and built perfectly. Now, if I switch this line:

puts("Write a number: ");

with this one:

printf("Write a number: ");

it compiles with no errors but when the compiled object launches, it immediately stops and an anti-virus warning pops up saying it identified a trojan horse. Before taking any conclusions, I built it several times and after getting the same message I scanned it in virustotal.com and this was the result.

Well I know puts is actually more correct than printf given the objective, but still it should work just fine...

What's wrong here?

I'm using AVG anti-virus, and Pelles C to compile.

Thanks in advance.

like image 582
K09P Avatar asked Oct 18 '13 20:10

K09P


People also ask

How do I stop Windows from saying virus detected?

In the Windows Search, search for "Windows Security" and open the app. In the left-sidebar, click Virus & threat protection. In the right-hand pane, click Manage settings. Under Exclusions, click Add or remove exclusions.

Which virus is hiding in a program?

Any virus that tries to avoid detection by antivirus software is considered a stealth virus. A stealth virus has an intelligent architecture, making it difficult to eliminate it completely from a computer system.

How do you check if a program is a virus?

Scan the EXE with an Antivirus Perhaps one of the quickest ways to tell if a file is a virus is by scanning it with your antivirus. Windows has several free antiviruses you can install. These antivirus programs usually allow you to right-click on the questionable file and select to scan it.

What is program that prevents detects and removes a virus?

Antivirus software is a class of program designed to prevent, detect and remove malware infections on individual computing devices, networks and IT systems.


2 Answers

It's a false positive, obviously. The generated machine code just happens to resemble code that is in the malware database. This has nothing to do with the use of puts().

like image 72
Nikos C. Avatar answered Sep 23 '22 10:09

Nikos C.


Anti virus software work on signatures which are basically known patterns in executable code used by virus software.

Some virus in the wild has a similar pattern to the printf version of code you wrote (I searched all of the people who did flag you as a virus, unfortunately none of them publish what their signature files are checking for). Due to the fact you should never call printf with one argument it is likely many anti-virus software providers may use that as part of their signature process.

The two options you have are don't call printf with a single argument (which you shouldn't anyway) or submit your program as a false positive to the antivirus vendors that said your program was a virus and they may update their signatures to rule out your program as a false positive.

like image 42
Scott Chamberlain Avatar answered Sep 23 '22 10:09

Scott Chamberlain