Inside Out was one of the challenges I set up for DOME CTF 2020. The challenge description goes like this: “You’ve reached the location where an important piece of data is located. Much to your dismay you need to unlock a particular door to get inside. Once you solve that and get in, you’re met with another puzzle that you have to crack.”
You’re given an apk and you have to decompile it using a tool like APK Studio available on Windows.
Once you decompile the apk, go to androidmanifest.xml
From the file we can understand that the starting activity is MainActivity.java
Go to MainActivity.java
From onCreate, we can understand that mMessageDigest is used as SHA-1algorithm.
There is only one function that has View as a parameter. It shows that it must be a login button action.
From the code we can see that the username is stored in “R.string.username”.
From this we can get the idea that the username and password are stored in strings.xml.
Search using Grep username
Then go to string and we get username as “user@domctfin”
Now for the password:
From the code we get that the first input password is converted to SHA-1, and then it is encoded using Encoder.java.
Then that encoded value is compared to the value stored in string.xml “R.string.phash” .
So we have to decode it in reverse order. In order to do that we have to find the algorithm used in Encoder.java.
Here we get the encryption key input “domctf2020” is used and the algorithm AES/ECB/PKCS5PADDING is used.
For secret : from the code The key is first converted to bytes The sha1 algorithm used to digest the key. Then Byte is again changed 16 bit, Then new SecretKeySpec(bArr2, “AES”) Is finally used
Create java class for decrypting of phash. From strings.xml we get phash.
Similarly we get a hash of password from strings.xml.
moG4UJAMANaAGIhv6qKgeTFDHxxg0EpLSjnOXHmu55IM
Write a java code to decompile the hash.
Decrypt hash using secret. “domctf2020”.
2b749c8c9b2f8ebe3a81e5eb9013793b807ee0c3
Search for SHA-1 on Google. We get the password “~saint~”
Now we got the username and password. Then from the code we can see that the combination of username and password is xored to:
u s e r @d o m c t f i n ~ s a i n t ~ 0 1 2 3 4 5 6 7 8 910 11 12 0 1 2 3 4 5 6
We already have the function for decrypting: “AES/ECB/PKCS5PADDING”
After decrypting we get flag “sOcekBZRw3c263wBPV6kzmUxgLcUAJbQ”.
domectf{sOcekBZRw3c263wBPV6kzmUxgLcUAJbQ}
Automated human-like penetration testing for your web apps & APIs
Teams using Beagle Security are set up in minutes, embrace release-based CI/CD security testing and save up to 65% with timely remediation of vulnerabilities. Sign up for a free account to see what it can do for you.