Challenge 5 – Tickets
Get tickets to the Show.Enjoy the Show.
Last updated
Get tickets to the Show.Enjoy the Show.
Last updated
Enjoy going to the movies? This page is for booking the show. Unfortunately, there is only one ticket left. All the other tickets were sold offline. Whoever is able to complete the transaction first will get the ticket.
Let us visualize the happy path with the help of a sequence diagram:
That is just the happy path for one user purchasing a ticket. Let us reimagine the same scenario but with two users acting at the same time.
There is only one condition to be met for a user to purchase the ticket - there should be at least one ticket available in the system.
Let us see if the application is performing those checks:
Go to the login page
Login as any user
Navigate to the buy tickets page
Click on Buy One Ticket button
Observe the message You have 1 ticket(s) message on top of the page
Click on Buy One Ticket button again
See that nothing happens
Logout and login as another user
Navigate to the buy tickets page
Click on Buy One Ticket button
See that user is not able to buy tickets since there are no more tickets left
We need to find a way to purchase two tickets. How can we do that? What if we click on the buy ticket button multiple times very fast? That won’t help cause the page needs to be loaded after each click.
It’s time to slow down TimeGap Theory:
On your browser, navigate to the Settings page
Change the time delay to 5 seconds
Click on the Save button
Now, TimeGap Theory will wait 5 seconds before every database write operation.
Preparation phase
Navigate to the Admin page
Click on the create default users button
Open two browsers side by side (Use private/incognito window if you do not have two browsers)
Navigate to the login page on both the browsers
On the first browser:
Click on the first user button on top
This will fill the user data for user Tom
Submit the form to log in as Tom
On the second browser:
Click on the second user button on top
This will fill the user data for user Jerry
Submit the form to log in as Jerry
Alright, the preparation is done. Here comes the exploitation phase.
Exploitation phase
On both the browsers:
Navigate to the buy tickets page
Click on the Buy One Ticket button
Let us see how that turns out.
Post-exploitation phase
Let us wait for both the browsers to complete the request
You can see that both the users have one ticket on their account
If you check your scores, you will see that you have got 100 points for completing the buy tickets challenge.
Don't forget to change the delay to 0 on the settings page.
Automation
As always, we need a way to automate this.
Pro-tip - you can skip this in real life if the webmaster is your friend and is ready to slow down the server for you.
First, we need a valid fetch request:
Open your browser (Chrome or Firefox)
Navigate to TimeGap Theory > Webapp > Login
Click on the first user button. This will load the user data for Tom
Click on the Sign in button
Navigate to the buy tickets page
Open up dev tools by pressing F12 on the browser
On Windows, you can use Ctrl + Shift + I
On Mac, you can use Cmd + Shift + I
Click on the Buy one ticket button
On the browser dev tools, click on the Network tab
Right click on the buy-ticket.php request
Click on Copy > Copy as fetch
Paste that on the Console tab of the browser dev tools. You will get something like the following:
Based on how playful your browser is, you may see a slightly long fetch request. Feel free to trim it down to the bare minimum version shown above.
Now we have a request.
And we need two requests.
It can be done by copy-pasting the fetch request without pressing the Enter key. However, it’s a good practice to separate each request with a comma. Let us do that
Before running this new command, we need to clear the slate. It involves three simple steps:
Ensure that there is no delay
Go to TimeGap Theory > Settings
Ensure that the delay is set to 0
Reset database and create users
Go to TimeGap Theory > Admin
Click on reset database button
Go back to TimeGap Theory > Admin
Click on create default users button
Clear the current score
Go to TimeGap Theory > Score
Click on the Clear button
Alright, our slate is clear. Let us execute the attack now:
Navigate to the Login page
Click on the first user button on top. This will fill the user data for user Tom
Click on the Sign In button
Enter the combined fetch request on the Console tab of browser dev tools
Press the Enter key
Refresh the page
You will see that our attack attempt is unsuccessful.
What happened?
Two things went wrong:
The Buy Tickets page of TimeGap Theory is authenticated. We need to supply the cookie as well in order for this request to be successful
Since an authenticated session is involved, webapp is treating the executing requests one by one when it is from the same session
We need to solve both these problems for the automation to be successful.
Problem 1 - Cookie
Fetch request does not support sending cookies. We need an alternate solution. cURL supports sending cookies. We can use that.
Problem 2 - Only one request per session
This can be solved by creating two sessions for the same user. How can we do that?
We will sign into Tom’s account on the first browser.
We will sign into Jerry’s account on the second browser.
This way we will get two separate active sessions.
Now, we need valid cURL requests with session tokens in it.
Let us obtain the first one:
Open your browser ( Chrome or Firefox)
Navigate to TimeGap Theory > Webapp > Login
Click on the first user button. This will load the user data for Tom
Click on the Sign in button
Navigate to the Buy Tickets page
Open up dev tools by pressing F12 on the browser
On Windows, you can use Ctrl + Shift + I
On Mac, you can use Cmd + Shift + I
Click on the Buy One Ticket button.
On the browser dev tools, click on the Network tab
Right-click on the buy-tickets.php request.
Click on Copy > Copy as cURL
For getting the second one:
Open another browser ( Chrome or Firefox)
Navigate to TimeGap Theory > Webapp > Login
Click on the second user button. This will load the user data for Jerry
Click on the Sign in button
Navigate to the Buy Tickets page
Open up dev tools by pressing F12 on the browser
On Windows, you can use Ctrl + Shift + I
On Mac, you can use Cmd + Shift + I
Click on the Buy One Ticket button
On the browser dev tools, click on the Network tab
Right click on the buy-tickets.php request.
Click on Copy > Copy as cURL
Now that we have both the requests. Let us run them in parallel. Before doing that, we need to clear all the previous purchases of tickets. This can be done by reloading the create-users.php page located at TimeGapTheory > Webapp > Admin > Create Users.
Once you have reloaded the create-users.php page, follow the steps below:
Open your command prompt/Terminal window
If you are on Windows 5
Type start /b
Put a space
Enter the first cURL request
Put a space
Enter the ampersand symbol (&) 6
Put a space again
If you are on Windows
Type start /b
Put a space
Enter the second cURL request
If you are on Windows
Remove the following parameter from both the requests “--compress”. Some versions of cURL do not support this feature.
Now, press the Enter/Return key
Let us see if we are successful or not:
Go to the first browser window
Refresh the Buy Tickets page
Note the message on the top that says You have 1 ticket(s)
Go to the second browser window
Refresh the Buy Tickets page
Note the message on the top that says You have 1 ticket(s)
Check if you got points for completing the Buy Tickets challenge
What would be the business impact of such an attack? Depending on how the app is designed, there are several possibilities:
A legitimate user may show up for the show and realize that another user also got the same ticket
Business would end up having unhappy customers, giving compensations etc.
Let us review what we did:
The buy tickets page checks the stock of the tickets before allowing the user to book it
You analyzed this behavior by trying to purchase two tickets
First, you slowed down the system and bypassed the business logic
Then you tried bypassing the business logic using fetch requests on browser dev tools and failed
You learned that fetch requests are not useful while trying to send cookies to the server
You moved onto cURL as it supports sending cookies and you were able to purchase one ticket each for two users.
Now you know how TOC/TOU security issues can affect buy tickets pages