This post is about PKCE [RFC7636], a protection mechanism for OAuth and OpenIDConnect designed for public clients to detect the authorization code interception attack.
At the beginning of our research, we wrongly believed that PKCE protects mobile and native apps from the so called „App Impersonation" attacks. Considering our ideas and after a short discussion with the authors of the PKCE specification, we found out that PKCE does not address this issue.
In other words, the protection of PKCE can be bypassed on public clients (mobile and native apps) by using a maliciously acting app.
OAuth Code Flow
In Figure 1, we briefly introduce how the OAuth flow works on mobile apps and show show the reason why we do need PKCE.
In our example the user has two apps installed on the mobile phone: an Honest App and an Evil App. We assume that the Evil App is able to register the same handler as the Honest App and thus intercept messages sent to the Honest App. If you are more interested in this issue, you can find more information here [1].
Figure 1: An example of the "authorization code interception" attack on mobile devices. |
Step 1: A user starts the Honest App and initiates the authentication via OpenID Connect or the authorization via OAuth. Consequentially, the Honest App generates an Auth Request containing the OpenID Connect/OAuth parameters: client_id, state, redirect_uri, scope, authorization_grant, nonce, ….
Step 2: The Browser is called and the Auth Request is sent to the Authorization Server (usually Facebook, Google, …).
- The Honest App could use a Web View browser. However, the current specification clearly advice to use the operating system's default browser and avoid the usage of Web Views [2]. In addition, Google does not allow the usage of Web View browser since August 2016 [3].
Step 4: Now, the browser calls the Honest App registered handler. However, the Evil App is registered on this handler too and receives the code.
Step 5: The Evil App sends the stolen code to the Authorization Server and receives the corresponding access_token in step 6. Now, the Evil App can access the authorized ressources.
- Optionally, in step 5 the App can authenticate on the Authorization Server via client_id, client_secret. Since, Apps are public clients they do not have any protection mechanisms regarding the storage of this information. Thus, an attacker can easy get this information and add it to the Evil App.
Proof Key for Code Exchange - PKCE (RFC 7636)
Now, let's see how PKCE does prevent the attack. The basic idea of PKCE is to bind the Auth Request in Step 1 to the code redemption in Step 5. In other words, only the app generated the Auth Request is able to redeem the generated code.
Step 2: The Authorization Server receives the Auth Request and binds the code to the received code_challenge and challenge_method.
Figure 2: PKCE - RFC 7636 |
Step 1: The Auth Request is generated as previosly described. Additionally, two parameters are added:
- The Honest App generates a random string called code_verifier
- The Honest App computes the code_challenge=SHA-256(code_verifier)
- The Honest App specifies the challenge_method=SHA256
Step 2: The Authorization Server receives the Auth Request and binds the code to the received code_challenge and challenge_method.
- Later in Step 5, the Authorzation Server expects to receive the code_verifier. By comparing the SHA-256(code_verifier) value with the recieved code_challenge, the Authorization Server verifies that the sender of the Auth Request ist the same as the sender of the code.
Step 3-4: The code leaks again to the Evil App.
Step 5: Now, Evil App must send the code_verifier together with the code. Unfortunatelly, the App does not have it and is not able to compute it. Thus, it cannot redeem the code.
PKCE Bypass via App Impersonation
Again, PKCE binds the Auth Request to the coderedemption.
The question rises, if an Evil App can build its own Auth Request with its own code_verifier, code_challenge and challenge_method.The short answer is – yes, it can.
Figure 3: Bypassing PKCE via the App Impersonation attack |
Step 1: The Evil App generates an Auth Request. The Auth Request contains the client_id and redirect_uri of the Honest App. Thus, the User and the Authorization Server cannot recognize that the Evil App initiates this request.
Step 2-4: These steps do not deviate from the previous description in Figure 2.
Step 5: In Step 5 the Evil App sends the code_verifier used for the computation of the code_challenge. Thus, the stolen code can be successfully redeemed and the Evil App receives the access_token and id_token.
OAuth 2.0 for Native Apps
The attack cannot be prevented by PKCE. However, the IETF working group is currently working on a Draft describing recommendations for using OAuth 2.0 for native apps.
References
Vladislav Mladenov
Christian Mainka (@CheariX)
Christian Mainka (@CheariX)
More articles
- Pentest Tools Framework
- Hacker Tools Software
- Hack Rom Tools
- Hacker Tools Mac
- Install Pentest Tools Ubuntu
- Hack Website Online Tool
- Pentest Tools Subdomain
- Hacker Tools Online
- Hacker Tools Hardware
- Hacker Tools For Ios
- Hacks And Tools
- Computer Hacker
- Pentest Tools Apk
- Pentest Tools Online
- Hack App
- How To Make Hacking Tools
- Hacking Tools For Pc
- Hacking Tools For Pc
- Pentest Reporting Tools
- Hacking Tools Mac
- Tools For Hacker
- Hack And Tools
- Pentest Tools Download
- Hacker Tools 2019
- Tools Used For Hacking
- Hacker Tools Linux
- Pentest Tools Online
- Hacking Tools Windows 10
- Ethical Hacker Tools
- Hacking Tools 2019
- Pentest Tools Website
- Pentest Tools Open Source
- Best Pentesting Tools 2018
- Hacker Tools Linux
- Tools 4 Hack
- Pentest Tools Android
- Pentest Box Tools Download
- Hack Tools Pc
- Pentest Reporting Tools
- Hacker Tools For Mac
- Pentest Tools Github
- Hacker Search Tools
- Top Pentest Tools
- Hack Website Online Tool
- Hacking Tools Download
- Pentest Tools Alternative
- Pentest Tools Port Scanner
- Pentest Tools Github
- Best Pentesting Tools 2018
- Hacks And Tools
- Hacking Tools Pc
- Hacking Tools For Windows
- Hacker Tools Free Download
- Hack Tools
- Hacker Techniques Tools And Incident Handling
- How To Make Hacking Tools
- Hacker Security Tools
- Hack Apps
- Hacker Tools Linux
- Pentest Tools Linux
- Hacking Tools For Kali Linux
- Hackers Toolbox
- Hacker Tools Online
- Pentest Tools Kali Linux
- Termux Hacking Tools 2019
- Hacker Tools Apk
- Pentest Tools Github
- Tools For Hacker
- Pentest Automation Tools
- Hacking Tools
- Hacker Tools Linux
- Hacking Tools 2019
- Hack Tool Apk No Root
- Hack Tools 2019
- Hacking Tools Pc
- Best Pentesting Tools 2018
- Kik Hack Tools
- Hacking Tools For Pc
- Pentest Tools Nmap
- Hack Tools Github
- Pentest Box Tools Download
- Hacker Tools 2019
- Pentest Tools Online
- Pentest Reporting Tools
- Hacking Tools For Windows Free Download
- Nsa Hack Tools Download
- Pentest Tools Android
- Hacker Tools 2019
- Hacking Tools Free Download
- Hacker Tools For Ios
- Hack Tools For Ubuntu
- How To Make Hacking Tools
- Hacking Tools
- Android Hack Tools Github
- Physical Pentest Tools
- Wifi Hacker Tools For Windows
- Pentest Tools Online
- Hack Tools
- Pentest Tools Alternative
- Hacker Tools For Pc
- Bluetooth Hacking Tools Kali
- Hacking Tools For Windows
- Pentest Reporting Tools
- Hacker Tools For Pc
- Pentest Tools Alternative
- Best Hacking Tools 2019
- Pentest Tools Subdomain
- Hacker Tools
- Hack Tools Github
- Hackrf Tools
- Pentest Box Tools Download
- Pentest Tools For Mac
- Best Hacking Tools 2019
- Hacking App
- Ethical Hacker Tools
- Hack Tools Mac
- Bluetooth Hacking Tools Kali
- Hack And Tools
- Hacking Tools For Beginners
- Blackhat Hacker Tools
- Nsa Hack Tools
- Ethical Hacker Tools
- Hack Rom Tools
- Hack Tool Apk
- Pentest Tools Linux
- New Hacker Tools
- Hacker Tools 2020
- Hacking Tools Hardware
- World No 1 Hacker Software
- Hacking Tools For Games
- How To Make Hacking Tools
- Hacking Tools For Kali Linux
- Pentest Tools Kali Linux
- What Is Hacking Tools
- Pentest Tools Github
- Pentest Tools Alternative
- Hacker Tools 2020
- Pentest Tools Website
- Tools 4 Hack
- Hacker Tools List
- Hack Tools For Pc
- Hacking Tools For Games
- Hacks And Tools
- Tools 4 Hack
- Pentest Tools For Windows
- Android Hack Tools Github
- Pentest Tools Port Scanner
- Pentest Tools Nmap
- Hacking Tools For Windows
- Hacking Tools Pc
- Hacking Tools Usb
- Hack Tools 2019
- Hacker Tools For Windows
- Hacker Tools Linux
- Nsa Hacker Tools
- Hacker Tools For Pc
- Pentest Tools Framework
- Hacker Tools For Pc
- Pentest Tools Port Scanner
- Hack Tools Online
- Pentest Tools Review
- Pentest Box Tools Download
- Hacking Tools
- Hack Tools Online
- Hack Apps
- Pentest Tools List
- Bluetooth Hacking Tools Kali
- Nsa Hacker Tools
- Hacker Tools
- Android Hack Tools Github
- Hack Tools Github
- Hacker Tools 2020
- Pentest Tools Find Subdomains
- Beginner Hacker Tools
- What Is Hacking Tools
- Hacker Tools Windows
- Pentest Tools For Ubuntu
No comments:
Post a Comment