<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Clear Path Security Ltd</title>
    <description>The latest articles on DEV Community by Clear Path Security Ltd (@clearpathsecurity).</description>
    <link>https://dev.to/clearpathsecurity</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4131773%2F5e4f38d2-b1da-4666-bb73-a19a8e22f9c3.png</url>
      <title>DEV Community: Clear Path Security Ltd</title>
      <link>https://dev.to/clearpathsecurity</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/clearpathsecurity"/>
    <language>en</language>
    <item>
      <title>Risks of hard-coded secrets in software</title>
      <dc:creator>Clear Path Security Ltd</dc:creator>
      <pubDate>Wed, 23 Sep 2026 14:13:59 +0000</pubDate>
      <link>https://dev.to/clearpathsecurity/risks-of-hard-coded-secrets-in-software-9jo</link>
      <guid>https://dev.to/clearpathsecurity/risks-of-hard-coded-secrets-in-software-9jo</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on the ClearPath Security site: &lt;a href="https://clearpathsecurity.co.uk/risks-of-hard-coded-secrets-in-software/" rel="noopener noreferrer"&gt;https://clearpathsecurity.co.uk/risks-of-hard-coded-secrets-in-software/&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Risks of hard-coded secrets in software
&lt;/h1&gt;

&lt;p&gt;For many UK SMEs, software is now part of day-to-day business operations, whether it supports sales, customer service, finance, or operations. That makes the way software is built and maintained a business issue, not just a technical one. One of the most common and avoidable mistakes is putting secrets directly into code or related files.&lt;/p&gt;

&lt;p&gt;A secret is any value that should stay private because it gives access to something valuable. That might be a password, an application token, an API key, or a connection string. If that information is written into software and later exposed, the impact can spread well beyond the original mistake. It can affect customers, suppliers, revenue, and reputation.&lt;/p&gt;

&lt;p&gt;This article explains the risks of hard-coded secrets in software in plain English, where they usually appear, how they get exposed, and what SMEs can do to reduce the risk without slowing delivery.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hard-coded secrets can expose multiple systems at once, turning a small coding mistake into a wider business incident.&lt;/li&gt;
&lt;li&gt;The main risks are downtime, fraud, data loss, and reputational damage if a secret is copied or exposed.&lt;/li&gt;
&lt;li&gt;Keep secrets out of code, store them in a dedicated secrets manager, and limit who can access them.&lt;/li&gt;
&lt;li&gt;Rotate any secret that may have been exposed and remove credentials that are no longer needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What hard-coded secrets are and why they matter
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Simple definition in plain English
&lt;/h3&gt;

&lt;p&gt;Hard-coded secrets are private values written directly into source code, scripts, or configuration files instead of being stored securely elsewhere. In practice, that means the secret is fixed in the software itself rather than being supplied safely when the software runs.&lt;/p&gt;

&lt;p&gt;This is risky because code is often copied, shared, reviewed, backed up, and deployed in many places. Once a secret is embedded in that flow, it becomes much harder to control. Even if the code is later changed, older copies may still exist in repositories, backups, test systems, or developer machines.&lt;/p&gt;

&lt;h3&gt;
  
  
  Common examples in business software
&lt;/h3&gt;

&lt;p&gt;In an SME environment, hard-coded secrets often include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Passwords for databases or admin accounts&lt;/li&gt;
&lt;li&gt;Application keys used to connect to cloud services&lt;/li&gt;
&lt;li&gt;Tokens for payment, messaging, or customer support tools&lt;/li&gt;
&lt;li&gt;Certificates or private keys used to prove identity between systems&lt;/li&gt;
&lt;li&gt;Test credentials left in scripts or sample files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These values are often added for convenience during development, then forgotten. The problem is not only that they are visible in code. It is that they are easy to copy into other places and difficult to track once they have spread.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why hard-coded secrets create business risk
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How one exposed secret can affect multiple systems
&lt;/h3&gt;

&lt;p&gt;A single exposed secret can open the door to more than one system. For example, one application token might allow access to a cloud platform, a database, and a third-party service. If that token is reused across environments, the same mistake can affect development, testing, and live systems at the same time.&lt;/p&gt;

&lt;p&gt;That is why hard-coded secrets are not just a coding issue. They can become a route into core business services. If an attacker or unauthorised user finds one secret, they may be able to use it to reach other connected systems that trust it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Likely business impacts: downtime, fraud, data loss, and reputation damage
&lt;/h3&gt;

&lt;p&gt;The business impact depends on what the secret protects, but common outcomes include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Service disruption if systems have to be shut down or rebuilt&lt;/li&gt;
&lt;li&gt;Fraud or misuse if a payment or account token is abused&lt;/li&gt;
&lt;li&gt;Data loss or unauthorised access if a database credential is exposed&lt;/li&gt;
&lt;li&gt;Customer concern if sensitive information is accessed or leaked&lt;/li&gt;
&lt;li&gt;Reputational damage if the issue becomes public or affects a client&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For an SME, even a short interruption can be costly. Staff may lose time investigating the issue, customers may be unable to use a service, and the business may need urgent support from developers or external specialists. If the secret is tied to a supplier or customer integration, the problem can also affect relationships and contract confidence.&lt;/p&gt;

&lt;p&gt;Hard-coded secrets can also create a false sense of security. A team may believe a system is protected because access is limited in one place, while the same secret is sitting in plain text elsewhere. That is why secure development needs to be treated as part of business risk management. If you are building or buying software, it is worth considering the wider secure development approach described in &lt;a href="https://clearpathsecurity.co.uk/secure-software-development-why-it-matters/" rel="noopener noreferrer"&gt;Secure Software Development – Why It Matters&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where hard-coded secrets usually appear
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Source code and configuration files
&lt;/h3&gt;

&lt;p&gt;The most obvious place is source code. Developers may place a password, token, or key directly in a file so the software works quickly during testing. Configuration files are another common location, especially where teams want to keep settings separate from the main code but still store them in the same project.&lt;/p&gt;

&lt;p&gt;This is especially common in small teams where people wear multiple hats and deadlines are tight. The issue is understandable, but it should not become normal practice. If secrets are in code or configuration files, they are more likely to be copied, committed to version control, or shared with others who do not need them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scripts, build pipelines, and test environments
&lt;/h3&gt;

