Пример #1
0
        public void Save(Configuration item)
        {
            try
            {
                using (FocaContextDb context = new FocaContextDb())
                {
                    var config = context.Configurations.FirstOrDefault() ?? new Configuration();

                    config.AvaliableTechExtensions = item.AvaliableTechExtensions;
                    config.BingApiKey = item.BingApiKey;
                    config.DefaultDnsCacheSnooping = item.DefaultDnsCacheSnooping;
                    config.FingerPrintingAllFtp    = item.FingerPrintingAllFtp;
                    config.FingerPrintingAllHttp   = item.FingerPrintingAllHttp;
                    config.FingerPrintingAllSmtp   = item.FingerPrintingAllSmtp;
                    config.FingerPrintingDns       = item.FingerPrintingDns;
                    config.GoogleApiCx             = item.GoogleApiCx;
                    config.GoogleApiKey            = item.GoogleApiKey;
                    config.MaxRecursion            = item.MaxRecursion;
                    config.SimultaneousDownloads   = item.SimultaneousDownloads;
                    config.ProjectConfigFile       = item.ProjectConfigFile;
                    config.ParallelDnsQueries      = item.ParallelDnsQueries;
                    config.UseAllDns = item.UseAllDns;
                    config.UseHead   = item.UseHead;
                    config.SelectedTechExtensions = item.SelectedTechExtensions;
                    config.SPathsPlugins          = item.SPathsPlugins;
                    config.ShodanApiKey           = item.ShodanApiKey;

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #2
0
        public void Save(ThreadSafeList <FilesItem> items)
        {
            try
            {
                if (items.Count == 0)
                {
                    return;
                }

                using (FocaContextDb context = new FocaContextDb())
                {
                    foreach (var fileItem in items)
                    {
                        fileItem.Date         = DateTime.Now;
                        fileItem.ModifiedDate = DateTime.Now;
                        context.Files.AddOrUpdate(fileItem);
                    }

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
 public List <Project> GetAllProjects()
 {
     using (FocaContextDb context = new FocaContextDb())
     {
         return(context.Projects.ToList());;
     }
 }
Пример #4
0
        public ThreadSafeList <ComputersItem> GetComputersByIdProject(int idProject)
        {
            using (FocaContextDb context = new FocaContextDb())
            {
                var result = context.Computers.Where(x => x.IdProject == idProject).
                             Include("Description").
                             Include("Description.Items").
                             Include("Printers").
                             Include("Printers.Items").
                             Include("Printers.Items.RemoteUsers").
                             Include("Printers.Items.RemoteUsers.Items").
                             Include("RemoteFolders").
                             Include("RemoteFolders.Items").
                             Include("RemoteFolders.Items.RemoteUsers").
                             Include("RemoteFolders.Items.RemoteUsers.Items").
                             Include("RemotePasswords").
                             Include("RemotePasswords.Items").
                             Include("RemotePrinters").
                             Include("RemotePrinters.Items").
                             Include("RemotePrinters.Items.RemoteUsers").
                             Include("RemotePrinters.Items.RemoteUsers.Items").
                             Include("RemoteUsers").
                             Include("RemoteUsers.Items").
                             Include("Software").
                             Include("Software.Items").
                             Include("Users").
                             Include("Users.Items");

                return(new ThreadSafeList <ComputersItem>(result));
            }
        }
Пример #5
0
        public void Save(HttpMap item)
        {
            using (FocaContextDb context = new FocaContextDb())
            {
                var listDocuments = item.Documents.Select(x => new HttpMapTypesFiles()
                {
                    IdHttMap = item.Id, IdType = 2, Value = x.ToString()
                }).ToList();
                var listFiles = item.Files.Select(x => new HttpMapTypesFiles()
                {
                    IdHttMap = item.Id, IdType = 3, Value = x.ToString()
                }).ToList();
                var listFolders = item.Folders.Select(x => new HttpMapTypesFiles()
                {
                    IdHttMap = item.Id, IdType = 4, Value = x.ToString()
                }).ToList();
                var listParametrized = item.Parametrized.Select(x => new HttpMapTypesFiles()
                {
                    IdHttMap = item.Id, IdType = 5, Value = x.ToString()
                }).ToList();

                context.HttpMapTypesFiles.AddRange(listDocuments);
                context.HttpMapTypesFiles.AddRange(listFiles);
                context.HttpMapTypesFiles.AddRange(listFolders);
                context.HttpMapTypesFiles.AddRange(listParametrized);

                context.SaveChanges();
            }
        }
Пример #6
0
        public ThreadSafeList <FilesItem> GetFilesByIdProject(int idProject)
        {
            using (FocaContextDb context = new FocaContextDb())
            {
                var result = context.Files.Where(x => x.IdProject == idProject)
                             .Include("Metadata")
                             .Include("Metadata.FoundUsers")
                             .Include("Metadata.FoundUsers.Items")
                             .Include("Metadata.FoundEmails")
                             .Include("Metadata.FoundEmails.Items")
                             .Include("Metadata.FoundDates")
                             .Include("Metadata.FoundPrinters")
                             .Include("Metadata.FoundPrinters.Items")
                             .Include("Metadata.FoundPaths")
                             .Include("Metadata.FoundPaths.Items")
                             .Include("Metadata.FoundOldVersions")
                             .Include("Metadata.FoundOldVersions.Items")
                             .Include("Metadata.FoundHistory")
                             .Include("Metadata.FoundHistory.Items")
                             .Include("Metadata.FoundMetaData")
                             .Include("Metadata.FoundMetaData.Applications")
                             .Include("Metadata.FoundMetaData.Applications.Items")
                             .Include("Metadata.FoundServers")
                             .Include("Metadata.FoundServers.Items")
                             .Include("Metadata.FoundPasswords")
                             .Include("Metadata.FoundPasswords.Items");

                return(new ThreadSafeList <FilesItem>(result));
            }
        }
Пример #7
0
 public ThreadSafeList <Plugin> GetAllPlugins()
 {
     using (FocaContextDb context = new FocaContextDb())
     {
         var result = context.Plugins.ToList();
         return(new ThreadSafeList <Plugin>(result));;
     }
 }
Пример #8
0
 public ThreadSafeList <RelationsItem> GetReltationsByIdProject(int idProject)
 {
     using (FocaContextDb context = new FocaContextDb())
     {
         var result = context.Relations.Where(x => x.IdProject == idProject).Include("Domain").Include("Ip");
         return(new ThreadSafeList <RelationsItem>(result));
     }
 }
Пример #9
0
 public ThreadSafeList <ComputerIPsItem> GetComputerIpsByIdProject(int idProject)
 {
     using (FocaContextDb context = new FocaContextDb())
     {
         var result = context.ComputerIps.Where(x => x.IdProject == idProject).Include("Computer").Include("Ip");
         return(new ThreadSafeList <ComputerIPsItem>(result));
     }
 }
Пример #10
0
        public void Save(Project item)
        {
            using (FocaContextDb context = new FocaContextDb())
            {
                context.Projects.AddOrUpdate(item);

                context.SaveChanges();
            }
        }
Пример #11
0
        public ThreadSafeList <IPsItem> GetIpsByIdProject(int idProject)
        {
            using (FocaContextDb context = new FocaContextDb())
            {
                var result = context.Ips.Where(x => x.IdProject == idProject);

                return(new ThreadSafeList <IPsItem>(result));
            }
        }
Пример #12
0
        public ThreadSafeList <string> GetItemsByTypeById(int i, int id)
        {
            using (FocaContextDb context = new FocaContextDb())
            {
                var result = context.HttpMapTypesFiles.Where(x => x.IdHttMap == id && x.IdType == i).ToList();

                return(new ThreadSafeList <string>(result.Select(x => x.Value)));;
            }
        }
Пример #13
0
        public ThreadSafeList <Limits> GetLimitsByIdProject(int idProject)
        {
            using (FocaContextDb context = new FocaContextDb())
            {
                var result = context.Limits.Where(x => x.IdProject == idProject);

                return(new ThreadSafeList <Limits>(result));
            }
        }
Пример #14
0
        public Configuration GetConfiguration()
        {
            using (FocaContextDb context = new FocaContextDb())
            {
                Configuration config = context.Configurations.FirstOrDefault() ?? LoadDefaultConfig();

                return(config);
            }
        }
Пример #15
0
        /// <summary>
        /// Get Domains by Id.
        /// </summary>
        /// <param name="idProject"></param>
        /// <returns></returns>
        public ThreadSafeList <DomainsItem> GetDomainsById(int idProject)
        {
            using (FocaContextDb context = new FocaContextDb())
            {
                var result = context.Domains.Where(x => x.IdProject == idProject).Include("fingerPrinting").Include("map");
                LoadHttpMapValues(result);

                return(new ThreadSafeList <DomainsItem>(result));
            }
        }
Пример #16
0
 public Project GetProjectById(int idProject)
 {
     try
     {
         using (FocaContextDb context = new FocaContextDb())
         {
             return(context.Projects.FirstOrDefault(x => x.Id == idProject));
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Пример #17
0
        public virtual void Save(IList <T> items)
        {
            if (items.Count == 0)
            {
                return;
            }

            using (FocaContextDb context = new FocaContextDb())
            {
                foreach (var item in items)
                {
                    context.Set <T>().AddOrUpdate(item);
                }

                context.SaveChanges();
            }
        }
Пример #18
0
        private Configuration LoadDefaultConfig()
        {
            var config = new Configuration
            {
                FingerPrintingAllFtp      = false,
                FingerPrintingAllHttp     = true,
                FingerPrintingAllSmtp     = true,
                FingerPrintingDns         = true,
                PassiveFingerPrintingHttp = true,
                PasiveFingerPrintingSmtp  = true,
                ResolveHost             = true,
                UseHead                 = true,
                DefaultDnsCacheSnooping = "www.google.com",
                GoogleApiKey            = string.Empty,
                GoogleApiCx             = string.Empty,
                BingApiKey              = string.Empty,
                ShodanApiKey            = string.Empty,
                NumberOfTasks           = 15,
                MaxRecursion            = 4,
                ParallelDnsQueries      = 4,
                ProjectConfigFile       = string.Empty,
                ScanNetranges255        = true,
                SelectedTechExtensions  = new List <string>(),
                SimultaneousDownloads   = 15,
                SPathsPlugins           = string.Empty,
                UseAllDns               = true,
                webSearcherEngine       = 2,
                DiarioAPIKey            = "LfUxRse6mjsRA3DZNBuq",
                DiarioAPISecret         = "ThyDYxcaGdHHK6TC3YcMqG2kFexF4D8djmdpcMy8"
            };

            using (FocaContextDb context = new FocaContextDb())
            {
                context.Configurations.Add(config);
                context.SaveChanges();
            }

            return(config);
        }
Пример #19
0
        public void Save(ThreadSafeList <DomainsItem> items)
        {
            if (items.Count == 0)
            {
                return;
            }

            using (FocaContextDb context = new FocaContextDb())
            {
                HttpMapController httpMap = new HttpMapController();

                foreach (var domainsItem in items)
                {
                    context.Domains.AddOrUpdate(domainsItem);

                    context.SaveChanges();

                    httpMap.Save(domainsItem.map);
                }

                context.SaveChanges();
            }
        }
Пример #20
0
        public override void Save(IList <Plugin> items)
        {
            try
            {
                if (items.Count == 0)
                {
                    return;
                }

                using (FocaContextDb context = new FocaContextDb())
                {
                    var allPlugins = context.Plugins.ToList();
                    context.Plugins.RemoveRange(allPlugins);
                    context.Plugins.AddRange(items);

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #21
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            System.Threading.Thread splashThread = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
            {
                splashScreen = new FormSplashFOCA(ProgramVersion);
                Application.Run(splashScreen);
                Application.ExitThread();
            }));

            splashThread.SetApartmentState(System.Threading.ApartmentState.STA);
            splashThread.Start();

            Application.DoEvents();
            //Load the FOCA
            Running = true;


            SqlConnectionStringBuilder connectionStringBuilder = null;
            bool csUpdated = false;

            try
            {
                ConnectionStringSettings csFromConfig = ConfigurationManager.ConnectionStrings[nameof(FocaContextDb)];
                //If there is no connection string configured, try with SQLEXPRESS instance
                if (csFromConfig == null || String.IsNullOrEmpty(csFromConfig.ConnectionString))
                {
                    connectionStringBuilder = new SqlConnectionStringBuilder(SQLExpressConnectionString);
                    csUpdated = true;
                }
                else
                {
                    connectionStringBuilder = new SqlConnectionStringBuilder(csFromConfig.ConnectionString);
                    if (String.IsNullOrWhiteSpace(connectionStringBuilder.InitialCatalog))
                    {
                        connectionStringBuilder.InitialCatalog = FocaDatabaseName;
                    }
                }
            }
            catch (ArgumentException)
            {
                csUpdated = true;
                connectionStringBuilder = new SqlConnectionStringBuilder(SQLExpressConnectionString);
            }

            while (!FocaContextDb.IsDatabaseAvailable(connectionStringBuilder.ToString()))
            {
                splashScreen.Invoke((MethodInvoker)(() => MessageBox.Show(splashScreen, "FOCA needs a SQL database. Please setup your connection and try again.", "Database not found", MessageBoxButtons.OK, MessageBoxIcon.Error)));

                // Display the connection dialog
                using (DataConnectionDialog dlg = new DataConnectionDialog(connectionStringBuilder))
                {
                    DialogResult connectionResult = DialogResult.Cancel;
                    splashScreen.Invoke((MethodInvoker)(() => connectionResult = dlg.ShowDialog(splashScreen)));

                    if (DialogResult.OK != connectionResult)
                    {
                        Environment.Exit(0);
                    }
                }
                csUpdated = true;
            }

            if (csUpdated)
            {
                UpdateConnectionString(connectionStringBuilder.ToString());
            }

            data                     = new Data();
            FormMainInstance         = new FormMain();
            FormMainInstance.TopMost = true;
            FormMainInstance.Shown  += FormMainInstance_Shown;

            FormOptionsInstance = new FormOptions();

            InitializeServicePointManager();

            Application.Run(FormMainInstance);
        }
Пример #22
0
 public static void DisposeContext()
 {
     FocaContextDbValue = new FocaContextDb();
 }
Пример #23
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            FormSplashFOCA splashScreen = new FormSplashFOCA("Open Source");

            splashScreen.Show();
            Application.DoEvents();
            //Load the FOCA
            Running = true;

            SqlConnectionStringBuilder connectionStringBuilder = null;
            bool csUpdated = false;

            try
            {
                ConnectionStringSettings csFromConfig = ConfigurationManager.ConnectionStrings[nameof(FocaContextDb)];
                //If there is no connection string configured, try with SQLEXPRESS instance
                if (csFromConfig == null || String.IsNullOrEmpty(csFromConfig.ConnectionString))
                {
                    connectionStringBuilder = new SqlConnectionStringBuilder(SQLExpressConnectionString);
                    csUpdated = true;
                }
                else
                {
                    connectionStringBuilder = new SqlConnectionStringBuilder(csFromConfig.ConnectionString);
                    if (String.IsNullOrWhiteSpace(connectionStringBuilder.InitialCatalog))
                    {
                        connectionStringBuilder.InitialCatalog = FocaDatabaseName;
                    }
                }
            }
            catch (ArgumentException)
            {
                csUpdated = true;
                connectionStringBuilder = new SqlConnectionStringBuilder(SQLExpressConnectionString);
            }

            while (!FocaContextDb.IsDatabaseAvailable(connectionStringBuilder.ToString()))
            {
                MessageBox.Show("FOCA needs a SQL database. Please setup your connection and try again.", "Database not found", MessageBoxButtons.OK, MessageBoxIcon.Error);

                // Display the connection dialog
                using (DataConnectionDialog dlg = new DataConnectionDialog(connectionStringBuilder))
                {
                    if (DialogResult.OK != dlg.ShowDialog(splashScreen))
                    {
                        Environment.Exit(0);
                    }
                }
                csUpdated = true;
            }

            if (csUpdated)
            {
                UpdateConnectionString(connectionStringBuilder.ToString());
            }

            data                = new Data();
            FormMainInstance    = new FormMain();
            FormOptionsInstance = new FormOptions();

            splashScreen.Close();
            splashScreen.Dispose();

            InitializeServicePointManager();

            Application.Run(FormMainInstance);
        }