bananabr / ulua

A python script to apply a known plain text attack to Lua 5.1 bytecode files obfuscated with instruction swapping.
GNU General Public License v3.0
12 stars 1 forks source link

key error on opcode_map #1

Closed learncyber-co-il closed 1 year ago

learncyber-co-il commented 3 years ago

Hi! First of all allow me to thank you for this magnificant piece of software! Unfortunately, I stumbled upon an error while running it on lua bytecodes extracted from tp-link TL-R480T+v9 bin file. I followed your great guide at https://vovohelo.medium.com/unscrambling-lua-7bccb3d5660, but after the script finished building the opcode_map, it raised an error:

Patching file firmware.lua ...
Traceback (most recent call last):
  File "ulua.py", line 454, in <module>
    chunk = lc.parse(bytecode, opcode_map=opcode_map)
  File "ulua.py", line 260, in parse
    chunk, main=True, opcode_map=opcode_map)
  File "ulua.py", line 225, in decode_chunk
    chunk, main=False, opcode_map=opcode_map))
  File "ulua.py", line 178, in decode_chunk
    opcode = opcode_map[opcode]
KeyError: 8

Debug Printing opcode_map assured there is no '8' key:

{5: 5, 1: 1, 6: 6, 28: 28, 10: 10, 9: 9, 7: 7, 36: 36, 30: 30, 0: 0, 23: 23, 22: 22, 11: 11, 26: 26, 33: 33, 3: 3, 29: 29, 2: 2, 4: 4, 24: 24, 25: 25, 34: 34, 14: 14, 15: 15, 16: 16, 12: 12, 21: 21, 32: 32, 31: 31, 27: 27, 35: 35}

By the way, it seems like all opcodes were mapped to themselves. Am I wrong to assume that atleast some of them were supposed to be mapped to different ones?

I'd appericiate if you could have a look and advice. Many thanks in advance!

bananabr commented 3 years ago

Hey @learncyber-co-il, Thanks for the feedback :) Can you send me the Lua bytecode file?

learncyber-co-il commented 3 years ago

Hi @bananabr , thanks for your reply! Is it possible to send the file over email?

bananabr commented 3 years ago

Can you dm me on Twitter? @bananabr I don't want to disclose my email here.

b4sh5i commented 3 years ago
Patching file crypto.lua ...
Traceback (most recent call last):
  File "ulua.py", line 454, in <module>
    chunk = lc.parse(bytecode, opcode_map=opcode_map)
  File "ulua.py", line 260, in parse
    chunk, main=True, opcode_map=opcode_map)
  File "ulua.py", line 225, in decode_chunk
    chunk, main=False, opcode_map=opcode_map))
  File "ulua.py", line 178, in decode_chunk
    opcode = opcode_map[opcode]
KeyError: 22

i have same error. also am using tp-link firmware bin files.

bananabr commented 3 years ago

@b4sh5i,

You are getting a key error probably cause the built dictionary does not contain a map for byte 22. You either need more distinct files in your ref folder or to manually set a value for byte 22. Could you send me the samples you are working with?

b4sh5i commented 3 years ago

@bananabr can i send msg your twitter ? i can not send msg your account xD

bananabr commented 3 years ago

Hey @b4sh5i,

You should be able to msg me on Twitter now.

b4sh5i commented 3 years ago

@bananabr can i check my DM ?

bananabr commented 3 years ago

I can't see any message on my Twitter inbox. Are the Lua files you are using confidential? Can't you just upload it in Google Drive or something on share it here?

rssample commented 2 years ago

When analyzing the TP-Link router firmware, it is difficult to find the corresponding Lua file, and the results in the map are not completely correct. Is there any other way to solve this problem?

francoataffarel commented 1 year ago

@rssample any news?

bananabr commented 1 year ago

I never got the files to analyze the original case.

Here are some common problems you might face:

bananabr commented 1 year ago

I am closing this issue as the original complaints were addressed privately. If any other user has similar problems, feel free to post another issue providing me with the files required for testing.