Example #1
0
# Nexus 6P Launch_RAM fix: overwrite an unused HCI handler
# Here it is not called within the handler table but within another function.
patch = asm("b 0x%x" % ASM_LOCATION_RNG, vma=0x59042)
if not internalblue.patchRom(0x59042, patch):
    internalblue.logger.critical("Could not implement our launch RAM fix!")
    exit(-1)

# Disable original RNG
patch = asm("bx lr; bx lr", vma=FUN_RNG)  # 2 times bx lr is 4 bytes and we can only patch 4 bytes
if not internalblue.patchRom(FUN_RNG, patch):
    internalblue.logger.critical("Could not disable original RNG!")
    exit(-1)

internalblue.logger.info("Installed all RNG hooks.")
adb.process(["su", "-c", "svc wifi disable"])
internalblue.logger.info("Disabled Wi-Fi core.")


"""
We cannot call HCI Read_RAM from this callback as it requires another callback (something goes wrong here),
so we cannot solve this recursively but need some global status variable. Still, polling this is way faster
than polling a status register in the Bluetooth firmware itself.
"""
# global status
internalblue.rnd_done = False
def rngStatusCallback(record):
    hcipkt = record[0]  # get HCI Event packet

    if not issubclass(hcipkt.__class__, hci.HCI_Event):
        return
Example #2
0
    def _setupSerialSu(self):
        """
        To run on any rooted device, we can also use some shellscripting.
        This is slower but at least works on any device.
        Commands on a S10e with Samsung Stock ROM + Magisk + busybox:

             tail -f -n +0 /data/log/bt/btsnoop_hci.log | nc -l -p 8872

             nc -l -p 8873 >/sdcard/internalblue_input.bin
             tail -f /sdcard/internalblue_input.bin >>/dev/ttySAC1

        Locations of the Bluetooth serial interface and btsnoop log file might differ.
        The second part *could* be combined, but it somehow does not work (SELinux?).

        The ADB Python bindings will kill the processes automatically :)

        """

        # In sending direction, the format is different.
        self.serial = True

        saved_loglevel = context.log_level
        context.log_level = "warn"

        try:
            # check dependencies
            if adb.which("su") is None:
                log.critical("su not found, rooted smartphone required!")
                return False

            if adb.process(["su", "-c", "which", "nc"]).recvall() == "":
                log.critical("nc not found, install busybox!")
                return False

            # automatically detect the proper serial device with lsof
            logfile = (adb.process([
                "su", "-c",
                "lsof | grep btsnoop_hci.log | tail -1 | awk '{print $NF}'"
            ]).recvall().strip().decode("utf-8"))
            log.info("Android btsnoop logfile %s...", logfile)
            interface = (adb.process([
                "su", "-c",
                "lsof | grep bluetooth | grep tty | awk '{print $NF}'"
            ]).recvall().strip().decode("utf-8"))
            log.info("Android Bluetooth interface %s...", interface)

            if logfile == "":
                log.critical(
                    "Could not find Bluetooth logfile. Enable Bluetooth snoop logging."
                )
                return False

            if interface == "":
                log.critical(
                    "Could not find Bluetooth interface. Enable Bluetooth.")
                return False

            # spawn processes
            adb.process(
                ["su", "-c",
                 "tail -f -n +0 %s | netcat -l -p 8872" % logfile])
            adb.process([
                "su", "-c", "netcat -l -p 8873 >/sdcard/internalblue_input.bin"
            ])
            adb.process([
                "su", "-c",
                "tail -f /sdcard/internalblue_input.bin >>%s" % interface
            ])
            sleep(2)

        except PwnlibException as e:
            log.warn("Serial scripting setup failed: " + str(e))
            return False
        finally:
            context.log_level = saved_loglevel

        return True