Skip to content

A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol

add mouse jiggle and keyboard bridge for bt

Geofd9339d6dccf
diff --git a/src/Controllers/BluetoothController.cpp b/src/Controllers/BluetoothController.cpp
index 343a6623..3fc31f51 100644
--- a/src/Controllers/BluetoothController.cpp
+++ b/src/Controllers/BluetoothController.cpp
@@ -6,12 +6,16 @@ Constructor
BluetoothController::BluetoothController(
ITerminalView& terminalView,
IInput& terminalInput,
+ IInput& deviceInput,
BluetoothService& bluetoothService,
- ArgTransformer& argTransformer
+ ArgTransformer& argTransformer,
+ UserInputManager& userInputManager
) : terminalView(terminalView),
terminalInput(terminalInput),
+ deviceInput(deviceInput),
bluetoothService(bluetoothService),
- argTransformer(argTransformer) {}
+ argTransformer(argTransformer),
+ userInputManager(userInputManager) {}
/*
Entry point for BT command
@@ -158,16 +162,56 @@ void BluetoothController::handleKeyboard(const TerminalCommand& cmd) {
return;
}
- auto text = cmd.getSubcommand();
- if (text.empty()) {
- terminalView.println("Usage: keyboard <text>");
+ auto sub = cmd.getSubcommand();
+ if (sub.empty() || sub == "bridge") {
+ handleKeyboardBridge();
return;
}
- bluetoothService.sendKeyboardText(text);
+ // if spaces in text, use cmd.getArgs()
+ auto full = cmd.getArgs().empty() ?
+ cmd.getSubcommand() :
+ cmd.getSubcommand() + " " + cmd.getArgs();
+
+ bluetoothService.sendKeyboardText(full);
terminalView.println("Bluetooth Keyboard: String sent.");
}
+/*
+Keyboard Bridge
+*/
+void BluetoothController::handleKeyboardBridge() {
+ terminalView.println("Bluetooth Keyboard Bridge: Sending all keys to BLE HID.");
+
+ terminalView.println("\n[WARNING] If the BLE device is plugged on the same host as");
+ terminalView.println(" the terminal, it may cause looping issues with ENTER.");
+ terminalView.println(" (That makes no sense to bridge your keyboard on the same host)\n");
+
+ const bool sameHost = userInputManager.readYesNo("Are you connected on the same host? (y/n)", true);
+ if (sameHost) {
+ terminalView.println("Same host, ENTER key will not be sent to BLE HID.");
+ }
+
+ terminalView.println("Bluetooth Keyboard: Bridge started.. Press [ANY ESP32 BUTTON] to stop.");
+
+ while (true) {
+ // Stop if any esp32 button pressed
+ char k = deviceInput.readChar();
+ if (k != KEY_NONE) {
+ terminalView.println("\r\nBluetooth Keyboard Bridge: Stopped by user.");
+ break;
+ }
+
+ // Relay terminal -> BLE HID
+ char c = terminalInput.readChar();
+ if (c != KEY_NONE) {
+ if (c == '\n' && sameHost) continue;
+ bluetoothService.sendKeyboardText(std::string(1, c));
+ delay(20);
+ }
+ }
+}
+
/*
Mouse
*/
@@ -184,6 +228,12 @@ void BluetoothController::handleMouse(const TerminalCommand& cmd) {
return;
}
+ // mouse jiggle
+ if (cmd.getSubcommand() == "jiggle") {
+ handleMouseJiggle(cmd);
+ return;
+ }
+
auto args = argTransformer.splitArgs(cmd.getArgs());
// mouse move x y
@@ -214,6 +264,45 @@ void BluetoothController::handleMouse(const TerminalCommand& cmd) {
terminalView.println("Bluetooth Mouse: Moved by (" + std::to_string(x) + ", " + std::to_string(y) + ")");
}
+/*
+Mouse Jiggle
+*/
+void BluetoothController::handleMouseJiggle(const TerminalCommand& cmd) {
+ int intervalMs = 1000; // default
+
+ // Optional interval arg
+ const std::string& arg = cmd.getArgs();
+ if (!arg.empty() && argTransformer.isValidNumber(arg)) {
+ intervalMs = argTransformer.parseHexOrDec32(arg);
+ }
+
+ terminalView.println(
+ "Bluetooth Mouse: Jiggle started (" + std::to_string(intervalMs) +
+ " ms)... Press [ENTER] to stop."
+ );
+
+ while (true) {
+ // Random move
+ int8_t dx = (int8_t)random(-127, 127);
+ int8_t dy = (int8_t)random(-127, 127);
+ if (dx == 0 && dy == 0) dx = 1;
+
+ bluetoothService.mouseMove(dx, dy);
+ delay(30);
+
+ // Wait for interval while listening for ENTER
+ unsigned long t0 = millis();
+ while ((millis() - t0) < (unsigned long)intervalMs) {
+ int c = terminalInput.readChar();
+ if (c == '\r' || c == '\n') {
+ terminalView.println("Bluetooth Mouse: Jiggle stopped.\n");
+ return;
+ }
+ delay(10);
+ }
+ }
+}
+
/*
Spoof
*/
@@ -265,9 +354,11 @@ void BluetoothController::handleHelp() {
terminalView.println(" sniff");
terminalView.println(" status");
terminalView.println(" server");
+ terminalView.println(" keyboard");
terminalView.println(" keyboard <text>");
terminalView.println(" mouse <x> <y>");
terminalView.println(" mouse click");
+ terminalView.println(" mouse jiggle [ms]");
terminalView.println(" reset");
}
diff --git a/src/Controllers/BluetoothController.h b/src/Controllers/BluetoothController.h
index 02baff95..c285e000 100644
--- a/src/Controllers/BluetoothController.h
+++ b/src/Controllers/BluetoothController.h
@@ -6,14 +6,17 @@
#include "Services/BluetoothService.h"
#include "Transformers/ArgTransformer.h"
#include "Models/TerminalCommand.h"
+#include "Managers/UserInputManager.h"
class BluetoothController {
public:
BluetoothController(
ITerminalView& terminalView,
IInput& terminalInput,
+ IInput& deviceInput,
BluetoothService& bluetoothService,
- ArgTransformer& argTransformer
+ ArgTransformer& argTransformer,
+ UserInputManager& userInputManager
);
// Entry point for BT command
@@ -25,8 +28,10 @@ public:
private:
ITerminalView& terminalView;
IInput& terminalInput;
+ IInput& deviceInput;
BluetoothService& bluetoothService;
ArgTransformer& argTransformer;
+ UserInputManager& userInputManager;
bool configured = false;
// Scan for BT devices
@@ -47,9 +52,15 @@ private:
// Handle KB action
void handleKeyboard(const TerminalCommand& cmd);
+ // Handle keyboard bridge
+ void handleKeyboardBridge();
+
// Handle mouse action
void handleMouse(const TerminalCommand& cmd);
+ // Handle mouse jiggle until enter is pressed
+ void handleMouseJiggle(const TerminalCommand& cmd);
+
// Sniff BT server I/O
void handleSniff(const TerminalCommand& cmd);