Minesweeper Hacked : How we Hacked an Android Game and Ranked First globally

Recently, we came across an Android game of Minesweeper. The game has been nicely developed and was fun to play. Although it was very tough to win the game and even tougher to be in top ranks on the leaderboard. That’s when it struck us, why not “play” with the game some other way and figure out ways to hack minesweeper. . So we started analysing the game.


What is Minesweeper game

Minesweeper has a very basic gameplay style. In its original form, mines are scattered throughout a board. This board is divided into cells, which have three states: uncovered, covered and flagged. A covered cell is blank and clickable, while an uncovered cell is exposed, either containing a number (the mines adjacent to it), or a mine. When a cell is uncovered by a player click, and if it bears a mine, the game ends. A flagged cell is similar to a covered one, in the way that mines are not triggered when a cell is flagged, and it is impossible to lose through the action of flagging a cell. However, flagging a cell implies that a player thinks there is a mine underneath, which causes the game to deduct an available mine from the display.

In order to win the game, players must logically deduce where mines exist through the use of the numbers given by uncovered cells. To win, all non-mine cells must be uncovered and all mine cells must be flagged. At this stage, the timer is stopped.

When a player left-clicks on a cell, the game will uncover it. If there are no mines adjacent to that particular cell, the mine will display a blank tile or a “0”, and all adjacent cells will automatically be uncovered. Right-clicking on a cell will flag it, causing a flag to appear on it. Note that flagged cells are still covered, and a player can click on it to uncover it, like a normal covered cell.

Source: Wikipedia

Minesweeper Hacked: Introduction

Initially, our goal was to win the game irrespective of the time required. During the analysis we found that it was possible to reverse engineer the application and change values of some of the functions and win the game. We were able to achieve this task using two different methods.

Our next goal was to top the global leaderboards of all the difficulty levels, i.e. Beginner, Easy, Intermediate and Expert. In order to do that, we started analysing the application dynamically and checked the network traffic between the application and the server it was communicating with. We analysed source code of the apk even further and tampered the request accordingly to top the global rankings for every difficulty level.

Note: The name of the game has been redacted on purpose. The game has 1M+ downloads on play store.


How we Did it

Find the package name of installed application and decompiling it

There are multiple ways to achieve this, whether with ADB or from playstore URL https://play.google.com/store/apps/details?id=<app package name>

  1. To extract the APK from the device, we used the adb tool.Connect the device to the computer and make sure debugging is enabled. Start adb server and pull the apk using the following command.
    adb pull $(adb shell pm path <app package name> | cut -d':' -f2)
    mv base.apk game.apk
    
  2. To decompile the application, we will use apkx tool.apkx is a Python wrapper to popular free dex converters and Java decompilers. Extracts Java source code directly from the APK. Useful for experimenting with different converters/decompilers without having to worry about classpath settings and command line args.
    apkx game.apk
    

    Reference: Download apkx here


Different Methods Using Which we Hacked the Application

  • METHOD 1: Hook the application at run-time and toggle return value of GameActivity.finishgame function.
  • METHOD 2: Hook the application at run-time and print game board from game.GameBoard function.
  • METHOD 3: Hack the application by just sending a success message to server by tampering time required and the checksum.

Observation is the key to hack these kind of applications


Tools Used

For Method 1 & 2: Frida

For Method 3: BurpSuite or Curl (command line utility on Linux OS)


METHOD 1

Observe what actions are performed when you click on a bomb. The following observations are helpful

  1. Game ends
  2. Timer is stopped

We look for functions that trigger these operations.

Finish game snippet

finishgame function expects a boolean argument. Print the boolean argument to see what is passed into the function.

 1setTimeout(function() {
 2    Java.perform(function() {
 3
 4        var GameActivity = Java.use("<app package name>.GameActivity");
 5
 6        GameActivity.finishgame.implementation = function(bl2) {
 7            console.log(">>>>> Hacking minesweeper game: finsihgame return value = ", bl2);
 8            this.finishgame(bl2);
 9        }
10    })
11}, 10);

The below commands spawns a new process

frida -f <app package name> -U -l hook.js --no-pause

Now, observe what happens when a mine is clicked. A false value is passed to finishgame function.

Maybe that’s how it knows, we lost the game. Instead we will try to toggle the value of bl2 passed tofinishgame function.

 1setTimeout(function() {
 2    Java.perform(function() {
 3
 4        var GameActivity = Java.use("<app package name>.GameActivity");
 5
 6        GameActivity.finishgame.implementation = function(bl2) {
 7            console.log(">>>>> Hacking minesweeper game: finish game value = ", bl2);
 8            this.finishgame(true);
 9        }
10    })
11}, 10);

Execute the following command to start the application and hook Frida script

frida -f <app package name> -U -l hook.js --no-pause

We can see that we won the game when we click on the bomb, instead of losing the game.


METHOD 2

In the first method, we hooked the function that sends the message to finish game.

