コード例 #1
0
ファイル: core.py プロジェクト: CrackerCat/vscode-frida
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()
コード例 #2
0
def installed(device: frida.core.Device):
    try:
        pid = device.spawn('/usr/bin/debugserver')
    except frida.ExecutableNotFoundError:
        return False

    device.kill(pid)
    return True
コード例 #3
0
def apps(device: frida.core.Device) -> list:
    props = ['identifier', 'name', 'pid']

    def fmt(app):
        return '%s-%s' % (device.id, app.pid or app.identifier)

    wrap = info_wrap(props, fmt)
    try:
        apps = device.enumerate_applications(scope='full')
    except TypeError:
        raise RuntimeError(
            'Your frida python package is out of date. Please upgrade it')
    except frida.TransportError:
        apps = device.enumerate_applications()
    return [wrap(app) for app in apps]
コード例 #4
0
def ps(device: frida.core.Device) -> list:
    props = ['name', 'pid']

    def fmt(p):
        return '%s-%s' % (device.id, p.name or p.pid)

    wrap = info_wrap(props, fmt)

    try:
        ps = device.enumerate_processes(scope='full')
    except TypeError:
        raise RuntimeError(
            'Your frida python package is out of date. Please upgrade it')
    except frida.TransportError:
        ps = device.enumerate_processes()
    return [wrap(p) for p in ps]
コード例 #5
0
ファイル: core.py プロジェクト: sumerzhang/vscode-frida
def ps(device: frida.core.Device) -> list:
    props = ['name', 'pid']

    def wrap(p):
        obj = {prop: getattr(p, prop) for prop in props}
        obj['largeIcon'] = png.to_uri(p.get_large_icon())
        obj['smallIcon'] = png.to_uri(p.get_small_icon())
        return obj

    return [wrap(p) for p in device.enumerate_processes()]
コード例 #6
0
ファイル: core.py プロジェクト: sumerzhang/vscode-frida
def apps(device: frida.core.Device) -> list:
    props = ['identifier', 'name', 'pid']

    def wrap(app):
        obj = {prop: getattr(app, prop) for prop in props}
        obj['largeIcon'] = png.to_uri(app.get_large_icon())
        obj['smallIcon'] = png.to_uri(app.get_small_icon())
        return obj

    return [wrap(app) for app in device.enumerate_applications()]
コード例 #7
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
コード例 #8
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
コード例 #9
0
ファイル: core.py プロジェクト: sumerzhang/vscode-frida
def device_type(device: frida.core.Device) -> str:
    mapping = {
        'SpringBoard': 'iOS',
        'Dock': 'macOS',
        'explorer.exe': 'win32',
        'zygote': 'Android',
    }

    for proc in device.enumerate_processes():
        if proc.name in mapping:
            return mapping[proc.name]
    else:
        return 'Linux'
コード例 #10
0
ファイル: core.py プロジェクト: sumerzhang/vscode-frida
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