public HomeController(Neo4jConnector neo4j, IOptions <MainOptions> options) { _neo4j = neo4j; client.BaseAddress = new Uri("https://hack-docs.lex.tools/ch/cod/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", options.Value.LexToken); }
private void OpenConnection() { connector = Neo4jConnector.Instance(); }
static void Main(string[] args) { Stopwatch steptimer = new Stopwatch(); Stopwatch totaltimer = new Stopwatch(); string _appdir = AppDomain.CurrentDomain.BaseDirectory; string neoconfigfile = _appdir + @"\config\neoconfig.json"; string configfile = _appdir + @"\config\cmconfig.json"; bool batchmode = false; string scanid = ShortGuid.NewGuid().ToString(); string scannerid = string.Empty; IDriver driver = null; totaltimer.Start(); try { foreach (string arg in args) { string[] param = arg.Split(new[] { ":" }, 2, StringSplitOptions.None); switch (param[0].ToUpper()) { case "/?": ShowUsage(); Environment.Exit(0); break; case "/CONFIG": configfile = param[1]; break; case "/BATCH": batchmode = true; break; default: break; } } } catch { Console.WriteLine("There is a problem with arguments: " + string.Join(" ", args)); Console.WriteLine(""); ShowUsage(); Environment.Exit(1); } //load the config try { using (Configuration config = Configuration.LoadConfiguration(configfile)) { scannerid = config.ScannerID; if (string.IsNullOrEmpty(config.Username)) { Connector.Instance.Connect(config.SiteServer); } else { Connector.Instance.Connect(config.Username, config.Password, config.Domain, config.SiteServer); } } } catch (Exception e) { Console.WriteLine("There was an error connecting to the server with your configuration"); Console.WriteLine(e.Message); if (batchmode == false) { Console.ReadLine(); } Environment.Exit(1); } try { using (NeoConfiguration config = NeoConfiguration.LoadConfigurationFile(neoconfigfile)) { driver = Neo4jConnector.ConnectToNeo(config); } } catch (Exception e) { Console.WriteLine("There was an error loading your neo4j configuration"); Console.WriteLine(e.Message); if (batchmode == false) { Console.ReadLine(); } Environment.Exit(2); } NeoWriter.ScanID = scanid; List <IDataCollector> collectors = new List <IDataCollector> { CmCollections.GetInstance(), CmLimitingCollections.GetInstance(), CmApplications.GetInstance(), CmPackages.GetInstance(), CmPackagePrograms.GetInstance(), CmTaskSequences.GetInstance(), CmUsers.GetInstance(), CmDevices.GetInstance(), CmDeviceAdConnections.GetInstance(), CmUserAdConnections.GetInstance(), CmCollectionMemberships.GetInstance(), CmApplicationsInTaskSequences.GetInstance(), CmSoftwareUpdate.GetInstance(), CmSoftwareUpdateSupersedence.GetInstance(), CmSoftwareUpdateGroupMembers.GetInstance(), CmDeployments.GetInstance() }; NeoWriter.WriteHeaders(); foreach (IDataCollector collector in collectors) { NeoWriter.WriteIDataCollector(collector, driver, true, true); } //cleanup Cleanup.CleanupCmObjects(driver); if (batchmode == true) { Console.Write("Exiting."); for (int i = 0; i < 3; i++) { System.Threading.Thread.Sleep(500); Console.Write("."); } } else { Console.WriteLine(); Console.WriteLine("Press any key to exit"); Console.ReadLine(); } }
static void Main(string[] args) { Stopwatch steptimer = new Stopwatch(); Stopwatch totaltimer = new Stopwatch(); Configuration wuconfig = null; string _appdir = AppDomain.CurrentDomain.BaseDirectory; string neoconfigfile = _appdir + @"\config\neoconfig.json"; string configfile = _appdir + @"\config\wuconfig.json"; //int relcounter = 0; bool batchmode = false; string scanid = ShortGuid.NewGuid().ToString(); IUpdateServer _updateserver = null; IDriver driver = null; totaltimer.Start(); try { foreach (string arg in args) { string[] param = arg.Split(new[] { ":" }, 2, StringSplitOptions.None); switch (param[0].ToUpper()) { case "/?": ShowUsage(); Environment.Exit(0); break; case "/CONFIG": configfile = param[1]; break; case "/BATCH": batchmode = true; break; default: break; } } } catch { Console.WriteLine("There is a problem with arguments: " + string.Join(" ", args)); Console.WriteLine(""); ShowUsage(); Environment.Exit(1); } //load the config try { wuconfig = Configuration.LoadConfiguration(configfile); if (string.IsNullOrWhiteSpace(wuconfig.ServerName) || wuconfig.Port <= 0) { throw new ArgumentException("Configuration is invalid"); } } catch (Exception e) { Console.WriteLine("There was an error loading your configuration"); Console.WriteLine(e.Message); if (batchmode == false) { Console.ReadLine(); } Environment.Exit(1); } //load the neo4j config try { using (NeoConfiguration config = NeoConfiguration.LoadConfigurationFile(neoconfigfile)) { driver = Neo4jConnector.ConnectToNeo(config); } } catch (Exception e) { Console.WriteLine("There was an error loading your neo4j configuration"); Console.WriteLine(e.Message); if (batchmode == false) { Console.ReadLine(); } Environment.Exit(2); } try { if (!string.IsNullOrWhiteSpace(wuconfig.UserName)) { } else { Console.WriteLine("Connecting to server " + wuconfig.ServerName); _updateserver = AdminProxy.GetUpdateServer(wuconfig.ServerName, wuconfig.UseSSL, wuconfig.Port); } if (_updateserver == null) { throw new ArgumentException("Unable to connect to update server " + wuconfig.ServerName); } } catch (Exception e) { Console.WriteLine("There was an error communicating with the WSUS server: "); Console.WriteLine(e.Message); Console.WriteLine(e.TargetSite.ToString()); if (batchmode == false) { Console.ReadLine(); } Environment.Exit(1); } try { //The main bit UpdateResults updateinfo = new UpdateResults(); WUQueryHandler.PopulateUpdateResults(_updateserver, updateinfo); Console.WriteLine("Found " + updateinfo.Updates.Count + " updates"); Console.WriteLine("Found " + updateinfo.SupersededUpdates.Count + " superseded updates"); IEnumerable <object> sublist; Console.Write("Writing updates to database."); while (updateinfo.Updates.Count > 1000) { Console.Write("."); sublist = ListExtensions.ListPop(updateinfo.Updates, 1000); Writer.MergeUpdates(sublist, driver, scanid); } if (updateinfo.Updates.Count > 0) { sublist = updateinfo.Updates; Writer.MergeUpdates(sublist, driver, scanid); } Console.WriteLine(); Console.Write("Writing supersedence to database."); while (updateinfo.SupersededUpdates.Count > 1000) { Console.Write("."); sublist = ListExtensions.ListPop(updateinfo.SupersededUpdates, 1000); Writer.MergeSupersedence(sublist, driver, scanid); } if (updateinfo.SupersededUpdates.Count > 0) { Writer.MergeSupersedence(updateinfo.SupersededUpdates, driver, scanid); } Console.WriteLine(); Console.WriteLine("Finished"); } catch (Exception e) { Console.WriteLine("There was an error processing updates"); Console.WriteLine(e.Message); } if (batchmode == false) { Console.WriteLine("Press Enter to continue"); Console.ReadLine(); } }
static void Main(string[] args) { Stopwatch totaltimer = new Stopwatch(); string _appdir = AppDomain.CurrentDomain.BaseDirectory; string neoconfigfile = _appdir + @"\config\neoconfig.json"; string configfile = _appdir + @"\config\adconfig.json"; NeoWriter.ScanID = ShortGuid.NewGuid().ToString(); IDriver driver = null; PrincipalContext context = null; totaltimer.Start(); try { foreach (string arg in args) { string[] param = arg.Split(new[] { ":" }, 2, StringSplitOptions.None); switch (param[0].ToUpper()) { case "/?": ShowUsage(); Environment.Exit(0); break; case "/CONFIG": configfile = param[1]; break; case "/BATCH": _batchmode = true; break; default: break; } } } catch { Console.WriteLine("There is a problem with arguments: " + string.Join(" ", args)); Console.WriteLine(""); ShowUsage(); ExitError(1); } //load the config try { using (Configuration config = Configuration.LoadConfiguration(configfile)) { if (string.IsNullOrEmpty(config.ID)) { Console.WriteLine("Your configuration does not have a scanner ID. A random ID will be generated for you below:"); Console.WriteLine(ShortGuid.NewGuid().ToString()); Console.WriteLine(); ExitError(2); } NeoWriter.ScannerID = config.ID; context = Connector.CreatePrincipalContext(config); } } catch (Exception e) { ExitError(e, "There was an error loading your configuration", 1); } //load the neo4j config try { using (NeoConfiguration config = NeoConfiguration.LoadConfigurationFile(neoconfigfile)) { driver = Neo4jConnector.ConnectToNeo(config); } } catch (Exception e) { ExitError(e, "There was an error loading your neo4j configuration", 2); } Console.WriteLine($"Starting scan\nScanner ID: {NeoWriter.ScannerID}\nScan ID: {NeoWriter.ScanID}\n"); NeoWriter.WriteHeaders(); //write the foreign principals NeoWriter.WriteIDataCollector(new ForeignSecurityPrincipalCollector(context), driver, true, true); //process users NeoWriter.WriteIDataCollector(new UsersCollector(context), driver, true, true); //load the computers NeoWriter.WriteIDataCollector(new ComputersCollector(context), driver, true, true); //process groups GroupsCollector groupscollector = new GroupsCollector(context); NeoWriter.WriteIDataCollector(groupscollector, driver, true, true); NeoWriter.WriteIDataCollector(groupscollector.GetMembershipsCollector(), driver, true, true); //process foreign item connections NeoWriter.WriteIDataCollector(new ForeignSecurityPrincipalConnectionCollector(), driver, true, true); NeoWriter.WriteIDataCollector(new RemoteForeignSecurityPrincipalConnectionCollector(), driver, true, true); NeoQueryData nopropsdata = new NeoQueryData(); nopropsdata.ScanID = NeoWriter.ScanID; nopropsdata.ScannerID = NeoWriter.ScannerID; //create primary group mappings Console.Write("Setting primary groups"); NeoWriter.RunQuery(StandAloneQueries.SetPrimaryGroupRelationships, nopropsdata, driver, true, true); Console.WriteLine(); Console.WriteLine("*Cleaning up"); //*cleanup deleted items //remove group memberships that have been deleted Console.Write("Deleted group memberships"); NeoWriter.RunQuery(StandAloneQueries.DeletedGroupMemberships, nopropsdata, driver, true, true); Console.Write("Deleted foreign group memberships"); NeoWriter.RunQuery(StandAloneQueries.DeletedForeignGroupMemberShips, nopropsdata, driver, true, true); //mark deleted objects Console.Write("Mark deleted users"); NeoWriter.RunQuery(StandAloneQueries.GetMarkDeletedObjectsQuery(Types.User), nopropsdata, driver, true, true); Console.Write("Mark deleted computers"); NeoWriter.RunQuery(StandAloneQueries.GetMarkDeletedObjectsQuery(Types.Computer), nopropsdata, driver, true, true); Console.Write("Mark deleted groups"); NeoWriter.RunQuery(StandAloneQueries.GetMarkDeletedObjectsQuery(Types.Group), nopropsdata, driver, true, true); Console.WriteLine("*Finished cleaning up"); Console.WriteLine(); Console.Write("Setting group scopes"); NeoWriter.RunQuery(StandAloneQueries.SetGroupScope, nopropsdata, driver, true, true); Console.Write("Updating member counts"); NeoWriter.RunQuery(StandAloneQueries.UpdateMemberCounts, nopropsdata, driver, true, true); //cleanup driver.Dispose(); context.Dispose(); totaltimer.Stop(); double totaltime = totaltimer.ElapsedMilliseconds / 1000; Console.WriteLine(); Console.WriteLine("Finished in " + totaltime + "secs"); if (_batchmode == true) { Console.Write("Exiting."); for (int i = 0; i < 3; i++) { System.Threading.Thread.Sleep(500); Console.Write("."); } } else { Console.WriteLine("Press enter to exit"); Console.ReadLine(); } }
static void Main(string[] args) { Console.Title = "BirdsNest File System Scanner"; Stopwatch steptimer = new Stopwatch(); Stopwatch totaltimer = new Stopwatch(); Dictionary <string, NetworkCredential> credentials = new Dictionary <string, NetworkCredential>(); List <DataStore> datastores = new List <DataStore>(); string _appdir = AppDomain.CurrentDomain.BaseDirectory; string neoconfigfile = _appdir + @"\config\neoconfig.json"; string configfile = _appdir + @"\config\fsconfig.json"; //int relcounter = 0; bool batchmode = false; string scanid = ShortGuid.NewGuid().ToString(); IDriver driver = null; ConsoleWriter.InitLine(1); totaltimer.Start(); try { foreach (string arg in args) { string[] param = arg.Split(new[] { ":" }, 2, StringSplitOptions.None); switch (param[0].ToUpper()) { case "/?": ShowUsage(); Environment.Exit(0); break; case "/CONFIG": configfile = param[1]; break; case "/BATCH": batchmode = true; break; default: break; } } } catch { Console.WriteLine("There is a problem with arguments: " + string.Join(" ", args)); Console.WriteLine(""); ShowUsage(); Environment.Exit(ErrorCodes.ArgumentsError); } try { using (Configuration config = Configuration.LoadConfiguration(configfile)) { try { config.Validate(); } catch (ArgumentException e) { ConsoleWriter.WriteError(e.Message); if (batchmode == false) { Console.ReadLine(); } Environment.Exit(ErrorCodes.ConfigValidationError); } foreach (Credential cred in config.Credentials) { NetworkCredential netcred = new NetworkCredential(cred.Username, cred.Password, cred.Domain); credentials.Add(cred.ID, netcred); } datastores = config.Datastores; ConsoleWriter.ShowProgress = config.ShowProgress; ConsoleWriter.SetProgressLineCount(config.MaxThreads); } } catch (Exception e) { ConsoleWriter.WriteError("There was an error loading your configuration: " + e.Message); if (batchmode == false) { Console.ReadLine(); } Environment.Exit(ErrorCodes.ConfigLoadError); } try { using (NeoConfiguration config = NeoConfiguration.LoadConfigurationFile(neoconfigfile)) { driver = Neo4jConnector.ConnectToNeo(config); } } catch (Exception e) { ConsoleWriter.WriteError("There was an error loading your neo4j configuration: " + e.Message); if (batchmode == false) { Console.ReadLine(); } Environment.Exit(ErrorCodes.NeoConfigLoadError); } ConsoleWriter.WriteInfo("Initialising file system scanner, scan ID: " + scanid); foreach (DataStore ds in datastores) { foreach (FileSystem fs in ds.FileSystems) { if (string.IsNullOrEmpty(fs.Path)) { ConsoleWriter.WriteWarning("Filesystem missing \"path\" property"); continue; } if (string.IsNullOrEmpty(fs.ID)) { ConsoleWriter.WriteError("Filesystem does have have an ID configured: " + fs.Path); ConsoleWriter.WriteError("A random ID has been generated for you to use in your config: " + ShortGuid.NewGuid().ToString()); if (batchmode == false) { ConsoleWriter.WriteLine("Press enter to continue"); Console.ReadLine(); } continue; } Crawler crawler = new Crawler(driver, fs, scanid); NetworkCredential fscred; if (!string.IsNullOrEmpty(fs.CredentialID) && (credentials.TryGetValue(fs.CredentialID, out fscred))) { crawler.CrawlRoot(ds, fs.Path, fscred); } else { crawler.CrawlRoot(ds, fs.Path); } } } totaltimer.Stop(); ConsoleWriter.ShowProgress = false; ConsoleWriter.ClearProgress(); TimeSpan totaltime = new TimeSpan(totaltimer.ElapsedTicks); ConsoleWriter.WriteLine("Finished in " + totaltime.ToString()); ConsoleWriter.WriteLine("Done"); if (batchmode == true) { ConsoleWriter.Write("Exiting."); for (int i = 0; i < 3; i++) { System.Threading.Thread.Sleep(500); ConsoleWriter.Write("."); } } else { ConsoleWriter.WriteLine(); ConsoleWriter.WriteLine("Press enter to exit"); Console.ReadLine(); } }
static void Main(string[] args) { string appdir = AppDomain.CurrentDomain.BaseDirectory; string neoconfigfile = appdir + @"\config\neoconfig.json"; string configfile = appdir + @"\config\ciconfig.json"; bool batchmode = false; IDriver driver = null; string scanid = ShortGuid.NewGuid().ToString(); try { foreach (string arg in args) { string[] param = arg.Split(new[] { ":" }, 2, StringSplitOptions.None); switch (param[0].ToUpper()) { case "/?": ShowUsage(); Environment.Exit(0); break; case "/CONFIG": configfile = param[1]; break; case "/BATCH": batchmode = true; break; default: break; } } } catch { Console.WriteLine("There is a problem with arguments: " + string.Join(" ", args)); Console.WriteLine(""); ShowUsage(); Environment.Exit(1); } Configuration config = null; try { config = Configuration.LoadConfiguration(configfile); } catch (Exception e) { Console.WriteLine("There was an error loading config: " + configfile); Console.WriteLine(e.Message); Environment.Exit(2); } //load the neo4j config try { using (NeoConfiguration neoconfig = NeoConfiguration.LoadConfigurationFile(neoconfigfile)) { driver = Neo4jConnector.ConnectToNeo(neoconfig); } } catch (Exception e) { Console.WriteLine("There was an error loading your neo4j configuration"); Console.WriteLine(e.Message); if (batchmode == false) { Console.ReadLine(); } Environment.Exit(2); } foreach (CustomItem item in config.Items) { using (ISession session = driver.Session()) { object prop; if (item.Properties.TryGetValue(item.PrimaryProperty, out prop) == false) { Console.WriteLine("Primary property does not have a value"); Environment.Exit(10); } StringBuilder builder = new StringBuilder(); builder.AppendLine($"MERGE (n:{item.PrimaryType} {{{item.PrimaryProperty}:\"{prop}\"}})"); if (item.Types.Count > 1) { foreach (string type in item.Types) { if (type != item.PrimaryType) { builder.AppendLine($"SET n:{type}"); } } } foreach (string key in item.Properties.Keys) { object o = item.Properties[key]; string s = o as string; if (s == null) { builder.AppendLine($"SET n.{key}={o}"); } else { builder.AppendLine($"SET n.{key}=\"{s}\""); } } builder.AppendLine("RETURN n"); string query = builder.ToString(); NeoQueryData data = new NeoQueryData(); data.ScanID = scanid; data.ScannerID = config.ScannerID; data.Properties = config.Items; NeoWriter.RunQuery(query, data, driver, true); } } Console.WriteLine(); Console.WriteLine("Finished"); if (batchmode == true) { Console.Write("Exiting."); for (int i = 0; i < 3; i++) { System.Threading.Thread.Sleep(500); Console.Write("."); } } else { Console.WriteLine("Press any key to exit"); Console.ReadLine(); } }
static void Main(string[] args) { Stopwatch steptimer = new Stopwatch(); Stopwatch totaltimer = new Stopwatch(); string _appdir = AppDomain.CurrentDomain.BaseDirectory; string neoconfigfile = _appdir + @"\config\neoconfig.json"; string configfile = _appdir + @"\config\aadconfig.json"; bool batchmode = false; string scanid = ShortGuid.NewGuid().ToString(); string scannerid = string.Empty; IDriver driver = null; totaltimer.Start(); try { foreach (string arg in args) { string[] param = arg.Split(new[] { ":" }, 2, StringSplitOptions.None); switch (param[0].ToUpper()) { case "/?": ShowUsage(); Environment.Exit(0); break; case "/CONFIG": configfile = param[1]; break; case "/BATCH": batchmode = true; break; default: break; } } } catch { Console.WriteLine("There is a problem with arguments: " + string.Join(" ", args)); Console.WriteLine(""); ShowUsage(); Environment.Exit(1); } //load the config try { using (Configuration config = Configuration.LoadConfiguration(configfile)) { Console.WriteLine("Loading config for scanner: " + scannerid); scannerid = config.ScannerID; NeoWriter.ScannerID = scannerid; Connector.Instance.Init(config); } } catch (Exception e) { Console.WriteLine("There was an error connecting to the server with your configuration"); Console.WriteLine(e.Message); if (batchmode == false) { Console.ReadLine(); } Environment.Exit(1); } try { using (NeoConfiguration config = NeoConfiguration.LoadConfigurationFile(neoconfigfile)) { driver = Neo4jConnector.ConnectToNeo(config); } } catch (Exception e) { Console.WriteLine("There was an error loading your neo4j configuration"); Console.WriteLine(e.Message); if (batchmode == false) { Console.ReadLine(); } Environment.Exit(2); } NeoWriter.ScanID = scanid; var aadgroupmembers = new AadGroupMemberships(); aadgroupmembers.GroupIDs = AadGroups.Instance.GroupIDs; List <IDataCollectorAsync> collectors = new List <IDataCollectorAsync> { AadUsers.Instance, new AadUserToAdUserConnections(), AadGroups.Instance, aadgroupmembers, AadSites.Instance, new AadDrives() }; NeoWriter.WriteHeaders(); foreach (IDataCollectorAsync collector in collectors) { try { NeoWriter.WriteIDataCollector(collector, driver, true, true); } catch (Exception e) { Console.WriteLine("There was an error collecting data for " + collector.GetType()); Console.WriteLine(e.Message); } } //cleanup if (batchmode == true) { Console.Write("Exiting."); for (int i = 0; i < 3; i++) { System.Threading.Thread.Sleep(500); Console.Write("."); } } else { Console.WriteLine(); Console.WriteLine("Press any key to exit"); Console.ReadLine(); } }
/// <summary> /// Initializes the singleton connection /// </summary> public override void InitializeConnection() { connector = Neo4jConnector.Instance(); }