Now, we have to see where the bombs are located. Observe the decompiled java files to locate where the bombs are placed. We have to look for the function that places these bombs.

Game board

Open the game, start a new game and hook the above js scriptt to existing process.

 1var game_board_instance;
 2console.log(">>>>>>>>> Init frida script");
 3
 4setTimeout(function() {
 5    Java.perform(function() {
 6
 7        console.log(">>>>>>>>> Init Java perform module");
 8
 9        Java.choose("<app package name>.states.game.GameBoard", {
10            "onMatch": function(instance) {
11                game_board_instance = instance;
12                console.log("Captured game board instance");
13            },
14            "onComplete": function() {}
15        });
16
17        console.log("Height: ", game_board_instance.height.value);
18        console.log("Width: ", game_board_instance.width.value);
19
20        console.log("Extracting the game board sequence >>>>>>");
21
22        for(var i=0; i<game_board_instance.height.value; i++) {
23            var horizontal_sequence = "";
24            for(var j=0; j<game_board_instance.width.value; j++) {
25                horizontal_sequence = horizontal_sequence + " " + game_board_instance.tiles.value[i][j];
26            }
27            console.log(horizontal_sequence);
28        }
29   
30    })
31}, 10);

Run the following command to execute app and hook our Frida script

frida -U <app package name> -l hook.js --no-pause

We can see that the entire board is printed along with the pints. The value 9 is the bomb!

Minesweeper board hacked


METHOD 3

After we finish the game, there the application provides us with a global rank. These requests to the server can be intercepted with a proxy tool like BurpSuite.

For Reference you can check here! 

Note: The application had implemented SSL Pinning, which we were able to bypass using Objection. Since this is a blog showing how we hacked the app, we decided not to show how to bypass SSL pinning using Objection or Frida. We will write a new blog with step by step instructions on how to use Frida and Objection.

Upon intercpeting the request we realised, simpleDbTime parameter contains the time we took to finsih the game. If we can intercept this request and send a fake simpleDbTime to the server, we win. But its not easy. When we did that the result isn’t persistent, our scores weren’t reflected in global scoreboard. We realised there is a checksum that validates the request.

request sent by the app

We analyzed the code more and found the code corresponding to checksum.

check sum value

We can see the implementation of the checksum algorithm. Parameters like itemName, deviceId and simpleDbTime have been used with dot separated to calculate the md5sum of the request.

We computed the value of checksum locally that corresponds to our new simpleDbTime value by using the same logic as performed in application code above.

Let’s get MD5 checksum of the required parameters

MD5 checksum

We will now send request using Burp with tampered parameter values.

burp request

Send another request to check the leaderboard scores. We will see that we are ranked 1st on the leaderboard

Global leaderboard rank 1

Upon submitting this request, we can see that our data was successfully registered in the database and we can see it in the global highscores list as well.

RESULT

Expert level challenge solved in 0.01 seconds without even playing the game!

Expert level challenge

These bugs are fixed in the latest version of the application.


RESEARCHERS

TIMELILNE

| Status | Date | |——–|——| | Bug Submitted | 19 February 2020 | Bug Triaged | 25 February 2020 | Bug Resolved | 13 March 2020

Subscribe to our Newsletter
Subscription Form
DOWNLOAD THE DATASHEET

Fill in your details and get your copy of the datasheet in few seconds

CTI Report
DOWNLOAD THE EBOOK

Fill in your details and get your copy of the ebook in your inbox

Ebook Download
DOWNLOAD A SAMPLE REPORT

Fill in your details and get your copy of sample report in few seconds

Download ICS Sample Report
DOWNLOAD A SAMPLE REPORT

Fill in your details and get your copy of sample report in few seconds

Download Cloud Sample Report
DOWNLOAD A SAMPLE REPORT

Fill in your details and get your copy of sample report in few seconds

Download IoT Sample Report
DOWNLOAD A SAMPLE REPORT

Fill in your details and get your copy of sample report in few seconds

Download Code Review Sample Report
DOWNLOAD A SAMPLE REPORT

Fill in your details and get your copy of sample report in few seconds

Download Red Team Assessment Sample Report
DOWNLOAD A SAMPLE REPORT

Fill in your details and get your copy of sample report in few seconds

Download AI/ML Sample Report
DOWNLOAD A SAMPLE REPORT

Fill in your details and get your copy of sample report in few seconds

Download DevSecOps Sample Report
DOWNLOAD A SAMPLE REPORT

Fill in your details and get your copy of sample report in few seconds

Download Product Security Assessment Sample Report
DOWNLOAD A SAMPLE REPORT

Fill in your details and get your copy of sample report in few seconds

Download Mobile Sample Report
DOWNLOAD A SAMPLE REPORT

Fill in your details and get your copy of sample report in few seconds

Download Web App Sample Report

Let’s make cyberspace secure together!

Requirements

Connect Now Form

What our clients are saying!

Trusted by