Atlantiraptor Docs

Cloud.M365.PasswordSpray

Type: Server

Hunts Entra ID sign-in failures for password spraying (one address trying a few passwords against many accounts) and brute force (many failures against one account), and flags any account that then signed in successfully from a spraying address.

Needs Entra ID P1 or P2 and AuditLog.Read.All.

Parameters

Name Type Default Description
M365Secret string Name of the “Microsoft 365 Creds” secret for the tenant.
LookbackHours int 48
SprayMinUsers int 10 An address that failed against at least this many accounts is spraying.
BruteForceMinFailures int 30 At least this many failures against one account is brute force.
FailureCodes regex (see the artifact source) Entra sign-in error codes that count as a failed password or MFA attempt.

Source

Defined in artifacts/definitions/Cloud/M365/PasswordSpray.yaml.

name: Cloud.M365.PasswordSpray
description: |
  Hunts Entra ID sign-in failures for password spraying (one address
  trying a few passwords against many accounts) and brute force (many
  failures against one account), and flags any account that then signed
  in successfully from a spraying address.

  Needs Entra ID P1 or P2 and `AuditLog.Read.All`.

type: SERVER

parameters:
  - name: M365Secret
    description: Name of the "Microsoft 365 Creds" secret for the tenant.
  - name: LookbackHours
    type: int
    default: 48
  - name: SprayMinUsers
    type: int
    default: 10
    description: An address that failed against at least this many accounts is spraying.
  - name: BruteForceMinFailures
    type: int
    default: 30
    description: At least this many failures against one account is brute force.
  - name: FailureCodes
    type: regex
    default: "^(50126|50053|50034|50055|50056|50057|50064|50072|50074|50076|50079|50158|53003|500121)$"
    description: Entra sign-in error codes that count as a failed password or MFA attempt.

sources:
  - query: |
      LET WindowStart <= now() - LookbackHours * 3600

      LET SignIns <= SELECT timestamp(string=createdDateTime) AS Time,
             timestamp(string=createdDateTime).Unix AS Epoch,
             userPrincipalName AS User, ipAddress AS IPAddress,
             format(format="%v, %v", args=[location.city, location.countryOrRegion]) AS Location,
             str(str=status.errorCode) AS ErrorCode, status.errorCode = 0 AS Success,
             appDisplayName AS App, clientAppUsed AS ClientApp, userAgent AS UserAgent
      FROM m365_graph(secret=M365Secret, beta=TRUE,
          path="/auditLogs/signIns", time_field="createdDateTime",
          start=timestamp(epoch=WindowStart), params=dict(`$top`="999"))

      LET Failures <= SELECT * FROM SignIns WHERE ErrorCode =~ FailureCodes

      // Distinct accounts per address.
      LET PerAddressUser <= SELECT IPAddress, User, count() AS N, min(item=Epoch) AS First,
             Location, ClientApp, UserAgent
          FROM Failures GROUP BY IPAddress, User
      LET PerAddress <= SELECT IPAddress, count() AS Users, sum(item=N) AS Failures,
             enumerate(items=User) AS Targets, min(item=First) AS First,
             Location, ClientApp, UserAgent
          FROM PerAddressUser GROUP BY IPAddress

      LET Sprayers <= SELECT * FROM PerAddress WHERE Users >= SprayMinUsers
      LET SprayIPs <= to_dict(item={ SELECT IPAddress AS _key, Users AS _value FROM Sprayers })

      LET Spray = SELECT timestamp(epoch=First) AS Time, "high" AS Severity,
             "Password spray from this address" AS Detection,
             format(format="%v accounts", args=Users) AS User, IPAddress, Location,
             "" AS Device,
             dict(Failures=Failures, Accounts=Targets, ClientApp=ClientApp,
                  UserAgent=UserAgent) AS Details
      FROM Sprayers

      LET SprayThenSuccess = SELECT Time, "critical" AS Severity,
             "Successful sign-in from a password-spraying address" AS Detection,
             User, IPAddress, Location, "" AS Device,
             dict(App=App, ClientApp=ClientApp, UserAgent=UserAgent,
                  AccountsSprayed=get(item=SprayIPs, field=IPAddress)) AS Details
      FROM SignIns
      WHERE Success AND get(item=SprayIPs, field=IPAddress)
      GROUP BY User, IPAddress

      LET PerUser <= SELECT User, count() AS N, enumerate(items=IPAddress) AS Addresses,
             min(item=Epoch) AS First, Location
          FROM Failures GROUP BY User

      LET BruteForce = SELECT timestamp(epoch=First) AS Time, "medium" AS Severity,
             "Many failed sign-ins against one account" AS Detection,
             User, Addresses[0] AS IPAddress, Location, "" AS Device,
             dict(Failures=N, Addresses=Addresses) AS Details
      FROM PerUser
      WHERE N >= BruteForceMinFailures

      SELECT * FROM chain(a=Spray, b=SprayThenSuccess, c=BruteForce)

Edit this page on GitHub

© 2026 Atlant Security EOOD. Atlantiraptor is free software under the GNU Affero General Public License v3. It is based on Velociraptor by Velocidex, and keeps its copyright notices. Velociraptor is a trademark of its owner; Atlantiraptor is not affiliated with or endorsed by it.