예제 #1
0
def load_background(args: list = None) -> None:
    """
        Loads a Frida script and runs it in the background.

        :param args:
        :return:
    """

    if len(clean_argument_flags(args)) <= 0:
        click.secho(
            'Usage: import <local path to frida-script> (optional name)',
            bold=True)
        return

    source = args[0]

    # support ~ syntax
    if source.startswith('~'):
        source = os.path.expanduser(source)

    if not os.path.isfile(source):
        click.secho('Unable to import file {0}'.format(source), fg='red')
        return

    # read the hook sources
    with open(source, 'r') as f:
        hook = ''.join(f.read())

    agent = state_connection.get_agent()
    agent.background(hook)
예제 #2
0
def runonce():
    """
        Run an arbitrary script in the connected frida
        enabled device.

        Responses are JSON encoded by default, but can be raw by adding
        ?json=false as a query string parameter.

        :return:
    """

    source = request.data.decode('utf-8')

    if len(source) <= 0:
        return abort(jsonify(message='Missing or empty script received'))

    try:

        # run the script
        response = state_connection.get_agent().ad_hoc(source)

        if 'json' in request.args and request.args.get(
                'json').lower() == 'false':
            return response

    except Exception as e:
        return abort(
            jsonify(message='Script failed to run: {e}'.format(e=str(e))))

    return jsonify(response)
예제 #3
0
파일: plugin.py 프로젝트: ylkcy/objection
    def inject(self) -> None:
        """
            Injects the script sources in a new Frida session.

            :return:
        """

        if not self.script_src:
            raise Exception('Unable to discover Frida script source to inject')

        if not self.agent:
            self.agent = state_connection.get_agent()

        if not self.session:
            self.session = self.agent.get_session()

        if not self.script:
            self.script = self.session.create_script(source=self.script_src)

        # check for a custom message handler, otherwise fallback
        # to the default objection handler
        self.script.on('message', self.on_message_handler if self.on_message_handler else self.agent.on_message)

        self.script.load()
        self.api = self.script.exports