123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- # -*- codeing = utf-8 -*-
- # @Time : 2022/9/30 15:36
- # @Author : Clown
- # @File : frida_demo.py
- # @Software : PyCharm
- import frida
- import pprint
- import frida_dexdump
- import sys
- if 1==0:
- def on_message(message, data):
- print ("[on_message] message:", message, "data:", data)
- rdev = frida.get_usb_device ()
- process = rdev.enumerate_processes () # 获取手机所有进程
- pprint.pprint (process)
- session = rdev.attach ("美团") # frida-ps -U 查看到的app名字
- print (session)
- script = session.create_script ("""
- rpc.exports.enumerateModules=function(){
- return Process.enumerateModules();
- };
- """)
- script.on ("message", on_message)
- script.load ()
- # 获取进程使用的所有模块
- pprint.pprint ([m["name"] for m in script.exports.enumerate_modules ()])
- if 1==1:
- jscode = """
- Java.perform(function () {
- var SwitchConfig = Java.use('mtopsdk.mtop.global.SwitchConfig');
- SwitchConfig.isGlobalSpdySwitchOpen.overload().implementation = function(){
- var ret = this.isGlobalSpdySwitchOpen.apply(this, arguments);
- console.log("isGlobalSpdySwitchOpenl "+ret)
- return false
- }
- })
- """
- def on_message(message, data):
- if message['type'] == 'send':
- print ("[*] {0}".format (message['payload']))
- else:
- print (message)
- process = frida.get_usb_device ().attach ('美团')
- script = process.create_script (jscode)
- script.on ('message', on_message)
- script.load ()
- sys.stdin.read ()
- if 1 == 0:
- import os
- import zipfile
- import argparse
- def rename_class(path):
- files = os.listdir (path)
- dex_index = 0
- if path.endswith ('/'):
- path = path[:-1]
- print (path)
- for i in range (len (files)):
- if files[i].endswith ('.dex'):
- old_name = path + '/' + files[i]
- if dex_index == 0:
- new_name = path + '/' + 'classes.dex'
- else:
- new_name = path + '/' + 'classes%d.dex' % dex_index
- dex_index += 1
- if os.path.exists (new_name):
- continue
- os.rename (old_name, new_name)
- print ('[*] 重命名完毕')
- def extract_META_INF_from_apk(apk_path, target_path):
- r = zipfile.is_zipfile (apk_path)
- if r:
- fz = zipfile.ZipFile (apk_path, 'r')
- for file in fz.namelist ():
- if file.startswith ('META-INF'):
- fz.extract (file, target_path)
- else:
- print ('[-] %s 不是一个APK文件' % apk_path)
- def zip_dir(dirname, zipfilename):
- filelist = []
- if os.path.isfile (dirname):
- if dirname.endswith ('.dex'):
- filelist.append (dirname)
- else:
- for root, dirs, files in os.walk (dirname):
- for dir in dirs:
- # if dir == 'META-INF':
- # print('dir:', os.path.join(root, dir))
- filelist.append (os.path.join (root, dir))
- for name in files:
- # print('file:', os.path.join(root, name))
- filelist.append (os.path.join (root, name))
- z = zipfile.ZipFile (zipfilename, 'w', zipfile.ZIP_DEFLATED)
- for tar in filelist:
- arcname = tar[len (dirname):]
- if ('META-INF' in arcname or arcname.endswith ('.dex')) and '.DS_Store' not in arcname:
- # print(tar + " -->rar: " + arcname)
- z.write (tar, arcname)
- print ('[*] APK打包成功,你可以拖入APK进行分析啦!')
- z.close ()
- if __name__ == '__main__':
- args = {
- 'dex_path': '脱壳后dex路径',
- 'apk_path': '原始带壳apk路径',
- 'output': '脱壳后apk路径'
- }
- rename_class (args['dex_path'])
- extract_META_INF_from_apk (args['apk_path'], args['dex_path'])
- zip_dir (args['dex_path'], args['output'])
|