Example #1
0
def find_port(device: frida.core.Device) -> int:
    pid = device.spawn('/bin/sh')
    session = device.attach(pid)
    with (Path(__file__).parent.parent / 'agent' / 'socket.js').open('r', encoding='utf8') as fp:
        source = fp.read()
    script = session.create_script(source)
    script.load()
    return script.exports.find()
Example #2
0
def spawn_or_attach(device: frida.core.Device,
                    bundle: str) -> frida.core.Session:
    try:
        app = next(app for app in device.enumerate_applications()
                   if app.identifier == bundle)
    except StopIteration:
        raise ValueError('app "%s" not found' % bundle)

    if app.pid > 0:
        front = device.get_frontmost_application()
        if front and front.identifier == bundle:
            return device.attach(app.pid)

        raise RuntimeError(
            'Unable to attach to "%s"(%d) as it is a background app.' %
            (bundle, app.pid))

    devtype = device_type(device)
    if devtype == 'Android':
        module = 'libc.so'
    elif devtype == 'iOS':
        module = 'Foundation'
    else:
        raise RuntimeError('Unknown device type %s' % devtype)

    source = 'Module.ensureInitialized("%s"); rpc.exports.ok = function() { return true }' % module
    pid = device.spawn(bundle)
    session = device.attach(pid)
    device.resume(pid)
    script = session.create_script(source)
    script.load()
    MAX_RETRY = 5
    for i in range(MAX_RETRY):
        try:
            time.sleep(0.2)
            if script.exports.ok():
                break
        except:
            continue
    else:
        raise RuntimeError('Unable to create process')

    script.unload()
    return session
Example #3
0
def setup(device: frida.core.Device):
    if device_type(device) != 'iOS':
        raise ValueError('This command is for iOS only')

    if installed(device):
        return True

    with (Path(__file__).parent / 'ent.xml').open('r') as fp:
        content = fp.read()

    pid = device.spawn('/bin/sh')
    session = device.attach(pid)
    script = session.create_script(read_agent())
    script.load()
    script.exports.sign_debugserver(content)
    session.detach()
    device.kill(pid)

    return True
Example #4
0
def install(device: frida.core.Device):
    if device_type(device) != 'iOS':
        raise ValueError('This command is for iOS only')

    pubkey = Path.home() / '.ssh' / 'id_rsa.pub'
    if not (pubkey.exists() and pubkey.is_file()):
        raise RuntimeError('id_rsa.pub does not exists')

    with pubkey.open('r') as fp:
        content = fp.read().strip()

    pid = device.spawn('/bin/sh')
    session = device.attach(pid)
    script = session.create_script(read_agent())
    script.load()
    script.exports.copyid(content)
    session.detach()
    device.kill(pid)

    return True