[update] support dump specified bundle id
This commit is contained in:
parent
33c4ac14c4
commit
fd88a4818c
25
app.js
25
app.js
|
@ -20,12 +20,33 @@ function getbundleid(name){
|
||||||
return ""
|
return ""
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getdisplayname(bundleid){
|
||||||
|
const workspace = LSApplicationWorkspace.defaultWorkspace();
|
||||||
|
const apps = workspace.allApplications();
|
||||||
|
var result;
|
||||||
|
for(var index = 0; index < apps.count(); index++){
|
||||||
|
var proxy = apps.objectAtIndex_(index);
|
||||||
|
if(proxy.bundleIdentifier() && proxy.bundleIdentifier().toString() == bundleid){
|
||||||
|
return proxy.localizedName().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
function handleMessage(message) {
|
function handleMessage(message) {
|
||||||
const bundleid = getbundleid(message);
|
var bundleid;
|
||||||
|
var displayname;
|
||||||
|
if(message['name']){
|
||||||
|
displayname = message['name']
|
||||||
|
bundleid = getbundleid(displayname);
|
||||||
|
}else if(message['bundleid']){
|
||||||
|
bundleid = message['bundleid']
|
||||||
|
displayname = getdisplayname(bundleid);
|
||||||
|
}
|
||||||
if(bundleid.length > 0){
|
if(bundleid.length > 0){
|
||||||
openApplication(bundleid);
|
openApplication(bundleid);
|
||||||
}
|
}
|
||||||
send({opened: "ok"});
|
send({ opened: displayname });
|
||||||
}
|
}
|
||||||
|
|
||||||
recv(handleMessage);
|
recv(handleMessage);
|
169
dump.py
169
dump.py
|
@ -11,6 +11,7 @@ import threading
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import time
|
import time
|
||||||
|
import getopt
|
||||||
|
|
||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf8')
|
sys.setdefaultencoding('utf8')
|
||||||
|
@ -26,6 +27,15 @@ finished = threading.Event()
|
||||||
global session
|
global session
|
||||||
global name
|
global name
|
||||||
|
|
||||||
|
#show usage
|
||||||
|
def usage():
|
||||||
|
print '-------------------------frida-ios-dump(by AloneMonkey v2.0)----------------------------'
|
||||||
|
print '\t%-20s\t%s' % ('-h,--help','Show help menu.');
|
||||||
|
print '\t%-20s\t%s' % ('displayname','Decrypt the application of the specified display name. ps: ./dump.py 微信');
|
||||||
|
print '\t%-20s\t%s' % ('-l','List the app has been installed.');
|
||||||
|
print '\t%-20s\t%s' % ('-b bundleid','Decrypt the application of the specified bundleid. ps: ./dump.py com.tencent.xin');
|
||||||
|
exit(0)
|
||||||
|
|
||||||
def get_usb_iphone():
|
def get_usb_iphone():
|
||||||
dManager = frida.get_device_manager();
|
dManager = frida.get_device_manager();
|
||||||
changed = threading.Event()
|
changed = threading.Event()
|
||||||
|
@ -60,9 +70,11 @@ def gen_ipa(target):
|
||||||
finished.set();
|
finished.set();
|
||||||
|
|
||||||
def on_message(message,data):
|
def on_message(message,data):
|
||||||
|
global name;
|
||||||
if message.has_key('payload'):
|
if message.has_key('payload'):
|
||||||
payload = message['payload']
|
payload = message['payload']
|
||||||
if payload.has_key("opened"):
|
if payload.has_key("opened"):
|
||||||
|
name = payload["opened"]
|
||||||
opened.set();
|
opened.set();
|
||||||
if payload.has_key("dump"):
|
if payload.has_key("dump"):
|
||||||
orign_path = payload["path"]
|
orign_path = payload["path"]
|
||||||
|
@ -80,7 +92,88 @@ def on_message(message,data):
|
||||||
gen_ipa(os.getcwd()+"/"+OUTPUT)
|
gen_ipa(os.getcwd()+"/"+OUTPUT)
|
||||||
finished.set();
|
finished.set();
|
||||||
|
|
||||||
def loadJsFile(session, filename):
|
def compare_applications(a, b):
|
||||||
|
a_is_running = a.pid != 0
|
||||||
|
b_is_running = b.pid != 0
|
||||||
|
if a_is_running == b_is_running:
|
||||||
|
if a.name > b.name:
|
||||||
|
return 1
|
||||||
|
elif a.name < b.name:
|
||||||
|
return -1
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
elif a_is_running:
|
||||||
|
return -1
|
||||||
|
else:
|
||||||
|
return 1
|
||||||
|
|
||||||
|
def cmp_to_key(mycmp):
|
||||||
|
"Convert a cmp= function into a key= function"
|
||||||
|
class K:
|
||||||
|
def __init__(self, obj, *args):
|
||||||
|
self.obj = obj
|
||||||
|
def __lt__(self, other):
|
||||||
|
return mycmp(self.obj, other.obj) < 0
|
||||||
|
def __gt__(self, other):
|
||||||
|
return mycmp(self.obj, other.obj) > 0
|
||||||
|
def __eq__(self, other):
|
||||||
|
return mycmp(self.obj, other.obj) == 0
|
||||||
|
def __le__(self, other):
|
||||||
|
return mycmp(self.obj, other.obj) <= 0
|
||||||
|
def __ge__(self, other):
|
||||||
|
return mycmp(self.obj, other.obj) >= 0
|
||||||
|
def __ne__(self, other):
|
||||||
|
return mycmp(self.obj, other.obj) != 0
|
||||||
|
return K
|
||||||
|
|
||||||
|
def get_applications():
|
||||||
|
device = get_usb_iphone()
|
||||||
|
|
||||||
|
try:
|
||||||
|
applications = device.enumerate_applications()
|
||||||
|
except Exception as e:
|
||||||
|
print "Failed to enumerate applications: %s" % e
|
||||||
|
exit(1)
|
||||||
|
return
|
||||||
|
|
||||||
|
return applications
|
||||||
|
|
||||||
|
def list_applications():
|
||||||
|
applications = get_applications()
|
||||||
|
|
||||||
|
if len(applications) > 0:
|
||||||
|
pid_column_width = max(map(lambda app: len("%d" % app.pid), applications))
|
||||||
|
name_column_width = max(map(lambda app: len(app.name), applications))
|
||||||
|
identifier_column_width = max(map(lambda app: len(app.identifier), applications))
|
||||||
|
else:
|
||||||
|
pid_column_width = 0
|
||||||
|
name_column_width = 0
|
||||||
|
identifier_column_width = 0
|
||||||
|
|
||||||
|
header_format = "%" + str(pid_column_width) + "s " + "%-" + str(name_column_width) + "s " + "%-" + str(identifier_column_width) + "s"
|
||||||
|
print header_format % ("PID", "Name", "Identifier")
|
||||||
|
print "%s %s %s" % (pid_column_width * "-", name_column_width * "-", identifier_column_width * "-")
|
||||||
|
line_format = "%" + str(pid_column_width) + "s " + "%-" + str(name_column_width) + "s " + "%-" + str(identifier_column_width) + "s"
|
||||||
|
for app in sorted(applications, key=cmp_to_key(compare_applications)):
|
||||||
|
if app.pid == 0:
|
||||||
|
print line_format % ("-", app.name, app.identifier)
|
||||||
|
else:
|
||||||
|
print line_format % (app.pid, app.name, app.identifier)
|
||||||
|
|
||||||
|
def get_pid_by_bundleid(bundleid):
|
||||||
|
applications = get_applications()
|
||||||
|
|
||||||
|
return [app.pid for app in applications if app.identifier == bundleid][0]
|
||||||
|
|
||||||
|
def find_target_app(isbundleid, value):
|
||||||
|
applications = get_applications()
|
||||||
|
|
||||||
|
if not isbundleid:
|
||||||
|
return [app for app in applications if app.name == value]
|
||||||
|
else:
|
||||||
|
return [app for app in applications if app.identifier == value]
|
||||||
|
|
||||||
|
def load_js_file(session, filename):
|
||||||
source = ''
|
source = ''
|
||||||
with codecs.open(filename,'r','utf-8') as f:
|
with codecs.open(filename,'r','utf-8') as f:
|
||||||
source = source + f.read();
|
source = source + f.read();
|
||||||
|
@ -89,12 +182,12 @@ def loadJsFile(session, filename):
|
||||||
script.load()
|
script.load()
|
||||||
return script
|
return script
|
||||||
|
|
||||||
def ClearAndQuit(session):
|
def clear_and_quit(session):
|
||||||
if session:
|
if session:
|
||||||
session.detach()
|
session.detach()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def createDir(path):
|
def create_dir(path):
|
||||||
path = path.strip()
|
path = path.strip()
|
||||||
path = path.rstrip("\\")
|
path = path.rstrip("\\")
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
|
@ -102,37 +195,73 @@ def createDir(path):
|
||||||
else:
|
else:
|
||||||
print path + u" is existed!";
|
print path + u" is existed!";
|
||||||
|
|
||||||
def main(target):
|
def open_target_app(isbundleid, value):
|
||||||
global session
|
|
||||||
global name
|
|
||||||
session = None
|
|
||||||
device = get_usb_iphone();
|
device = get_usb_iphone();
|
||||||
#open app
|
|
||||||
name = u'SpringBoard';
|
name = u'SpringBoard';
|
||||||
print "open target app......"
|
print "open target app......"
|
||||||
session = device.attach(name);
|
session = device.attach(name);
|
||||||
script = loadJsFile(session, APP_JS);
|
script = load_js_file(session, APP_JS);
|
||||||
name = target.decode('utf8');
|
if not isbundleid:
|
||||||
script.post(name);
|
script.post({'name': value})
|
||||||
|
else:
|
||||||
|
script.post({'bundleid': value})
|
||||||
opened.wait();
|
opened.wait();
|
||||||
session.detach();
|
session.detach();
|
||||||
createDir(os.getcwd()+"/"+OUTPUT)
|
create_dir(os.getcwd()+"/"+OUTPUT)
|
||||||
print 'Waiting for the application to open......'
|
print 'Waiting for the application to open......'
|
||||||
time.sleep(5);
|
time.sleep(5);
|
||||||
|
|
||||||
|
def start_dump(target):
|
||||||
print "start dump target app......"
|
print "start dump target app......"
|
||||||
session = device.attach(name);
|
device = get_usb_iphone();
|
||||||
script = loadJsFile(session, DUMP_JS);
|
session = device.attach(target);
|
||||||
|
script = load_js_file(session, DUMP_JS);
|
||||||
script.post("dump");
|
script.post("dump");
|
||||||
finished.wait();
|
finished.wait();
|
||||||
ClearAndQuit(session);
|
clear_and_quit(session);
|
||||||
|
|
||||||
|
def dump_by_display_name(display_name):
|
||||||
|
open_target_app( 0, display_name)
|
||||||
|
start_dump(display_name);
|
||||||
|
|
||||||
|
def dump_by_bundleid(bundleid):
|
||||||
|
open_target_app( 1, bundleid)
|
||||||
|
start_dump(get_pid_by_bundleid(bundleid));
|
||||||
|
|
||||||
|
def check_args():
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
usage()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
opts,args = getopt.getopt(sys.argv[1:],"hlb:",["help"]);
|
||||||
|
except getopt.GetoptError:
|
||||||
|
usage()
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
for opt,value in opts:
|
||||||
|
if opt in ("-h","--help"):
|
||||||
|
usage()
|
||||||
|
if opt in ("-l"):
|
||||||
|
list_applications()
|
||||||
|
if opt in ("-b"):
|
||||||
|
if not find_target_app(1, value):
|
||||||
|
print "can not find target app '%s'" % value
|
||||||
|
else:
|
||||||
|
dump_by_bundleid(value)
|
||||||
|
|
||||||
|
if len(opts) == 0 and len(sys.argv) == 2:
|
||||||
|
name = sys.argv[1].decode('utf8');
|
||||||
|
if not find_target_app(0, name):
|
||||||
|
print "can not find target app '%s'" % name
|
||||||
|
else:
|
||||||
|
dump_by_display_name(name)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) < 2:
|
|
||||||
print "usage: ./dump.py 微信"
|
|
||||||
sys.exit(0)
|
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
main(sys.argv[1])
|
check_args()
|
||||||
|
pass
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
if session:
|
if session:
|
||||||
session.detach()
|
session.detach()
|
||||||
|
|
Loading…
Reference in New Issue