From d88fe7d0587c330e38eb2cbff54821da72eb9553 Mon Sep 17 00:00:00 2001 From: Opabinia <144001335+pentestfunctions@users.noreply.github.com> Date: Wed, 17 Jan 2024 14:21:20 +1300 Subject: [PATCH] Create register_device.py --- utils/register_device.py | 226 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 utils/register_device.py diff --git a/utils/register_device.py b/utils/register_device.py new file mode 100644 index 0000000..96571ea --- /dev/null +++ b/utils/register_device.py @@ -0,0 +1,226 @@ +import dbus +import dbus.service +import dbus.mainloop.glib +from gi.repository import GLib +import logging as log + +class Agent(dbus.service.Object): + @dbus.service.method("org.bluez.Agent1", in_signature="", out_signature="") + def Cancel(self): + log.debug("Agent.Cancel") + +class Profile(dbus.service.Object): + @dbus.service.method("org.bluez.Profile1", in_signature="", out_signature="") + def Cancel(self): + print("Profile.Cancel") + +def agent_loop(target_path): + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + loop = GLib.MainLoop() + bus = dbus.SystemBus() + path = "/test/agent" + agent = Agent(bus, path) + agent.target_path = target_path + obj = bus.get_object("org.bluez", "/org/bluez") + manager = dbus.Interface(obj, "org.bluez.AgentManager1") + manager.RegisterAgent(path, "NoInputNoOutput") + manager.RequestDefaultAgent(path) + log.debug("'NoInputNoOutput' pairing-agent is running") + loop.run() + + +def register_hid_profile(iface, addr): + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + bus = dbus.SystemBus() + get_obj = lambda path, iface: dbus.Interface(bus.get_object("org.bluez", path), iface) + addr_str = addr.replace(":", "_") + path = "/org/bluez/%s/dev_%s" % (iface, addr_str) + manager = get_obj("/org/bluez", "org.bluez.ProfileManager1") + profile_path = "/test/profile" + profile = Profile(bus, profile_path) + hid_uuid = "00001124-0000-1000-8000-00805F9B34FB" + + # Hardcoded XML content + xml_content = """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +""" + + opts = {"ServiceRecord": xml_content} + log.debug("calling RegisterProfile") + manager.RegisterProfile(profile, hid_uuid, opts) + loop = GLib.MainLoop() + try: + log.debug("running dbus loop") + loop.run() + except KeyboardInterrupt: + log.debug("calling UnregisterProfile") + manager.UnregisterProfile(profile)