Beispiel #1
0
def finish(exit_code):
   if output_file:
      output_file.close()
   devices = android_get_devices()
   for device in devices:
      baselog('[{0}] Closing frida-server...'.format(device))
      android_close_frida_server(device)
   sys.stdin.close()
   sys.exit(exit_code)
Beispiel #2
0
def android_get_frida_server_by_cpu(device):
	cmd = ['adb', '-s', device, 'shell', 'cat', '/proc/cpuinfo']
	output = _exec_command(cmd)
	frida_server = None
	if 'ARMv7' in output:
		baselog('[{0}] frida-server for 32bit selected'.format(device))
		frida_server = CODE_DIR + '/frida-server/' + 'frida-server-' + FRIDA_SERVER_VERSION + '-android-arm'
	elif 'ARMv8' in output or 'AArch64' in output:
		baselog('[{0}] frida-server for 64bit selected'.format(device))
		frida_server = CODE_DIR + '/frida-server/' + 'frida-server-' + FRIDA_SERVER_VERSION + '-android-arm64'
	return frida_server
Beispiel #3
0
def message_callback(message, data):
   if output_file:
      write_to_file = True
   else:
      write_to_file = False
   msg_to_write = None
   if 'payload' in message:
      if 'msg' in message['payload']:
         msg = message['payload']['msg']
         msg_to_write = baselog(msg, write_to_file, is_quiet)
      elif 'command' in message['payload']:
         cmd = message['payload']['command']
         params = message['payload']['params']
         if 'finish' in cmd:
            if params and len(params) > 0:
               exit_code = params[0]
               finish(exit_code)
      else:
         source = 'No Source'
         args = 'No Args'
         result = 'No Result'
         if 'source' in message['payload']:
            source = message['payload']['source']
         if 'args' in message['payload']:
            args = message['payload']['args']
         if 'result' in message['payload']:
            result = message['payload']['result']
         msg_to_write = log(source, args, result, write_to_file, is_quiet)
   if output_file:
      if msg_to_write:
         output_file.write(msg_to_write + '\n')
Beispiel #4
0
def android_install_frida(device):
	baselog('[{0}] Finding the relevant frida-server...'.format(device))
	frida_server = android_get_frida_server_by_cpu(device)
	baselog('[{0}] Pushing frida-server...'.format(device))
	cmd = ['adb', '-s', device, 'push', frida_server, '/data/local/tmp/frida-server']
	output = _exec_command(cmd)
	if output and '1 file pushed' in output:
		frida_server_file = '/data/local/tmp/frida-server'
		baselog('[{0}] Setting chmod +x for frida-server...'.format(device))
		cmd = ['adb', '-s', device, 'shell', 'chmod', '+x', FRIDA_SERVER_PATH]
		_exec_command(cmd)
		return True
	return False
Beispiel #5
0
def setup():
	# Check if frida-tools exists, and if not install
	try:
		import frida
		return True
	except ImportError:
		baselog('Frida is not installed, so installing...')
		if(install_frida_tools()):
			baselog('Frida installed successfully!')
			return True
		else:
			baselog('Failed to install frida, exiting!')
			exit(2)
	return False
Beispiel #6
0
def android_setup_frida_server(device):
	frida_installed = False
	frida_running = False
	if not android_is_device_rooted(device):
		baselog("[{0}] Can't install frida-server, device not rooted!".format(device))
	else:
		baselog('[{0}] Device is rooted...'.format(device))
		if android_is_frida_running(device):
			baselog('[{0}] frida-server is running!'.format(device))
			frida_installed = True
			frida_running = True
		elif android_is_frida_installed(device):
			baselog('[{0}] frida-server is installed!'.format(device))
			frida_installed = True
			
		if not frida_installed:
			frida_installed = android_install_frida(device)
			if frida_installed:
				baselog('[{0}] frida-server is installed!'.format(device))
		if frida_installed and not frida_running:
			frida_running = android_run_frida(device)
			if frida_running:
				baselog('[{0}] frida-server is running!'.format(device))	
	return frida_installed and frida_running
Beispiel #7
0
def android_run_frida(device):
	baselog('[{0}] Starting frida-server...'.format(device))
	cmd = ['adb', '-s', device, 'shell', '.' + FRIDA_SERVER_PATH, '&']
	_exec_command_timed(cmd, timeout=10)
	return android_is_frida_running(device)
Beispiel #8
0
def android_close_frida_server(device):
	cmd = ['adb', '-s', device, 'shell', 'killall', '-s', '9', 'frida-server']
	output = _exec_command(cmd)
	print output
	baselog('[{0}] frida-server killed!'.format(device))
Beispiel #9
0
         result = 'No Result'
         if 'source' in message['payload']:
            source = message['payload']['source']
         if 'args' in message['payload']:
            args = message['payload']['args']
         if 'result' in message['payload']:
            result = message['payload']['result']
         msg_to_write = log(source, args, result, write_to_file, is_quiet)
   if output_file:
      if msg_to_write:
         output_file.write(msg_to_write + '\n')

app = sys.argv[1] # <package>

# Make sure everything is installed
baselog('Making sure everything is installed...')
if setup():
   import frida

   try:
      baselog('Getting connected devices...')
      devices = frida.get_device_manager().enumerate_devices()
      if devices and len(devices) > 0:
         for device in devices:
            if device.type == 'usb':
               is_device_prepared = android_setup_frida_server(device.id)
               if not is_device_prepared:
                  baselog('No devices to work with!')
                  finish(2)
               pid = None
               try: