0x0:起因
在一次apk渗透的时候,通过直接修改apk后缀为zip然后解压获取到了文件。在分析其中assests文件夹的时候,发现了后缀为luac的文件,luac文件已经加密,如果不解密,你无法获取到apk重要信息,所以有了这篇文章。
0x1:第一种获取key
要求:ida软件
下载apk 使用apktool对apk进行解压
找到 jmmlibarmeabi-v7alibqpry_lua.so
使用ida进行反编译,或者winhex查找字符串 shift+F12
查找密钥 RY_QP_2016
key:RY_QP_MBCLIENT_!2016
2.如果找不到字符串 在functions windows 搜索--applicationDidFinishLaunching--F5反编译源码
0x2 第二种方法获取key
要求:root的手机,ida软件
libgame解密法
拷贝IDA目录下dbgsrvandroid_server 到手机存储
或者使用adb命令拷贝
.adb.exe push android_server /storage/emulated/0
.adb shell
进入手机命令行
获取手机root权限
su
新建/data/tmp/目录
mkdir /data/tmp/
将android_server移动到/data/tmp/目录
mv /storage/emulated/0/android_server /data/tmp/
6切换到cd /data/tmp目录, android_server添加执行权限,然后运行android_server
cd /data/tmp
chmod +x android_server
./android_server
获得目标apk的包名 com.wode.wd090a96
手机上启动目标app
IDA连接手机调试
输入手机ip地址(手机和电脑必须在同一个网内)
附加对应的进程(包名)
进程附加成功后点击按钮恢复被暂停的程序运行
在modules窗口双击要解密的so文件
ctrl+f搜索 _byds_d_ 双击进入此函数
左上方窗口F5 反编译 ,第8行 v5=a4 处(这个根据代码来,你可以把代码所有的地方下断点或者关键地方下断点) F2下断点
下好断点后app上随便操作,等待触发断点暂停,然后点击yes
下方窗口选择R2,获得key
0x1:解密文件
在使用软件对文件进行解密
XXTEADecrypt工具
下载:
https://wwor.lanzoue.com/iqAlY1d9zxcj 密码:3yeb
如果解密后的luac文件打开看着还是乱码,可能对方使用了zlib压缩了,可以使用下面python文件进行解压
#!/user/bin/python
#!conding=utf8
import zlib
import sys
import os
def compressStr(msg):
compressed = zlib.compress(msg)
return compressed
def decompressStr(commsg):
decompressed = zlib.decompress(commsg)
return decompressed
def compress(infile, dst, level=9):
infile = open(infile, 'rb')
dst = open(dst, 'wb')
compress = zlib.compressobj(level)
data = infile.read(1024)
while data:
dst.write(compress.compress(data))
data = infile.read(1024)
dst.write(compress.flush())
def decompress(infile, dst):
infile = open(infile, 'rb')
dst = open(dst, 'wb')
decompress = zlib.decompressobj()
data = infile.read(1024)
while data:
dst.write(decompress.decompress(data))
data = infile.read(1024)
dst.write(decompress.flush())
def decompressDir(dirpath):
dirpath=dirpath.strip()
dirpath=dirpath.rstrip("\")
newDir = dirpath + "plain"
##parentDir = os.path.abspath(os.path.join(dirpath, ".."))
g = os.walk(dirpath)
for path,d,filelist in g:
#print d;
for filename in filelist:
filepath = os.path.join(path, filename)
print filepath
distPath = filepath.replace(dirpath,newDir)
fileDir , tmpName = os.path.split(distPath)
isExists=os.path.exists(fileDir)
if not isExists:
os.makedirs(fileDir)
decompress(filepath, distPath)
print distPath + "succeed!"
if __name__ == "__main__":
#compress('in.txt', 'out.txt')
if(len(sys.argv) < 2):
print sys.argv[0] + " filePath / destPath"
sys.exit()
if(os.path.isfile(sys.argv[1])):
decompress(sys.argv[1], sys.argv[2])
sys.exit()
if(os.path.isdir(sys.argv[1])):
decompressDir(sys.argv[1])
sys.exit()
print ( " path is error! " )
原文始发于微信公众号(红队笔记录):揭秘APK逆向:两种高级方法获取LUAC解密密钥!
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论