&lt;p&gt;Secrets also appear in scripts used to deploy software, run tests, or connect systems together. Build pipelines can be another weak point if credentials are added directly into automated steps. Test environments are particularly risky because people often treat them as temporary and less sensitive, even though they may still contain real data or access to real services.&lt;/p&gt;

&lt;p&gt;It is also common for teams to use the same secret in more than one place because it is easier to manage in the short term. That convenience can create a bigger problem later, because one exposed value may affect several environments at once.&lt;/p&gt;

&lt;h2&gt;
  
  
  How secrets get exposed in real-world operations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Shared code repositories and copied files
&lt;/h3&gt;

&lt;p&gt;Secrets are often exposed through everyday working habits rather than a dramatic attack. A file may be copied into a shared folder, checked into a code repository, or sent to a colleague for troubleshooting. Once that happens, the secret may be visible to more people than intended.&lt;/p&gt;

&lt;p&gt;Version control systems can make this worse because they keep a history of changes. Even if a secret is removed from the latest version, it may still exist in earlier commits or branches. That means the problem can remain long after the team thinks it has been fixed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Backups, logs, and developer workstations
&lt;/h3&gt;

&lt;p&gt;Backups can preserve secrets that were supposed to be temporary. Logs may also capture values that were never meant to be recorded, especially if an application prints configuration details during startup or error handling. Developer workstations are another common exposure point because they often contain local copies of code, test files, and credentials.&lt;/p&gt;

&lt;p&gt;For SMEs, this matters because the same small set of people often manage development, deployment, and support. That makes it easier for secrets to spread across laptops, shared drives, and cloud tools without anyone noticing. Good control is less about blame and more about reducing the number of places where a secret can live.&lt;/p&gt;

&lt;h2&gt;
  
  
  What attackers or unauthorised users can do with exposed secrets
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Access cloud services, databases, or third-party tools
&lt;/h3&gt;

&lt;p&gt;If a secret is exposed, it may allow access to cloud services, databases, messaging platforms, payment systems, or customer support tools. The exact impact depends on the permissions attached to the secret. Even a limited account can still be useful if it provides a starting point into a wider environment.&lt;/p&gt;

&lt;p&gt;Unauthorised access is not always obvious at first. A stolen token may be used quietly, or a password may be tested later. That delay can make the issue harder to spot and investigate.&lt;/p&gt;

&lt;h3&gt;
  
  
  Move through connected systems or misuse trusted integrations
&lt;/h3&gt;

&lt;p&gt;Many business systems are connected through trusted integrations. That is useful for efficiency, but it also means one exposed secret can be used to move between systems that trust each other. An attacker may not need to break in through the front door if a trusted connection is already available.&lt;/p&gt;

&lt;p&gt;This is one reason why hard-coded secrets are so important to address early. They can turn a small mistake into a wider incident because they sit at the point where systems, suppliers, and business processes meet. If your organisation relies heavily on third-party tools, it is also worth reviewing the broader supply chain angle in How third-party software introduces cyber risk for UK SMEs.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to reduce the risk without slowing delivery
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Use a dedicated secrets manager instead of storing values in code
&lt;/h3&gt;

&lt;p&gt;The safest approach is to keep secrets out of code and store them in a dedicated secrets manager. This is a secure place designed to hold private values and provide them to applications when needed. The software then reads the secret at run time rather than carrying it around in the codebase.&lt;/p&gt;

&lt;p&gt;For SMEs, the important point is not the brand of tool. It is the principle. Keep secrets in one controlled place, limit who can view them, and make sure applications only receive the access they need. If you are building this capability, our guide to &lt;a href="https://clearpathsecurity.co.uk/secrets-management-using-key-vaults-and-hsms-a-practical-guide-for-uk-smes/" rel="noopener noreferrer"&gt;secrets management using key vaults and HSMs&lt;/a&gt; explains the practical options in more detail.&lt;/p&gt;

&lt;h3&gt;
  
  
  Limit access, rotate secrets, and remove unused credentials
&lt;/h3&gt;

&lt;p&gt;Access should be restricted to the smallest practical group of people and systems. Not every developer, tester, or contractor needs access to every secret. If a secret is no longer needed, remove it. If it may have been exposed, change it quickly. This is often called rotation, which simply means replacing the old value with a new one.&lt;/p&gt;

&lt;p&gt;It is also sensible to review whether some secrets are still in use at all. SMEs often keep old credentials around because nobody wants to break a live integration. A regular review helps remove forgotten accounts and reduces the number of places an attacker could try.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practical checks for SMEs
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Review code, repositories, and deployment scripts
&lt;/h3&gt;

&lt;p&gt;A practical first step is to look for secrets in the places where they are most likely to hide. Check source code, configuration files, deployment scripts, and any shared repository used by the team. Pay attention to old branches, sample files, and test data as well as the main application code.&lt;/p&gt;

&lt;p&gt;It is worth making this a routine check rather than a one-off clean-up. Secrets can slip back in when teams are under pressure, especially during urgent fixes or new releases.&lt;/p&gt;

&lt;h3&gt;
  
  
  Check who can access secrets and how often they are changed
&lt;/h3&gt;

&lt;p&gt;Ask three simple questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Who can see each secret?&lt;/li&gt;
&lt;li&gt;Where is it stored?&lt;/li&gt;
&lt;li&gt;When was it last changed?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the answer is unclear, that is a sign the process needs tightening. You do not need a large security programme to improve this. Many SMEs can make meaningful progress by tightening access, documenting where secrets live, and setting a regular review cycle.&lt;/p&gt;

&lt;p&gt;If your team is still building secure development habits, it may help to revisit the basics in Secure coding principles explained for product teams and then add simple checks into everyday delivery.&lt;/p&gt;

&lt;h2&gt;
  
  
  A simple action plan for teams
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Find and replace hard-coded secrets
&lt;/h3&gt;

&lt;p&gt;Start by identifying where secrets are currently stored. Replace hard-coded values with secure references to a secrets manager or another controlled storage method. Remove old copies from code, scripts, and test files where possible.&lt;/p&gt;

&lt;p&gt;Then rotate any secret that may already have been exposed. If a value has been in code, in a shared file, or in a public repository, assume it should be treated as compromised until proven otherwise. That is a cautious but sensible position for business protection.&lt;/p&gt;

&lt;h3&gt;
  
  
  Set rules for secure storage and handling going forward
