--- title: "Google CTF 2018 - Shall We Play a Game?" section: "Mobile" sectionSlug: "mobile-pentesting" sourcePath: "src/mobile-pentesting/android-app-pentesting/google-ctf-2018-shall-we-play-a-game.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/mobile-pentesting/android-app-pentesting/google-ctf-2018-shall-we-play-a-game.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0" --- # Google CTF 2018 - Shall We Play a Game? The original Google CTF repository preserves the 2018 challenges, and community write-ups preserve this APK and its reversing workflow.[[1]](#references)[[2]](#references) Upload the APK to an isolated emulator service such as Appetize.io, or install it on a disposable local emulator/device, to observe its behavior:[[3]](#references) ![Appetize.io emulator running the Shall We Play a Game APK](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28421%29.png) The game requires 1,000,000 wins to reveal the flag. Following the [Android pentesting](/hacktricks/mobile-pentesting/android-app-pentesting/overview) workflow, decode the APK with Apktool and inspect decompiled Java with JADX.[[2]](#references) Reading the java code: ![Google CTF 2018 - Shall We Play a Game?: Reading the java code](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28495%29.png) The function that prints the flag is `m()`. ## **Smali changes** ### **Call m() the first time** To make the application call `m()` when `this.o != 1000000`, invert the branch condition: ```text if-ne v0, v9, :cond_2 ``` to: ```text if-eq v0, v9, :cond_2 ``` ![Before](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28383%29.png) ![After](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28838%29.png) Follow the [Android pentesting](/hacktricks/mobile-pentesting/android-app-pentesting/overview) workflow to rebuild and sign the APK, then run it again: ![Appetize.io emulator showing the modified APK after changing the Smali condition](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28128%29.png) The displayed flag is not fully decrypted because the per-win transformation must run 1,000,000 times; merely bypassing the comparison does not reproduce those iterations.[[2]](#references) Another approach is to leave the branch instruction intact and change its operands: ![Alternative Smali change: keep the branch instruction and change the compared registers](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28840%29.png) **Another way** is instead of comparing with 1000000, set the value to 1 so this.o is compared with 1: ![Smali changes - Call m() the first time: Another way is instead of comparing with 1000000, set the value to 1 so this.o is compared with 1](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28629%29.png) A fourth approach is to move the value of `v9` (1,000,000) into `v0` (`this.o`): ![Smali changes - Call m() the first time: A forth way is to add an instruction to move to value of v9(1000000) to v0 (this.o)](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28414%29.png) ![Smali changes - Call m() the first time: A forth way is to add an instruction to move to value of v9(1000000) to v0 (this.o)](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28424%29.png) ## Solution Make the application run the win/decryption loop **1,000,000 times** after the first win. Create the `:goto_6` loop and jump back while `this.o` has not reached 1,000,000:[[2]](#references) ![Call m() the first time - Solution: Make the application run the loop 100000 times when you win the first time. To do so, you only need to create the :goto 6 loop and make the...](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%281090%29.png) The original experiment succeeded on a physical device but not its emulator. That is an observation about that setup rather than an inherent requirement; emulator CPU speed, watchdogs, or service limits can make the million-iteration loop appear to hang. ## References - [1] [Google CTF challenge repository](https://github.com/google/google-ctf/tree/master/2018) - [2] [CTFtime — Google CTF 2018 “Shall we play a game?” write-up](https://ctftime.org/writeup/10277) - [3] [Appetize.io Android emulator](https://appetize.io/)