Jump to content

6 posts in this topic

Recommended Posts

Posted

Intro:
There's a bunch of tries to to decrypting lua but none of it isnt clear enough how to do it. I'm aware that this approach isnt good enough, because too much step that you'll not need to do but i'm still write it instead. Code in this tutorial ofcourse just bunch of copy-pasta stackoverflow.

Prerequisites
1. Frida (optional)
2. Disassembler (IDA, r2, ..)
3. Python (optional) (I'll use python in this tutorial)
4. A little knowledge about this

What will you need to do?
1. Get the KEY for decryption,
2. Write a script for decryption,
3. Edit the lua (Self explanation),
4. Encrypt back the file (Self explaination) (Same as step 2, but you'll encrypt instead of decrypt),
5. PROFIT.

---- Step by step ----

Get the KEY for decryption
There's bunch of way to do it, some of them:
1. XREFS for XXTeaLuaLoader::setXXTeaKey(string), and you can see it clearly. Most used methods among many games.
nJX33Yr.png
2. Use Frida. I'll explain it on 2nd post.
3. http://forum.xda-developers.com/showthread.php?p=12853986#post12853986
4. etc.. You get the idea.

Write a script for decryption
This is an example of use for XXTEA encryption, requirements(xxtea-py)

 
Code (Text):





#!/usr/bin/env python
import xxtea

chiper = open("assets/script/fund.lua", "rb").read()

out = open("out.lua", "wb")

key = b'mrgj'

out.write(xxtea.encrypt(chiper, key))

out.close()END

Example of use of frida (https://github.com/antojoseph/frida-android-hooks)

As described here, 

Opening the lua files with hex editor reveals that they use XXTEA block cipher.

Analyze libjinqu.so and it blatantly shows the following decryption subroutines:
xxtea_decrypt
cocos2d::extra::CCCrypto::decryptXXTEA

Get a pseudocode generator and copy the program in C++.

. We need to put a hook either at xxtea_decrypt or cocos2d::extra::CCCrypto::decryptXXTEA. Then prints out the arguments passed.
We know that args[2] is the one holding the pointer to key from decompile xxtea_decrypt lib.so
Oh5SCFC.png 
Explaination, v9 is the one holding the chiper text, v30 chipertext len(?), v13 pointer to key, v14 is key.length.
Its obvious if we want to leak the key we need to print args[3] bytes at args[2]. This is an example of use for it.

 

#!/usr/bin/env python
import frida
import sys

package_name = "com.gamebau.pq"

def get_messages_from_js(message, data):
            print(message)

jsc = """
Interceptor.attach (Module.findExportByName( "libgame.so", "xxtea_decrypt"), {
    onEnter: function (args) {
        console.log("----------------BEGIN----------------");
        console.log(hexdump(Memory.readByteArray(args[2], 12),{
         offset: 0,
         length: 12,
         header: true,
         ansi: true
        }));
    },
    onLeave: function (retval) {
        console.log("Decrypt:");
        console.log(hexdump(Memory.readByteArray(retval, 16),{
         offset: 0,
         length: 16,
         header: true,
         ansi: true
        }));
        console.log("-----------------END-----------------");   
    }
});
"""

process = frida.get_usb_device().attach(package_name)
script = process.create_script(jsc)
script.on('message',get_messages_from_js)
script.load()
sys.stdin.read()

profit,
gohBm09.png
 
--Update, forgot to mention about this. Another note, some games tries to pack the assets with common file compressor. While loading it, it tries to unpack the assets on stream. As you can see on the image, its PK file header. With simple google search you can deduce its a zip alike compression. Try to extract the decrypted file with 7zip/Winrar/etc.. and you could see the unpacked file.

Image:
gohBm09.png
 
 
Credits: Wobm And Stack Overflow

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Our picks

    • Era Merge v1.0.1 [ +4 Cheats ] Currency Max
      Modded/Hacked App: Era Merge By ANLOFT YAZILIM LIMITED SIRKETI
      Bundle ID: com.anloft.eramerge
      App Store Link: https://apps.apple.com/us/app/era-merge/id6783998492?uo=4

      🤩 Hack Features

      - Auto ADS No
      - Unlimited Gems
      - Unlimited Coins
      - Unlimited Ticket
      • 0 replies
    • Era Merge v1.0.1 [ +4 Jailed ] Currency Max
      Modded/Hacked App: Era Merge By ANLOFT YAZILIM LIMITED SIRKETI
      Bundle ID: com.anloft.eramerge
      App Store Link: https://apps.apple.com/us/app/era-merge/id6783998492?uo=4

      🤩 Hack Features

      - Auto ADS No
      - Unlimited Gems
      - Unlimited Coins
      - Unlimited Ticket
      • 0 replies
    • Merge Cat Cafe: Decorate v1.1.50 [ +11 Cheats ] Currency Max
      Modded/Hacked App: Merge Cat Cafe: Decorate By StandEgg Co., Ltd
      Bundle ID: com.standegg.mergecatcafe2
      App Store Link: https://apps.apple.com/us/app/merge-cat-cafe-decorate/id6670415194?uo=4

      🤩 Hack Features

      - Gems Freeze
      - Coins Freeze
      - Booster Freeze
      - Box Items Freeze
      - Energy 0 Play Unlimited
      :::: VIP ::::
      - ADS NO
      - Unlimited Gems
      - Unlimited Coins
      - Unlimited Energy
      - Unlimited Booster
      - Unlimited Box Items
      • 0 replies
    • Merge Cat Cafe: Decorate v1.1.50 [ +11 Jailed ] Currency Max
      Modded/Hacked App: Merge Cat Cafe: Decorate By StandEgg Co., Ltd
      Bundle ID: com.standegg.mergecatcafe2
      App Store Link: https://apps.apple.com/us/app/merge-cat-cafe-decorate/id6670415194?uo=4

      🤩 Hack Features

      - Gems Freeze
      - Coins Freeze
      - Booster Freeze
      - Box Items Freeze
      - Energy 0 Play Unlimited
      :::: VIP ::::
      - ADS NO
      - Unlimited Gems
      - Unlimited Coins
      - Unlimited Energy
      - Unlimited Booster
      - Unlimited Box Items
      • 0 replies
    • Crossword Master - Word Puzzle v2.1.0 [ +3 Cheats  ] Currency Max
      Modded/Hacked App: Crossword Master - Word Puzzle By Easybrain Ltd
      Bundle ID: com.easybrain.crossword.puzzles
      App Store Link: https://apps.apple.com/us/app/crossword-master-word-puzzle/id6547858927?uo=4

      🤩 Hack Features

      - Auto ADS No
      - Unlimited Coins
      - Unlimited Booster
      • 0 replies
    • Crossword Master - Word Puzzle v2.1.0 [ +3 Jailed ] Currency Max
      Modded/Hacked App: Crossword Master - Word Puzzle By Easybrain Ltd
      Bundle ID: com.easybrain.crossword.puzzles
      App Store Link: https://apps.apple.com/us/app/crossword-master-word-puzzle/id6547858927?uo=4

      🤩 Hack Features

      - Auto ADS No
      - Unlimited Coins
      - Unlimited Booster
      • 0 replies
    • ZakuzakuSlash +5 Jailed Cheats [ Damage & Defence ]
      Modded/Hacked App: ZakuzakuSlash By nekosuko
      Bundle ID: jp.nekosuko.zakuzakuslash
      App Store Link: https://apps.apple.com/us/app/zakuzakuslash/id6749934570?uo=4

       


      🤩 Hack Features

      - Damage Multiplier
      - Defence Multiplier
      - God Mode
      - XP Multiplier
      - Unlimited Gold -> Will increase instead of decrease.
      • 2 replies
    • Piggy Land 3D v1.2.2 [ +4 Jailed ] Currency Max
      Modded/Hacked App: Piggy Land 3D By PIXON PTE. LTD.
      Bundle ID: farm.piggy.animal.jam.away
      App Store Link: https://apps.apple.com/us/app/piggy-land-3d/id6762121301?uo=4

      🤩 Hack Features

      - Auto ADS No
      - Unlimited Coin
      - Unlimited Booster
      - Custom Level
      • 1 reply
    • Piggy Land 3D v1.2.2 [ +4 Cheats ] Currency Max
      Modded/Hacked App: Piggy Land 3D By PIXON PTE. LTD.
      Bundle ID: farm.piggy.animal.jam.away
      App Store Link: https://apps.apple.com/us/app/piggy-land-3d/id6762121301?uo=4

      🤩 Hack Features

      - Auto ADS No
      - Unlimited Coin
      - Unlimited Booster
      - Custom Level
      • 0 replies
    • Dwarfs Diggers: Idle Master v0.7.4 [ +4 Jailed ] Currency Freeze
      Modded/Hacked App: Dwarfs Diggers: Idle Master By BLACK BOX DIGITAL LLP
      Bundle ID: com.bbdigital.idle.dwarfs.master
      App Store Link: https://apps.apple.com/us/app/dwarfs-diggers-idle-master/id6769121279?uo=4

      🤩 Hack Features

      - Currency Freeze
      - Resources Freeze
      - Energy Freeze
      - Troop Drop Unlimited
      • 3 replies
    • Dwarfs Diggers: Idle Master v0.7.4 [ +4 Cheats ] Currency Freeze
      Modded/Hacked App: Dwarfs Diggers: Idle Master By BLACK BOX DIGITAL LLP
      Bundle ID: com.bbdigital.idle.dwarfs.master
      App Store Link: https://apps.apple.com/us/app/dwarfs-diggers-idle-master/id6769121279?uo=4

      🤩 Hack Features

      - Currency Freeze
      - Resources Freeze
      - Energy Freeze
      - Troop Drop Unlimited
      • 1 reply
    • Metal Slug Rush v1.0.0 [ +9 APK MOD ] Currency Max
      Mod APK Game Name: Metal Slug Rush
      Rooted Device: Not Required.
      Google Play Store Link: https://play.google.com/store/apps/details?id=com.ringgames.msm

      🤩 Hack Features

      - Unlimited Gold
      - Unlimited Gems
      - Unlimited Energy
      - Unlimited Silver keys
      - Unlimited Golden Keys
      - Unlimited Special Keys
      - Unlimited Blueprint
      - Unlimited Token
      - Unlimited Ticket +3
      • 1 reply
×
  • Create New...

Important Information

We would like to place cookies on your device to help make this website better. The website cannot give you the best user experience without cookies. You can accept or decline our cookies. You may also adjust your cookie settings. Privacy Policy - Guidelines