Category
Pwn
Description
My Valentine, Alex, has been kidnapped and is being held hostage! Help me save Alex by defeating the boss in this game.
Notes:
Every round, enter a number between 1 and the ATK (attack) of the entity whose turn it is (your's or the enemy's). Your opponent will also select a number from this range and if these numbers match, the attack is blocked (unless the attacker is the boss, whose attacks are not blockable). If they do not match, the attacking entity scores a hit and some damage is dealt based on the attacker's ATK.
At the beginning of a match, the entity with the smaller PRI (priority) attacks first.
You will face 3 enemies before the final boss. Make sure to keep upgrading your stats in the Shop! You earn money by winning battles.
The game is over once you have faced all 4 enemies, regardless of how well you do.
The Valentine will be displayed once you defeat the boss.
Solution
Connecting to the challenge server we see the following.
Welcome to...
...the MHSCTF BATTLE ARENA!
[ENTER]
SHOP ($15)
0. Leave Shop
1. HP Upgrade
2. ATK Upgrade
3. PRI Upgrade
Taking a look at the HP upgrade we see that we can upgrade our HP with at most nine HP with our current balance.
HP Upgrade ($15)
1. +3 HP ($5)
2. +15 HP ($20)
3. +50 HP ($50)
Trying to buy three +50 HP will return a message that we don’t have enough money.
Quantity? 3
Total Price: $150
NOT ENOUGH MONEY!
Similarly, we can only upgrade our ATK with one point with our current balance.
ATK Upgrade ($15)
1. +1 ATK ($10)
Quantity?
Taking a look at the PRI upgrade prices, we find out that we can’t even buy one.
PRI Upgrade ($15)
1. -1 PRI ($20)
Quantity?
Leaving the shop, we encounter our first enemy.
Player, your turn!
YOUR STATS:
HP ATK PRI
100 3 4
OPPONENT STATS:
HP ATK PRI
129 5 6
Press [ENTER] to play turn...
#(1-3):
After taking turns with the enemy, we will most likely lose the fight.
Enemy turn!
YOUR STATS:
HP ATK PRI
14 3 4
OPPONENT STATS:
HP ATK PRI
94 5 6
Press [ENTER] to play turn...
#(1-5): 3
Your #: 3 Attacker #: 5
HIT! (16)
ENEMY WINS!
Taking a look at the attached source for the game server, we find out that the shop is using an signed int for the amounts, but also that any negative number will be converted to a positive number.
But we might be able to overflow the underlying int to get enough money to buy our upgrades needed to defeat all enemies and finally the boss.
So if we try to buy a lot of PRI upgrades, we succeed in overflowing the int and get a lot of money.
PRI Upgrade ($15)
1. -1 PRI ($20)
Quantity? 100000000000
Total Price: $-1454759936
You have $1454759951 left.
Now we are able to upgrade our HP and ATK.
HP Upgrade ($1454759951)
1. +3 HP ($5)
2. +15 HP ($20)
3. +50 HP ($50)
3
Quantity? 1000
Total Price: $50000
You have $1454709951 left.
ATK Upgrade ($1454709951)
1. +1 ATK ($10)
Quantity? 1000
Total Price: $10000
You have $1454699951 left.
Now when we exit the shop and meet our first enemy, we easily win.
Player, your turn!
YOUR STATS:
HP ATK PRI
50100 1003 -1215752188
OPPONENT STATS:
HP ATK PRI
125 4 2
Press [ENTER] to play turn...
#(1-1003): 3
Your #: 3 Attacker #: 168
HIT! (2205)
YOU WIN! +14 coins
After defeating the third enemy, we get a BOSS FIGHT message.
Player, your turn!
YOUR STATS:
HP ATK PRI
50100 1003 -1215752188
OPPONENT STATS:
HP ATK PRI
68 5 2
Press [ENTER] to play turn...
#(1-1003): 4
Your #: 4 Attacker #: 874
HIT! (2558)
YOU WIN! +9 coins
BOSS FIGHT TIME!
We easily defeat the boss and get the flag.
YOU SAVED ALEX!
Here's your flag: valentine{phew_s4f3_and_50und}