1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# Introduction
The s-boot-usb-exploit project is heavily based on the "Samsung GT-I9300 eMMC
toolbox" project from which it borrows most of the code.
The Samsung GT-I9300 eMMC toolbox project which is a collection of tools
used to revive and experiment with Samsung GT-I9300 eMMC chips (VTU00M).
It contains an exploit for the stock bootloader (s-boot 4.0) of the
Samsung Galaxy SIII (GT-I9300). The exploit is used to load code inside s-boot.
This exploit and the associated shellcode can be reused for other use cases.
# Use cases
## Testing upstream linux-libre with s-boot 4.0
The s-boot 4.0 bootloader is incompatible with upstream Linux[1], so
in theory it might be possible to use the s-boot exploit to clear the
MMU and data cache before loading Linux somehow. But so far nobody
wrote code to do that.
[1] https://redmine.replicant.us/projects/replicant/wiki/BootloadersIncompatibleWithLinux
## Backups
Load linux-libre kernel directly in s-boot and jumping to it would also enable
to do complete backup of the stock OS without any need to disassemble the device
or use nonfree u-boot versions.
Generally speaking, running the stock OS is a really bad idea as it's full of
nonfree software. In addition there is no incentive to store and restore the
stock OS for warranties purposes as the devices are already out of warranties
from Samsung, and second hand vendors probably don't care about the OS that
runs on the device.
However there are still valid use cases for doing a full backup: Running the
stock OS can help understand certain things related to the modem like the fact
that there is an AT interpreter on the device UART, or how to switch the USB
port to the modem CDC interface in order to add support for tools like xgoldmon
in Replicant.
## Instructions
### Reviving a dead Samsung Galaxy S3 (GT-I9300)
Prerequesities (for Debian stretch, should work on other apt-based distributions as well):
```shell
$ sudo apt install python3 python3-libusb1 libusb-1.0-0 gcc-arm-none-eabi binutils-arm-none-eabi
$ make -C shellcode
```
### Booting into download mode
If your device can boot into download mode normally, you have some version of sboot installed on your device. The shellcode should theoretically work on any sboot version, but it is only guaranteed to work on sboot XXELLA. If it doesn't work, it might need some adaptations for your sboot version; be advised that some reverse engineering skill is required. If you don't know which sboot version you have, [dump sboot from your eMMC](#dumping-sboot).
If your device cannot boot into download mode (i.e. it's entirely dead - you see nothing), you first need a charged battery. Then, proceed to [prepare a recovery SD card with sboot XXELLA](#preparing-a-recovery-sd-card-with-sboot-xxella). Once it's ready, just insert the SD card to your device, insert the battery, press power+volume down+home buttons for approx. 2-3 seconds, release all of them and press the volume up button once. Plug in the device over USB to your computer and it should be visible under `lsusb`. You might see some funky stuff on the phone's screen -- just ignore it.
### Dumping sboot
In case you ever need to obtain sboot from your device (in case eMMC's boot partition is still intact), you can use `exploit/sboot_exploit.py --dump -o SBOOT`, and the exploit will dump sboot to a file named `SBOOT`. It actually dumps a 1MB chunk starting at address 0x43e00000, so the binary's loading address is 0x43e00000.
### Exploit
The `exploit/` folder contains the sboot exploit in order to run code in the sboot environment.
* sboot_exploit.py: sboot exploit using PIT file packets vulnerabilities; should work on all GT-I9300 sboot versions
* odin.py: Quick and dirty approach for implementing Odin's protocol in Python
## Shellcodes
The `shellcode/` folder contains a collection of sboot shellcodes for interaction with the eMMC.
* shellcode.h: Addresses for linking against sboot.
* common.c, common.h: Common functions for shellcode operation.
* helloworld.c: Prints a "Hello, world!" message on sboot's screen.
In addition, the "Samsung GT-I9300 eMMC toolbox project" had specific shellcodes
that were left for reference purposes. The source code can be used as an example
to write new shellcodes. Since they deal with eMMC recovery, it's better not to
run them as most of them will destroy all the data on the eMMC, including the
bad block table and block usage statistics.
* write_fw.c: Writes a new firmware to the eMMC.
* dump_fw.c Dumps the firmware from a working (non-brick) eMMC.
* dump_fw_bootrom.c: Dumps the firmware from any eMMC (even bricked ones).
* change_boot_partition_size.c: Resizes the eMMC boot partition using its own mechanism.
* demo.c: Extremely dangerous shellcode for eMMC talk.
|