- Name - pewpewboat.exe
- Category - Reverse Engineering
- Points - 1
- Binary - Download here
- Sets up the curses text-based user interface (sub_4031E1)
- Displays the grid (sub_403263)
- Processes the coordinate to determine if we've hit a ship or not, checks if we have completed the level and displays the appropriate messages (sub_4038D6)
- Asks the user to input the next coordinate (sub_40377D)
import md5 m = md5.new("GHND").digest() print ''.join(["%02X" % (256 + ~ord(x)) for x in m])At this point we can continue playing the game and try to beat each level by guessing the coords. Of course we're not doing that as it is very time consuming and painful. So, the next step is to find a way to reveal where the ships are for each level. A good way to checking this is to trace what happens to our input coord and how a HIT or MISS is determined based on this input. Our input is read in sub_40377D():
unsigned __int64 __fastcall sub_40377D(__int64 a1) { [ .. snip .. ] printf(format, &v6); if ( fgets(&s, 17, stdin) ) { row = (char)(s & 0xDF) - 0x41; col = v5 - 0x31; if ( row < 0 || row > 7 || col < 0 || col > 7 ) { sub_403411(&s, 17LL); } else { *(_QWORD *)(a1 + 8) |= 1LL << (8 * (unsigned __int8)row + col); *(_BYTE *)(a1 + 28) = s & 0xDF; *(_BYTE *)(a1 + 29) = v5; } } return __readfsqword(0x28u) ^ v28; }The function reads our input at line 7 and maps the row and column to a number between 0 and 7 on lines 9 and 10. For example, 'B6' translates to row = 1 & col = 5 whilst 'E2' translates to row = 4 & col = 1. Both values are then validated on line 11 to ensure they're on the board. Finally, at line 17, the values are combined into a single value that represents the input coordinate. This is the important part as it will be used to determine a HIT or a MISS. The following is a python 1-liner, which we'll use later on, to compute this value:
singlify = 1 << (row * 8 + col)We now move onto the part where a HIT or MISS is determined. This happens in sub_4038D6() which also decides what message is displayed to the user based on their coord input: The decision happens in the yellow basic block. On the 4th line of this block, RAX holds a level configuration number which determines the location of all the ships. This value is AND'd with our coord number. If the number remains the same, then it goes to the green basic block which signifies a HIT, if not it goes to the red basic block which displays the message 'You missed :('. If we put a breakpoint and collect the configuration number for the first level we get: 0x0008087808087800. We now combine everything we know. The following is a python script which, given a configuration number, determines all the hits and also displays them on a grid:
def draw_ships(input): hits = [] for row in range(8): for col in range(8): singlify = 1 << (row * 8 + col) if singlify & input == singlify: hits.append(chr(row + 0x41) + chr(col + 0x31)) print "X", else: print "_", print print return hits ship_config = 0x0008087808087800 print draw_ships(ship_config)Running the script gives us:
Command Prompt
C:\>python solution.py
_ _ _ _ _ _ _ _
_ _ _ X X X X _
_ _ _ X _ _ _ _
_ _ _ X _ _ _ _
_ _ _ X X X X _
_ _ _ X _ _ _ _
_ _ _ X _ _ _ _
_ _ _ _ _ _ _ _
['B4', 'B5', 'B6', 'B7', 'C4', 'D4', 'E4', 'E5', 'E6', 'E7', 'F4', 'G4']
C:\>
Notice that this coincides perfectly with what we've gotten when we played the game manually (check 2nd image from above). With these 2 scripts we're now guaranteed to hit all the ships before running out of ammo and also solve the NotMd5hash challenge each time. Make sure to put a break point to collect the configuration number at each level and get a list of HIT coords from the script.
Going through the 10 levels, we collect the string 'FHGUZREJVO' from the solutions, and the game displays the following message:
Removing the PEWs we get:
Aye! You found some letters did ya? To find what you're looking for, you'll want to re-order them: 9, 1, 2, 7, 3, 5, 6, 5, 8, 0, 2, 3, 5, 6, 1, 4. Next you let 13 ROT in the sea! THE FINAL SECRET CAN BE FOUND WITH ONLY THE UPPER CASE.
This is referring to the string 'FHGUZREJVO'. After we do what we're told we end up with 'BUTWHEREISTHERUM'. Feeding this to the game instead of a coordinate:
No comments:
Post a Comment