🖥️
Offensive security concepts
  • Introduction
  • 💿Virtualbox network setup
    • What is VirtualBox?
    • NAT
    • NAT network
    • Bridged adapter
    • Internal network
    • pfSense
    • vboxmanage
    • Overview
  • 🕵️OSINT
    • What is OSINT?
    • Google dorks
    • Metadata
    • Social media
      • osintagram
  • Tools
    • waybackurls
    • recon-ng
    • sherlock
    • maltego
    • theHarvester
    • photon
  • 😨Social Engineering
    • What is social engineering?
    • 7 tricks of social engineering
    • Email phishing
    • Typosquatting
    • Compiled resources
  • 😈MitM attack
    • What is MitM attack?
    • ARP spoof/poison
    • DNS spoof/poison
    • HTTP MitM attack
    • ICMP redirect attack
    • DHCP spoofing
    • Evil twin attack
    • Experiment (guest network)
    • Compiled resources
  • 🔌UPnP exploitation
    • What is UPnP?
    • What is SSDP?
    • IGD functions
    • LAN devices
    • Compiled resources
  • Network Reconnaissance & Attacks
    • What is network hacking?
  • 1️⃣Network live host discovery
    • What is network live host discovery?
    • nmap
    • arp-scan
    • masscan
  • 2️⃣Network port scan/services enumeration
    • What is network port scan/services enumeration?
    • nmap
    • netcat
  • 3️⃣Network services vulnerability scanning & exploitation
    • What is network vulnerability scanning/exploitation?
    • 20/21 ~ FTP
    • 22 ~ SSH
    • 25 ~ SMTP
    • 53 ~ DNS
    • 80/443 ~ HTTP/HTTPS
    • 110 ~ POP3
    • 111/2049 ~ RPC/NFS
    • 139/445 ~ SMB
    • 143 ~ IMAP
    • 3389 ~ RDP
  • Vulnerability & exploitation
    • Database
    • Metasploit
    • Msfvenom
  • Misconfigurations
    • .DS_Store
  • Web Application Penetration Testing
    • Introduction
    • Directories/URLs gathering
    • Subdomain enumeration
    • File inclusion & Path traversal
    • Insecure Direct Object Reference (IDOR)
    • Upload vulnerabilities
      • File extension cheat-sheet
    • SSRF
    • CSRF
    • XSS
    • SQL injection
  • Authentication/session management
    • OWASP WSTG-SESS-10 ~ JSON Web Token (JWT)
    • OWASP WSTG-ATHZ-05 ~ OAuth weaknesses
  • Webshell
  • Web API pentesting
    • Resources
    • Methodology
    • jq
    • httpx
    • ParamSpider
  • Web app pentesting methodology
  • OWASP
    • OWASP top 10
    • OWASP API top 10
    • Web Security Testing Guide (WSTG)
      • WSTG-ATHZ
        • WSTG-ATHZ-05 ~ OAuth weaknesses
      • WSTG-SESS
        • WSTG-SESS-10 ~ JWT
  • General web knowledge
    • URI standard (RFC 3986)
    • HTTP headers
  • 🛣️Attacks on routing protocols
    • What are attacks on routing protocols?
    • BGP hijacking
  • 🏕️To explore
    • MQTT
    • Routersploit
    • DNS rebinding attack
    • LLMNR/mDNS poisoning
  • 👤Anonymity
    • VPN
    • Proxychains
    • TOR
    • Obfuscation
  • Credentials brute-force/cracking
    • Introduction
    • Windows SAM database
    • Dictionary attack
    • Rainbow attack
      • Hash database
    • Tools
      • Hydra
      • John the ripper
      • Hashcat
      • hash-identifier
  • Post-exploitation
    • Gaining shell
      • netcat
      • socat
      • powershell
      • bash
      • PHP
    • Repository
  • Privilege escalation
    • Linux
      • Repositories
      • Enumeration
      • Vulnerabilities exploit
        • General
        • Kernel exploit
        • Sudo
        • SUID
        • Capabilities
        • Cronjobs
        • $PATH
        • NFS (target-machine)
        • Filesystem sharing
          • NFS (attacker-machine)
    • Windows
      • Password harvesting
      • Vulnerabilities exploit
        • Scheduled tasks
        • AlwaysInstallElevated
        • Service misconfigurations
          • Insecure permissions on service executable
          • Unquoted service path
          • Insecure service permission
        • Abusing privileges
  • Ⓜ️MITRE ATT&CK
    • Introduction
  • 🧰Tools/services
    • Introduction
    • Web hacking
      • Web fuzzing
      • Password brute-forcing
      • Burp Suite (Community)
      • nikto
      • ZAP (Zed Attack Proxy)
      • nuclei
    • Information gathering/reconnaissance
    • Network hacking
      • nmap (general overview)
      • scapy
      • bettercap
    • General
      • impacket
    • Wordlists
      • cewl
  • Professional report writing
    • Report template
      • Web applicaton pentesting
        • OWASP report layout
  • Tasks on-the-go
    • Note taking on-the-go
    • Other tips
  • Practice
    • Metasploitable 2
    • TryHackMe
  • Operational Security (OpSec)
    • Hardening
      • General
      • Oracle VirtualBox
      • Web Browser
  • Write-ups
    • TryHackMe
      • Silver Platter
      • Light
      • Pickle Rick
      • Hammer
        • Enumeration (active recon)
          • /hmr
          • Further directory discovery
          • /phpmyadmin
          • burp suite sitemap
        • Brute forcing 4-digit code
      • OWASP Top 10 - 2021 (task 22)
    • OverTheWire
      • Untitled
    • OWASP
      • OWASP Juice Shop
      • OWASP WebGoat
  • AI prompt
    • ChatGPT
