public void ScanKnownFile() { //Create the EICAR test virus. See http://www.eicar.org/86-0-Intended-use.html FileInfo fileInfo = new FileInfo("EICAR.txt"); File.WriteAllText(fileInfo.FullName, @"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"); ScanResult fileResult = _virusTotal.ScanFile(fileInfo); //It should always be in the VirusTotal database. Assert.AreEqual(ScanResponseCode.Queued, fileResult.ResponseCode); }
private static void FileScan(string file, bool rescan) { try { VirusTotal virusTotal = new VirusTotal(api_key); virusTotal.UseTLS = true; FileInfo fileInfo = new FileInfo(file); FileReport fileReport = virusTotal.GetFileReport(fileInfo); bool hasFileBeenScannedBefore = fileReport.ResponseCode == ReportResponseCode.Present; Console.WriteLine("File has been scanned before: " + (hasFileBeenScannedBefore ? "Yes" : "No")); if (hasFileBeenScannedBefore) { if (rescan) { ScanResult fileResult = virusTotal.RescanFile(fileInfo); PrintScan(fileResult); } else { PrintScan(fileReport); } } else { ScanResult fileResult = virusTotal.ScanFile(fileInfo); PrintScan(fileResult); } } catch (Exception e) { Console.WriteLine(e.Message); } }
private async Task getFileReport(System.IO.FileInfo fileInfo) { virusTotal = new VirusTotal(API_KEY); //Use HTTPS instead of HTTP virusTotal.UseTLS = true; //Check if the file has been scanned before. FileReport fileReport = await virusTotal.GetFileReport(fileInfo); bool hasFileBeenScannedBefore = fileReport.ResponseCode == ReportResponseCode.Present; //already there is file if (hasFileBeenScannedBefore) { addReport(fileReport, fileInfo.FullName); countTask(fileInfo.Name); } // upload the file else { ScanResult fileResults = await virusTotal.ScanFile(fileInfo); if (fileResults.SHA256.Length != 0) { scanFileReport(fileInfo); } } }
private void button2_Click_1(object sender, EventArgs e) { VirusTotal virusTotal = new VirusTotal(System.Configuration.ConfigurationManager.AppSettings["ApiKey"]); //Use HTTPS instead of HTTP virusTotal.UseTLS = true; string chosenfile = listView1.FocusedItem.SubItems[2].Text;; FileInfo fileInfo = new FileInfo(chosenfile); // File.WriteAllText(fileInfo.FullName, @"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"); string hashreport1 = String.Empty; //Check if the file has been scanned before. VirusTotalNET.Objects.Report fileReport = virusTotal.GetFileReport(fileInfo); bool hasFileBeenScannedBefore = fileReport.ResponseCode == ReportResponseCode.Present; DialogResult dialogresult = MessageBox.Show("File has been scan before: ", " hasFileBeenScannedBefore", MessageBoxButtons.YesNo); //If the file has been scanned before, the results are embedded inside the report. if (dialogresult == DialogResult.Yes) { PrintScan(fileReport); string str = Convert.ToString(fileReport.Positives); //string[] splitedStrings = str.Split('-'); //string requestedValue = splitedStrings[0]; //textBox4.Text = str; foreach (ScanEngine scan in fileReport.Scans) { //string[] row1 = { scan.Name, Convert.ToString(scan.Detected) }; //listView1.Items.Add("Detect:").SubItems.AddRange(row1); MessageBox.Show(scan.Result); } } else { VirusTotalNET.Objects.ScanResult fileResult = virusTotal.ScanFile(fileInfo); PrintScan(fileResult); string str = Convert.ToString(fileReport.Positives); //string[] splitedStrings = str.Split('-'); // string requestedValue = splitedStrings[0]; //textBox4.Text = str; //textBox4.Text = str; foreach (ScanEngine scan in fileReport.Scans) { //string[] row1 = { scan.Name, Convert.ToString(scan.Detected) }; //listView1.Items.Add("Detect:").SubItems.AddRange(row1); MessageBox.Show(scan.Result); } } }
public async Task RescanSmallFile() { ScanResult fileResult = await VirusTotal.ScanFile(new byte[1], "VirusTotal.NET-Test.txt"); //It has been scanned before, we expect it to return queued. Assert.Equal(ScanResponseCode.Queued, fileResult.ResponseCode); }
public async Task ScanLargeFile2() { VirusTotal.Timeout = TimeSpan.FromSeconds(250); ScanResult result = await VirusTotal.ScanFile(new byte[VirusTotal.FileSizeLimit], "VirusTotal.NET-Test.txt"); Assert.Equal(ScanResponseCode.Queued, result.ResponseCode); Assert.False(string.IsNullOrWhiteSpace(result.ScanId)); }
//FileInfo fileInfo = new FileInfo("C:\\Users\\Antonio\\Documents\\file.txt"); public List <VirusTotalAux> send() { _virusTotal = new VirusTotal(ConfigurationManager.AppSettings["ApiKey"]); _listaScan.Clear(); _listaResultados.Clear(); int count = 0; while (count < 2) { string ruta = _lista[count].Proceso; ruta = ruta.Replace(@"\", @"\\"); FileInfo fileInfo = new FileInfo(ruta); _virusTotal.UseTLS = true; FileReport fileReport = _virusTotal.GetFileReport(fileInfo); bool hasFileBeenScannedBefore = fileReport.ResponseCode == ReportResponseCode.Present; if (hasFileBeenScannedBefore) { VirusTotalAux aux = new VirusTotalAux { Nombre = fileInfo.Name, Mensaje = fileReport.VerboseMsg, Positivos = fileReport.Positives.ToString() + "/" + fileReport.Total.ToString(), ScanDate = fileReport.ScanDate.ToString() }; foreach (ScanEngine scan in fileReport.Scans) { VirusTotalResultAux aux2 = new VirusTotalResultAux { Antivirus = scan.Name, Infectado = scan.Detected, Virus = scan.Result }; _listaResultados.Add(aux2); } aux.resultados = _listaResultados; _listaScan.Add(aux); //PrintScan(fileReport); } else { ScanResult fileResult = _virusTotal.ScanFile(fileInfo); VirusTotalAux aux = new VirusTotalAux { Mensaje = fileResult.VerboseMsg }; aux.resultados = _listaResultados; //Console.WriteLine(fileResult.VerboseMsg); //PrintScan(fileResult); } count++; } return(_listaScan); }
static void Main(string[] args) { VirusTotal virusTotal = new VirusTotal(ConfigurationManager.AppSettings["ApiKey"]); //Use HTTPS instead of HTTP virusTotal.UseTLS = true; FileInfo fileInfo = new FileInfo("testfile.txt"); //Create a new file File.WriteAllText(fileInfo.FullName, "This is a test file!"); //Check if the file has been scanned before. Report fileReport = virusTotal.GetFileReport(fileInfo).First(); bool hasFileBeenScannedBefore = fileReport.ResponseCode == 1; Console.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) { PrintScan(fileReport); } else { ScanResult fileResult = virusTotal.ScanFile(fileInfo); PrintScan(fileResult); } Console.WriteLine(); Report urlReport = virusTotal.GetUrlReport(ScanUrl).First(); bool hasUrlBeenScannedBefore = urlReport.ResponseCode == 1; Console.WriteLine("URL has been scanned before: " + (hasUrlBeenScannedBefore ? "Yes" : "No")); //If the url has been scanned before, the results are embedded inside the report. if (hasUrlBeenScannedBefore) { PrintScan(urlReport); } else { List <ScanResult> urlResults = virusTotal.ScanUrl(ScanUrl); urlResults.ForEach(PrintScan); } Console.WriteLine("Press a key to continue"); Console.ReadLine(); }
static void Main(string[] args) { VirusTotal virusTotal = new VirusTotal(ConfigurationManager.AppSettings["ApiKey"]); //Use HTTPS instead of HTTP virusTotal.UseTLS = true; //Create the EICAR test virus. See http://www.eicar.org/86-0-Intended-use.html FileInfo fileInfo = new FileInfo("EICAR.txt"); File.WriteAllText(fileInfo.FullName, @"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"); //Check if the file has been scanned before. Report fileReport = virusTotal.GetFileReport(fileInfo); bool hasFileBeenScannedBefore = fileReport.ResponseCode == ReportResponseCode.Present; Console.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) { PrintScan(fileReport); } else { ScanResult fileResult = virusTotal.ScanFile(fileInfo); PrintScan(fileResult); } Console.WriteLine(); Report urlReport = virusTotal.GetUrlReport(ScanUrl); bool hasUrlBeenScannedBefore = urlReport.ResponseCode == ReportResponseCode.Present; Console.WriteLine("URL has been scanned before: " + (hasUrlBeenScannedBefore ? "Yes" : "No")); //If the url has been scanned before, the results are embedded inside the report. if (hasUrlBeenScannedBefore) { PrintScan(urlReport); } else { ScanResult urlResult = virusTotal.ScanUrl(ScanUrl); PrintScan(urlResult); } Console.WriteLine("Press a key to continue"); Console.ReadLine(); }
public async Task ScanUnknownFile() { string guid = "VirusTotal.NET" + Guid.NewGuid(); FileInfo fileInfo = new FileInfo("VirusTotal.NET-Test.txt"); File.WriteAllText(fileInfo.FullName, guid); ScanResult fileResult = await VirusTotal.ScanFile(fileInfo); //It should never be in the VirusTotal database. Assert.Equal(ScanResponseCode.Queued, fileResult.ResponseCode); }
private static async Task RunExample() { VirusTotal virusTotal = new VirusTotal("YOUR API KEY HERE"); //Use HTTPS instead of HTTP virusTotal.UseTLS = true; //Create the EICAR test virus. See http://www.eicar.org/86-0-Intended-use.html FileInfo fileInfo = new FileInfo("EICAR.txt"); File.WriteAllText(fileInfo.FullName, @"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.GetFileReport(fileInfo); bool hasFileBeenScannedBefore = fileReport.ResponseCode == ReportResponseCode.Present; Console.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) { PrintScan(fileReport); } else { ScanResult fileResult = await virusTotal.ScanFile(fileInfo); PrintScan(fileResult); } Console.WriteLine(); UrlReport urlReport = await virusTotal.GetUrlReport(ScanUrl); bool hasUrlBeenScannedBefore = urlReport.ResponseCode == ReportResponseCode.Present; Console.WriteLine("URL has been scanned before: " + (hasUrlBeenScannedBefore ? "Yes" : "No")); //If the url has been scanned before, the results are embedded inside the report. if (hasUrlBeenScannedBefore) { PrintScan(urlReport); } else { UrlScanResult urlResult = await virusTotal.ScanUrl(ScanUrl); PrintScan(urlResult); } }
static void Main(string[] args) { VirusTotal virusTotal = new VirusTotal(ConfigurationManager.AppSettings["ApiKey"]); //Use HTTPS instead of HTTP virusTotal.UseTLS = true; //Create the EICAR test virus. See http://www.eicar.org/86-0-Intended-use.html FileInfo fileInfo = new FileInfo("EICAR.txt"); File.WriteAllText(fileInfo.FullName, @"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 = virusTotal.GetFileReport(fileInfo); bool hasFileBeenScannedBefore = fileReport.ResponseCode == ReportResponseCode.Present; Console.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) { PrintScan(fileReport); } else { ScanResult fileResult = virusTotal.ScanFile(fileInfo); PrintScan(fileResult); } Console.WriteLine(); UrlReport urlReport = virusTotal.GetUrlReport(ScanUrl); bool hasUrlBeenScannedBefore = urlReport.ResponseCode == ReportResponseCode.Present; Console.WriteLine("URL has been scanned before: " + (hasUrlBeenScannedBefore ? "Yes" : "No")); //If the url has been scanned before, the results are embedded inside the report. if (hasUrlBeenScannedBefore) { PrintScan(urlReport); } else { ScanResult urlResult = virusTotal.ScanUrl(ScanUrl); PrintScan(urlResult); } Console.WriteLine("Press a key to continue"); Console.ReadLine(); }
async void panel1_DragDrop(object sender, DragEventArgs e) { textBox2.Clear(); files = (string[])e.Data.GetData(DataFormats.FileDrop); VirusTotal virusTotal = new VirusTotal(apiKey); await Task.Run(() => { resultID = virusTotal.ScanFile(files[0]); result = virusTotal.GetResults(resultID); }); var r = ParseJSON(result); }
public void GetReportForRecentFile() { //We create an unknown file string guid = "VirusTotal.NET" + Guid.NewGuid(); FileInfo fileInfo = new FileInfo("VirusTotal.NET-Test.txt"); File.WriteAllText(fileInfo.FullName, guid); //Attempt to submit it for scan ScanResult result = _virusTotal.ScanFile(fileInfo); FileReport fileReport = _virusTotal.GetFileReport(result.ScanId); //It should not be in the VirusTotal database already, which means it should return error. Assert.AreEqual(ReportResponseCode.StillQueued, fileReport.ResponseCode); }
private async void startVTAsyncFile() { using (new WaitCursor()) { if (string.IsNullOrEmpty((ScanFile.Text))) { return; } VirusTotal vt = new VirusTotal(ConfigurationManager.AppSettings["virusTotalAPIKey"].ToString()); vt.UseTLS = true; FileInfo fileInfo = new FileInfo(ScanFile.Text); //get filename string fileName = System.IO.Path.GetFileNameWithoutExtension(ScanFile.Text); byte[] byteArray; using (StreamReader reader = new StreamReader(new FileStream(ScanFile.Text, FileMode.Open), new UTF8Encoding())) // do anything you want, e.g. read it { byteArray = Encoding.UTF8.GetBytes(reader.ReadToEnd()); } File.WriteAllText(fileInfo.FullName, System.Text.Encoding.UTF8.GetString(byteArray)); //MessageBox.Show(System.Text.Encoding.UTF8.GetString(byteArray)); FileReport fileReport = await vt.GetFileReport(fileInfo); bool hasFileBeenScannedBefore = fileReport.ResponseCode == ReportResponseCode.Present; Console.WriteLine("File has been scanned before: " + (hasFileBeenScannedBefore ? "Yes" : "No")); MessageBox.Show("File has been scanned before: " + (hasFileBeenScannedBefore ? "Yes" : "No")); //If the file has been scanned before, the results are embedded inside the report. if (hasFileBeenScannedBefore) { PrintScan(fileReport, fileName); } else { ScanResult fileResult = await vt.ScanFile(fileInfo); PrintScan(fileResult); } } }
public async void GetReportForRecentFile() { IgnoreMissingJson(" / MD5", " / Permalink", " / Positives", " / scan_date", " / Scans", " / SHA1", " / SHA256", " / Total"); //We create an unknown file string guid = "VirusTotal.NET" + Guid.NewGuid(); FileInfo fileInfo = new FileInfo("VirusTotal.NET-Test.txt"); File.WriteAllText(fileInfo.FullName, guid); //Attempt to submit it for scan ScanResult result = await VirusTotal.ScanFile(fileInfo); FileReport fileReport = await VirusTotal.GetFileReport(result.ScanId); //It should not be in the VirusTotal database already, which means it should return error. Assert.Equal(ReportResponseCode.StillQueued, fileReport.ResponseCode); }
private void iTalk_Button_22_Click(object sender, EventArgs e) { // initializing VT with API key VirusTotal VT = new VirusTotal("c9836f1fb3196ec1205c4eb4f58cc50be1b41915f2b18633927e8a7333457cc8"); // Yes we want to use HTTPS instead of HTTP VT.UseTLS = true; // Getting our file FileInfo fileInfo = new FileInfo("asdf.txt"/*iTalk_TextBox_Small2.Text*/); //debug purpose File.WriteAllText(fileInfo.FullName, @"purpletestfislekkkk"); // Getting our fileReport FileReport fileReport = VT.GetFileReport(fileInfo); // Checking weather or not there is a previous scan on the file bool prevScan = fileReport.ResponseCode == ReportResponseCode.Present; // If there was a previous scan or if prevScan = true ( its a bool ) // Update our label to let the users know there is a pervious scan // else // We want to upload the file and get the scan report // ( this is where PrintScan(ScanResult scanresult) comes into play ) if (prevScan) { PrintScan(fileReport); iTalk_Label7.Text = "YES"; iTalk_Label7.ForeColor = Color.Green; } else { ScanResult fileReport2 = VT.ScanFile(fileInfo); PrintScan(fileReport2); iTalk_Label7.Text = "NO"; iTalk_Label7.ForeColor = Color.Red; } }
public static void scanFile(string fnPath, ScannedFileItem _scannedFile) { try { if (File.Exists(fnPath)) { _scanW.WorkerReportsProgress = true; _scanW.WorkerSupportsCancellation = true; _scanW.RunWorkerAsync(); _scanW.DoWork += (o, e) => { var virusTotal = new VirusTotal(apiKey); virusTotal.UseTLS = true; var fInfo = new FileInfo(fnPath); _report = new FileReport(); var fReport = virusTotal.GetFileReport(fInfo); _report = fReport; bool hasFileBeenScannedBefore = fReport.ResponseCode == ReportResponseCode.Present; if (!hasFileBeenScannedBefore) { var fResult = virusTotal.ScanFile(fInfo); } }; _scanW.RunWorkerCompleted += (m, e) => { if (_report != null) { var scanWin = new ScanResultWin(); scanWin.init(_report, _scannedFile); scanWin.ShowDialog(); } }; } } catch (Exception ex) { GeneralSettings.LogException(ex); } }
private void virusTotalScan(string PID) { try { FileInfo file = new FileInfo("EICAR.txt"); //File.WriteAllText(file.FullName, @"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"); File.WriteAllText(file.FullName, @"Hello World"); Process p = Process.GetProcessById(Int32.Parse(PID)); string filename = p.MainModule.FileName; //Find if the file has been already scanned DataTable processes = new DataTable(); DatabaseFactory.connectToDatabase(); string query = "select filename from malicious where filename = '" + Path.GetFileName(filename) + "'"; NpgsqlCommand objCommand = new NpgsqlCommand(query, DatabaseFactory.getCurrentConnection()); NpgsqlDataReader dr = objCommand.ExecuteReader(); DatabaseFactory.closeConnection(); if (!dr.HasRows) { byte[] resource; using (var md5 = MD5.Create()) { using (var stream = File.OpenRead(filename)) { resource = md5.ComputeHash(Encoding.UTF8.GetBytes(stream.ToString())); } } StringBuilder sBuilder = new StringBuilder(); // Loop through each byte of the hashed data // and format each one as a hexadecimal string. for (int i = 0; i < resource.Length; i++) { sBuilder.Append(resource[i].ToString("x2")); } string r = sBuilder.ToString(); Report fileReport = virusTotal.GetFileReport(file); bool hasFileBeenScannedBefore = fileReport.ResponseCode == ReportResponseCode.Present; //If the file has been scanned before, the results are embedded inside the report. if (hasFileBeenScannedBefore) { PrintScan(fileReport, Path.GetFileName(filename)); } else { FileInfo fileInfo = new FileInfo(filename); VirusTotalNET.Objects.ScanResult fileResult = virusTotal.ScanFile(fileInfo); PrintScan(fileResult); } } } catch (ArgumentException e) { //Process removed } catch (InvalidOperationException e) { //Process removed } catch (Win32Exception e) { //cannot scan system files } }
private void button1_Click(object sender, EventArgs e) { VirusTotal virusTotal = new VirusTotal(System.Configuration.ConfigurationManager.AppSettings["ApiKey"]); //Use HTTPS instead of HTTP virusTotal.UseTLS = true; //Create the EICAR test virus. See http://www.eicar.org/86-0-Intended-use.html string chosenfile = ""; openFileDialog1.InitialDirectory = "C:"; openFileDialog1.Title = "insert file"; openFileDialog1.FileName = ""; openFileDialog1.ShowDialog(); chosenfile = openFileDialog1.FileName; textBox1.Text = chosenfile; FileInfo fileInfo = new FileInfo(textBox1.Text); File.WriteAllText(fileInfo.FullName, @"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"); //Check if the file has been scanned before. VirusTotalNET.Objects.Report fileReport = virusTotal.GetFileReport(fileInfo); bool hasFileBeenScannedBefore = fileReport.ResponseCode == ReportResponseCode.Present; Console.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) { PrintScan(fileReport); } else { VirusTotalNET.Objects.ScanResult fileResult = virusTotal.ScanFile(fileInfo); PrintScan(fileResult); } Console.WriteLine(); Report urlReport = virusTotal.GetUrlReport(ScanUrl); bool hasUrlBeenScannedBefore = urlReport.ResponseCode == ReportResponseCode.Present; Console.WriteLine("URL has been scanned before: " + (hasUrlBeenScannedBefore ? "Yes" : "No")); //If the url has been scanned before, the results are embedded inside the report. if (hasUrlBeenScannedBefore) { PrintScan(urlReport); } else { ScanResult urlResult = virusTotal.ScanUrl(ScanUrl); PrintScan(urlResult); } Console.WriteLine("Press a key to continue"); Console.ReadLine(); }
public async Task ScanLargeFile() { //We expect it to throw a SizeLimitException because the file is above the legal limit await Assert.ThrowsAsync <SizeLimitException>(async() => await VirusTotal.ScanFile(new byte[VirusTotal.FileSizeLimit + 1], "VirusTotal.NET-Test.txt")); }
private static void VirusScanFile(string filePath) { VirusTotal virusTotal = new VirusTotal("555e487a82c5885d48c50f33037393f2f3140db9f5e0b256eb30e5654f601486"); virusTotal.UseTLS = true; FileInfo fileInfo = new FileInfo(filePath); if (!fileInfo.Exists) return; //Check if the file has been scanned before. Debug.WriteLine("Getting report for " + Path.GetFileName(filePath)); Report report = virusTotal.GetFileReport(fileInfo); if (report == null || report.ResponseCode == 0) { Debug.WriteLine("No report for " + Path.GetFileName(filePath) + " - sending file to VT"); try { ScanResult result = virusTotal.ScanFile(fileInfo); Debug.WriteLine("Opening report for " + Path.GetFileName(filePath)); Process.Start(result.Permalink); } catch (RateLimitException) { MessageBox.Show("Virus Total limits the number of calls you can make to 4 calls each 60 seconds.", "Rate limit"); } catch (SizeLimitException) { MessageBox.Show("Virus Total limits the filesize to 32 MB.", "File too large"); } } else { Debug.WriteLine("Opening report for " + Path.GetFileName(filePath)); Process.Start(report.Permalink); } }