Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scan a file with antivirus on upload in Java? [closed]

I am working on an application which requires file upload and it also requires to scan the file with available antivirus on server.

I have heard abt APIS available from Symantec for application server.

Situatuion is like, I need to deploy the application at different places in the future. So, I am thinking to place a configuration file from where I am going to fetch available Antivirus & its path.

I want to use any available antivirus on server and then using command line, I want to pass file name and result back.

I am confused in passing file and retrieving back results.

Is it possible?

like image 363
Hardik Mishra Avatar asked Jan 18 '11 07:01

Hardik Mishra


People also ask

How do I scan an infected file?

Open the Start menu and select Settings. Click on Update & Security and then select Windows Security in the menu. Among the many Protection Areas, click on Virus and Threat Protection to open the scan window. Click on the Scan Options to view the three options, including a Quick Scan, Full Scan, and a Custom Scan.

Can I make an antivirus in Java?

What you have to do is just need to concentrate on characters which are identifiable (consider the image below). 1. Install Java and set the path- C:\Program Files\Java\jdk1. 7.0_25\bin; in environmental variable.


2 Answers

Use the following code.

String[] commands =  new String[5];
                  commands[0] = "cmd";
                  commands[1] = "/c";
                  commands[2] = "C:\\Program Files\\AVG\\AVG10\\avgscanx.exe";
                  commands[3] = "/scan=" + filename;
                  commands[4] = "/report=" + virusoutput;


                 Runtime rt = Runtime.getRuntime();
                 Process proc = rt.exec(commands);

Commnad line would be better option for you. then read the log file to solve the problem.

like image 188
Ashfak Balooch Avatar answered Oct 06 '22 15:10

Ashfak Balooch


I just googled up and found an interesting article have a look at here

To implement a virus file scan in Java, a third-party package needs to be used. For the purposes of this article, I will use Symantec Scan Engine (SSE) package, which comes with Java APIs. This package is an application that serves as a TCP/IP server and has a programming interface and enables Java applications to incorporate support for content scanning technologies. For this article, I used Symantec Scan Engine 5.1, which is available as a Unix or Windows install.

quick reference:

public void scanFile(byte[] fileBytes, String fileName)
   throws IOException, Exception {

   if (scan) {
      AVClient avc = new AVClient(avServer, avPort, avMode);
      if (avc.scanfile(fileName, fileBytes) == -1) {
         throw new VirusException("WARNING: A virus was detected in
            your attachment: " + fileName + "<br>Please scan
            your system with the latest antivirus software with
            updated virus definitions and try again.");
      }
   }
}

then

catch (Exception ex) {
   logger.error(ex);
   if (ex instanceof VirusException) {
      // do something here
   }
   else {
      // there was some other error – handle it
   }
}
like image 45
jmj Avatar answered Oct 06 '22 16:10

jmj