public ActionResult Edit(user user) { var DbAux = new vinisandboxContext(); if (DbAux.users.Count(p => p.email == user.email) > 0) { ModelState.AddModelError("email", "Email já cadastrado."); } ModelState.Remove("password"); if (ModelState.IsValid) { if (!string.IsNullOrEmpty(user.password)) { user.password = MD5Helper.StringToMD5(user.password); } else { user.password = DbAux.users.ToList().Find(p => p.id == user.id).password; } try { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(Content("ok")); } catch (Exception ex) { } } return(PartialView(user)); }
public void Save(file_detail file_det) { vinisandboxContext cx = new vinisandboxContext(); file_det = cx.file_detail.Find(file_det.id); foreach (var anti_scan in antivirus_scans) { var antivirus = anti_scan.antivirus; var bdV = cx.antivirus.ToArray().FirstOrDefault(p => p.Equals(antivirus)); if (bdV != null) { anti_scan.antivirus = bdV; bdV.antivirus_scan.Add(anti_scan); } analysis.antivirus_scan.Add(anti_scan); } foreach (var comp_event in computer_events) { analysis.computer_event.Add(comp_event); } foreach (var dns in dns_list) { var domain = dns; var bdDns = cx.dns.ToArray().FirstOrDefault(p => p.Equals(dns)); if (bdDns != null) { domain = bdDns; } domain.analyses.Add(analysis); analysis.dns.Add(domain); } foreach (var re_file in result_file) { analysis.result_file.Add(re_file); } foreach (var misc in miscellaneous) { analysis.miscellaneous.Add(misc); } file_det.analyses.Add(analysis); foreach (var res in resources) { var bdRes = cx.resource_type.ToArray().FirstOrDefault(p => p.Equals(res.resource_type)); if (bdRes != null) { res.resource_type = bdRes; bdRes.resources.Add(res); } pe_file.resources.Add(res); } foreach (var sec in sections) { pe_file.sections.Add(sec); } foreach (var exp_func in export_functions) { pe_file.export_function.Add(exp_func); } foreach (var imp_lib in import_libraries) { var imp_lib_rec = imp_lib; var bdIl = cx.import_library.ToArray().FirstOrDefault(p => p.Equals(imp_lib)); if (bdIl != null) { imp_lib_rec = bdIl; } foreach (var imp_func in imp_lib.import_function) { imp_func.import_library = imp_lib_rec; var imp_func_rec = imp_func; var bdIf = cx.import_function.ToArray().FirstOrDefault(p => p.Equals(imp_func)); if (bdIf != null) { imp_func_rec = bdIf; } else { imp_func_rec.import_library = imp_lib_rec; } pe_file.import_function.Add(imp_func_rec); } } pe_file aux2 = cx.pe_file.SingleOrDefault(p => p.id == file_det.id); if (aux2 != null) { var remRes = aux2.resources.ToList(); for (int i = 0; i < remRes.Count; i++) { cx.resources.Remove(remRes[i]); } aux2.resources.Clear(); var remSec = aux2.sections.ToList(); for (int i = 0; i < remSec.Count; i++) { cx.sections.Remove(remSec[i]); } aux2.sections.Clear(); var remExp = aux2.export_function.ToList(); for (int i = 0; i < remExp.Count; i++) { cx.export_function.Remove(remExp[i]); } aux2.export_function.Clear(); var remImp = aux2.import_function; aux2.import_function.Clear(); cx.pe_file.Remove(aux2); cx.SaveChanges(); } file_det.pe_file = pe_file; pe_file.file_detail = file_det; file_det.type = file_detail.type; file_det.md5 = file_detail.md5; file_det.sha1 = file_detail.sha1; file_det.sha256 = file_detail.sha256; file_det.sha512 = file_detail.sha512; file_det.crc32 = file_detail.crc32; file_det.ssdeep = file_detail.ssdeep; file_det.modified_date = file_detail.modified_date; file_det.create_date = file_detail.create_date; cx.SaveChanges(); }
public static void Main(string[] args) { if (IsSingleInstance()) { StringArgument silentArg = new StringArgument("quiet", "Hide application window", "Run application in background"); StringArgument logFileArg = new StringArgument("log", "Log File", "Path to log file"); StringArgument verbArg = new StringArgument("verbose", "Verbose level", "3 - Debug\r\n2 - Normal\r\n1 - Error"); ArgumentParser argParser = new ArgumentParser("Vinisandbox", "Analyze static and dynamically file"); argParser.Add("\\", "quiet", silentArg); argParser.Add("\\", "log", logFileArg); argParser.Add("\\", "verbose", verbArg); LogManager.VerboseLevel = LogManager.EVerboseLevel.Normal; try { if (args.Contains("\\quiet")) { var aux = args.ToList(); aux.Remove("\\quiet"); args = aux.ToArray(); HideWindow(); } argParser.Parse(args); if (argParser.HelpMode) { argParser.WriteLongArgumentsUsage(); Console.Read(); return; } if (logFileArg.Defined) { LogManager.LogPath = (string)logFileArg.ObjectValue; try { if (!File.Exists(LogManager.LogPath)) { File.Create(LogManager.LogPath).Close(); } } catch (Exception) { LogManager.WriteLine("Invalid Log File", LogManager.EVerboseLevel.Error); argParser.WriteShortArgumentsUsage(); Console.Read(); return; } } if (verbArg.Defined) { try { LogManager.VerboseLevel = (LogManager.EVerboseLevel)Enum.ToObject(typeof(LogManager.EVerboseLevel), Convert.ToInt32((string)verbArg.ObjectValue)); } catch (Exception) { LogManager.WriteLine("Invalid Verbose level", LogManager.EVerboseLevel.Error); argParser.WriteShortArgumentsUsage(); Console.Read(); return; } } LogManager.WriteLine("Arguments Parsed", LogManager.EVerboseLevel.Debug); } catch (Exception) { } vinisandboxContext cx = null; try { cx = new vinisandboxContext(); LogManager.WriteLine("DbContext created", LogManager.EVerboseLevel.Debug); } catch (Exception ex) { LogManager.WriteLine("Error on create DbContext: " + ex.ToString(), LogManager.EVerboseLevel.Error); return; } //cx.Configuration.ProxyCreationEnabled = true; //cx.Configuration.LazyLoadingEnabled = true; Configuration config = null; try { config = LoadConfiguration(); LogManager.WriteLine("Configuration Loaded", LogManager.EVerboseLevel.Debug); } catch (Exception ex) { LogManager.WriteLine("Error on load configurations:" + ex.ToString(), LogManager.EVerboseLevel.Error); return; } Sandbox sandbox = null; try { sandbox = new Sandbox(config); LogManager.WriteLine("Sandbox instanciated", LogManager.EVerboseLevel.Debug); } catch (Exception ex) { LogManager.WriteLine("Error on instanciate Sandbox: " + ex.ToString(), LogManager.EVerboseLevel.Error); return; } try { DirectoryInfo di = new DirectoryInfo(config.TempFolder); di.Create(); LogManager.WriteLine("Temporary directory created", LogManager.EVerboseLevel.Debug); } catch (Exception ex) { LogManager.WriteLine("Error on create temporary directory: " + ex.ToString(), LogManager.EVerboseLevel.Error); return; } /*string pat = @"C:\Users\Vinicius\Downloads\sed-4.2.1-setup.exe"; * file_detail fd = new file_detail(); * fd.data = File.ReadAllBytes(pat); * fd.files = new List<file>(); * fd.files.Add(new file() { name = "sed-4.2.1-setup.exe" }); * cx.file_detail.Add(fd); * cx.SaveChanges();*/ LogManager.WriteLine("Waiting for files", LogManager.EVerboseLevel.Normal); while (true) { foreach (var file_det in cx.file_detail.Where(p => !p.analyzed.HasValue || !p.analyzed.Value).Include("files").ToList()) { sandbox.Analyze(file_det); /*foreach (var file in file_det.files) * { * file.analyzed = true; * }*/ file_det.analyzed = true; try { cx.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } Thread.Sleep(config.CheckFrequence); } } else { Console.WriteLine("Ja existe outra instancia do programa rodando."); } }
//private static bool checkFile(string path) //{ // return File.Exists(path); //} public static void Main(string[] args) { if (IsSingleInstance()) { StringArgument silentArg = new StringArgument("quiet", "Hide application window", "Run application in background"); StringArgument logFileArg = new StringArgument("log", "Log File", "Path to log file"); StringArgument verbArg = new StringArgument("verbose", "Verbose level", "3 - Debug\r\n2 - Normal\r\n1 - Error"); ArgumentParser argParser = new ArgumentParser("Vinisandbox", "Analyze static and dynamically file"); argParser.Add("\\", "\\quiet", silentArg); argParser.Add("\\", "\\log", logFileArg); argParser.Add("\\", "\\v", verbArg); LogManager.VerboseLevel = LogManager.EVerboseLevel.Normal; try { argParser.Parse(args); if (silentArg.Defined) { HideWindow(); } if (logFileArg.Defined) { LogManager.LogPath = (string)logFileArg.ObjectValue; try { File.Create(LogManager.LogPath); } catch (Exception) { Console.WriteLine("Invalid Log File"); argParser.WriteShortArgumentsUsage(); Console.Read(); return; } } if (verbArg.Defined) { try { LogManager.VerboseLevel = (LogManager.EVerboseLevel)Enum.ToObject(typeof(LogManager.EVerboseLevel), (string)verbArg.ObjectValue); } catch (Exception) { Console.WriteLine("Invalid Verbose level"); argParser.WriteShortArgumentsUsage(); Console.Read(); return; } } } catch (Exception) { } vinisandboxContext cx = new vinisandboxContext(); cx.Configuration.ProxyCreationEnabled = true; cx.Configuration.LazyLoadingEnabled = true; Configuration config = LoadConfiguration(); Sandbox sandbox = new Sandbox(config); DirectoryInfo di = new DirectoryInfo(config.TempFolder); di.Create(); /*string pat = @"C:\Users\Vinicius\Downloads\sed-4.2.1-setup.exe"; * file_detail fd = new file_detail(); * fd.data = File.ReadAllBytes(pat); * fd.files = new List<file>(); * fd.files.Add(new file() { name = "sed-4.2.1-setup.exe" }); * cx.file_detail.Add(fd); * cx.SaveChanges();*/ while (true) { foreach (var file_det in cx.file_detail.Where(p => p.files.Count(j => j.analyzed == false) > 0).Include("files").ToList()) { sandbox.Analyze(file_det); foreach (var file in file_det.files) { file.analyzed = true; } try { cx.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } Thread.Sleep(10000); } } else { Console.WriteLine("Ja existe outra instancia do programa rodando."); } //if (args.Length != 1) //{ // //Erro // Console.WriteLine("Parametros errados."); // return; //} //if (!checkFile(args[0])) //{ // Console.WriteLine(args[0] + " não foi encontrado."); // return; //} //if (IsSingleInstance()) //{ // StartServer(); // Sandbox s = new Sandbox(LoadConfiguration()); // listMutex.WaitOne(); // files.Add(args[0]); // while (files.Count != 0) // { // listMutex.ReleaseMutex(); // s.Analyze(files[0]); // files.RemoveAt(0); // //faz analise // listMutex.WaitOne(); // } // ServerRunning = false; // programMutex.Close(); //} //else //{ // SendPath(args[0]); //} }