2021-08-01 16:19:56 -04:00
# mtkclient
2021-08-01 16:49:35 -04:00
Just some mtk tool for exploitation, reading/writing flash and doing crazy stuff. For linux, a patched kernel is only needed for kamakiri (see Setup folder) (except for read/write flash).
2021-08-04 16:40:41 -04:00
For windows, you need to install the stock mtk port and the usbdk driver (see instructions below).
2021-08-01 16:25:44 -04:00
Once the mtk script is running, boot into brom mode by powering off device, press and hold either
vol up + power or vol down + power and connect the phone. Once detected by the tool,
release the buttons.
2021-08-02 10:17:59 -04:00
## Credits
2021-08-02 10:19:02 -04:00
- kamakiri [xyzz]
2021-08-03 04:35:21 -04:00
- linecode exploit [chimera]
2021-08-02 10:19:02 -04:00
- Chaosmaster
- All contributors
2021-08-02 10:00:57 -04:00
2021-08-01 16:25:44 -04:00
## Installation
2021-08-05 07:42:20 -04:00
### Use Re LiveDVD (everything ready to go, based on Ubuntu):
[Download Re Live DVD V2 ](https://drive.google.com/file/d/1VUK0toC6I0jhJ4ZTFPREhSXFTkSe9_gl/view?usp=sharing )
2021-08-01 16:25:44 -04:00
User: livedvd, Password:livedvd
## Install
2021-08-04 16:59:53 -04:00
### Linux - (Ubuntu recommended, no patched kernel needed except for kamakiri)
2021-08-01 16:25:44 -04:00
#### Install python >=3.8, git and other deps
```
sudo apt install python3 git libusb1.0
```
#### Grab files
```
git clone https://github.com/bkerler/mtkclient
cd mtkclient
pip3 install -r requirements.txt
python3 setup.py build
python3 setup.py install
```
#### Install rules
```
2021-08-04 17:05:49 -04:00
sudo usermod -a -G plugdev $USER
sudo usermod -a -G dialout $USER
2021-08-01 16:25:44 -04:00
sudo cp Setup/Linux/*.rules /etc/udev/rules.d
sudo udevadm control -R
```
2021-08-04 16:59:15 -04:00
Make sure to reboot after adding the user to dialout/plugdev.
2021-08-01 16:25:44 -04:00
2021-08-04 17:03:25 -04:00
---------------------------------------------------------------------------------------------------------------
2021-08-04 16:59:15 -04:00
### Windows
#### Install python + git
- Install python 3.9 and git
- If you install python from microsoft store, "python setup.py install" will fail, but that step isn't required.
- WIN+R ```cmd```
#### Grab files and install
```
git clone https://github.com/bkerler/mtkclient
cd mtkclient
pip3 install -r requirements.txt
```
#### Get latest UsbDk 64-Bit
- Install normal MTK Serial Port driver (or use default Windows COM Port one, make sure no exclamation is seen)
- Get usbdk installer (.msi) from [here ](https://github.com/daynix/UsbDk/releases/ ) and install it
- Test on device connect using "UsbDkController -n" if you see a device with 0x0E8D 0x0003
- Works fine under Windows 10 and 11 :D
2021-08-04 17:03:25 -04:00
---------------------------------------------------------------------------------------------------------------
### Use kamakiri (optional, only needed for mt6260 or older)
2021-08-01 16:25:44 -04:00
- For linux (kamakiri attack), you need to recompile your linux kernel using this kernel patch :
```
sudo apt-get install build-essential libncurses-dev bison flex libssl-dev libelf-dev libdw-dev
git clone https://git.kernel.org/pub/scm/devel/pahole/pahole.git
cd pahole & & mkdir build & & cd build & & cmake .. & & make & & sudo make install
sudo mv /usr/local/libdwarves* /usr/local/lib/ & & sudo ldconfig
```
```
wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-`uname -r`.tar.xz
tar xvf linux-`uname -r`.tar.xz
cd linux-`uname -r`
patch -p1 < .. / Setup / kernelpatches / disable-usb-checks-5 . 10 . patch
cp -v /boot/config-$(uname -r) .config
make menuconfig
make
sudo make modules_install
sudo make install
```
- These aren't needed for current ubuntu (as make install will do, just for reference):
```
sudo update-initramfs -c -k `uname -r`
sudo update-grub
```
See Setup/kernels for ready-to-use kernel setups
- Reboot
```
sudo reboot
```
2021-08-04 17:03:25 -04:00
---------------------------------------------------------------------------------------------------------------
2021-08-01 16:25:44 -04:00
## Usage
2021-08-05 02:36:23 -04:00
### Read flash
Dump boot partition to filename boot.bin via preloader
```
python mtk r boot boot.bin
```
Dump boot partition to filename boot.bin via bootrom
```
python mtk r boot boot.bin [--preloader=Loader/Preloader/your_device_preloader.bin]
```
Read full flash to filename flash.bin (use --preloader for brom)
```
python mtk rf flash.bin
```
Dump all partitions to directory "out". (use --preloader for brom)
```
python mtk rl out
```
Show gpt (use --preloader for brom)
```
python mtk printgpt
```
### Write flash
(use --preloader for brom)
Write filename boot.bin to boot partition
```
python mtk w boot boot.bin
```
Write filename flash.bin as full flash (currently only works in da mode)
```
python mtk wf flash.bin
```
Write all files in directory "out" to the flash partitions
```
python mtk wl out
```
### Erase flash
Erase boot partition (use --preloader for brom)
```
python mtk e boot
```
2021-09-03 04:49:12 -04:00
### Leave flash mode and reboot
```
python mtk reset
```
2021-08-05 02:36:23 -04:00
---------------------------------------------------------------------------------------------------------------
2021-08-01 16:25:44 -04:00
### Bypass SLA, DAA and SBC (using generic_patcher_payload)
``
2021-08-05 02:36:23 -04:00
python mtk payload
2021-08-01 16:25:44 -04:00
``
If you want to use SP Flash tool afterwards, make sure you select "UART" in the settings, not "USB".
2021-08-05 02:36:23 -04:00
### Dump preloader
- Device has to be in bootrom mode and preloader has to be intact on the device
```
python mtk dumppreloader [--ptype=["amonet","kamakiri","kamakiri2","hashimoto"]] [--filename=preloader.bin]
```
2021-08-01 16:25:44 -04:00
### Dump brom
- Device has to be in bootrom mode, or da mode has to be crashed to enter damode
- if no option is given, either kamakiri or da will be used (da for insecure targets)
- if "kamakiri" is used as an option, kamakiri is enforced
- Valid options are : "kamakiri" (via usb_ctrl_handler attack), "amonet" (via gcpu)
and "hashimoto" (via cqdma)
```
2021-08-05 02:36:23 -04:00
python mtk dumpbrom --ptype=["amonet","kamakiri","hashimoto"] [--filename=brom.bin]
2021-08-01 16:25:44 -04:00
```
2021-08-04 16:59:15 -04:00
For to dump unknown bootroms, use brute option :
```
2021-08-05 02:36:23 -04:00
python mtk brute
2021-08-04 16:59:15 -04:00
```
If it's successful, please add an issue over here and append the bootrom in order to add full support.
2021-08-05 02:36:23 -04:00
---------------------------------------------------------------------------------------------------------------
2021-08-04 16:59:15 -04:00
2021-08-05 02:36:23 -04:00
### Crash da in order to enter brom
2021-08-01 16:25:44 -04:00
```
2021-08-05 02:36:23 -04:00
python mtk crash [--vid=vid] [--pid=pid] [--interface=interface]
2021-08-01 16:25:44 -04:00
```
### Read memory using patched preloader
- Boot in Brom or crash to Brom
```
2021-08-05 02:36:23 -04:00
python mtk peek [addr] [length] --preloader=patched_preloader.bin
2021-08-01 16:25:44 -04:00
```
### Run custom payload
```
2021-08-05 02:36:23 -04:00
python mtk payload --payload=payload.bin [--var1=var1] [--wdt=wdt] [--uartaddr=addr] [--da_addr=addr] [--brom_addr=addr]
2021-08-01 16:25:44 -04:00
```
2021-08-05 02:36:23 -04:00
---------------------------------------------------------------------------------------------------------------
## Stage2 usage
### Run python mtk stage (brom) or mtk plstage (preloader)
#### Run stage2 in bootrom
2021-08-01 16:25:44 -04:00
``
2021-08-05 02:36:23 -04:00
python mtk stage
2021-08-01 16:25:44 -04:00
``
2021-08-05 02:36:23 -04:00
#### Run stage2 in preloader
2021-08-01 16:25:44 -04:00
``
2021-08-05 02:36:23 -04:00
python mtk plstage
2021-08-01 16:25:44 -04:00
``
2021-08-05 02:36:23 -04:00
#### Run stage2 plstage in bootrom
- Boot in Brom or crash to Brom
```
python mtk plstage --preloader=preloader.bin
```
### Use stage2 tool
2021-08-02 06:46:18 -04:00
### Leave stage2 and reboot
``
2021-08-05 02:36:23 -04:00
python stage2 reboot
2021-08-02 06:46:18 -04:00
``
2021-08-01 16:25:44 -04:00
### Read rpmb in stage2 mode
``
2021-08-05 02:36:23 -04:00
python stage2 rpmb
2021-08-01 16:25:44 -04:00
``
### Read preloader in stage2 mode
``
2021-08-05 02:36:23 -04:00
python stage2 preloader
2021-08-01 16:25:44 -04:00
``
### Read memory as hex data in stage2 mode
``
2021-08-05 02:36:23 -04:00
python stage2 memread [start addr] [length]
2021-09-03 04:49:12 -04:00
python stage2 memread 0x140000 0x10
python stage2 memread 0x140000 16
2021-08-01 16:25:44 -04:00
``
### Read memory to file in stage2 mode
``
2021-08-05 02:36:23 -04:00
python stage2 memread [start addr] [length] --filename filename.bin
2021-08-01 16:25:44 -04:00
``
2021-09-03 04:49:12 -04:00
### Write data to memory in stage2 mode
2021-08-01 16:25:44 -04:00
``
2021-09-03 04:49:12 -04:00
python stage2 memwrite [start addr] [data as hexstring or hex int or filename]
python stage2 memwrite 0x140000 112233445566778899
python stage2 memwrite 0x140000 0x12345678
python stage2 memwrite 0x140000 data.bin
2021-08-02 06:46:18 -04:00
``
### Extract keys
``
2021-09-03 04:49:12 -04:00
python stage2 keys
2021-08-01 16:25:44 -04:00
``
2021-08-02 06:46:18 -04:00
For dxcc, you need to use plstage instead of stage
2021-08-01 16:25:44 -04:00
2021-08-04 17:03:25 -04:00
---------------------------------------------------------------------------------------------------------------
2021-08-05 02:36:23 -04:00
2021-08-04 17:03:25 -04:00
## Compile payloads (optional)
### Install gcc armeabi compiler
```
sudo apt-get install gcc-arm-none-eabi
```
### Compile
See src/readme.build for detailed instructions.
```
cd src
make
```
---------------------------------------------------------------------------------------------------------------
### I have issues ....... please send logs and full console details !
2021-08-01 16:25:44 -04:00
- Run the mtk tool with --debugmode. Log will be written to log.txt (hopefully)
## Rules / Infos
### Chip details / configs
- Go to config/brom_config.py
- Unknown usb vid/pids for autodetection go to config/usb_ids.py