&lt;/h3&gt;

&lt;p&gt;Once the immediate clean-up is done, set a simple rule: secrets must not be stored in code. Back that up with a practical process for storing, approving, and changing them. Make sure developers, contractors, and anyone who deploys software understands the rule and knows where to put secrets instead.&lt;/p&gt;

&lt;p&gt;It also helps to add a basic check before release, so secrets are spotted before software goes live. For growing teams, that kind of control is often more effective than relying on memory or good intentions.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to get outside help
&lt;/h2&gt;

&lt;h3&gt;
  
  
  If secrets are spread across multiple systems
&lt;/h3&gt;

&lt;p&gt;If you suspect secrets are already spread across code, repositories, backups, and cloud tools, it may be difficult to clean up safely without help. The main challenge is not just finding the secrets. It is understanding which ones are still active, which systems depend on them, and what needs to be changed first.&lt;/p&gt;

&lt;p&gt;Outside support can help you reduce the risk in a structured way and avoid accidental disruption to live services. That is often useful when the business depends on a small number of people who already have full workloads.&lt;/p&gt;

&lt;h3&gt;
  
  
  If you need help improving secure development practices
&lt;/h3&gt;

&lt;p&gt;If hard-coded secrets are only one part of a wider development issue, it may be time to improve the overall secure development process. That can include clearer rules for code review, safer release steps, better access control, and more consistent handling of sensitive information.&lt;/p&gt;

&lt;p&gt;For SMEs that want a practical, risk-based approach, external advice can help turn a one-off fix into a repeatable way of working. If that would be useful, you can speak to a consultant for support tailored to your environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Hard-coded secrets are easy to overlook because they often start as a convenience. The business risk appears later, when those secrets are copied, exposed, or reused in more places than intended. At that point, a small coding shortcut can become a wider incident involving downtime, fraud, data loss, or reputational harm.&lt;/p&gt;

&lt;p&gt;For UK SMEs, the most practical response is straightforward. Keep secrets out of code, store them in a dedicated secrets manager, limit access, rotate them when needed, and build simple checks into everyday development and release work. Those steps do not need to be complicated to be effective.&lt;/p&gt;

&lt;p&gt;If you want help reviewing your current approach or improving secure development practices across your team, a short conversation with an experienced adviser can be a sensible place to start.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is the meaning of risk?
&lt;/h3&gt;

&lt;p&gt;Risk is the chance that something bad will happen and the impact it would have if it does. In software, that usually means asking how likely a problem is and how much it could cost the business.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are examples of risk in software?
&lt;/h3&gt;

&lt;p&gt;Examples include exposed passwords, insecure data handling, service outages, unauthorised access, and software defects that affect customers or operations. Hard-coded secrets are a good example because they can create several of these problems at once.&lt;/p&gt;

</description>
      <category>security</category>
      <category>cybersecurity</category>
      <category>devops</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Detecting OAuth consent phishing in Microsoft 365 audit logs</title>
      <dc:creator>Clear Path Security Ltd</dc:creator>
      <pubDate>Wed, 23 Sep 2026 14:13:56 +0000</pubDate>
      <link>https://dev.to/clearpathsecurity/detecting-oauth-consent-phishing-in-microsoft-365-audit-logs-49dd</link>
      <guid>https://dev.to/clearpathsecurity/detecting-oauth-consent-phishing-in-microsoft-365-audit-logs-49dd</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on the ClearPath Security site: &lt;a href="https://clearpathsecurity.co.uk/detecting-oauth-consent-phishing-in-microsoft-365-audit-logs/" rel="noopener noreferrer"&gt;https://clearpathsecurity.co.uk/detecting-oauth-consent-phishing-in-microsoft-365-audit-logs/&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;OAuth consent phishing is a practical identity attack that abuses the trust users place in application consent prompts. Instead of stealing a password directly, the attacker persuades a user to grant a malicious app access to mailbox data, profile information, files, or other Microsoft 365 resources. Once consent is granted, the app can keep operating until the grant is removed, which makes this a persistence mechanism as well as an initial access technique.&lt;/p&gt;

&lt;p&gt;For UK SMEs, the risk is less about a headline-grabbing breach and more about quiet abuse of normal business workflows. A compromised mailbox can be used for invoice fraud, internal phishing, data theft, or follow-on access to other cloud services. The good news is that Microsoft 365 and Entra ID provide enough telemetry to detect many of these cases if you know which events and fields matter, and if you treat consent activity as a first-class detection problem rather than a one-off admin task.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Detect OAuth consent phishing by correlating consent grants, service principal changes, and sign-in activity, not by relying on one log source.&lt;/li&gt;
&lt;li&gt;Treat first-seen applications, unusual permission scopes, and consent from unexpected users or locations as high-value hunting signals.&lt;/li&gt;
&lt;li&gt;Revoke malicious grants quickly, disable the application or service principal, and review mailbox access and token use for follow-on abuse.&lt;/li&gt;
&lt;li&gt;Reduce future risk by restricting user consent, using admin consent workflows, and alerting on new or high-risk grants.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What OAuth consent phishing is and why it matters
&lt;/h2&gt;

&lt;p&gt;In a typical consent phishing scenario, the attacker registers or uses an application that requests permissions such as Mail.Read, offline_access, Files.Read.All, or User.Read. The victim is then directed to a legitimate Microsoft consent screen, often via a convincing email, Teams message, or external website. If the user approves the request, the app receives an access token and, in some cases, a refresh token that can be used repeatedly without re-prompting the user.&lt;/p&gt;

&lt;p&gt;This differs from password theft in two important ways. First, the attacker may not need the user’s credentials at all, which means password resets alone may not remove the access path. Second, the activity can look like normal application usage unless you inspect consent events, service principal creation, and subsequent token use together. That is why detection needs to span identity logs, audit logs, and sign-in telemetry rather than relying on a single signal.&lt;/p&gt;

&lt;p&gt;Microsoft’s audit trail is especially useful because it can show when an application was created, when permissions were granted, and which actor approved the request. If you already have a central logging approach in place, as discussed in our guide to &lt;a href="https://clearpathsecurity.co.uk/what-security-logs-you-actually-need-and-why/" rel="noopener noreferrer"&gt;what security logs you actually need and why&lt;/a&gt;, consent events are one of the identity sources worth prioritising.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which Microsoft 365 and Entra ID logs to review
&lt;/h2&gt;

