public static void AnalyzeWordPressUrl(StoryUrlStats urlStats) { if (endsWithExtensionRegEx.IsMatch(urlStats.Url)) { return; //URL has extension not WordPress blog } using (var client = new WebClient()) { try { var pageContent = client.DownloadString(urlStats.Url); var themeNames = new HashSet <string>(); foreach (Match match in wpThemesRegEx.Matches(pageContent)) { themeNames.Add(match.Groups[1].Value); } var pluginNames = new HashSet <string>(); foreach (Match match in wpPluginsRegEx.Matches(pageContent)) { pluginNames.Add(match.Groups[1].Value); } urlStats.ThemeNames = themeNames.ToDelimitedString("/"); urlStats.PluginNames = pluginNames.ToDelimitedString("/"); } catch (WebException wex) { urlStats.FecthErrorStatus = wex.Status.ToString(); urlStats.FetchErrorMessage = wex.Message; } } }
public static void AnalyzeWordPressUrl(StoryUrlStats urlStats) { if (endsWithExtensionRegEx.IsMatch(urlStats.Url)) return; //URL has extension not WordPress blog using (var client = new WebClient()) { try { var pageContent = client.DownloadString(urlStats.Url); var themeNames = new HashSet<string>(); foreach (Match match in wpThemesRegEx.Matches(pageContent)) themeNames.Add(match.Groups[1].Value); var pluginNames = new HashSet<string>(); foreach (Match match in wpPluginsRegEx.Matches(pageContent)) pluginNames.Add(match.Groups[1].Value); urlStats.ThemeNames = themeNames.ToDelimitedString("/"); urlStats.PluginNames = pluginNames.ToDelimitedString("/"); } catch (WebException wex) { urlStats.FecthErrorStatus = wex.Status.ToString(); urlStats.FetchErrorMessage = wex.Message; } } }
public async Task <string> GetSicCodesAsync(string companyNumber) { if (companyNumber.IsNumber()) { companyNumber = companyNumber.PadLeft(8, '0'); } var codes = new HashSet <string>(); var company = await GetCompanyAsync(companyNumber); if (company == null) { return(null); } if (company.SicCodes != null) { foreach (var code in company.SicCodes) { codes.Add(code); } } return(codes.ToDelimitedString()); }
//public static EmployerRecord GetEmployer(string companyNumber) //{ // var task = Task.Run<string>(async () => await GetCompany(companyNumber)); // dynamic company = JsonConvert.DeserializeObject(task.Result); // if (string.IsNullOrWhiteSpace(company)) return null; // var employer = new EmployerRecord // { // Name = company.company_name, // CompanyNumber = company.company_number, // Address1 = company.registered_office_address.address_line_1, // Address2 = company.registered_office_address.address_line_2, // Address3 = company.registered_office_address.locality, // Country = company.registered_office_address.country, // PostCode = company.registered_office_address.postal_code, // PoBox = company.registered_office_address.po_box, // SicCodes = company.sic_codes // }; // return employer; //} public static string GetSicCodes(string companyNumber) { var codes = new HashSet <string>(); var task = Task.Run <string>(async() => await GetCompany(companyNumber)); dynamic company = JsonConvert.DeserializeObject(task.Result); if (company == null) { return(null); } if (company.sic_codes != null) { foreach (var code in company.sic_codes) { codes.Add(code.Value); } } return(codes.ToDelimitedString()); }
public static void Applications( string appDisplayName, string appId, HashSet <string> permissionsSet, HashSet <string> userIdSet, string principalId, string homePage, string appOwnerOrganizationId) { try { var gremlinVertices = new List <GremlinVertex>(); var gremlinEdges = new List <GremlinEdge>(); var vertex = new GremlinVertex(appId, nameof(Models.BloodHound.Application)); vertex.AddProperty(CosmosDbHelper.CollectionPartitionKey, appId.GetHashCode()); vertex.AddProperty(nameof(Application.DisplayName), appDisplayName?.ToUpper() ?? string.Empty); vertex.AddProperty(nameof(permissionsSet), permissionsSet.ToDelimitedString(",") ?? string.Empty); vertex.AddProperty(nameof(principalId), principalId ?? string.Empty); vertex.AddProperty(nameof(homePage), homePage ?? string.Empty); vertex.AddProperty(nameof(appOwnerOrganizationId), appOwnerOrganizationId ?? string.Empty); gremlinVertices.Add(vertex); if (appOwnerOrganizationId != null) { var vertexDomain = new GremlinVertex(appOwnerOrganizationId, nameof(Models.BloodHound.Domain)); vertexDomain.AddProperty(CosmosDbHelper.CollectionPartitionKey, appOwnerOrganizationId.GetHashCode()); vertexDomain.AddProperty(nameof(Application.DisplayName), appOwnerOrganizationId.ToUpper()); gremlinVertices.Add(vertexDomain); gremlinEdges.Add( new GremlinEdge( appOwnerOrganizationId + appId, "Owner", appOwnerOrganizationId, appId, nameof(Models.BloodHound.Domain), nameof(Application), appOwnerOrganizationId.GetHashCode(), appId.GetHashCode() )); } if (permissionsSet.Any(_ => string.Equals(_, "Directory.AccessAsUser.All", StringComparison.OrdinalIgnoreCase))) { userIdSet.ForEach(userId => gremlinEdges.Add( new GremlinEdge( appId + userId, "AccessAsUser", appId, userId, nameof(Models.BloodHound.Application), nameof(User), appId.GetHashCode(), userId.GetHashCode() )) ); } CosmosDbHelper.RunImportVerticesBlock.Post(gremlinVertices); CosmosDbHelper.RunImportEdgesBlock.Post(gremlinEdges); } catch (Exception e) { Console.WriteLine(e); throw; } }
// Cache last user roles and monitor for changes private void CacheLastUserRoles(object state) { try { // Using an inter-process cache for user roles using (UserRoleCache userRoleCache = UserRoleCache.GetCurrentCache()) { HashSet<string> currentRoles; string[] cachedRoles; // Retrieve current user roles currentRoles = new HashSet<string>(UserData.Roles, StringComparer.OrdinalIgnoreCase); // Attempt to retrieve cached user roles cachedRoles = userRoleCache[UserData.Username]; bool rolesChanged = false; string message; EventLogEntryType entryType; if ((object)cachedRoles == null) { if (currentRoles.Count == 0) { // New user access granted message = string.Format("Initial Encounter: user \"{0}\" attempted login with no assigned roles.", UserData.Username); entryType = EventLogEntryType.FailureAudit; rolesChanged = true; } else { // New user access granted message = string.Format("Initial Encounter: user \"{0}\" granted access with role{1} \"{2}\".", UserData.Username, currentRoles.Count == 1 ? "" : "s", currentRoles.ToDelimitedString(", ")); entryType = EventLogEntryType.Information; rolesChanged = true; } } else if (!currentRoles.SetEquals(cachedRoles)) { if (currentRoles.Count == 0) { // New user access granted message = string.Format("Subsequent Encounter: user \"{0}\" attempted login with no assigned roles - role assignment that existed at last login was \"{1}\".", UserData.Username, cachedRoles.ToDelimitedString(", ")); entryType = EventLogEntryType.FailureAudit; rolesChanged = true; } else { // User role access changed message = string.Format("Subsequent Encounter: user \"{0}\" granted access with new role{1} \"{2}\" - role assignment is different from last login, was \"{3}\".", UserData.Username, currentRoles.Count == 1 ? "" : "s", currentRoles.ToDelimitedString(", "), cachedRoles.ToDelimitedString(", ")); entryType = EventLogEntryType.Warning; rolesChanged = true; } } else { if (currentRoles.Count == 0) { // New user access granted message = string.Format("Subsequent Encounter: user \"{0}\" attempted login with no assigned roles - same as last login attempt.", UserData.Username); entryType = EventLogEntryType.FailureAudit; rolesChanged = true; } else { message = string.Format("Subsequent Encounter: user \"{0}\" granted access with role{1} \"{2}\" - role assignment is the same as last login.", UserData.Username, currentRoles.Count == 1 ? "" : "s", currentRoles.ToDelimitedString(", ")); entryType = EventLogEntryType.SuccessAudit; } } // Log granted role access to event log try { LogEvent(ApplicationName, message, entryType, 0); } catch (Exception ex) { LogError(ex.Source, ex.ToString()); } // If role has changed, update cache if (rolesChanged) { userRoleCache[UserData.Username] = currentRoles.ToArray(); userRoleCache.WaitForSave(); } } } catch (Exception ex) { LogError(ex.Source, ex.ToString()); } }
public static void Applications( string appDisplayName, string appId, HashSet <string> permissionsSet, string principalId) { try { var gremlinVertices = new List <GremlinVertex>(); var gremlinEdges = new List <GremlinEdge>(); var vertex = new GremlinVertex(appId, nameof(Application)); vertex.AddProperty(CosmosDbHelper.CollectionPartitionKey, appId.GetHashCode()); vertex.AddProperty(nameof(appDisplayName), appDisplayName?.ToUpper() ?? string.Empty); vertex.AddProperty(nameof(permissionsSet), permissionsSet.ToDelimitedString(",") ?? string.Empty); gremlinVertices.Add(vertex); var outVertexId = principalId ?? "AccessToAllPrincipals"; var gremlinEdge = new GremlinEdge( outVertexId + appId, "Granted", appId, outVertexId, nameof(Models.BloodHound.User), nameof(Application), appId.GetHashCode(), outVertexId.GetHashCode()); gremlinEdge.AddProperty(nameof(permissionsSet), permissionsSet.ToDelimitedString(",") ?? string.Empty); gremlinEdges.Add(gremlinEdge); var mailPermissions = new List <string> { "Mail.Read", "Mail.ReadBasic", "Mail.ReadWrite", "Mail.Read.Shared", "Mail.ReadWrite.Shared", "Mail.Send", "Mail.Send.Shared", "MailboxSettings.Read", "Mail.Read", "Mail.ReadWrite", "Mail.Send", "MailboxSettings.Read", "MailboxSettings.ReadWrite" }; if (permissionsSet.Overlaps(mailPermissions)) { gremlinEdge = new GremlinEdge( appId + "MailBoxes", "CanManipulate", appId, "MailBoxes", nameof(Application), nameof(Application), appId.GetHashCode(), "MailBoxes".GetHashCode()); gremlinEdges.Add(gremlinEdge); } CosmosDbHelper.RunImportVerticesBlock.Post(gremlinVertices); CosmosDbHelper.RunImportEdgesBlock.Post(gremlinEdges); } catch (Exception e) { Console.WriteLine(e); throw; } }
public override string ToString() { return(targets.ToDelimitedString() + " " + backendType.Name); }
public override string ToString() { return("rep named {" + name + "} members: " + members.ToDelimitedString()); }