Flag Shop
Easy
150
Description
I'm only selling 1 product and that's flags! Please make sure you calculate how much money you have before coming here.
34.126.175.135:8001
Solution
TL;DR
Perform Integer Overflow to overflow
pay_priceto be < 100(balance).
Analysis
Program is pretty simple and limited with what you can do, so it is pretty straightforward.
The only option you have is to exit or provide the number of flags you want to buy, so our vulnerability is in the number of flags we provide.
We can see that our input is placed into the quantity variable, then the program calculates pay_price = flag_price * quantity;, and then checks if our balance is more than pay_price.
The thing to note is that the pay_price variable is assigned a type of unsigned int as seen at the start of the purchase function.
This means that the value of pay_price cannot go into the negative (unsigned), but the problem lies in where is doesn't check for how big the value of pay_price might get.
The int type has a maximum value that it can store, any number above that value would cause an integer overflow, where the number wraps around and gives a smaller number than intended.
Searching online for the maximum value of int, we find at https://learn.microsoft.com/en-us/cpp/c-language/cpp-integer-limits?view=msvc-170:
UINT_MAX Maximum value for a variable of type unsigned int. 4294967295 (0xffffffff)
So we can essentially craft a script that loops through the numbers of flags we can purchase, making sure to account for our integer overflow, and loop through till our pay_price <= 100.
Last updated
Was this helpful?