Business-logic
Table of Contents
- Excessive trust in client-side controls
- High-level logic vulnerability
- Low-level logic flaw
- Inconsistent handling of exceptional input
- Inconsistent security controls
- Weak isolation on dual-use endpoint
- Insufficient workflow validation
- Authentication bypass via flawed state machine
- Flawed enforcement of business rules
- Infinite money logic flaw
Excessive trust in client-side controls
Solution
- With Burp running, log in and attempt to buy the leather jacket. The order is rejected because you don't have enough store credit.
- In Burp, go to "Proxy" > "HTTP history" and study the order process. Notice that when you add an item to your cart, the corresponding request contains a
priceparameter. Send thePOST /cartrequest to Burp Repeater. - In Burp Repeater, change the price to an arbitrary integer and send the request. Refresh the cart and confirm that the price has changed based on your input.
- Repeat this process to set the price to any amount less than your available store credit.
- Complete the order to solve the lab.
High-level logic vulnerability
Reference: https://portswigger.net/web-security/logic-flaws/examples/lab-logic-flaws-high-level
Solution
- With Burp running, log in and add a cheap item to your cart.
- In Burp, go to "Proxy" > "HTTP history" and study the corresponding HTTP messages. Notice that the quantity is determined by a parameter in the
POST /cartrequest. - Go to the "Intercept" tab and turn on interception. Add another item to your cart and go to the intercepted
POST /cartrequest in Burp. - Change the
quantityparameter to an arbitrary integer, then forward any remaining requests. Observe that the quantity in the cart was successfully updated based on your input. - Repeat this process, but request a negative quantity this time. Check that this is successfully deducted from the cart quantity.
- Request a suitable negative quantity to remove more units from the cart than it currently contains. Confirm that you have successfully forced the cart to contain a negative quantity of the product. Go to your cart and notice that the total price is now also a negative amount.
- Add the leather jacket to your cart as normal. Add a suitable negative quantity of the another item to reduce the total price to less than your remaining store credit.
- Place the order to solve the lab.
Low-level logic flaw
Reference: https://portswigger.net/web-security/logic-flaws/examples/lab-logic-flaws-low-level
Quick Solution
This one is a little bit tricky. Once you add a huge number of leather jackets the price value becomes a huge negative number and then it keeps raising until it reaches a value near zero. Add some other product to reach a price between 0 and 100 and you are done!
Solution
- With Burp running, log in and attempt to buy the leather jacket. The order is rejected because you don't have enough store credit. In the proxy history, study the order process. Send the
POST /cartrequest to Burp Repeater. - In Burp Repeater, notice that you can only add a 2-digit quantity with each request. Send the request to Burp Intruder.
- Go to Burp Intruder. On the "Positions" tab, clear all the default payload positions and set the
quantityparameter to 99. - On the "Payloads" tab, select the payload type "Null payloads". Under "Payload options", select "Continue indefinitely". Start the attack.
- While the attack is running, go to your cart. Keep refreshing the page every so often and monitor the total price. Eventually, notice that the price suddenly switches to a large negative integer and starts counting up towards 0. The price has exceeded the maximum value permitted for an integer in the back-end programming language (2,147,483,647). As a result, the value has looped back around to the minimum possible value (-2,147,483,648).
- Clear your cart. In the next few steps, we'll try to add enough units so that the price loops back around and settles between $0 and the $100 of your remaining store credit. This is not mathematically possible using only the leather jacket.
- Create the same Intruder attack again, but this time, under "Payloads" > "Payload Options", choose to generate exactly 323 payloads.
- Go to the "Resource pool" tab and add the attack to a resource pool with the "Maximum concurrent requests" set to 1. Start the attack.
- When the Intruder attack finishes, go to the
POST /cartrequest in Burp Repeater and send a single request for 47 jackets. The total price of the order should now be-$1221.96. - Use Burp Repeater to add a suitable quantity of another item to your cart so that the total falls between $0 and $100.
- Place the order to solve the lab.
Inconsistent handling of exceptional input
Quick Solution
This lab is actually pretty tricky. You need to register a new user with a pretty long email to understand that the backend cuts the email to 255 characters. Once you understand it you have to create a new user with the following structure:
<219-random-characters>@dontwannacry.com.<your-exploit-db-domain>
The new user will be considered a member of the dontwannacry.com domain and it will be possible to access the admin panel.
Solution
- While proxying traffic through Burp, open the lab and go to the "Target" > "Site map" tab. Right-click on the lab domain and select "Engagement tools" > "Discover content" to open the content discovery tool.
- Click "Session is not running" to start the content discovery. After a short while, look at the "Site map" tab in the dialog. Notice that it discovered the path
/admin. - Try to browse to
/admin. Although you don't have access, an error message indicates thatDontWannaCryusers do. - Go to the account registration page. Notice the message telling
DontWannaCryemployees to use their company email address. - From the button in the lab banner, open the email client. Make a note of the unique ID in the domain name for your email server (
@YOUR-EMAIL-ID.web-security-academy.net). - Go back to the lab and register with an exceptionally long email address in the format:
very-long-string@YOUR-EMAIL-ID.web-security-academy.net
The very-long-string should be at least 200 characters long.
7. Go to the email client and notice that you have received a confirmation email. Click the link to complete the registration process.
8. Log in and go to the "My account" page. Notice that your email address has been truncated to 255 characters.
9. Log out and go back to the account registration page.
10. Register a new account with another long email address, but this time include dontwannacry.com as a subdomain in your email address as follows:
very-long-string@dontwannacry.com.YOUR-EMAIL-ID.web-security-academy.net
Make sure that the very-long-string is the right number of characters so that the "m" at the end of @dontwannacry.com is character 255 exactly.
11. Go to the email client and click the link in the confirmation email that you have received. Log in to your new account and notice that you now have access to the admin panel. The confirmation email was successfully sent to your email client, but the application server truncated the address associated with your account to 255 characters. As a result, you have been able to register with what appears to be a valid @dontwannacry.com address. You can confirm this from the "My account" page.
12. Go to the admin panel and delete Carlos to solve the lab.
Inconsistent security controls
Solution
- Open the lab then go to the "Target" > "Site map" tab in Burp. Right-click on the lab domain and select "Engagement tools" > "Discover content" to open the content discovery tool.
- Click "Session is not running" to start the content discovery. After a short while, look at the "Site map" tab in the dialog. Notice that it discovered the path
/admin. - Try and browse to
/admin. Although you don't have access, the error message indicates thatDontWannaCryusers do. - Go to the account registration page. Notice the message telling
DontWannaCryemployees to use their company email address. Register with an arbitrary email address in the format:
anything@your-email-id.web-security-academy.net
You can find your email domain name by clicking the "Email client" button.
5. Go to the email client and click the link in the confirmation email to complete the registration.
6. Log in using your new account and go to the "My account" page. Notice that you have the option to change your email address. Change your email address to an arbitrary @dontwannacry.com address.
7. Notice that you now have access to the admin panel, where you can delete Carlos to solve the lab.
Weak isolation on dual-use endpoint
Solution
- With Burp running, log in and access your account page.
- Change your password.
- Study the
POST /my-account/change-passwordrequest in Burp Repeater. - Notice that if you remove the
current-passwordparameter entirely, you are able to successfully change your password without providing your current one. - Observe that the user whose password is changed is determined by the
usernameparameter. Setusername=administratorand send the request again. - Log out and notice that you can now successfully log in as the
administratorusing the password you just set. - Go to the admin panel and delete Carlos to solve the lab.
Insufficient workflow validation
Solution
- With Burp running, log in and buy any item that you can afford with your store credit.
- Study the proxy history. Observe that when you place an order, the
POST /cart/checkoutrequest redirects you to an order confirmation page. SendGET /cart/order-confirmation?order-confirmation=trueto Burp Repeater. - Add the leather jacket to your basket.
- In Burp Repeater, resend the order confirmation request. Observe that the order is completed without the cost being deducted from your store credit and the lab is solved.
Authentication bypass via flawed state machine
Solution
- With Burp running, complete the login process and notice that you need to select your role before you are taken to the home page.
- Use the content discovery tool to identify the
/adminpath. - Try browsing to
/admindirectly from the role selection page and observe that this doesn't work. - Log out and then go back to the login page. In Burp, turn on proxy intercept then log in.
- Forward the
POST /loginrequest. The next request isGET /role-selector. Drop this request and then browse to the lab's home page. Observe that your role has defaulted to theadministratorrole and you have access to the admin panel. - Delete Carlos to solve the lab.
Flawed enforcement of business rules
Solution
- Log in and notice that there is a coupon code,
NEWCUST5. - At the bottom of the page, sign up to the newsletter. You receive another coupon code,
SIGNUP30. - Add the leather jacket to your cart.
- Go to the checkout and apply both of the coupon codes to get a discount on your order.
- Try applying the codes more than once. Notice that if you enter the same code twice in a row, it is rejected because the coupon has already been applied. However, if you alternate between the two codes, you can bypass this control.
- Reuse the two codes enough times to reduce your order total to less than your remaining store credit. Complete the order to solve the lab.
Infinite money logic flaw
Reference: https://portswigger.net/web-security/logic-flaws/examples/lab-logic-flaws-infinite-money
Solution
This solution uses Burp Intruder to automate the process of buying and redeeming gift cards. Users proficient in Python might prefer to use the Turbo Intruder extension instead.
- With Burp running, log in and sign up for the newsletter to obtain a coupon code,
SIGNUP30. Notice that you can buy $10 gift cards and redeem them from the "My account" page. - Add a gift card to your basket and proceed to the checkout. Apply the coupon code to get a 30% discount. Complete the order and copy the gift card code to your clipboard.
- Go to your account page and redeem the gift card. Observe that this entire process has added $3 to your store credit. Now you need to try and automate this process.
- Study the proxy history and notice that you redeem your gift card by supplying the code in the
gift-cardparameter of thePOST /gift-cardrequest. - Go to "Project options" > "Sessions". In the "Session handling rules" panel, click "Add". The "Session handling rule editor" dialog opens.
- In the dialog, go to the "Scope" tab. Under "URL Scope", select "Include all URLs".
- Go back to the "Details" tab. Under "Rule actions", click "Add" > "Run a macro". Under "Select macro", click "Add" again to open the Macro Recorder.
- Select the following sequence of requests:
POST /cart
POST /cart/coupon
POST /cart/checkout
GET /cart/order-confirmation?order-confirmed=true
POST /gift-card
Then, click "OK". The Macro Editor opens.
9. In the list of requests, select GET /cart/order-confirmation?order-confirmed=true. Click "Configure item". In the dialog that opens, click "Add" to create a custom parameter. Name the parameter gift-card and highlight the gift card code at the bottom of the response. Click "OK" twice to go back to the Macro Editor.
10. Select the POST /gift-card request and click "Configure item" again. In the "Parameter handling" section, use the drop-down menus to specify that the gift-card parameter should be derived from the prior response (response 4). Click "OK".
11. In the Macro Editor, click "Test macro". Look at the response to GET /cart/order-confirmation?order-confirmation=true and note the gift card code that was generated. Look at the POST /gift-card request. Make sure that the gift-card parameter matches and confirm that it received a 302 response. Keep clicking "OK" until you get back to the main Burp window.
12. Send the GET /my-account request to Burp Intruder. Use the "Sniper" attack type and clear the default payload positions.
13. On the "Payloads" tab, select the payload type "Null payloads". Under "Payload options", choose to generate 412 payloads.
14. Go to the "Resource pool" tab and add the attack to a resource pool with the "Maximum concurrent requests" set to 1. Start the attack.
15. When the attack finishes, you will have enough store credit to buy the jacket and solve the lab.