2020-07-15 15:43:14 +00:00
# Google CTF 2018 - Shall We Play a Game?
Download the APK here:
2021-10-18 11:21:18 +00:00
I am going to upload the APK to [https://appetize.io/ ](https://appetize.io ) (free account) to see how the apk is behaving:
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
 . png > )
2020-07-15 15:43:14 +00:00
Looks like you need to win 1000000 times to get the flag.
Following the steps from [pentesting Android ](./ ) you can decompile the application to get the smali code and read the Java code using jadx.
Reading the java code:
2021-10-18 11:21:18 +00:00
 . png > )
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
It looks like the function that is going print the flag is **m(). **
2020-07-15 15:43:14 +00:00
## **Smali changes**
2021-10-18 11:21:18 +00:00
### **Call m() the first time**
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
Lets make the application call m() if the variable _this.o != 1000000_ to do so, just cange the condition:
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
if-ne v0, v9, :cond_2
```
to:
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
if-eq v0, v9, :cond_2
```
2021-10-18 11:21:18 +00:00
.png>)
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
.png>)
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
Follow the steps of [pentest Android ](./ ) to recompile and sign the APK. Then, upload it to [https://appetize.io/ ](https://appetize.io ) and lets see what happens:
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
 . png > )
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
Looks like the flag is written without being completely decrypted. Probably the m() function should be called 1000000 times.
2020-07-15 15:43:14 +00:00
**Other way** to do this is to not change the instrucction but change the compared instructions:
2021-10-18 11:21:18 +00:00
 . png > )
2020-07-15 15:43:14 +00:00
**Another way** is instead of comparing with 1000000, set the value to 1 so this.o is compared with 1:
2021-10-18 11:21:18 +00:00
 . png > )
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
A forth way is to add an instruction to move to value of v9(1000000) to v0 _(this.o)_ :
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
 . png > )
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
 . png > )
2020-07-15 15:43:14 +00:00
## Solution
2021-10-18 11:21:18 +00:00
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**:
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
 . png > )
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
You need to do this inside a physical device as (I don't know why) this doesn't work in an emulated device.