githubEdit

REQUEST FORGERY AND HIJACKING

Cross-Site Request Forgery (CSRF)

The flow of a CSRF attack
  • CSRF attacks target clients by forcing them to perform unwanted actions.

  • These actions are usually state-changing, such as updating a user's email or password, transferring money, or disabling security settings.

  • CSRF takes advantage of the fact that browsers send necessary information, like session cookies, in every HTTP request to a site, and web servers cannot differentiate between legitimate and malicious requests.

  • HTML forms can use only GET and POST methods.

  • An attacker can use a crafted HTML form to make a request to a vulnerable application by tricking a user.

  • CSRF attacks are limited to the actions a victim is allowed to perform.

  • GraphQL servers sometimes support operations over GET, and they might intentionally reject GET-based mutations to allow read operations using GET only. If a target uses any GET-based queries to perform state changes, that is a vulnerability.

  • To prevent CSRF, applications should implement anti-CSRF tokens, which are unique, unpredictable values included in requests that the server verifies.

Locating State-Changing Actions

  • Mutation field names can be extracted using an introspection query.

  • State-changing actions such as createUser, importPaste, editPaste, uploadPaste, deletePaste, and createPaste can be identified through introspection.

  • Queries can also perform state-changing actions, for example, a deleteAllPastes query.

The introspection query shown in should return the mutation fields that exist in a schema

Testing for POST-Based Vulnerabilities

  • A crafted HTML form can be used to perform a POST-based CSRF attack.

  • A hidden input tag ensures the form remains invisible to the victim.

Testing for GET-Based Vulnerabilities

  • GET-based CSRF attacks involve sending a malicious link to a victim.

  • GET requests with state-changing queries can be exploited via HTML injection.

Automating Testing with BatchQL and GraphQL Cop

The SameSite Flag

Server-Side Request Forgery (SSRF)

  • SSRF attacks target servers, aiming to obtain sensitive data, probe for internal services, make internal requests to restricted networks, or access cloud environment information.

  • SSRF allows attackers to forge requests on behalf of servers.

  • An SSRF vulnerability can give an attacker access to services they otherwise wouldn't be able to reach directly.

  • This includes cross-site port attacks (XSPA), where a server makes a request to an internal port that isn't directly accessible.

  • Preventing SSRF involves sanitizing and validating user input in request fields and limiting the scope of request operations.

Cross-Site WebSocket Hijacking (CSWSH)

  • CSWSH involves stealing another user's session via WebSocket connections.

  • WebSocket handshakes can be hijacked if they lack anti-CSRF tokens, enabling attackers to forge messages using the victim's authenticated session.

  • Attackers can exfiltrate GraphQL subscription responses via CSWSH.

  • A WebSocket connection handshake is initiated over HTTP and may include cookies for authentication.

  • Introspection can be used to identify subscription field names.

  • To simulate a CSWSH attack, an attacker can set up a Netcat listener to receive exfiltrated data after a victim is tricked into loading malicious code.

As mentioned in this talkarrow-up-right, check if it might be possible to connect to graphQL via WebSockets as that might allow you to bypass a potential WAF and make the websocket communication leak the schema of the graphQL:

Last updated