反向编译OpenWrt的Lua字节码 (Decompile Lua bytecode of OpenWRT)

  1. Lua有一种预编译机制,能够把文本代码预编译成Bytecode/Opcode 提高解析、执行速度,降低内存占用
  2. 原版Lua(Vanilla Lua)默认的Bytecode的字节结构和OpenWrt的并不相同,因为OpenWrt为了一系列需要,在截止我写此文时候,在Lua5.1.5的版本主线上对原版的LUA引擎打了补丁导致其产生的字节码和原版的Lua产生的并不一样,( http://lua-users.org/lists/lua-l/2012-06/msg00065.html ),因此也不能使用原版的Lua引擎解释,会报类似 bad header in precompiled chunk 的错误
  3. 本机尝试逆向原版的Lua产生的LuaC, 使用这个luadec 项目无任何问题   ,但是逆向Openwrt上的luaC失败,所以需要在Openwrt的Patch过的Lua lib的基础上,编译luadec
  4. 过程记录如下,全程在Linux Deepin 15.5上完成:

到这一步 其实会出现错误的,有提示

lauxlib.o: relocation R_X86_64_PC32 against symbol `[email protected]@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC

需要修改Makefile 给CFLAGS加上 -fPIC 选项 另外,为了使得Patch过后生成的so文件带版本号,还需要加上版本,最终生成的是如下的lua-5.1/src/Makefile的补丁

继续执行make linux应该不会报错了,然后按照luadec的教程继续做完就可以了

生成的3个可执行文件luadec luaopswap luareplace就是全部,她就可以直接解码openwrt的luaC的Bytecode了 这里提供编译好的文件下载

Author Info :
  • From:反向编译OpenWrt的Lua字节码 (Decompile Lua bytecode of OpenWRT)
  • URL:https://blog.ihipop.com/2018/05/5110.html
  • Please Reserve This Link,Thanks!
  • 《反向编译OpenWrt的Lua字节码 (Decompile Lua bytecode of OpenWRT)》上有5条评论

    1. gcc -o lua -L. -llua lua.o -lm -Wl,-E -ldl
      /usr/bin/ld: lua.o: in function lstop':
      lua.c:(.text+0x3b): undefined reference to
      lua_sethook'
      /usr/bin/ld: lua.o: in function pushline':
      lua.c:(.text+0xfa): undefined reference to
      lua_getfield'
      /usr/bin/ld: lua.c:(.text+0x109): undefined reference to lua_tolstring'
      /usr/bin/ld: lua.c:(.text+0x127): undefined reference to
      lua_settop'
      /usr/bin/ld: lua.c:(.text+0x1c7): undefined reference to lua_pushstring'
      /usr/bin/ld: lua.c:(.text+0x205): undefined reference to
      lua_getfield'
      /usr/bin/ld: lua.c:(.text+0x214): undefined reference to lua_tolstring'
      /usr/bin/ld: lua.c:(.text+0x251): undefined reference to
      lua_pushfstring'
      /usr/bin/ld: lua.o: in function `docall':
      make linux 报错

    2. 大人,请问一下,为什么我拿到的lua文件中的000B这个头地址,数据是04?不是01也不是02。该怎么反编译?

    发表评论

    您的电子邮箱地址不会被公开。