# Google CTF 2018 - Shall We Play a Game?

Download the APK here:

I am going to upload the APK to <https://appetize.io/> (free account) to see how the apk is behaving:

![](https://4153509160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MaoGr_g3I50alM2whW0%2Fsync%2F9c2d709838516fde396c13b5ab575d7d73902bbd.png?generation=1622227478267384\&alt=media)

Looks like you need to win 1000000 times to get the flag.

Following the steps from [pentesting Android](https://chinnidiwakar.gitbook.io/githubimport/mobile-apps-pentesting/android-app-pentesting) you can decompile the application to get the smali code and read the Java code using jadx.

Reading the java code:

![](https://4153509160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MaoGr_g3I50alM2whW0%2Fsync%2F69f7551988f2a068f4f5adebdb281d4f6c704d1c.png?generation=1622227477841494\&alt=media)

It looks like the function that is going print the flag is **m().**

## **Smali changes**

### **Call m() the first time**

Lets make the application call m() if the variable *this.o != 1000000* to do so, just cange the condition:

```
 if-ne v0, v9, :cond_2
```

to:

```
 if-eq v0, v9, :cond_2
```

![Before](https://4153509160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MaoGr_g3I50alM2whW0%2Fsync%2Fdbc5a377d00b63a1d0533115f1c461240e76b1df.png?generation=1622227477398498\&alt=media)

![After](https://4153509160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MaoGr_g3I50alM2whW0%2Fsync%2Fc46cb0acad83c6f6bc197f58ca71dc6967caa967.png?generation=1622227477353254\&alt=media)

Follow the steps of [pentest Android](https://chinnidiwakar.gitbook.io/githubimport/mobile-apps-pentesting/android-app-pentesting) to recompile and sign the APK. Then, upload it to <https://appetize.io/> and lets see what happens:

![](https://4153509160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MaoGr_g3I50alM2whW0%2Fsync%2Fe4156b03795e8de5be3059171da0367ddeb84b63.png?generation=1622227477579306\&alt=media)

Looks like the flag is written without being completely decrypted. Probably the m() function should be called 1000000 times.

**Other way** to do this is to not change the instrucction but change the compared instructions:

![](https://4153509160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MaoGr_g3I50alM2whW0%2Fsync%2Fd82da439e23322ed9a052cec9568183c5740eb90.png?generation=1622227477484584\&alt=media)

**Another way** is instead of comparing with 1000000, set the value to 1 so this.o is compared with 1:

![](https://4153509160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MaoGr_g3I50alM2whW0%2Fsync%2Ff071911a51ec471c0a02e5baf944680fbdca17de.png?generation=1622227477527371\&alt=media)

A forth way is to add an instruction to move to value of v9(1000000) to v0 *(this.o)*:

![](https://4153509160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MaoGr_g3I50alM2whW0%2Fsync%2F75bf909418aff703c1d656cb149633236b170dfa.png?generation=1622227477646337\&alt=media)

![](https://4153509160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MaoGr_g3I50alM2whW0%2Fsync%2F3cc71d97302660cc58d1d9a0364fddf3fdcdebbe.png?generation=1622227477755425\&alt=media)

## 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 application **junp there if** ***this.o*** **does not value 100000**:

![](https://4153509160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MaoGr_g3I50alM2whW0%2Fsync%2F63675cea2d188711a2feadd1dc895bd3cfedcfcd.png?generation=1622227477613195\&alt=media)

You need to do this inside a physical device as (I don't know why) this doesn't work in an emulated device.