&lt;p&gt;The main sources are Microsoft 365 audit logs, Entra ID sign-in logs, and service principal activity. In practice, you want all three because each answers a different question. Audit logs tell you what changed, sign-in logs tell you who authenticated and from where, and service principal records tell you what the application can now do.&lt;/p&gt;

&lt;p&gt;Start with the Unified Audit Log in Microsoft Purview if it is available in your tenant. This is where you are most likely to see consent-related operations, application registrations, and permission changes. In Entra ID, sign-in logs help you validate whether the consented app was followed by unusual authentication patterns, such as token use from a new country, a new device, or a non-interactive sign-in that does not match the user’s normal behaviour.&lt;/p&gt;

&lt;p&gt;Service principal and enterprise application data are equally important. A malicious app may be created in the tenant, or a third-party app may be granted permissions that are broader than the business intended. If you are already hunting for identity abuse patterns, the techniques in &lt;a href="https://clearpathsecurity.co.uk/kql-queries-for-detecting-risky-entra-id-sign-ins-in-sentinel/" rel="noopener noreferrer"&gt;KQL queries for detecting risky Entra ID sign-ins in Sentinel&lt;/a&gt; can be adapted to correlate consent events with suspicious sign-in behaviour.&lt;/p&gt;

&lt;p&gt;Retention and licensing matter. If your audit retention window is short, you may miss the original consent event and only see downstream activity. That creates a blind spot, especially where the attacker waits before using the grant. Make sure your detection design accounts for the fact that some tenants will have richer audit history than others, and that older events may need to be exported into a SIEM for longer retention.&lt;/p&gt;

&lt;h2&gt;
  
  
  High-signal audit events and fields to look for
&lt;/h2&gt;

&lt;p&gt;The most useful events are those that show consent being granted, applications being registered, or permissions being assigned. Depending on your tenant configuration and log source, the exact operation names vary, but the pattern is consistent: look for app creation, service principal creation, consent grant, permission assignment, and admin consent approval.&lt;/p&gt;

&lt;p&gt;Useful fields include the actor, target application name, application or client ID, service principal ID, granted scopes, IP address, user agent, and timestamp. If the event includes the resource being requested, that is particularly valuable because it lets you distinguish a low-risk app from one asking for broad mailbox or directory access. Also capture whether the action was performed by a standard user or an administrator, because that changes both the likely abuse path and the response.&lt;/p&gt;

&lt;p&gt;For example, a newly created application with a generic name, a recently seen publisher, and high-privilege scopes such as Mail.ReadWrite, offline_access, or Directory.Read.All deserves more attention than a known line-of-business app with a stable client ID and a long history of use. The same applies if the consent comes from an account that normally never approves applications. That is where baselining becomes useful, not as a perfect detector, but as a way to separate expected business behaviour from unusual events.&lt;/p&gt;

&lt;h2&gt;
  
  
  Detection logic for suspicious consent activity
&lt;/h2&gt;

&lt;p&gt;A strong detection strategy starts with rarity. If an application has never been seen in your tenant before, or if it is first seen by a user who does not usually approve apps, that is worth investigating. You can also flag unusual permission scopes, especially when the requested access is broader than the app’s stated purpose. A calendar add-in asking for mail access, for example, is a classic mismatch.&lt;/p&gt;

&lt;p&gt;Location and device context also help. Consent granted from an unmanaged device, a new country, or an IP address that does not match the user’s usual working pattern increases suspicion. This is particularly relevant for UK SMEs with hybrid workforces, where a user may normally sign in from the office or home network and suddenly approve an app from a different region.&lt;/p&gt;

&lt;p&gt;Separate user-consent abuse from admin-consent abuse. User-consent abuse often relies on convincing an ordinary user to approve delegated permissions. Admin-consent abuse is more serious because it can grant tenant-wide access or permissions that bypass normal user boundaries. If your tenant allows user consent at all, you should treat consent to high-risk scopes as a detection event, not just a configuration issue. If only admins can approve apps, then any admin consent event should be monitored closely and correlated with change records or ticket references.&lt;/p&gt;

&lt;p&gt;One practical rule is to alert when a new or rarely seen application receives permissions that include mail, files, directory, or offline access, especially if the consent is followed by immediate token use. Another is to alert when the consenting user is outside a known approver group or when the app name resembles a common productivity tool but the publisher is unverified. These are not proof of compromise, but they are good triage candidates.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example hunting approach in Microsoft Sentinel or KQL
&lt;/h2&gt;

&lt;p&gt;In Microsoft Sentinel, a sensible starting point is to build a baseline of consent activity over 30 to 90 days. You want to know which applications are normally approved, by whom, from where, and at what frequency. That baseline can then be used to identify outliers such as first-seen app IDs, unusual scopes, or consent events outside business hours.&lt;/p&gt;

&lt;p&gt;A simple hunting pattern is to query audit logs for app consent or application registration events, then summarise by app ID, actor, and scope. From there, join to sign-in logs to see whether the same user or service principal generated unusual authentication events shortly afterwards. If you are using Sentinel, a KQL pattern might look like this in concept: filter the audit table for consent-related operations, extract the app identifier and scopes, then join on sign-in records for the same identity within a short time window. The exact table names and operation strings depend on your connector and tenant, so validate them in your environment before turning the logic into an analytic rule.&lt;/p&gt;

&lt;p&gt;For teams already using detection engineering practices, this is a good candidate for a Sigma-style rule translated into your SIEM, with a correlation layer that ties consent, sign-in, and mailbox access together. If you need a broader refresher on query structure and hunting workflow, our article on &lt;a href="https://clearpathsecurity.co.uk/kql-threat-hunting-with-microsoft-sentinel-a-practical-guide-for-uk-smes/" rel="noopener noreferrer"&gt;KQL threat hunting with Microsoft Sentinel&lt;/a&gt; covers the mechanics of building and tuning hunts.&lt;/p&gt;

&lt;p&gt;Correlating consent with mailbox access is especially useful. A malicious app may not trigger obvious interactive sign-ins, but it may still access mail via Graph API shortly after consent. If you see a new app consent followed by a burst of mailbox reads, attachment downloads, or directory enumeration, that is a stronger signal than consent alone.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to triage a suspected illicit consent grant
&lt;/h2&gt;

