Exemplo n.º 1
0
        public override ScanOutput Scan(string FilePath)
        {
            try
            {
                ScanOutput output = new ScanOutput();
                fileLog.Status   = ScanStatus.Queued;
                fileLog.FilePath = FilePath;
                fileLog.Scanner  = _serviceName;

                Task <List <VTScanResult> > task = Task.Run <List <VTScanResult> >(async() => await RunExample(FilePath, fileLog));

                _message           = "File is queued! Please check back after some time";
                output.Result      = false;
                output.Message     = "Please check back in a while";
                output.ServiceName = _serviceName;

                return(output);
            }
            catch (Exception ex)
            {
                fileLog.Status  = ScanStatus.Error;
                fileLog.Message = ex.Message;
                throw new AvscanException(ex);
            }
            finally
            {
                ScanFileLogRepo.Record(fileLog);
            }
        }
Exemplo n.º 2
0
        public ActionResult CheckReport(int scanid)
        {
            VTScanner vt = new VTScanner();

            ScanFileLog fileLog = ScanFileLogRepo.GetbyId(scanid);

            if (fileLog.Status == ScanStatus.Queued)
            {
                if (fileLog.Scanner.ToLower() == "virus total")
                {
                    vt.GetReport(fileLog);
                }
            }

            return(RedirectToAction("Details", new { id = scanid }));
        }
Exemplo n.º 3
0
        public override ScanOutput Scan(string FilePath)
        {
            ScanOutput          output     = new ScanOutput();
            VTScanResult        scanResult = new VTScanResult();
            List <VTScanResult> logresult  = new List <VTScanResult>();
            bool result = false;

            try
            {
                _filepath         = FilePath;
                fileLog.StartTime = DateTime.Now.ToString();
                fileLog.Status    = ScanStatus.Started;
                fileLog.FilePath  = FilePath;
                fileLog.Scanner   = _serviceName;

                ScanUtility.ExecuteCommand(RunUtil, RunCommand);
                _message = (String.IsNullOrEmpty(ScanUtility.Output) ? "(none)" : ScanUtility.Output);
                result   = (ScanUtility.Result == 0) ? false : true;

                fileLog.FinishTime = DateTime.Now.ToString();
                fileLog.Status     = (ScanUtility.Result == 0) ? ScanStatus.Passed : ScanStatus.Failed;
                fileLog.Message    = _message;

                output.Result      = result;
                output.Message     = _message;
                output.ServiceName = _serviceName;
            }
            catch (Exception ex)
            {
                _message       = ex.Message;
                fileLog.Status = ScanStatus.Error;
                result         = false;
                //throw new AvscanException(ex);
            }
            finally
            {
                scanResult.ScanId     = _serviceName;
                scanResult.VirusFound = result;
                scanResult.Result     = _message;
                logresult.Add(scanResult);

                fileLog.ScanResults = logresult;
                ScanFileLogRepo.Record(fileLog);
            }
            return(output);
        }
Exemplo n.º 4
0
        //private static async Task RunExample(string test)
        private async Task <List <VTScanResult> > RunExample(string strfile, ScanFileLog scanFileinfo)
        {
            List <VTScanResult> log = new List <VTScanResult>();

            Debug.WriteLine(DateTime.Now + ": RunExample Task Started ");
            ScanFileLog scanFileLog = ScanFileLogRepo.GetbyId(scanFileinfo.ScanId);

            scanFileLog.StartTime = DateTime.Now.ToString();
            scanFileLog.Status    = ScanStatus.Started;

            try
            {
                VirusTotal virusTotal = new VirusTotal("86c775d4d351a9a180f798b3957d51cf9bd838b80f88cd226f28dbaa6a4d3102");

                //Use HTTPS instead of HTTP
                virusTotal.UseTLS = true;

                //Create the EICAR test virus. See http://www.eicar.org/86-0-Intended-use.html
                //byte[] eicar = Encoding.ASCII.GetBytes(@"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*");

                //Check if the file has been scanned before.
                //FileReport fileReport = await virusTotal.GetFileReportAsync(eicar);
                FileReport fileReport = await virusTotal.GetFileReportAsync(new System.IO.FileInfo(strfile));

                bool hasFileBeenScannedBefore = fileReport.ResponseCode == FileReportResponseCode.Present;

                Debug.WriteLine("File has been scanned before: " + (hasFileBeenScannedBefore ? "Yes" : "No"));

                //If the file has been scanned before, the results are embedded inside the report.
                if (hasFileBeenScannedBefore)
                {
                    scanFileLog.Status  = ScanStatus.Completed;
                    scanFileLog.Message = (fileReport.Positives > 0) ? string.Format("Virus Found {0}", fileReport.Positives) : fileReport.VerboseMsg;

                    if (fileReport.ResponseCode == FileReportResponseCode.Present)
                    {
                        foreach (KeyValuePair <string, ScanEngine> scan in fileReport.Scans)
                        {
                            Debug.WriteLine("{0,-25} Detected: {1}", scan.Key, scan.Value.Detected);
                            log.Add(new VTScanResult
                            {
                                ScanId     = scan.Key,
                                VirusFound = scan.Value.Detected,
                                Result     = scan.Value.Result
                            });
                        }
                    }
                }
                else
                {
                    //ScanResult fileResult = await virusTotal.ScanFileAsync(eicar, "EICAR.txt");
                    scanFileLog.Status = ScanStatus.Queued;
                    ScanResult fileResult = await virusTotal.ScanFileAsync(new System.IO.FileInfo(strfile));

                    scanFileLog.Message = fileResult.VerboseMsg;

                    log.Add(new VTScanResult
                    {
                        ScanId = fileResult.ScanId,
                        Result = fileResult.VerboseMsg
                    });
                }
            }
            catch (Exception ex)
            {
                scanFileLog.Status  = ScanStatus.Error;
                scanFileLog.Message = ex.Message;
                //throw new;
            }
            finally
            {
                scanFileLog.FinishTime  = DateTime.Now.ToString();
                scanFileLog.ScanResults = log;
                // ScanFileLogRepo.Record(scanFileLog);
            }

            return(log as List <VTScanResult>);
        }
Exemplo n.º 5
0
        public ActionResult Details(int id)
        {
            ScanFileLog fileLog = ScanFileLogRepo.GetbyId(id);

            return(View(fileLog));
        }