static void Main(string[] args) { if(args == null || args.Length != 1) { Console.WriteLine("Invalid arguments. Usage: nClam.ConsoleTest [FileName]"); return; } var fileName = args[0]; var client = new ClamClient("localhost", 3310); Console.WriteLine("GetVersion(): {0}", client.GetVersion()); Console.WriteLine("GetPing(): {0}", client.Ping()); Console.WriteLine("ScanFileOnServer(): {0}", client.ScanFileOnServer(fileName)); Console.WriteLine("ScanFileOnServerMultithreaded(): {0}", client.ScanFileOnServerMultithreaded(fileName)); if (!IsFolder(fileName)) { try { Console.WriteLine("SendAndScanFile(string): {0}", client.SendAndScanFile(fileName)); Console.WriteLine("SendAndScanFile(byte[]): {0}", client.SendAndScanFile(File.ReadAllBytes(fileName))); } catch (MaxStreamSizeExceededException msee) { Console.WriteLine(msee.Message); } } else { Console.WriteLine("SendAndScanFile(): Not run because argument is a folder, not a file."); } Console.WriteLine("Finished, Press <enter> to quit."); Console.ReadLine(); }
static void Main(string[] args) { if (args == null || args.Length != 1) { Console.WriteLine("Invalid arguments. Usage: nClam.ConsoleTest [FileName]"); return; } var fileInfo = new FileInfo(args[0]); var client = new ClamClient("localhost", 3310); Console.WriteLine("GetVersion(): {0}", client.GetVersion()); Console.WriteLine("GetPing(): {0}", client.Ping()); if (!fileInfo.Exists) { Console.WriteLine("{0} could not be found. Exiting.", fileInfo.FullName); return; } Console.WriteLine("ScanFileOnServer(): {0}", client.ScanFileOnServer(fileInfo.FullName)); Console.WriteLine("ScanFileOnServerMultithreaded(): {0}", client.ScanFileOnServerMultithreaded(fileInfo.FullName)); if (!IsFolder(fileInfo.FullName)) { Console.WriteLine("SendAndScanFile(string): {0}", client.SendAndScanFile(fileInfo.FullName)); Console.WriteLine("SendAndScanFile(byte[]): {0}", client.SendAndScanFile(File.ReadAllBytes(fileInfo.FullName))); } else { Console.WriteLine("SendAndScanFile(): Not run because argument is a folder, not a file."); } Console.WriteLine("Finished, Press <enter> to quit."); Console.ReadLine(); }
/// <summary> /// Scans your data stream for virus /// </summary> /// <param name="stream">The stream you want to check</param> public ScanResult ScanStream(Stream stream) { var clam = new ClamClient("localhost", 3310); return(MapScanResult(clam.SendAndScanFile(stream))); }
/// <summary> /// Scans some bytes for virus /// </summary> /// <param name="data">byte data to scan</param> public ScanResult ScanBytes(byte[] data) { var clam = new ClamClient("localhost", 3310); return(MapScanResult(clam.SendAndScanFile(data))); }
private static void ScanUpload(Config config, TeknikEntities db, Upload upload, int totalCount, int currentCount, ref int totalViruses) { // Initialize ClamAV ClamClient clam = new ClamClient(config.UploadConfig.ClamServer, config.UploadConfig.ClamPort); clam.MaxStreamSize = config.UploadConfig.MaxUploadSize; string subDir = upload.FileName[0].ToString(); string filePath = Path.Combine(config.UploadConfig.UploadDirectory, subDir, upload.FileName); if (File.Exists(filePath)) { // If the IV is set, and Key is set, then scan it if (!string.IsNullOrEmpty(upload.Key) && !string.IsNullOrEmpty(upload.IV)) { byte[] keyBytes = Encoding.UTF8.GetBytes(upload.Key); byte[] ivBytes = Encoding.UTF8.GetBytes(upload.IV); FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); AesCounterStream aesStream = new AesCounterStream(fs, false, keyBytes, ivBytes); // We have the data, let's scan it ClamScanResult scanResult = clam.SendAndScanFile(aesStream); // Close file stream fs.Close(); switch (scanResult.Result) { case ClamScanResults.Clean: string cleanMsg = string.Format("[{0}] Clean Scan: {1}/{2} Scanned | {3} - {4}", DateTime.Now, currentCount, totalCount, upload.Url, upload.FileName); Output(cleanMsg); break; case ClamScanResults.VirusDetected: string msg = string.Format("[{0}] Virus Detected: {1} - {2} - {3}", DateTime.Now, upload.Url, upload.FileName, scanResult.InfectedFiles.First().VirusName); Output(msg); lock (scanStatsLock) { totalViruses++; File.AppendAllLines(virusFile, new List <string> { msg }); } lock (dbLock) { string urlName = upload.Url; // Delete from the DB db.Uploads.Remove(upload); // Delete the File if (File.Exists(filePath)) { File.Delete(filePath); } // Add to transparency report if any were found Takedown report = db.Takedowns.Create(); report.Requester = TAKEDOWN_REPORTER; report.RequesterContact = config.SupportEmail; report.DateRequested = DateTime.Now; report.Reason = "Malware Found"; report.ActionTaken = string.Format("Upload removed: {0}", urlName); report.DateActionTaken = DateTime.Now; db.Takedowns.Add(report); // Save Changes db.SaveChanges(); } break; case ClamScanResults.Error: string errorMsg = string.Format("[{0}] Scan Error: {1}", DateTime.Now, scanResult.RawResult); File.AppendAllLines(errorFile, new List <string> { errorMsg }); Output(errorMsg); break; case ClamScanResults.Unknown: string unkMsg = string.Format("[{0}] Unknown Scan Result: {1}", DateTime.Now, scanResult.RawResult); File.AppendAllLines(errorFile, new List <string> { unkMsg }); Output(unkMsg); break; } } } }