&lt;p&gt;When a suspicious grant appears, start by confirming the application identity. Check the display name, app ID, publisher, redirect URI, and the permissions granted. A legitimate business app should usually have a recognisable owner, a documented purpose, and a stable history. A suspicious app often has a generic name, a recently created service principal, or a publisher that does not match the business context.&lt;/p&gt;

&lt;p&gt;Next, determine the blast radius. Did the app receive delegated permissions for one user only, or application permissions that apply tenant-wide? Was the consent granted by a standard user, an admin, or a privileged role holder? Did the app request offline access, which can allow long-lived access without repeated user interaction? These questions help you decide whether the issue is limited to one mailbox or whether it may affect multiple accounts and data sets.&lt;/p&gt;

&lt;p&gt;Then look for persistence and downstream abuse. Review sign-in logs for the consenting account and the service principal. Check for mailbox access, file downloads, directory reads, or unusual API activity after the grant. If the app is part of a broader campaign, you may also see follow-on phishing from the compromised mailbox, changes to inbox rules, or attempts to add additional OAuth grants. This is where it helps to think in terms of attack chains rather than isolated alerts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Containment and remediation actions
&lt;/h2&gt;

&lt;p&gt;If you confirm the grant is malicious or likely malicious, revoke the consent promptly and disable the application or service principal. In many tenants, that means removing the enterprise application, deleting the app registration if it was created in your tenant, and revoking active sessions for the affected account. If the app was granted admin consent, review whether any other users or groups were exposed through the same app.&lt;/p&gt;

&lt;p&gt;Reset credentials for affected accounts where appropriate, but do not assume a password reset alone is enough. Review refresh tokens, active sessions, and mailbox rules. If the account had access to sensitive data or privileged roles, consider a broader review of recent activity and any other consented applications. You may also need to check whether the app has been used to access SharePoint, OneDrive, or other Microsoft 365 services.&lt;/p&gt;

&lt;p&gt;Conditional Access should be reviewed as part of containment, but it is not a complete answer on its own. It can reduce the chance of risky sign-ins, yet it does not automatically stop a user from approving a malicious app if your consent settings are permissive. That is why consent governance and identity controls need to work together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hardening to reduce future consent phishing risk
&lt;/h2&gt;

&lt;p&gt;The most effective hardening step is to reduce who can grant what. If your business can operate with user consent restricted, do that. Where user consent is allowed, limit it to low-risk permissions and consider requiring verified publishers. For higher-risk permissions, use an admin consent workflow so that requests are reviewed rather than approved ad hoc.&lt;/p&gt;

&lt;p&gt;Review your app governance settings regularly. Remove stale enterprise applications, disable unused app registrations, and keep an inventory of approved business apps with owners and purposes. This makes it much easier to spot a new or unexpected consent event. Least privilege still applies here: if an app only needs read-only access to a single mailbox or site, do not approve tenant-wide permissions.&lt;/p&gt;

&lt;p&gt;Alerting on new grants is also worthwhile. A lightweight rule that flags first-seen app IDs, high-risk scopes, or consent by non-approvers can give a small team enough time to investigate before the app is used at scale. If you already have a broader identity hardening programme, our guide to &lt;a href="https://clearpathsecurity.co.uk/secure-baseline-configurations-for-microsoft-365/" rel="noopener noreferrer"&gt;secure baseline configurations for Microsoft 365&lt;/a&gt; is a useful companion piece for tightening the surrounding controls.&lt;/p&gt;

&lt;h2&gt;
  
  
  Operationalising the detection in a small security team
&lt;/h2&gt;

&lt;p&gt;For a small team, the main challenge is not writing a single query. It is keeping the detection useful over time. Start by documenting the business-approved applications, the people allowed to approve them, and the normal permission patterns. Then tune your analytic rule so that it suppresses known-good apps but still alerts on new client IDs, unusual scopes, and suspicious consent locations.&lt;/p&gt;

&lt;p&gt;Map the detection to MITRE ATT&amp;amp;CK so that it is easier to explain in incident reviews and control mapping exercises. OAuth consent phishing aligns well with adversary-in-the-middle style initial access and persistence through valid accounts and tokens, although the exact technique mapping depends on the behaviour you observe. The value of the mapping is not the label itself, but the consistency it brings to detection coverage and reporting.&lt;/p&gt;

&lt;p&gt;Finally, tie the alert into your incident response playbook. The playbook should say who checks the app, who revokes access, who resets accounts, and who decides whether wider notification or recovery steps are needed. If you already maintain evidence and logs for investigations, keep the relevant audit records and sign-in data long enough to support that process. Our article on &lt;a href="https://clearpathsecurity.co.uk/retaining-evidence-and-logs-for-investigations-a-practical-guide-for-uk-smes/" rel="noopener noreferrer"&gt;retaining evidence and logs for investigations&lt;/a&gt; is a useful reference point for that operational discipline.&lt;/p&gt;

&lt;p&gt;Handled well, OAuth consent detection becomes a manageable part of identity monitoring rather than a specialist project. The key is to combine audit log visibility, sensible baselines, and a clear response path so that a suspicious grant is investigated quickly and consistently.&lt;/p&gt;

&lt;p&gt;If you want help reviewing your Microsoft 365 detection coverage, consent settings, or incident response workflow, speak to a consultant.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How do I detect OAuth consent phishing in Microsoft 365 audit logs?
&lt;/h3&gt;

&lt;p&gt;Look for consent grant events, application registrations, and permission assignments in the audit logs, then correlate them with Entra ID sign-in activity and service principal use. The strongest signals are first-seen apps, unusual scopes such as mail or directory access, and consent from unexpected users, locations, or devices.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Microsoft 365 log sources are most useful for finding illicit consent grants?
&lt;/h3&gt;

&lt;p&gt;The most useful sources are Microsoft 365 audit logs, Entra ID sign-in logs, and service principal or enterprise application records. Audit logs show the change, sign-in logs show the authentication context, and service principal data shows what the app can access after consent.&lt;/p&gt;

