Railway. LSHIY. Different Auth Flows, but the Same Lesson We Keep Skipping
Two distinct campaigns exploited Microsoft 365 authentication flow misconfigurations to bypass MFA at scale. The Railway campaign leveraged device code phishing via Railway.com PaaS infrastructure (attributed to the EvilTokens PhaaS platform), compromising 344 organizations by harvesting OAuth tokens valid up to 90 days. The LSHIY campaign used the deprecated ROPC OAuth flow to replay credentials against Azure CLI, attempting 81 million logins and compromising 78 accounts—55 of which had MFA policies that failed to cover the attack path due to scoping gaps, report-only enforcement, or mislabeled trusted locations.
- filenameAgreement_Review.pdfPhishing lure attachment filename used in Railway campaign device code phishing emails; construction RFP-themed
Detection / Hunteropenrouter
What Happened
Attackers found two ways to break into Microsoft 365 accounts without needing to steal passwords or defeat multi-factor authentication (MFA) directly. In the first campaign, they tricked users into entering a code on Microsoft's real login page, which gave the attackers a valid login token lasting up to 90 days. In the second, they used an older, rarely-blocked login method that let them submit usernames and passwords directly, bypassing MFA prompts entirely. Over 400 organizations were affected across multiple countries. Many victims believed they were protected because they had MFA turned on, but their security settings had gaps the attackers found and exploited. Organizations should review their Microsoft 365 security policies to ensure all login methods—including older ones—are covered by MFA, and that policies apply to all users and all applications, not just a subset.
Key Takeaways
- Device code phishing sidesteps MFA entirely by abusing Microsoft's OAuth device authorization grant flow, yielding tokens valid up to 90 days regardless of MFA completion
- ROPC (Resource Owner Password Credentials) flow bypasses most Conditional Access MFA policies because it targets the /token endpoint directly and is often excluded from Azure CLI coverage
- 55 of 78 LSHIY-compromised accounts had active MFA Conditional Access policies that failed to protect them due to scoping gaps, report-only mode, or mislabeled trusted locations
- EvilTokens operates as a commercial Phishing-as-a-Service platform with AI-assisted lure generation, storefront, and 24/7 support, industrializing device code phishing
- Over 50% of Huntress-recommended identity controls were missing in 60% of 12,000+ tenants reviewed during Managed ISPM early access
Affected Systems
- Microsoft 365 / Entra ID tenants
- Azure CLI (used as ROPC authentication client)
- Microsoft OAuth 2.0 Device Authorization Grant flow
- Organizations with Conditional Access policies scoped to specific apps, user groups, or locations rather than All Cloud Apps / All Users
Vulnerabilities (CVEs)
None identified.
Attack Chain
- Initial Access (Railway): Phishing emails with construction RFP themes delivered triple-wrapped URLs through Cisco, Trend Micro, and Microsoft SafeLinks to evade email filtering
- Authentication Abuse (Railway): Victims directed to Microsoft's legitimate deviceauth endpoint and tricked into entering a device code (e.g., EZ84KREMH), completing MFA which validates the attacker's OAuth token request
- Token Harvesting (Railway): Attackers collect valid OAuth tokens lasting up to 90 days via Railway.com PaaS infrastructure with clean IP reputation, evading Microsoft Identity Protection risk scoring
- Initial Access (LSHIY): Attackers obtain validated credentials and replay them at massive scale (81 million attempts) using ROPC flow against Azure CLI /token endpoint
- Token Minting (LSHIY): ROPC flow mints fresh user tokens without triggering MFA prompts because Conditional Access policies omit Azure CLI or legacy auth client types
- Persistence/Access: Both campaigns yield valid OAuth tokens granting full account access without passwords or malware, exploitable for up to 90 days
Detection Availability
- YARA Rules: No
- Sigma Rules: No
- Snort/Suricata Rules: No
- KQL Queries: No
- Splunk SPL Queries: No
- EQL Queries: No
- Other Detection Logic: No
The article does not provide specific detection rules or queries. It references Huntress Managed ITDR for detection of active compromises and Managed ISPM for posture management, but no rule content is included.
Detection Engineering Assessment
| Dimension | Rating | Rationale |
|---|---|---|
| EDR Visibility | Low | Both campaigns are cloud identity attacks targeting Microsoft 365 authentication flows. No endpoint malware or execution is involved, so EDR telemetry would not directly capture the authentication abuse. |
| Network Visibility | Medium | Sign-in logs from Azure AD / Entra ID would show anomalous login patterns from Railway.com IPs or LSHIY IPv6 ranges. Network-level visibility into the authentication traffic itself is limited since it flows to legitimate Microsoft endpoints over HTTPS. |
| Detection Difficulty | Moderate | Detecting anomalous sign-in patterns from specific IP ranges is straightforward with Entra ID logs. However, identifying Conditional Access policy gaps requires proactive posture assessment rather than reactive detection, and distinguishing legitimate device code flow usage from abuse is challenging without behavioral baselining. |
Required Log Sources
- Azure AD / Entra ID sign-in logs (interactive and non-interactive)
- Conditional Access policy evaluation logs
- Microsoft 365 audit logs
- Azure AD Identity Protection risk logs
- Exchange Online mail flow logs (for phishing email detection)
Hunting Hypotheses
| Hypothesis | Telemetry | ATT&CK Stage | FP Risk |
|---|---|---|---|
| Consider hunting for successful sign-ins using the device code authentication flow (T1621) in Entra ID logs, especially from IP ranges associated with cloud hosting or PaaS platforms, as this flow is rarely used legitimately by most organizations. | Entra ID sign-in logs filtered by client app type 'Microsoft Authentication Broker' or authentication method 'Device code flow' | Initial Access / Credential Access | Medium — legitimate device code flow usage exists for input-constrained devices (smart TVs, printers, IoT); correlate with known device inventory to reduce noise. |
| Consider hunting for successful ROPC authentication events in Entra ID non-interactive sign-in logs, particularly those targeting Azure CLI as the client app, as ROPC is deprecated and rarely needed in modern environments. | Entra ID non-interactive sign-in logs filtered by client app 'Azure CLI' and grant type 'Resource Owner Password Credentials' | Initial Access / Authentication | Low to Medium — some legacy automation or scripts may legitimately use ROPC; correlate with known service accounts and expected authentication patterns. |
| Consider hunting for Conditional Access policy configurations where MFA requirements are scoped to specific applications rather than 'All Cloud Apps,' as these gaps allow attackers to authenticate via excluded apps like Azure CLI. | Entra ID Conditional Access policy configuration logs and Microsoft Graph API policy exports | Defense Evasion / Configuration drift | Low — identifying policy scope gaps is a posture assessment activity; false positives would be intentional exclusions that should be documented and reviewed. |
| Consider hunting for sign-in events where the authentication location was scored as non-risky despite originating from cloud hosting provider IP ranges, as attackers abuse clean PaaS infrastructure to evade Identity Protection risk scoring. | Entra ID sign-in logs cross-referenced with IP reputation databases and cloud hosting provider IP ranges | Initial Access / Defense Evasion | Medium — legitimate developers or cloud engineers may authenticate from PaaS infrastructure; correlate with known user roles and expected geographic patterns. |
| Consider hunting for Conditional Access policies in report-only mode that have remained in that state beyond a reasonable learning period, as these policies provide no enforcement and create a false sense of security. | Entra ID Conditional Access policy configuration via Microsoft Graph API, filtering for reportOnly state | Configuration drift / Defense Evasion | Low — report-only policies in production for extended periods are almost always misconfigurations or abandoned deployments. |
Control Gaps
- Conditional Access policies scoped to specific apps (e.g., Admin Portals) rather than 'All Cloud Apps' allow ROPC and Azure CLI traffic to bypass MFA
- Conditional Access policies scoped to specific user groups leave accounts outside those groups unprotected
- MFA policies conditioned on trusted locations can be bypassed when attacker IPs are mislabeled or geographically close
- Conditional Access policies in report-only mode provide zero enforcement despite appearing configured
- Microsoft Identity Protection does not inherently flag logins from legitimate PaaS platforms like Railway.com as risky
- Email filtering stacks may pass triple-wrapped URLs that chain through trusted domains (Cisco, Trend Micro, Microsoft SafeLinks)
Key Behavioral Indicators
- Successful sign-ins using device code flow from cloud hosting/PaaS IP ranges
- Non-interactive sign-ins via Azure CLI using ROPC grant type
- High-volume authentication attempts from single IPv6 ranges (e.g., 81 million attempts indicating credential spray)
- Conditional Access policies named to block specific clients (e.g., 'Block Azure CLI') that do not actually match the intended client app
- OAuth tokens with 90-day refresh token lifetimes originating from device code flow authentication
- Phishing emails with construction RFP themes containing triple-wrapped redirect URLs
False Positive Assessment
Medium — Device code flow and ROPC have legitimate use cases (input-constrained devices, legacy automation), so blocking them entirely may impact some users or service accounts. Conditional Access policy changes carry lockout risk if scoped incorrectly. Hunting for these authentication methods will require tuning against known legitimate usage patterns.
Recommendations
Immediate Mitigation
- Verify against your organization's incident response runbook and team escalation paths before acting. Consider reviewing all Entra ID Conditional Access policies to confirm they cover All Users and All Cloud Apps, including legacy authentication client types like ROPC and Azure CLI.
- Consider blocking or restricting the OAuth device code flow via Conditional Access policy across your tenant, limiting it only to specific accounts that demonstrably require it.
- If your Entra ID tenant supports the userStrongAuthClientAuthNRequired setting, consider enabling it to enforce strong authentication at the client level and block ROPC flows.
- Consider auditing all Conditional Access policies currently in report-only mode and evaluate whether they should be promoted to enforced status.
- Consider reviewing recent Entra ID sign-in logs for successful authentications via device code flow or ROPC grant type, especially from cloud hosting provider IP ranges.
Infrastructure Hardening
- Consider deploying Conditional Access policies with All Users / All Cloud Apps / All Client App Types scope to eliminate scoping gaps that attackers can predict and exploit.
- If supported by your licensing tier, consider enabling Microsoft Identity Protection risk policies to flag anomalous sign-in locations and impossible travel events.
- Consider implementing a periodic Conditional Access policy drift review process to detect when policies have been modified or excluded from their intended scope.
- Evaluate whether your email filtering stack can detect and block triple-wrapped URLs that chain through trusted redirector domains (Cisco, Trend Micro, Microsoft SafeLinks).
- Consider reviewing and restricting which users or groups are permitted to use the device code authentication flow if a full block is not feasible.
User Protection
- Consider deploying Microsoft Authenticator with number-matching or passwordless authentication to reduce the effectiveness of device code phishing lures.
- If applicable, consider enabling system-preferred MFA to ensure users authenticate through the strongest available method.
- Consider educating users on the device code phishing technique, specifically warning them not to enter authentication codes received via email or chat into Microsoft's deviceauth page unless they initiated the request from a known device.
- Consider restricting non-admin users from consenting to third-party applications in the tenant to reduce the OAuth token attack surface.
Security Awareness
- Consider incorporating device code phishing awareness into existing security training programs, emphasizing that legitimate Microsoft login pages can be abused if the user did not initiate the authentication request.
- Consider training IT staff on the distinction between MFA being 'enabled' versus 'enforced for all authentication paths,' as this was the core gap exploited in the LSHIY campaign.
- Consider adding construction RFP-themed phishing lures to existing phishing simulation campaigns, as this theme was specifically observed at scale in the Railway campaign.
- If your organization has a change management process for identity policies, consider documenting the risk of report-only mode policies being mistaken for enforced controls.