Powered by GitBook
On this page
  • General OAuth flow
  • OWASP WSTG-ATHZ-05
  • 05-Testing for OAuth weaknesses
  • 05.1-Testing for OAuth server weaknesses
  • 1. Consent page CSRF
  • 05.2-Testing for OAuth client weaknesses
  • 1. Redirect URI CSRF/Login CSRF
  1. Authentication/session management

OWASP WSTG-ATHZ-05 ~ OAuth weaknesses

PreviousOWASP WSTG-SESS-10 ~ JSON Web Token (JWT) NextWebshell

Last updated 1 day ago

General OAuth flow

Common terms:

  • OAuth provider: The third-party service that implementing OAuth that a user wishes to integrate/authenticate with (eg. Google, Github).

  • Resource Owner: An entity that can grant access to a protected resource (eg. an end-user).

  • Client: Application requesting access to a protected resource on behalf of the Resource Owner (eg. a web application).

  • Resource Server: A server hosting protected resource (eg. API to access).

  • Authorization Server (AS): A server that authenticates the Resource Owner and issues Access Tokens after a proper authorization process.

  • Authorization Code: A string value used to request for an Access Token.

  • Access Tokens: A string value used to validate a user's access to protected resource

1

Start of OAuth process

A user performs an action to start an OAuth process on a Client application

2

Authorization request

2.1 The application redirects the user to an Authorization Server (/authorize endpoint).

This process is often displayed as a small pop-up window or redirect initiated by the OAuth provider.

The authorization server URL may look like:

https://[client_addr].com/oauth/authorize?client_id=xxx&response_type=code&... 

With the following list of parameters:

  • response_type (eg. code)

  • state: CSRF token

  • client_id: uniquely identifies the client application

  • redirect_uri: the URL that AS will redirect the user

  • scope: level of access requested

Take note of the state value, as this is an important parameter involved in various CSRF-based attacks discussed below.

2.2 The user will be prompted to login (to verify his/her identity with the protected resource). Following that, a consent screen will be displayed to inform the user of the scope of permissions that the Client application is requesting access to.

3

Consent page & redirect

If the user accepts the permissions displayed in the consent screen (eg. click the "Authorize" button)

3.1 The Authorization Server will handle the consent internally

This may include a request to an internal endpoint with the state and relevant scope(s).

Example internal request:

POST https://[AS_addr].com/oauth/consent?state=xxx&scope=... 

3.2 The Authorization Server then redirects the user to the redirect_uri specified earlier, with a generated Authorization Code and the state provided by the client application in the first request.

Example redirect:

https://[client_addr].com/callback?code=xxx&state=xxxx
  • The Client application must validate the state to ensure that it matches the one sent in the initial request. This ensures that the response is linked to the Client's initial request

Note: The state parameter is important in preventing server-side CSRF vulnerabilities (OWASP WSTG-ATHZ-05 — 05.1-Testing for OAuth server weaknesses)

4

Request for Access Token

The Authorization Code can be used to request for an Access Token.

OWASP WSTG-ATHZ-05

05-Testing for OAuth weaknesses

05.1-Testing for OAuth server weaknesses

1. Consent page CSRF

Refer to the Testing for Consent Page Cross-Site Request Forgery header in the main link above (OWASP WSTG-05.1-Testing for OAuth server weaknesses)

Testing for weaknesses in the Authorization Server:

  1. Improper or missing validation of the state parameter by the Authorization Server.

  2. Predictable or reusedstate parameter value.

The goal of this CSRF-based attack is to trick an Authorization Server into generating an Authorization Code with permissions/scopes defined by an attacker. Typically, the scopes defined will provide the attacker access to sensitive information about a target user.