</description>
      <category>security</category>
      <category>cybersecurity</category>
      <category>devops</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Baselining and detecting anomalous PowerShell with script block logging</title>
      <dc:creator>Clear Path Security Ltd</dc:creator>
      <pubDate>Fri, 18 Sep 2026 16:50:27 +0000</pubDate>
      <link>https://dev.to/clearpathsecurity/baselining-and-detecting-anomalous-powershell-with-script-block-logging-1ej5</link>
      <guid>https://dev.to/clearpathsecurity/baselining-and-detecting-anomalous-powershell-with-script-block-logging-1ej5</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on the ClearPath Security site: &lt;a href="https://clearpathsecurity.co.uk/baselining-and-detecting-anomalous-powershell-with-script-block-logging/" rel="noopener noreferrer"&gt;https://clearpathsecurity.co.uk/baselining-and-detecting-anomalous-powershell-with-script-block-logging/&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;PowerShell is one of the most useful administrative tools in Windows environments, which is exactly why it deserves dedicated detection coverage. It is used for software deployment, identity and endpoint administration, cloud management, and routine automation. It is also frequently abused because it can run in memory, invoke native Windows components, and blend into normal administrator activity.&lt;/p&gt;

&lt;p&gt;For UK SMEs, the goal is not to treat every PowerShell invocation as suspicious. The aim is to understand what normal looks like in your environment, collect enough telemetry to spot meaningful deviations, and turn that into detections that are useful to a small security team. If you already have basic logging in place, &lt;a href="https://clearpathsecurity.co.uk/logging-and-monitoring-basics-for-small-teams/" rel="noopener noreferrer"&gt;logging and monitoring basics for small teams&lt;/a&gt; is a sensible companion topic. This article focuses on the next step: building a baseline for PowerShell and using script block logging to identify anomalous behaviour.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Script block logging is most useful when combined with process, identity, and network telemetry rather than used in isolation.&lt;/li&gt;
&lt;li&gt;Build a baseline around trusted hosts, users, parent processes, and script locations so that detections focus on meaningful deviations.&lt;/li&gt;
&lt;li&gt;Prioritise high-signal patterns such as encoded commands, unusual execution paths, and suspicious parent-child relationships.&lt;/li&gt;
&lt;li&gt;Tune detections using frequency, rarity, and context to reduce noise without suppressing genuine abuse.&lt;/li&gt;
&lt;li&gt;Review and validate PowerShell detections regularly because legitimate automation and administration patterns change over time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why PowerShell deserves dedicated detection coverage
&lt;/h2&gt;

&lt;p&gt;PowerShell is not just another command shell. It exposes access to Windows Management Instrumentation, the registry, Active Directory, scheduled tasks, services, and network functions. In legitimate use, that makes it efficient for administrators. In malicious use, it gives an operator a flexible way to enumerate systems, stage payloads, disable controls, or move laterally.&lt;/p&gt;

&lt;p&gt;That dual use matters because many defensive tools see only fragments of the activity. Process creation logs may show &lt;code&gt;powershell.exe&lt;/code&gt;, but not the full script. Network logs may show a connection, but not the command that initiated it. Script block logging fills part of that gap by recording the content PowerShell interprets after de-obfuscation.&lt;/p&gt;

&lt;p&gt;In practice, PowerShell detections work best when they are part of a wider Windows telemetry strategy. Process telemetry, Windows Security logs, Sysmon, and network data all add context. If you are already using endpoint controls to reduce attack surface, &lt;a href="https://clearpathsecurity.co.uk/reducing-attack-surface-using-system-hardening-techniques-for-uk-smes/" rel="noopener noreferrer"&gt;reducing attack surface using system hardening techniques&lt;/a&gt; can help you decide which PowerShell features should be restricted or monitored more closely.&lt;/p&gt;

&lt;h2&gt;
  
  
  What script block logging captures and what it does not
&lt;/h2&gt;

&lt;p&gt;Script block logging records the content of PowerShell script blocks, typically through Event ID 4104 in the Microsoft-Windows-PowerShell operational log. The value is that it captures the script after PowerShell has parsed it, which can expose decoded or expanded content that would otherwise be hidden by simple command-line obfuscation.&lt;/p&gt;

&lt;p&gt;That makes it useful for detecting suspicious strings, unusual function calls, encoded content, and common tradecraft such as download cradles or reflective loading patterns. It is especially helpful when an attacker uses short, heavily obfuscated commands that would be hard to triage from process creation alone.&lt;/p&gt;

&lt;p&gt;However, script block logging is not complete visibility. It does not guarantee that every malicious action will be logged, and it does not tell you intent. It also depends on the relevant logging being enabled, the event reaching your collection point, and the script being executed through PowerShell in a way that produces useful content. Some activity may occur through other interpreters, native binaries, WMI, scheduled tasks, or remote management channels. For that reason, detections should correlate PowerShell events with broader telemetry rather than relying on a single log source.&lt;/p&gt;

&lt;p&gt;There is also a practical distinction between content and context. A script block may look unusual in isolation, but be perfectly normal for a deployment tool or a management script. That is why baselining is essential.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building a useful baseline for normal PowerShell activity
&lt;/h2&gt;

&lt;p&gt;A baseline is not a static allowlist. It is a working understanding of what normal PowerShell activity looks like across your estate, so that you can identify outliers. Start by identifying the systems, users, and tools that legitimately generate PowerShell at scale.&lt;/p&gt;

&lt;p&gt;For most SMEs, those will include endpoint management platforms, patching tools, software deployment agents, backup agents, and a small set of privileged administrators. Record which hosts generate PowerShell, which accounts run it, which parent processes launch it, and which command patterns recur. This gives you a practical view of expected behaviour.&lt;/p&gt;

&lt;p&gt;Separate routine automation from interactive use. A scheduled task that runs a signed script from a known path every night is very different from an administrator opening an interactive shell on a finance workstation at 11pm. The first may be normal. The second may still be legitimate, but it deserves context.&lt;/p&gt;

&lt;p&gt;When building the baseline, focus on a few dimensions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Trusted hosts, such as jump servers, management servers, and endpoint management consoles.&lt;/li&gt;
&lt;li&gt;Trusted users and groups, especially privileged accounts and service accounts.&lt;/li&gt;
&lt;li&gt;Trusted parent processes, such as management agents or approved automation runners.&lt;/li&gt;
&lt;li&gt;Trusted script locations, for example signed scripts in controlled repositories.&lt;/li&gt;
&lt;li&gt;Expected frequency, such as daily patching windows or weekly maintenance jobs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is also useful to compare PowerShell usage by device class. A domain controller, a management server, and a user laptop should not look the same. If they do, that may indicate over-permissive administration or a lack of role separation. For a broader view of how PowerShell abuse fits into attacker behaviour, &lt;a href="https://clearpathsecurity.co.uk/detecting-fileless-malware-and-living-off-the-land-attacks-a-practical-guide-for-uk-smes/" rel="noopener noreferrer"&gt;detecting fileless malware and living-off-the-land attacks&lt;/a&gt; provides useful context.&lt;/p&gt;

