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

    • Match Factory! v1.40.118 +3 Jailed Cheats [ Unlimited Everything ]
      Modded/Hacked App: Match Factory! By Peak Games
      Bundle ID: net.peakgames.match
      iTunes Store Link: https://apps.apple.com/gb/app/match-factory/id6449094229?uo=4


      Hack Features:
      - Unlimited Everything -> Will increase instead of decrease. Use coins for energy.
      - Auto Win -> Pick up an item.
      - Unlimited Time -> Will not decrease.
        • Informative
        • Agree
        • Haha
        • Thanks
        • Winner
        • Like
      • 55 replies
    • Match Factory! v1.40.118 +3 Cheats [ Unlimited Everything ]
      Modded/Hacked App: Match Factory! By Peak Games
      Bundle ID: net.peakgames.match
      iTunes Store Link: https://apps.apple.com/gb/app/match-factory/id6449094229?uo=4


      Hack Features:
      - Unlimited Everything -> Will increase instead of decrease. Use coins for energy.
      - Auto Win -> Pick up an item.
      - Unlimited Time -> Will not decrease.


      Non-Jailbroken & No Jailbreak required hack(s): [Non-Jailbroken Hack] Match Factory v1.1.30 +2 Jailed Cheats [ Unlimited Everything ] - Free Non-Jailbroken IPA Cheats - iOSGods
      Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      For more fun, check out the Club(s): https://iosgods.com/clubs/
        • Informative
        • Agree
        • Thanks
        • Winner
        • Like
      • 50 replies
    • Night Valley - Tower Defense v1.0.7 [+2 Jailed Cheats]
      Modded/Hacked App: Night Valley - Tower Defense By Pitaya Group, Inc, The
      Bundle ID: com.pitaya.natv
      App Store Link: https://apps.apple.com/us/app/night-valley-tower-defense/id6467846624?uo=4



      🤩 Hack Features

      - Never Die
      - Add Currency
      • 0 replies
    • Night Valley - Tower Defense v1.0.7 [+2 Cheats]
      Modded/Hacked App: Night Valley - Tower Defense By Pitaya Group, Inc, The
      Bundle ID: com.pitaya.natv
      App Store Link: https://apps.apple.com/us/app/night-valley-tower-defense/id6467846624?uo=4



      🤩 Hack Features

      - Never Die
      - Add Currency
       
      • 0 replies
    • MeChat - Interactive Stories v4.33.1 +5 Jailed Cheats [ Unlimited Gems ]
      Modded/Hacked App: MeChat - Interactive Stories By IMPONILOX LIMITED
      Bundle ID: world.playme.mechat
      App Store Link: https://apps.apple.com/us/app/mechat-interactive-stories/id1536157979?uo=4

       

      📌 Mod Requirements

      - Non-Jailbroken/Jailed or Jailbroken iPhone or iPad.
      - Sideloadly or alternatives.
      - Computer running Windows/macOS/Linux with iTunes installed.

       

      🤩 Hack Features

      - Unlimited Gems -> Will increase instead of decrease.
      - Unlock All Photos
      - Unlock All Audio Clips
      -- VIP Enabled

      VIP
      - Unlimited Gems -> Earn some then disable this feature. DO NOT SPEND ANY GEMS WHILST THIS FEATURE IS ENABLED!
        • Informative
        • Agree
        • Haha
        • Thanks
        • Winner
        • Like
      • 771 replies
    • MeChat - Interactive Stories v4.33.1 +5 Cheats [ Unlimited Gems ]
      Modded/Hacked App: MeChat - Interactive Stories By IMPONILOX LIMITED
      Bundle ID: world.playme.mechat
      App Store Link: https://apps.apple.com/us/app/mechat-interactive-stories/id1536157979?uo=4

       

      📌 Mod Requirements

      - Jailbroken iPhone or iPad.
      - iGameGod / Filza / iMazing.
      - Cydia Substrate, ElleKit, Substitute or libhooker depending on your jailbreak (from Sileo, Cydia or Zebra).

       

      🤩 Hack Features

      - Unlimited Gems -> Will increase instead of decrease.
      - Unlock All Photos
      - Unlock All Audio Clips
      -- VIP Enabled

      VIP
      - Unlimited Gems -> Earn some then disable this feature. DO NOT SPEND ANY GEMS WHILST THIS FEATURE IS ENABLED!
        • Informative
        • Agree
        • Haha
        • Thanks
        • Winner
        • Like
      • 309 replies
    • Wizario v1.0.86 +5 Jailed Cheats [ Unlimited Everything ]
      Modded/Hacked App: Wizario By Estoty LLC
      Bundle ID: com.kolkagames.wizario
      iTunes Store Link: https://apps.apple.com/us/app/wizario/id6572310997?uo=4


      Hack Features:
      - Unlimited Everything -> Earn some then restart the game.
      - Damage Multiplier
      - Health Multiplier
      - Tool Damage Multiplier
      - No Ads -> Head to Settings and toggle the Restore Purchases button.


      Jailbreak required hack(s): [Mod Menu Hack] Wizario v1.0.56 +5 Cheats [ Unlimited Everything ] - Free Jailbroken Cydia Cheats - iOSGods
      Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      For more fun, check out the Club(s): https://iosgods.com/clubs/
        • Informative
        • Thanks
        • Winner
        • Like
      • 25 replies
    • Wizario v1.0.86 +5 Cheats [ Unlimited Everything ]
      Modded/Hacked App: Wizario By Estoty LLC
      Bundle ID: com.kolkagames.wizario
      iTunes Store Link: https://apps.apple.com/us/app/wizario/id6572310997?uo=4


      Hack Features:
      - Unlimited Everything -> Earn some then restart the game.
      - Damage Multiplier
      - Health Multiplier
      - Tool Damage Multiplier
      - No Ads -> Head to Settings and toggle the Restore Purchases button.


      Non-Jailbroken & No Jailbreak required hack(s): [IPA Mod Menu] Wizario v1.0.56 +5 Jailed Cheats [ Unlimited Everything ] - Free Non-Jailbroken IPA Cheats - iOSGods
      Modded Android APK(s): https://iosgods.com/forum/68-android-section/
      For more fun, check out the Club(s): https://iosgods.com/clubs/
        • Agree
        • Haha
        • Thanks
        • Winner
        • Like
      • 21 replies
    • Prison Break Idle v0.1.3 [+3 Cheats]
      Modded/Hacked App: Prison Break Idle By Anisoft Yazilim Derya Bagdinli ve Ortagi Kollektif Sirketi
      Bundle ID: com.anisoftgames.prisonbreakidle
      iTunes Store Link: https://apps.apple.com/us/app/prison-break-idle/id6739884706?uo=4



      🤩 Hack Features

      - Never Die
      - Unlimited Currency (Spend to earn)
       
        • Like
      • 2 replies
    • Prison Break Idle v0.1.3 [+3 Jailed Cheats]
      Modded/Hacked App: Prison Break Idle By Anisoft Yazilim Derya Bagdinli ve Ortagi Kollektif Sirketi
      Bundle ID: com.anisoftgames.prisonbreakidle
      iTunes Store Link: https://apps.apple.com/us/app/prison-break-idle/id6739884706?uo=4

       

      🤩 Hack Features

      - Never Die
      - Unlimited Currency (Spend to earn) 
        • Like
      • 4 replies
    • Base Commander v3.0.0 Cheat Menu [+3 Jailed Cheats]
      Modded/Hacked App: Base Commander By Supercent Inc.
      Bundle ID: com.yalp.basecommander
      iTunes Store Link: https://apps.apple.com/us/app/base-commander/id6504986006?uo=4



      🤩 Hack Features

      - Cheat Menu Enabled (QA is the cheat menu)
        • Like
      • 5 replies
    • Base Commander v3.0.0 Cheat Menu [+3 Cheats]
      Modded/Hacked App: Base Commander By Supercent Inc.
      Bundle ID: com.yalp.basecommander
      iTunes Store Link: https://apps.apple.com/us/app/base-commander/id6504986006?uo=4



      🤩 Hack Features

      - Cheat Menu Enabled (QA is the cheat menu)
       
      • 3 replies
×
  • 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