diff options
| author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2021-09-21 21:40:58 +0200 |
|---|---|---|
| committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2026-10-15 05:01:41 +0200 |
| commit | 9167ff1f242fa10ec9c43458ccc9836887eee666 (patch) | |
| tree | 5e5fd3b6f3c2f312b3791d33c19ed02bc9cfffb0 | |
| parent | df328fc2076b23cf4b21c99c14f1b9230f962821 (diff) | |
| download | s-boot_usb_exploit-main.tar.gz s-boot_usb_exploit-main.tar.bz2 s-boot_usb_exploit-main.zip | |
Add reboot shellcodemain
With this shellcode we can simply reboot normally:
$ make -C shellcode
$ exploit/sboot_exploit.py -n \
--shellcode shellcode/reboot.bin
We can also put exact same code in the recovery partition:
$ make -C shellcode
$ mkbootimg --base 0x40000000 --kernel shellcode/reboot.bin -o recovery.img
That produces a very small image that is about 6k:
$ du --bytes recovery.img
6144 recovery.img
We can then install it on the GT-I9300 with heimdall as usual:
$ heimdall flash --RECOVERY recovery.img
And when we boot on the RECOVERY partition, it will reboot again to
the normal partition.
This can be useful because if the RECOVERY partition is empty (full of
zeros) or that an initramfs is flashed there, (re)booting to recovery
ends up (re)booting directly to the bootloader. In that case it shows
the following:
[Android logo]
Downloading....
Do not rurn off target !!
and there is no other way to make it boot to the BOOT partition
other than flashing code (like a recovery) that makes it reboot
to the normal BOOT partition. Even 'heimdall close-pc-screen'
doesn't change the boot mode.
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
| -rw-r--r-- | README.md | 8 | ||||
| -rwxr-xr-x | exploit/sboot_exploit.py | 20 | ||||
| -rw-r--r-- | shellcode/Makefile | 11 | ||||
| -rw-r--r-- | shellcode/reboot.c | 28 |
4 files changed, 58 insertions, 9 deletions
@@ -87,6 +87,14 @@ The following were made for Replicant: the modem staying in low power mode when using u-boot and the nonfree BL1 that u-boot dependend on. +* reboot.c: code that reboots and boots into the BOOT partition. The + same code can also be installed in a partition with with 'mkbootimg + --base 0x40000000 --kernel shellcode/reboot.bin -o recovery.img' and + 'heimdall flash --RECOVERY recovery.img'. This is better than + leaving the recovery partition empty as if you do you can end up in + a reboot loop. This requires you to make sure that that what is + installed in the BOOT partition always work. + In addition, the "Samsung GT-I9300 eMMC toolbox project" had specific shellcodes that were left for reference purposes. diff --git a/exploit/sboot_exploit.py b/exploit/sboot_exploit.py index b1e935c..4f6001f 100755 --- a/exploit/sboot_exploit.py +++ b/exploit/sboot_exploit.py @@ -32,6 +32,7 @@ class Exploit(object): self._sboot = b'' self.inited = False + self.shellcode_communication = True def close(self): self._odin.close() @@ -176,7 +177,7 @@ class Exploit(object): self.write(data) ret = self.read_nofail(8) - if not ret: + if not ret and self.shellcode_communication: logging.warning('Cannot write buffer') return ret @@ -203,7 +204,8 @@ class Exploit(object): self.inited = True return True - def run_shellcode(self, shellcode): + def run_shellcode(self, shellcode, shellcode_communication=True): + self.shellcode_communication = shellcode_communication if not self.inited: raise RuntimeError("Exploit isn't initialized") @@ -350,7 +352,9 @@ class Exploit(object): 'use same sboot version as the shellcode?') ret = self.write_buf(b'\0'*(0x2000-0x100) + arena_memory) - if ret == b'oranav': + if not self.shellcode_communication and not ret: + break + elif ret == b'oranav': break else: raise RuntimeError( @@ -458,6 +462,9 @@ if __name__ == '__main__': help='eMMC firmware to send if shellcode requests') parser.add_argument('--output', '-o', type=argparse.FileType('wb'), help='output file (if shellcode outputs anything)') + parser.add_argument('--no-feedback', '-n', default=False, + action='store_true', + help='Do not expect feedback from the shellcode.') parser.add_argument('--verbose', '-v', default=False, action='store_true') args = parser.parse_args() @@ -478,13 +485,16 @@ if __name__ == '__main__': if args.shellcode: # Normal exploitation - run a shellcode try: - exploit.run_shellcode(args.shellcode.read()) + exploit.run_shellcode(args.shellcode.read(), not args.no_feedback) except RuntimeError as e: print('ERROR: {}'.format(str(e)), file=sys.stderr) exploit.close() sys.exit(1) - sys.exit(shellcode_handler(exploit, args)) + if args.no_feedback: + sys.exit(0) + else: + sys.exit(shellcode_handler(exploit, args)) elif args.dump: # Dump sboot from the device diff --git a/shellcode/Makefile b/shellcode/Makefile index 9810182..6a36e7c 100644 --- a/shellcode/Makefile +++ b/shellcode/Makefile @@ -1,3 +1,4 @@ +SENTINEL= CROSS_COMPILE=arm-none-eabi- CC=${CROSS_COMPILE}gcc @@ -8,13 +9,15 @@ CFLAGS += -fno-stack-protector -fno-common -fomit-frame-pointer -fPIE -static -O LDFLAGS += -nostdlib all: \ - helloworld.bin \ - demo.bin \ - write_fw.bin \ change_boot_partition_size.bin \ + demo.bin \ + dump-exynos4412-modem-gpios.bin \ dump_fw.bin \ dump_fw_bootrom.bin \ - dump-exynos4412-modem-gpios.bin \ + helloworld.bin \ + reboot.bin \ + write_fw.bin \ + $(SENTINEL) %.bin: %.elf ${OBJCOPY} -j .text -j .rodata -j .data -O binary $< $@ diff --git a/shellcode/reboot.c b/shellcode/reboot.c new file mode 100644 index 0000000..e8aaf0b --- /dev/null +++ b/shellcode/reboot.c @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2021 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include "shellcode.h" +#include "common.h" + +__asm__( +".global _start\n" +"_start:\n" +); + +int main() { + reboot(BOOT_MODE_NORMAL); +} |