&lt;h2&gt;
  
  
  Telemetry sources to combine with script block logging
&lt;/h2&gt;

&lt;p&gt;Script block logging is strongest when combined with other Windows telemetry. At minimum, pair it with PowerShell operational logs, Windows Security logs, and Sysmon if you can support it operationally.&lt;/p&gt;

&lt;p&gt;PowerShell operational logs help you see engine lifecycle events and script block content. Windows Security logs provide logon events, privilege use, and process creation if configured appropriately. Sysmon adds richer process creation, network connections, image loads, and command-line detail. Together, they let you answer not just what script ran, but who ran it, from where, and what it touched next.&lt;/p&gt;

&lt;p&gt;Useful correlations include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Event ID 4104 with process creation events to identify the parent process and command line.&lt;/li&gt;
&lt;li&gt;PowerShell activity followed by outbound network connections to unfamiliar destinations.&lt;/li&gt;
&lt;li&gt;PowerShell launched from office applications, archive utilities, or script hosts that are unusual for the user.&lt;/li&gt;
&lt;li&gt;PowerShell activity on servers that should rarely need interactive administration.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sysmon is particularly valuable where you need process ancestry and network context. If you are tuning that layer as well, detecting living-off-the-land binaries with Sysmon process events is a good reference point for building process-based detections that complement PowerShell telemetry.&lt;/p&gt;

&lt;h2&gt;
  
  
  Patterns that often indicate suspicious PowerShell behaviour
&lt;/h2&gt;

&lt;p&gt;There is no single malicious PowerShell signature that works everywhere, but there are recurring patterns that deserve attention. The most common include encoded commands, heavy obfuscation, unusual execution switches, and scripts that retrieve or execute content from remote sources.&lt;/p&gt;

&lt;p&gt;Encoded commands are often used to hide the real content from casual inspection. Obfuscation may involve string concatenation, variable indirection, alias abuse, or deliberate formatting changes. Suspicious command-line switches include &lt;code&gt;-EncodedCommand&lt;/code&gt;, &lt;code&gt;-ExecutionPolicy Bypass&lt;/code&gt;, and combinations that suppress profile loading or hide the window. None of these are proof of malicious intent on their own, but they are strong indicators when they appear on endpoints that should not need them.&lt;/p&gt;

&lt;p&gt;Download cradles are another common pattern. These are commands that fetch content from the network and execute it immediately, often using native web request functions. In-memory execution, reflective loading, and script injection techniques may leave little on disk, which is why script block content and process context matter. Attackers also frequently use PowerShell as a staging mechanism before moving to other tools, so the PowerShell event may be only the first observable step.&lt;/p&gt;

&lt;p&gt;Look for unusual combinations rather than isolated strings. For example, a script block that uses web requests, base64 decoding, and process injection APIs is far more concerning than a simple administrative query. Similarly, PowerShell running from a user profile path, temporary directory, or email attachment location is more suspicious than a signed script from a controlled deployment share.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practical detection logic for small security teams
&lt;/h2&gt;

&lt;p&gt;Small teams need detections that are high signal and maintainable. Start with a small number of rules that are easy to explain and triage. Good candidates include rare parameter usage, suspicious parent-child relationships, unusual execution paths, and scripts that contain known risky behaviours.&lt;/p&gt;

&lt;p&gt;A practical rule set might include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PowerShell with &lt;code&gt;-EncodedCommand&lt;/code&gt; or equivalent encoded content.&lt;/li&gt;
&lt;li&gt;PowerShell launched by office applications, browser processes, archive tools, or scripting hosts that are not normally used for administration.&lt;/li&gt;
&lt;li&gt;PowerShell executed from user-writable directories such as &lt;code&gt;%AppData%&lt;/code&gt;, &lt;code&gt;%Temp%&lt;/code&gt;, or downloads folders.&lt;/li&gt;
&lt;li&gt;PowerShell script blocks containing web download functions, reflection, AMSI tampering indicators, or suspicious process creation.&lt;/li&gt;
&lt;li&gt;PowerShell activity on servers or workstations outside approved maintenance windows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use allowlists carefully. They are useful for reducing noise from known deployment tools, but they can also hide abuse if they are too broad. Prefer scoped allowlists based on signed binaries, known service accounts, specific management servers, and controlled script paths. Avoid blanket exclusions for entire command patterns unless you have strong evidence that they are safe in your environment.&lt;/p&gt;

&lt;p&gt;When possible, score detections by context rather than treating them as binary. A rare command on a privileged account, from an unusual host, outside business hours, should rank higher than the same command from a known management server during a patch window. That approach is often easier to operationalise than trying to write one perfect rule.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to tune detections without losing coverage
&lt;/h2&gt;

&lt;p&gt;Tuning is where many PowerShell detections either become useful or get switched off. The main challenge is reducing false positives from legitimate administration, software deployment, and automation frameworks without creating blind spots.&lt;/p&gt;

&lt;p&gt;Start by measuring frequency and rarity. Which commands appear every day, and which appear only once a month? Which hosts generate the most script block events, and do those hosts align with your expected management architecture? Which accounts are responsible for the majority of activity? These questions help you identify the normal operating envelope.&lt;/p&gt;

&lt;p&gt;Then add context. A script block that looks suspicious on a user laptop may be routine on a patching server. A command that is normal for a service account may be unusual for an interactive administrator. Time of day, source host, parent process, and user group membership all matter.&lt;/p&gt;

&lt;p&gt;Be careful not to over-tune around a single tool. If you suppress every event from one deployment platform, you may miss abuse through that platform, especially if an attacker compromises the management plane. A better approach is to validate the platform’s normal command patterns and then alert on deviations from those patterns.&lt;/p&gt;

