This blog series expands upon a presentation given at DEF CON 29 on August 7, 2021.
In Part 1 of this series, we provided an overview of OAuth 2.0 and two of its authorization flows, the authorization code grant and the device authorization grant.
Phishing attacks are starting to evolve from the old-school faking of login pages that harvest passwords to attacks that abuse widely-used identity systems such as Microsoft Azure Active Directory or Google Identity, both of which utilize the OAuth authorization protocol for granting permissions to third-party applications using your Microsoft or Google identity.
In the past few years, we have seen illicit grant attacks that use malicious OAuth applications created by attackers to trick a victim into granting the attacker wider permissions to the victim’s data or resources:
- Phishing Attack Hijacks Office 365 Accounts Using OAuth Apps, Lawrence Abrams, 12/10/2019.
- DEMONSTRATION – ILLICIT CONSENT GRANT ATTACK IN AZURE AD / OFFICE 365, Joosua Santasalo, 10/25/2018
Instead of creating fake logins/websites, illicit grant attacks use the actual OAuth authentication/authorization flows in order to obtain the OAuth session tokens. This has the advantage of bypassing MFA authentication, with permanent or nearly indefinite access since the OAuth tokens can be continually refreshed in most cases.
In this blog series, we will review how various quirks in the implementation of different OAuth authorization flows can make it easier for attackers to phish victims due to:
- Attackers not needing to create infrastructure (e.g., no fake domains, websites, or applications), leading to easier and more hidden attacks
- An ability to easily reuse client ids of existing applications, obfuscating attacker actions in audit logs
- The use of default permissions (scopes), granting broad privileges to the attacker
- A lack of approval (consent) dialogs shown to the user
- An ability to obtain new access tokens with broader privileges and access, opening up lateral movement among services/APIs
Finally, we will discuss what users can do today to protect themselves from these potential new attacks.
In Part 2 of this blog series, we will look at how a phishing attack can be carried out by exploiting the device authorization grant flow.
Phishing using Device Authorization Grants
A phishing attack that exploits the OAuth device code authorization grant flow was described by Dr. Nestori Syynimaa in his blog, Introducing a new phishing technique for compromising Office 365 accounts.
Below, we will explain the attack scenario in detail, how it can be carried out, the underlying protocol issues that lead to this exposure, and what can be done about it.
When used in a phishing attack, the flow looks like this:
Step 1: The user does not initiate anything (no login step).
Step 2: The attacker initiates the attack by generating a user and device code. In the Microsoft device code flow implementation, well-known client application ids can be reused, such as Outlook’s id, and no other application authentication is required. No scopes need to be specified at this step either. The resource parameter specifies the API resources to be accessed, and the graph API is one of many that can be specified.
curl \
--data client_id=d3590ed6-52b3-4102-aeff-aad2292ab01c \
--data resource=https://graph.microsoft.com \
https://login.microsoftonline.com/common/oauth2/devicecode?api-version=1.0
Step 3: The user code (used by the user to verify themselves to the identity platform) and device codes (used by application or device to verify themselves) are returned along with the verification URL.
user_code : ELSEKDEZH
device_code : AAQBAAEAAAD--DLA3VO7QrddgJg7Wevri4xk7LwvoX90cGR…
verification_url: https://microsoft.com/devicelogin
expires_in : 900
interval : 5
message : To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code AGMKMPPLM to authenticate.
Step 4: The phish is delivered with content to trick the user into entering the user code when logging into the verification URL of the identity vendor.