Steps involved:

  1. The attacker will initiate an OAuth request from within a malicious Client application (eg. /oauth/authorize endpoint).

    • The attacker will then create a CSRF payload (eg. auto-submitting HTML element using a POST request) containing a malicious URL with the following format:

    Not all Authorization Server implementations expose /oauth/consent as a public endpoint. Some may process it internally.

https://[AS_addr].com/oauth/consent?state=xxx&scope=... 

Parameters in the URL:

a. state: A random/predictable value

b. scope: Desired scope

Note the following:

  1. The attacker is required to start an OAuth request to trick the Authorization Server into believing that an active OAuth process is happening for the malicious Client application.

  2. This URL is similar to the one shown in part 3.1 in the General OAuth flow section above.

The scope defined may contain highly sensitive permissions about the target user

  1. The attacker will trick a target user into visiting the malicious Client application containing the CSRF payload via a web browser — this can be through a social engineering attack.

    • However, for the attack to work, the target user's browser must be authenticated with the OAuth provider — a valid authenticated session must be established through an OAuth process prior to the attack.

    This is due to the nature of web browsers, which sends relevant information regarding the established session with the OAuth provider (eg. cookies, etc.) to identify the current user session

    • The CSRF attack occurs because the Authorization Server associates the scope processing with the session of the target user, instead of the attacker. This is due to the web browser sending session information about this particular user

    • Within the Authorization Server logic, without proper validation of the state parameter (see Prevention section below for more information), the server will treat this as a valid OAuth request, and continue the OAuth process by redirecting the user back to the redirect_uri (defined by the attacker in the initial request) with the Authorization Code passed as the parameter.

Since the redirect URI is controlled by the attacker, he/she can retrieve the Authorization Code.

  1. The attacker will be able to use this code to request for an Access Token, and perform actions for the target user within the Client application (controlled by the attacker) with the privileged scopes.

Prevention

The Authorization Server should validate the following conditions for thestate parameter:

  1. Linked to an existing active OAuth process

  2. Matches the user session.

  3. Uses a cryptographically secure and random algorithm.

This prevents an attacker from hijacking the OAuth flow.

OWASP reference: copy and paste this link on a chromium-based browser to directly view the relevant paragraph.

https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#:~:text=When%20a%20client%20issues%20a%20request

Final notes

This attack is categorized as a server-side vulnerability as the vulnerability (lack of state validation, etc.) lies within the Authorization Server itself.

05.2-Testing for OAuth client weaknesses

1. Redirect URI CSRF/Login CSRF

Testing for weaknesses in the Client application:

  1. Missing state parameter in the OAuth authorization server URL.

  2. Improper validation of the state parameter by the Client application.

  3. Predictable or reused state parameter value.

The goal of this CSRF-based attack is to trick a Client application into accepting an Authorization Code tied to an attacker-controlled account, causing the victim's session to be linked to the attacker's OAuth identity.

Steps involved:

  1. The attacker will initiate an OAuth request to retrieve an Authorization Code linked to a malicious account.

  2. The attacker will then craft a CSRF payload (eg. email) with an URL. The format of the URL will be similar to the redirect URI used in an OAuth process.

Example of malicious URL

https://[client_addr].com/callback?code=[attacker_authorization_code]

Note : this URL is similar to the one shown in part 3.2 in the General OAuth flow section above.

  1. A target user will be tricked into sending a GET request to the malicious URL via a web browser (eg. via social engineering)

  • However, for the attack to work, the target user's browser must be authenticated with the OAuth provider — a valid authenticated session must be established through an OAuth process prior to the attack.

  • If successful, the Client application will link the victim's session to the attacker's OAuth account.

  1. As a result:

    • Any subsequent actions performed on the Client application will be linked to the attacker's account instead

    • This may allow the attacker to view sensitive information about the target user.

Prevention

The Client application should validate the following conditions for the state parameter:

  1. Linked to an existing active OAuth process.

  2. Matches the one defined in the initial request (eg. /oauth/authorize endpoint).

  3. Uses a cryptographically secure and random algorithm.

Final notes

This attack is categorized as a client-side vulnerability as the vulnerability (lack of state validation, etc.) lies within the Client application itself.

Refer to TryHackMe task 7 for OAuth Vulnerabilities room:

https://tryhackme.com/room/oauthvulnerabilities
Authorization Code FlowAuth0 Docs
wstg/document/4-Web_Application_Security_Testing/05-Authorization_Testing/05.1-Testing_for_OAuth_Authorization_Server_Weaknesses.md at master · OWASP/wstgGitHub
wstg/document/4-Web_Application_Security_Testing/05-Authorization_Testing/05.2-Testing_for_OAuth_Client_Weaknesses.md at master · OWASP/wstgGitHub
Logo
Logo
wstg/document/4-Web_Application_Security_Testing/05-Authorization_Testing/05-Testing_for_OAuth_Weaknesses.md at master · OWASP/wstgGitHub
Logo
Logo