&lt;p&gt;For teams that want to improve detection quality systematically, the same principles used in broader detection engineering apply here: define the behaviour, measure the noise, tune by context, and review regularly. If you are already working on credential misuse detection, &lt;a href="https://clearpathsecurity.co.uk/detecting-credential-theft-and-misuse-patterns-for-uk-smes/" rel="noopener noreferrer"&gt;detecting credential theft and misuse patterns&lt;/a&gt; is a useful adjacent reference because PowerShell abuse often overlaps with account compromise.&lt;/p&gt;

&lt;h2&gt;
  
  
  Threat hunting questions to ask in PowerShell logs
&lt;/h2&gt;

&lt;p&gt;Hunting is where script block logging becomes especially valuable. Rather than waiting for a rule to fire, use the logs to ask structured questions about behaviour.&lt;/p&gt;

&lt;p&gt;Useful hunting questions include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which hosts generate the most PowerShell script blocks, and do those hosts match their intended role?&lt;/li&gt;
&lt;li&gt;Which users run PowerShell interactively, and is that consistent with their job function?&lt;/li&gt;
&lt;li&gt;Which script blocks contain web requests, encoded content, or suspicious string manipulation?&lt;/li&gt;
&lt;li&gt;Which parent processes launch PowerShell most often, and are any unexpected?&lt;/li&gt;
&lt;li&gt;Which scripts run outside normal maintenance windows or from unusual paths?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hunting is also a good way to validate your baseline. If a host suddenly starts producing far more PowerShell activity than usual, that may indicate a new automation job, but it may also indicate an attacker using the host as an execution point. The key is to compare current behaviour with the established pattern, not with an abstract idea of what is normal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Operationalising detections in Microsoft Sentinel or a SIEM
&lt;/h2&gt;

&lt;p&gt;In a SIEM, the main task is to make PowerShell events searchable, normalised, and easy to correlate. In Microsoft Sentinel, that usually means ensuring the relevant Windows logs are ingested into a workspace, then building analytics rules and hunting queries around Event ID 4104 and related process telemetry.&lt;/p&gt;

&lt;p&gt;Normalisation matters because PowerShell content is often messy. Script blocks can be multiline, contain escaped characters, or be split across events. If your SIEM supports parsing or custom fields, extract the command content, host, account, parent process, and execution time into searchable fields. That makes it much easier to write detections and triage alerts.&lt;/p&gt;

&lt;p&gt;A practical workflow is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Ingest PowerShell operational logs and process telemetry from your endpoints and servers.&lt;/li&gt;
&lt;li&gt;Build one or two high-signal analytics rules for obvious suspicious patterns.&lt;/li&gt;
&lt;li&gt;Create hunting queries for rare commands, unusual hosts, and off-hours activity.&lt;/li&gt;
&lt;li&gt;Review alerts weekly to identify recurring false positives and new legitimate use cases.&lt;/li&gt;
&lt;li&gt;Promote validated hunts into scheduled detections where they add value.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you are designing the broader pipeline rather than just the rule content, centralised security visibility explained for SMEs can help frame how PowerShell telemetry fits into a wider visibility model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Validation, tuning, and continuous improvement
&lt;/h2&gt;

&lt;p&gt;Detections should be tested against known-good administrative activity and safe simulations. You do not need to recreate real attacker behaviour to validate whether your logging and rules are working. Instead, use benign scripts that exercise the same telemetry paths, such as encoded commands in a lab, remote administration from approved hosts, or scheduled automation from service accounts.&lt;/p&gt;

&lt;p&gt;Check three things during validation. First, does the event arrive in your SIEM with the fields you need? Second, does the rule trigger on the behaviour you expect? Third, can an analyst triage the alert quickly using the available context? If the answer to any of those is no, the detection is not yet operationally ready.&lt;/p&gt;

&lt;p&gt;Measure alert quality over time. Track false positives, time to triage, and the proportion of alerts that lead to useful investigation. If a rule is noisy but occasionally valuable, tune it rather than removing it immediately. If it is consistently noisy and low value, retire it and replace it with a more contextual rule.&lt;/p&gt;

&lt;p&gt;Continuous improvement is especially important in PowerShell monitoring because legitimate usage changes. New management tools, new automation scripts, and new cloud integrations can all alter the baseline. Review your detections after major changes to endpoint management, identity administration, or software deployment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation checklist for UK SMEs
&lt;/h2&gt;

&lt;p&gt;If you are starting from scratch, a phased approach is usually the most practical.&lt;/p&gt;

&lt;p&gt;Phase one is logging enablement. Turn on PowerShell script block logging on the systems that matter most, especially privileged workstations, servers, and management hosts. Make sure logs are forwarded centrally and retained long enough for investigation. If storage is limited, prioritise high-value assets rather than trying to capture everything at once.&lt;/p&gt;

&lt;p&gt;Phase two is baseline creation. Identify trusted hosts, users, and tools. Document the common parent processes, command patterns, and maintenance windows. Use that baseline to define what should be normal, and where exceptions need review.&lt;/p&gt;

&lt;p&gt;Phase three is detection. Start with a handful of high-signal rules for encoded commands, suspicious parent processes, unusual paths, and risky script content. Keep the rules understandable so that they can be maintained by a small team.&lt;/p&gt;

&lt;p&gt;Phase four is review and improvement. Revisit the baseline monthly, tune alerts based on real activity, and add new detections when you see repeatable patterns. If you want support designing that operating model, the service most aligned to this work is our Speak to a consultant option, which can help you shape practical logging and detection improvements without overengineering the solution.&lt;/p&gt;

&lt;p&gt;For UK SMEs, the most effective PowerShell monitoring programmes are usually the ones that are focused, well-instrumented, and reviewed regularly. You do not need perfect coverage on day one. You need enough visibility to spot meaningful deviations, enough context to triage them, and enough discipline to keep improving the baseline as your environment changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently asked questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Is script block logging enough on its own to detect malicious PowerShell?
&lt;/h3&gt;

&lt;p&gt;No. It is a strong source of content visibility, but it works best when combined with process creation, logon, and network telemetry so you can see who ran the script, from where, and what happened next.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the difference between script block logging and PowerShell transcription?
&lt;/h3&gt;

&lt;p&gt;Script block logging records the script content that PowerShell interprets, which is useful for seeing decoded or expanded commands. Transcription records the interactive session output and input as a text transcript, which can be useful for context but does not replace script block logging.&lt;/p&gt;

</description>
      <category>security</category>
      <category>cybersecurity</category>
      <category>devops</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
