Boots BL2 and returns to debugger. BL2 not yet patcheable.
This commit is contained in:
parent
b0c2b414ca
commit
a75bf965cc
45
documentation/source/BootROM_8890/01_start.rst
Normal file
45
documentation/source/BootROM_8890/01_start.rst
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
==========
|
||||||
|
Start/Home
|
||||||
|
==========
|
||||||
|
The Exynos 8890 BootROM is a small piece of code that runs on the Exynos SoC at boot runtime. It is responsible for initializing the hardware and loading the first stage bootloader from storage. The BootROM is stored in a read-only memory and cannot be modified.
|
||||||
|
|
||||||
|
Useful links:
|
||||||
|
- `DTSI files for exynos8890 <https://github.com/LineageOS/android_kernel_samsung_universal8890/tree/lineage-18.1/arch/arm64/boot/dts>`_
|
||||||
|
- `Frederic exynos-usbdl on Github <https://github.com/frederic/exynos-usbdl/tree/master>`_'
|
||||||
|
- `Exynos8890 usbdl-recovery images/firmwares <https://github.com/ananjaser1211/exynos8890-exynos-usbdl-recovery>`_
|
||||||
|
|
||||||
|
Be sure to use the correct firmware and firmware version for your S7 when trying this exploit/Frederic's recovery boot (otherwise the booting will likely fail after sending BL31)!
|
||||||
|
|
||||||
|
Protections
|
||||||
|
-----------
|
||||||
|
There are no stack canaries or guard pages, and no ASLR. Meaning there are almost no protections in place. There is however an SMC and a MMU. The SMC is used to communicate with the secure world, and the MMU is used to map the memory.
|
||||||
|
|
||||||
|
Rom is at address 0x0 and is unwritable (Sometimes this is writeable due to MMU caching) and is 0x20000 bytes long.
|
||||||
|
|
||||||
|
Samsung Firmware
|
||||||
|
----------------
|
||||||
|
Samsung releases firmware files for their devices. These files contain the bootloader, modem, and other firmware files. To see how the ROM works we are interested in the sboot firmware, which contains multiple stages of the bootloader.
|
||||||
|
|
||||||
|
These files can then be used to boot the device into USB recovery. To extract the sboot.bin file from a samsung firmware file:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
$ unzip -p firmware.zip 'BL_*.tar.md5' | tar -Oxf - 'sboot.bin.lz4' | lz4 -d - sboot.bin
|
||||||
|
|
||||||
|
For additional bootloaders, see: `Github exynos8890-exynos-usbdl-recovery <https://github.com/ananjaser1211/exynos8890-exynos-usbdl-recovery>`_
|
||||||
|
|
||||||
|
Memory Layout
|
||||||
|
-------------
|
||||||
|
The memory layout of the Exynos 8890 is as follows:
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<iframe src="../_static/stack_and_functions.html" width="100%" height="1000px" frameborder="0" float='center'></iframe>
|
||||||
|
|
||||||
|
Download protocol
|
||||||
|
-----------------
|
||||||
|
When the ROM is unable to boot from the internal storage, it enters ``Exynos Recovery Mode``.
|
||||||
|
|
||||||
|
In this mode the bootROM accepts data over USB. There is little functionality other than receiving data, meaning almost no additional attack surface except for the download protocol.
|
||||||
|
|
||||||
|
The Exynos BootROM uses a custom protocol to download a bootable image over USB. This image is verified and executed by the BootROM. Unauthorized images are rejected. Initial authorisation is done using the '_auth_bl1' function. Frederic has exploited a vulnerability in the download protocol to load Unauthorized images.
|
148
documentation/source/BootROM_8890/02_frederics_exploit.rst
Normal file
148
documentation/source/BootROM_8890/02_frederics_exploit.rst
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
Frederic's Exploit
|
||||||
|
==================
|
||||||
|
|
||||||
|
dldata
|
||||||
|
^^^^^^
|
||||||
|
For uploading a stage to boot, a custom protocol is used. The dldata that has to be send is the following:
|
||||||
|
|
||||||
|
.. figure:: images/dl_packet.drawio.svg
|
||||||
|
|
||||||
|
The dldata packet is used to send data to the BootROM.
|
||||||
|
|
||||||
|
The size in the packet is the total size of the packet, including header and footer.
|
||||||
|
|
||||||
|
.. info::
|
||||||
|
|
||||||
|
This protocol remains *mostly* the same for newer Exynos SoCs.
|
||||||
|
|
||||||
|
USB Stack
|
||||||
|
---------
|
||||||
|
This information is largely based on the blogpost of Frederic on reversing the `USB stack of the Exynos BootROM <https://fredericb.info/2020/06/reverse-engineer-usb-stack-of-exynos-bootrom.html#reverse-engineer-usb-stack-of-exynos-bootrom>`_. We're looking at the proprietary USB protocol used by the Exynos BootROM.
|
||||||
|
|
||||||
|
The base address of the usb controller (dwusb3) is mapped at 0x1540000, with a size of 0x10000: (can be found at: `Exynos8890 dtsi <https://github.com/LineageOS/android_kernel_samsung_universal8890/tree/lineage-18.1/arch/arm64/boot/dts>`_).
|
||||||
|
|
||||||
|
.. code-block:: dts
|
||||||
|
|
||||||
|
udc: usb@15400000 {
|
||||||
|
compatible = "samsung,exynos8890-dwusb3";
|
||||||
|
clocks = <&clock 700>, <&clock 703>, <&clock 708>, <&clock 709>;
|
||||||
|
clock-names = "aclk", "sclk", "phyclock", "pipe_pclk";
|
||||||
|
reg = <0x0 0x15400000 0x10000>;
|
||||||
|
#address-cells = <2>;
|
||||||
|
#size-cells = <1>;
|
||||||
|
ranges;
|
||||||
|
usb-pm-qos-int = <255000>;
|
||||||
|
status = "disabled";
|
||||||
|
|
||||||
|
usbdrd_dwc3: dwc3 {
|
||||||
|
compatible = "synopsys,dwc3";
|
||||||
|
reg = <0x0 0x15400000 0x10000>;
|
||||||
|
interrupts = <0 213 0>;
|
||||||
|
phys = <&usbdrd_phy0 0>, <&usbdrd_phy0 1>;
|
||||||
|
phy-names = "usb2-phy", "usb3-phy";
|
||||||
|
};
|
||||||
|
};c
|
||||||
|
|
||||||
|
This is a basic USB controller, but some functions, that are also present in the linux kernel, should be visible in the bootROM as well. Available functions could be: `linux-kernel-dwc3 <https://android.googlesource.com/kernel/msm/+/android-msm-dory-3.10-kitkat-wear/drivers/usb/dwc3/core.h>`_.
|
||||||
|
|
||||||
|
The USB host sends a USB_REQ_SET_ADDRESS, `'0x05' <https://asf.microchip.com/docs/latest/common.services.usb.class.composite.device.example.hidms_msc.saml21_xplained_pro/html/group__usb__protocol__group.html>`_, which the connected device has to acknowledge, and will then start sending data to this address. Initially, the device will send data to '0x00'.
|
||||||
|
|
||||||
|
.. code:: c
|
||||||
|
|
||||||
|
usb_reqid {
|
||||||
|
USB_REQ_GET_STATUS = 0,
|
||||||
|
USB_REQ_CLEAR_FEATURE = 1,
|
||||||
|
USB_REQ_SET_FEATURE = 3,
|
||||||
|
USB_REQ_SET_ADDRESS = 5,
|
||||||
|
USB_REQ_GET_DESCRIPTOR = 6,
|
||||||
|
USB_REQ_SET_DESCRIPTOR = 7,
|
||||||
|
USB_REQ_GET_CONFIGURATION = 8,
|
||||||
|
USB_REQ_SET_CONFIGURATION = 9,
|
||||||
|
USB_REQ_GET_INTERFACE = 10,
|
||||||
|
USB_REQ_SET_INTERFACE = 11,
|
||||||
|
USB_REQ_SYNCH_FRAME = 12
|
||||||
|
}
|
||||||
|
|
||||||
|
Ghidra shows `DWC3_DCFG & 0xfffffc00 | DWC3_DCFG & 7 | (param_1 & 0x7f) << 3;`, essentially preserves bits 0-2 and 10-31, and sets bits 3-9 to the value of param_1, which is then likely the address of the device.
|
||||||
|
|
||||||
|
.. figure:: images/ghidra_dwc3_dcfg_devaddr.png
|
||||||
|
|
||||||
|
bootrom exynos 8890 dwc3_dcfg_devaddr
|
||||||
|
|
||||||
|
Other general device descriptors are also sent from the device to the host (to describe the device), these are visible in/at 'usb_init_device_descriptor' (6098) and usb_init_descriptors (610c). Two end point addresses are visible: bEndpointAddress 0x81 and 0x02. 0x81 is 10000001 in binary, with bit 7 being '1', which means that the bulk transfer direction is IN. 0x02 is 00000010 in binary, with bit '7' being '0', which means that the bulk transfer direction is OUT.
|
||||||
|
|
||||||
|
Data is transferred via Transfer Request Blocks (TRB), dwc3_depcmd_starttransfer is used. The TRB then contains a buffer address, where transferred data from the host is written to. The buffer allocation is done by 'usb_setup_event_buffer', which sets bufferHigh (DWC3_GEVNTADRLO), bufferLow (DWC3_GEVNTADRHI) and bufferSize (DWC3_GEVNTSIZ).
|
||||||
|
|
||||||
|
Bug 1 (Integer overflow)
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
Originally described in this `blogpost <https://fredericb.info/2020/06/exynos-usbdl-unsigned-code-loader-for-exynos-bootrom.html#exynos-usbdl-unsigned-code-loader-for-exynos-bootrom>`_.
|
||||||
|
|
||||||
|
The exynos bootrom uses a simple USB protocol to receive a bootloader binary from a USB host. The binary sent is called 'dldata'. In Ghidra, at 21518, we can see that it consists of unit32_t: ready?, uint32: size, ? : data, uint16: footer. The contents of this data are checked before being being written.
|
||||||
|
|
||||||
|
.. figure:: images/usb_setup_ready_to_0.png
|
||||||
|
|
||||||
|
The ready flag is set to 0 in the Exynos 8890 BootROM in an earlier function on pdVar1->size (pdVar1.size)
|
||||||
|
|
||||||
|
.. figure:: images/dl_data_struct.png
|
||||||
|
|
||||||
|
The dldata struct in the Exynos 8890 BootROM
|
||||||
|
|
||||||
|
.. code:: c
|
||||||
|
if ((pdVar1->size < 0x206ffff) && (0x206ffff < pdVar1->size + remaining)) {
|
||||||
|
*(undefined *)&pdVar1->ready = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
In essence, the payload is not allowed to be larger than 0x206fff (34013183), it checks so with 2 seperate checks
|
||||||
|
1) In the first condition, the size has to be smaller than 0x206ffff (`pdVar1->size < 0x206ffff`) (34013183 in decimal),
|
||||||
|
2) and in the second condition, it checks whether 0x206ffff is indeed still less than the size of the payload + remaining (size + remaining)(`0x206ffff < pdVar1->size + remaining`).
|
||||||
|
|
||||||
|
If both conditions are met, the payload will NOT be loaded. But this makes sense, as both checks just ensure that the payload is not larger than 0x206ffff.
|
||||||
|
|
||||||
|
The bug is however, that the check that the check is done on a uint32_t (2^32 = 4294967296), but the max value that can be checked by a uint32 is 0xFDFDE7FF = 4294967295. So a value of 0xFDFDE7FF + 1 = 0xFDFDE800 = 4294967296, which is larger than the max value of a uint32. So if a payload of this size or more is used, which is much larger than the max requested value 0x206ffff, the check will pass and the payload will still be loaded.
|
||||||
|
|
||||||
|
.. figure:: images/usb_payload_size_check.jpeg
|
||||||
|
|
||||||
|
The size check in the Exynos 8890 BootROM
|
||||||
|
|
||||||
|
Sending such large amounts of data can cause a memory overflow, and will cause the target to crash. Not interesting for exploitation in this context. However, the USB packages that are sent, are split into smaller packages with a size of 0xFFFE00.
|
||||||
|
|
||||||
|
.. figure:: images/max_allowed_chunck_size.jpeg
|
||||||
|
|
||||||
|
The max allowed chunk size, after which the payload is split.
|
||||||
|
|
||||||
|
The dl_buf pointer is set to the amount it expects to write, instead to the amount that it has written. By transferring a large amount of data, without actually writing it (so in a package, send no data, but tell the target that you're sending data with a length larger than 0xFDFDE800), will cause the pointer to move, without actually writing data.
|
||||||
|
|
||||||
|
The trick then becomes, to get the pointer to an address we would like to exploit unto. Then we have a little less than 512 bytes (502 according to dldata) to write our payload.
|
||||||
|
|
||||||
|
.. code:: c
|
||||||
|
|
||||||
|
typedef struct dldata_s {
|
||||||
|
u_int32_t ready; //start = 02021518, end = 0202151C. Length = 4
|
||||||
|
u_int32_t size; //start = 0202151C, end = 02021520. Length = 4
|
||||||
|
u_int8_t data[n]; //start = 02021520, end = 02021714. Length = 502 == MAX TRANSFER SIZE
|
||||||
|
u_int16_t footer; //start = 02021714, end = 02021716. Length = 2
|
||||||
|
} dldata;
|
||||||
|
|
||||||
|
Bug 2
|
||||||
|
^^^^^
|
||||||
|
|
||||||
|
.. caution::
|
||||||
|
|
||||||
|
Might be a 0/N-day if exploitable
|
||||||
|
|
||||||
|
@ELHER
|
||||||
|
|
||||||
|
There is a bug(unpatched?) in receiving the last packet of the usb image:
|
||||||
|
|
||||||
|
.. figure:: images/underflow_bug.png
|
||||||
|
|
||||||
|
The bug is an integer underflow in the calculation of the remaining size of the image.
|
||||||
|
|
||||||
|
DWC3
|
||||||
|
^^^^
|
||||||
|
The Exynos 8890 uses the Synopsys DesignWare USB 3.0 controller.
|
||||||
|
Much of the code is shared with the DWC3 driver in the Linux kernel, except that the ROM does not do any scheduling and a lot of features have been removed(OTG handling, etc).
|
||||||
|
|
||||||
|
Gupje
|
||||||
|
^^^^^
|
||||||
|
In order to run the debugger, a small amount of the bootROM was reversed in order to implement send/recv functionality.
|
309
documentation/source/BootROM_8890/03_exploit_boot_chain.rst
Normal file
309
documentation/source/BootROM_8890/03_exploit_boot_chain.rst
Normal file
@ -0,0 +1,309 @@
|
|||||||
|
.. _boot-chain-label:
|
||||||
|
==================
|
||||||
|
Exploit boot chain
|
||||||
|
==================
|
||||||
|
This part describes the boot chain of the ``Exynos 8890`` SoC.
|
||||||
|
|
||||||
|
Memory overview
|
||||||
|
===============
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
|
||||||
|
<iframe src="../_static/stack_and_functions.html" width="100%" height="1000px" frameborder="0" float='center'></iframe>
|
||||||
|
|
||||||
|
|
||||||
|
Exploitation
|
||||||
|
============
|
||||||
|
|
||||||
|
After exploitation the goal is to fully boot the device. The following part describes the current boot chain
|
||||||
|
|
||||||
|
.. important::
|
||||||
|
|
||||||
|
This is under development and will still change.
|
||||||
|
|
||||||
|
The first stage is downloading BL1, authenticating it and patching it after authentication.
|
||||||
|
This is done by overwriting the USB return address pointer and jumping back to the debugger.
|
||||||
|
In the debugger we can authenticate BL1, patch it and boot it. An overview of this process is shown below:
|
||||||
|
|
||||||
|
Booting an authenticated and patched BL1:
|
||||||
|
|
||||||
|
.. figure:: images/boot_chain_bl1.drawio.svg
|
||||||
|
:align: center
|
||||||
|
|
||||||
|
Boot chain
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
git commit 8cb5f2e1 fully boots, you can use this commit to patch bl1 only.
|
||||||
|
|
||||||
|
Next up is BL31, which is loaded by BL1.
|
||||||
|
|
||||||
|
``BL31`` is the secure monitor. The monitor uses memory that is also being used by the debugger, so we will have to relocate it to keep code exeuction.
|
||||||
|
|
||||||
|
.. figure:: images/bl31_debugger_memory_example.png
|
||||||
|
:align: center
|
||||||
|
|
||||||
|
Example of BL31 using debugger memory.
|
||||||
|
|
||||||
|
BL31 also configures the VBAR_EL3 and MMU so the memory mapping will probably change after this stage (preparation for trustzone?).
|
||||||
|
|
||||||
|
It would be nice to patch BL31 before it is being executed. However the current exploit boot flow does not allow this because the ROM function downloads the next stage.
|
||||||
|
|
||||||
|
Notes
|
||||||
|
-----
|
||||||
|
As done by Frederic, the bootrom can be dumped using his provided scripts, and can the be split into different boots:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
./exynos-usbdl e payloads/Exynos8890_dump_bootrom.bin dumped_sboot.bin
|
||||||
|
scripts/split-sboot-8890.sh dumped_sboot.bin
|
||||||
|
|
||||||
|
This results in the following files:
|
||||||
|
|
||||||
|
.. list-table:: bootrom stages
|
||||||
|
:header-rows: 1
|
||||||
|
|
||||||
|
* - File
|
||||||
|
- Strings output
|
||||||
|
- Likely boot stage?
|
||||||
|
* - sboot.bin.1.bin
|
||||||
|
- Exynos BL1
|
||||||
|
- BL1
|
||||||
|
* - sboot.bin.2.bin
|
||||||
|
- BL31 %s
|
||||||
|
- BL31
|
||||||
|
* - sboot.bin.3.bin
|
||||||
|
- Unsure. Contains strings like: TOP_DIV_ACLK_MFC_600 and APOLLO_DIV_APOLLO_RUN_MONITOR
|
||||||
|
- BL2?
|
||||||
|
* - sboot.bin.4.bin
|
||||||
|
- Contains more textual information, and references to post BL2 boot, and android information
|
||||||
|
- Kernel boot/BL33?
|
||||||
|
|
||||||
|
After loading the stage1 (entry.S - Frederic's exploit), we're allowed to send custom payloads to the device. The first payload that is then sent, is the debugger.
|
||||||
|
|
||||||
|
Debugger
|
||||||
|
--------
|
||||||
|
The initial debugger is written to ``0x2069000``, with debugger_stack and _storage at ``0x0206b000`` and ``0x0206d000`` respectively.
|
||||||
|
|
||||||
|
After the initial loading of the debugger, the processor state reported is (using ghidra assistant):
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
root | DEBUG |
|
||||||
|
X0 : 0x0 | X1 : 0xffffffff | X2 : 0x20215d8 | X3 : 0x2021894 | X4 : 0x4 | X5 : 0x0 | X6 : 0x0 |
|
||||||
|
X7 : 0x136c0008 | X8 : 0x2069000 | X9 : 0x0 | X10 : 0x2070000 | X11 : 0x0 | X12 : 0x0 | X13 : 0x0 |
|
||||||
|
X14 : 0xf | X15 : 0x206d000 | X16 : 0x9 | X17 : 0x0 | X18 : 0x1 | X19 : 0x2000 | X20 : 0x2069000 |
|
||||||
|
X21 : 0x0 | X22 : 0x0 | X23 : 0x0 | X24 : 0x0 | X25 : 0x0 | X26 : 0x0 | X27 : 0x1 |
|
||||||
|
X28 : 0x0 | X29 : 0x2020f00 | LR/X30 : 0x20219b8 | SP/X31 : 0x2020ef0
|
||||||
|
|
||||||
|
LR/X30 being the line register. This is the address the processor will jump to when the function is done (important to keep track off).
|
||||||
|
|
||||||
|
After a cache flush, the debugger seems to be cleared as well, so the debugger is relocated to ``0x20c0000``, with _stack and _storage now at ``0x20c2000`` and ``0x20c4000`` respectively. This is done by running:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
self.cd.arch_dbg.state.auto_sync = False
|
||||||
|
self.cd.arch_dbg.state.auto_sync_special = False
|
||||||
|
self.cd.arch_dbg.state.print_ctx()
|
||||||
|
|
||||||
|
def relocate_debugger():
|
||||||
|
# Seems to be cleared upon cache clearing??
|
||||||
|
debugger_reloc = open("/home/eljakim/Source/gupje/source/bin/samsung_s7/reloc_debugger.bin", "rb").read()
|
||||||
|
self.cd.memwrite_region(0x020c0000, debugger_reloc)
|
||||||
|
self.usb_write(b"FLSH") # Flush cache
|
||||||
|
self.cd.restore_stack_and_jump(0x020c0000)
|
||||||
|
assert self.usb_read(0x200) == b"GiAs", "Failed to relocate debugger"
|
||||||
|
self.cd.relocate_debugger(0x020c7000, 0x020c0000, 0x020c4000)
|
||||||
|
relocate_debugger()
|
||||||
|
|
||||||
|
The processor state reported then is:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
root | DEBUG |
|
||||||
|
X0 : 0x0 | X1 : 0x1 | X2 : 0x20215d8 | X3 : 0x2021894 | X4 : 0x4 | X5 : 0x0 | X6 : 0x0 |
|
||||||
|
X7 : 0x136c0008 | X8 : 0x2069000 | X9 : 0x0 | X10 : 0x2070000 | X11 : 0x0 | X12 : 0x0 | X13 : 0x0 |
|
||||||
|
X14 : 0xf | X15 : 0x20c4000 | X16 : 0x9 | X17 : 0x0 | X18 : 0x1 | X19 : 0x2000 | X20 : 0x2069000 |
|
||||||
|
X21 : 0x0 | X22 : 0x0 | X23 : 0x0 | X24 : 0x0 | X25 : 0x0 | X26 : 0x0 | X27 : 0x1 |
|
||||||
|
X28 : 0x0 | X29 : 0x2020f00 | LR/X30 : 0x20c0000 | SP/X31 : 0x2020ef0
|
||||||
|
|
||||||
|
Initial boot function (BL1)
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
.. figure:: images/initial_boot_function.png
|
||||||
|
:align: center
|
||||||
|
|
||||||
|
Overview of the initial boot function in the exynos 8890
|
||||||
|
|
||||||
|
BL1 needs to be authenticated. BL1 loads at address ``0x02024000`` and contains some form of header (ramdump). There seems to be a samsung header format, where the first 4 bytes define the entry point of the binary. In this case this entry is ``+0x10`` so we jump to ``0x02024010``. Authentication seems to be done at ``0x00012848``. Initially we thought that 0x0 indicated a verified boot state (as is plausible when reading the decompiled code in Ghidra). But after modifying BL1 in the header and contents, this value did not change.
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# Try loading bl1
|
||||||
|
bl1 = open("../S7/bl1.bin", "rb").read()
|
||||||
|
self.cd.memwrite_region(0x02021800, bl1)
|
||||||
|
# self.usb_write(b"FLSH")
|
||||||
|
AUTH_BL1 = 0x00012848
|
||||||
|
def auth_bl1(lr=0x2069000):
|
||||||
|
# Load the firmware
|
||||||
|
self.cd.arch_dbg.state.W0 = 1
|
||||||
|
self.cd.arch_dbg.state.X1 = 1
|
||||||
|
self.cd.arch_dbg.state.LR = lr #jump back to debugger when finished
|
||||||
|
self.cd.restore_stack_and_jump(AUTH_BL1)
|
||||||
|
assert self.usb_read(0x200) == b"GiAs", "Failed to jump back to debugger"
|
||||||
|
assert self.cd.arch_dbg.state.X0 == 0, "auth_bl1 returned with error!"
|
||||||
|
|
||||||
|
auth_bl1(0x020c0000)
|
||||||
|
|
||||||
|
.. figure:: images/bl1_auth_references.png
|
||||||
|
:align: center
|
||||||
|
|
||||||
|
BL1 authentication
|
||||||
|
|
||||||
|
At this point, we assumed that the authentication was succesful, and the bootROM would jump back to the debugger after loading, but this was not the case. After running this function, we were able to send a single packet, but never received a response. Indicating that the function we were executing never returned on us.
|
||||||
|
|
||||||
|
If authentication at auth_bl1 is succesful, the returns a value from a function at ``1230c``. This function does some things, but eventually jumps to a function at:
|
||||||
|
|
||||||
|
.. figure:: images/bl1_auth_follow-up_1230c.png
|
||||||
|
:align: center
|
||||||
|
|
||||||
|
BL1 authentication
|
||||||
|
|
||||||
|
After authentication the bootROM jumps to this function at, we can execute this function with the debugger.
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
self.cd.memwrite_region(0x02020f60, p32(0x020c0000))
|
||||||
|
BOOT_BL1 = 0x00019310
|
||||||
|
def jump_bl1(lr):
|
||||||
|
self.cd.arch_dbg.state.LR = lr
|
||||||
|
self.cd.restore_stack_and_jump(BOOT_BL1)
|
||||||
|
|
||||||
|
jump_bl1(0x020c0000)
|
||||||
|
|
||||||
|
jump_fwbl1()
|
||||||
|
|
||||||
|
BL1 is loaded at the download buffer and self copies to ``0x02022000`` and resumes execution there, with a size of 0x2000 (``0x02022000`` to ``0x02024000``).
|
||||||
|
|
||||||
|
However, this does not result in a jump back to the debugger. But the ROM still allows receival of one data package from the USB host (this is likely the system 'waiting' to receive the bootloader).
|
||||||
|
|
||||||
|
By adding the IMEM to ghidra, we can have a look at what is going here. After having modified the LR to jump back to the debugger and jumping into auth_bl1 at ``0x00012848`` we jump back to the debugger. Jumping into BL1 at ``2c0`` does not return us to the debugger. Here we need to hijack ``020200dc`` and ``02021880`` we're able to boot into BL1. We store the address of the hijacked function, to restore it later for a proper boot flow.
|
||||||
|
|
||||||
|
.. code:: python
|
||||||
|
auth_bl1(DEBUGGER_ADDR)
|
||||||
|
self.usb_write(b"FLSH") # Flush cache
|
||||||
|
hijacked_fun = u32(self.cd.memdump_region(0x020200dc, 4))
|
||||||
|
|
||||||
|
# BL1 patches
|
||||||
|
self.cd.memwrite_region(0x020200dc, p32(DEBUGGER_ADDR)) # hijack ROM_DOWNLOAD_USB for BL31
|
||||||
|
self.cd.memwrite_region(0x02021880, self.cd.arch_dbg.sc.branch_absolute(DEBUGGER_ADDR, branch_ins="br"))
|
||||||
|
|
||||||
|
Authentication of BL1 seems to be done at ``0x0012848``. With return value '0' expected when this function is executed, to execute other functions.
|
||||||
|
|
||||||
|
.. figure:: images/bl1_auth_references.png
|
||||||
|
:align: center
|
||||||
|
|
||||||
|
BL1 authentication.
|
||||||
|
|
||||||
|
purpose
|
||||||
|
^^^^^^^
|
||||||
|
bl1 interacts with several pheriperals, from the DTB these are:
|
||||||
|
|
||||||
|
.. code-block:: dtsi
|
||||||
|
|
||||||
|
/* FSYS0 */
|
||||||
|
pinctrl_5: pinctrl@10E60000 {
|
||||||
|
compatible = "samsung,exynos8890-pinctrl";
|
||||||
|
reg = <0x0 0x10E60000 0x1000>;
|
||||||
|
interrupts = <0 212 0>;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* FSYS1 */
|
||||||
|
pinctrl_6: pinctrl@15690000 {
|
||||||
|
compatible = "samsung,exynos8890-pinctrl";
|
||||||
|
reg = <0x0 0x15690000 0x1000>;
|
||||||
|
interrupts = <0 202 0>;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* PERIC1 */
|
||||||
|
pinctrl_9: pinctrl@14CC0000 {
|
||||||
|
compatible = "samsung,exynos8890-pinctrl";
|
||||||
|
reg = <0x0 0x14CC0000 0x1000>;
|
||||||
|
interrupts = <0 460 0>;
|
||||||
|
};
|
||||||
|
|
||||||
|
pmu_system_controller: system-controller@105C0000 {
|
||||||
|
compatible = "samsung,exynos8890-pmu", "syscon";
|
||||||
|
reg = <0x0 0x105C0000 0x10000>;
|
||||||
|
};
|
||||||
|
|
||||||
|
rtc@10070000 {
|
||||||
|
compatible = "samsung,s3c6410-rtc";
|
||||||
|
reg = <0x0 0x10070000 0x100>;
|
||||||
|
interrupts = <0 73 0>, <0 74 0>;
|
||||||
|
clocks = <&clock 157>;
|
||||||
|
clock-names = "gate_rtc";
|
||||||
|
};
|
||||||
|
|
||||||
|
Probably the only thing it does is set some clocks and prepare for BL31.
|
||||||
|
|
||||||
|
BL31
|
||||||
|
----
|
||||||
|
BL31 is written at ``0x02024000`` with the entry point at ``0x02024010``.
|
||||||
|
|
||||||
|
BL2
|
||||||
|
---
|
||||||
|
0x02e8dc mentions 'Onyx-OPR6-8511R1', which is likely sboot.
|
||||||
|
|
||||||
|
OLD
|
||||||
|
---
|
||||||
|
|
||||||
|
The reason for this is the following code in bl1:
|
||||||
|
|
||||||
|
.. code-block:: c
|
||||||
|
|
||||||
|
iVar3 = FUN_02024320();
|
||||||
|
if (iVar3 == 1) {
|
||||||
|
(*(code *)(ulong)uRam0000000002020108)(0,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
This code uses a predefined ROM function(I was looking for it) and jumps back to that function when it's done.
|
||||||
|
This function is at address ``0x020200e8``, looking in our IMEM dump we can see where in the ROM this points to:
|
||||||
|
|
||||||
|
.. code-block:: c
|
||||||
|
|
||||||
|
DAT_02020108 XREF[2]: FUN_00001708:000018b4(W),
|
||||||
|
FUN_02021970:02021a40(R)
|
||||||
|
02020108 90 57 00 00 undefined4 00005790h
|
||||||
|
|
||||||
|
Replacing this function with our debugger makes us jump back:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# Overwrite jump back
|
||||||
|
self.cd.memwrite_region(0x02020108, p32(0x2069000))
|
||||||
|
self.cd.memwrite_region(0x020200e8, p32(0x2069000))
|
||||||
|
|
||||||
|
def jump_bl1():
|
||||||
|
self.cd.arch_dbg.state.LR = 0x2069000
|
||||||
|
self.cd.restore_stack_and_jump(0x02024010)
|
||||||
|
# self.cd.restore_stack_and_jump(0x02021810)
|
||||||
|
|
||||||
|
bl1 = open("../S7/bl1.bin", "rb").read()
|
||||||
|
self.cd.memwrite_region(0x02024000, bl1)
|
||||||
|
self.usb_write(b"FLSH")
|
||||||
|
|
||||||
|
# auth_bl1()
|
||||||
|
jump_bl1()
|
||||||
|
assert self.usb_read(0x200) == b"GiAs", "not jumped back to debugger?"
|
||||||
|
self.cd.arch_dbg.state.print_ctx()
|
||||||
|
|
||||||
|
root | DEBUG |
|
||||||
|
X0 : 0xc00000 | X1 : 0x2069000 | X2 : 0x0 | X3 : 0x2023114 | X4 : 0x4 | X5 : 0x0 | X6 : 0x0 |
|
||||||
|
X7 : 0x136c0008 | X8 : 0x2069000 | X9 : 0x0 | X10 : 0x2070000 | X11 : 0x0 | X12 : 0x0 | X13 : 0x0 |
|
||||||
|
X14 : 0xf | X15 : 0x206d000 | X16 : 0x9 | X17 : 0x0 | X18 : 0x1 | X19 : 0x20200e8 | X20 : 0x0 |
|
||||||
|
X21 : 0x80000000 | X22 : 0x0 | X23 : 0x0 | X24 : 0x0 | X25 : 0x0 | X26 : 0x0 | X27 : 0x1 |
|
||||||
|
X28 : 0x0 | X29 : 0x2020ed8 | LR/X30 : 0x202419c | SP/X31 : 0x2020ec0
|
||||||
|
|
||||||
|
However this does not fully run bl1, so we will have to dig a bit deeper to see the puropose and when to jump back to the debugger.
|
||||||
|
|
38
documentation/source/BootROM_8890/04_notes.rst
Normal file
38
documentation/source/BootROM_8890/04_notes.rst
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
=====
|
||||||
|
Notes
|
||||||
|
=====
|
||||||
|
General notes on interesting/peculiar things found on the S7 USB recovery boot process
|
||||||
|
|
||||||
|
Emulator
|
||||||
|
========
|
||||||
|
What is interesting about the ROM is that it starts by checking MPIDR_EL1 register and doing a conditional branch to 0x20e0000.
|
||||||
|
|
||||||
|
.. code-block:: ghidra
|
||||||
|
|
||||||
|
undefined w0:1 <RETURN>
|
||||||
|
Reset XREF[1]: Entry Point(*)
|
||||||
|
00000000 bb 00 38 d5 mrs x27,mpidr_el1
|
||||||
|
00000004 7b 0f 78 92 and x27,x27,#0xf00
|
||||||
|
00000008 7f 03 00 f1 cmp x27,#0x0
|
||||||
|
0000000c 41 00 00 54 b.ne LAB_00000014
|
||||||
|
00000010 fc 7f 83 14 b LAB_020e0000
|
||||||
|
|
||||||
|
Week 35 - 2024
|
||||||
|
===============
|
||||||
|
After booting BL31, the MMU seems to be set up, and we're unable to do get any data off of spaces we're not 'allowed' to access. Patching the if-statement at 0x020244e8, disables the bit that says that the MMU is setup, but booting into recovery is possible (meaning the MMU is setup). Additionally, the memory at 0x02035600 is still not dumpable. At 0x02048000 is still accessible.
|
||||||
|
|
||||||
|
Weird space found at 0x105c2400. Seems to contain references to usb buffer (about 48-64 bytes).
|
||||||
|
|
||||||
|
Also space at 0x020307f0
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
self.cd.memdump_region(0x105c2400, 0x40).hex()
|
||||||
|
'0f0f00000f0008002100000000000000ffffffffffffffffffffffffffffffff0f0f00000f0008002101000000000000ffffffffffffffffffffffffffffffff'
|
||||||
|
|
||||||
|
Week 36 - 2024
|
||||||
|
===============
|
||||||
|
Interesting links:
|
||||||
|
- `Heap overflow <https://highaltitudehacks.com/2020/09/05/arm64-reversing-and-exploitation-part-1-arm-instruction-set-heap-overflow.html>`_
|
||||||
|
- `UART on S8 <https://grimler.se/posts/exynos-uart/>`_
|
||||||
|
|
||||||
|
By accident found space at 0x11207010. Seems to be a memory read/write space. Not executable however, unless the MMU is turned off.
|
File diff suppressed because it is too large
Load Diff
@ -17,4 +17,5 @@ start,end,name,order,comment,X0,LR
|
|||||||
0x02019e5c,0x02020e5c,Tried debugger space,,,,
|
0x02019e5c,0x02020e5c,Tried debugger space,,,,
|
||||||
0x020C7800,0x020C8000,modem_interface,,,,
|
0x020C7800,0x020C8000,modem_interface,,,,
|
||||||
0x14AC0000,0x14ac5000,mali@14AC0000,,,,
|
0x14AC0000,0x14ac5000,mali@14AC0000,,,,
|
||||||
0x2035600,0x2035608,TTBR0_EL3 address ptr,,,,
|
0x02035600,0x02035608,TTBR0_EL3 address ptr,,,,
|
||||||
|
0x11207010,0x11207010,memread/write space,,,,
|
|
File diff suppressed because one or more lines are too long
@ -11,8 +11,7 @@ Documentation on Samsung devices, currently mainly the Samsung S7.
|
|||||||
:maxdepth: 2
|
:maxdepth: 2
|
||||||
:caption: BootROMs:
|
:caption: BootROMs:
|
||||||
|
|
||||||
BootROM_8890/index.rst
|
BootROM_8890/01_start.rst
|
||||||
BootROM_8890/boot_chain.rst
|
BootROM_8890/02_frederics_exploit.rst
|
||||||
BootROM_8890/notes.rst
|
BootROM_8890/03_exploit_boot_chain.rst
|
||||||
|
BootROM_8890/04_notes.rst
|
||||||
|
|
||||||
|
BIN
dump/reloc_debugger_0x11200000.bin
Executable file
BIN
dump/reloc_debugger_0x11200000.bin
Executable file
Binary file not shown.
@ -323,26 +323,6 @@ class ExynosDevice():
|
|||||||
return dumped
|
return dumped
|
||||||
|
|
||||||
|
|
||||||
def check_mem_write_execute(self, region):
|
|
||||||
"""
|
|
||||||
NOT WORKING YET
|
|
||||||
|
|
||||||
Write opcode to memory which jumps back immediatelly to the LR register at that moment.
|
|
||||||
"""
|
|
||||||
# LR to jump back to:
|
|
||||||
lr = self.cd.arch_dbg.state.LR
|
|
||||||
|
|
||||||
# Write opcode
|
|
||||||
shellcode = f"""
|
|
||||||
ldr x0, target_addr
|
|
||||||
blr x0
|
|
||||||
target_addr: .quad {hex(lr)}
|
|
||||||
"""
|
|
||||||
shellcode = ks.asm(shellcode, as_bytes=True)[0]
|
|
||||||
self.cd.memwrite_region(region, shellcode)
|
|
||||||
self.cd.jump_to(region)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_guppy_debugger(self):
|
def setup_guppy_debugger(self):
|
||||||
"""
|
"""
|
||||||
Sets up guppy debugger on the device itself.
|
Sets up guppy debugger on the device itself.
|
||||||
@ -607,7 +587,6 @@ class ExynosDevice():
|
|||||||
"""
|
"""
|
||||||
At given address, test if it is possible to write and execute code, by writing a simple jump to, and jump back.
|
At given address, test if it is possible to write and execute code, by writing a simple jump to, and jump back.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.usb_write(b'PING')
|
self.usb_write(b'PING')
|
||||||
assert self.usb_read(0x200) == b'PONG', "Debugger not alive before test"
|
assert self.usb_read(0x200) == b'PONG', "Debugger not alive before test"
|
||||||
|
|
||||||
@ -624,19 +603,6 @@ class ExynosDevice():
|
|||||||
print(f'Jumped to {hex(address)} and back')
|
print(f'Jumped to {hex(address)} and back')
|
||||||
|
|
||||||
|
|
||||||
def get_all_special_regs(self):
|
|
||||||
"""
|
|
||||||
Get all special registers from the device.
|
|
||||||
"""
|
|
||||||
self.cd.fetch_special_regs()
|
|
||||||
|
|
||||||
# Get all valeus from self.cd.arch_dbg.state
|
|
||||||
|
|
||||||
|
|
||||||
self.cd.arch_dbg.state.print_ctx()
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def debugger_boot(self):
|
def debugger_boot(self):
|
||||||
"""
|
"""
|
||||||
Boot into USB recovery mode using the debugger.
|
Boot into USB recovery mode using the debugger.
|
||||||
@ -650,15 +616,20 @@ class ExynosDevice():
|
|||||||
DEBUGGER_ADDR = 0x2069000 # 0x2069000
|
DEBUGGER_ADDR = 0x2069000 # 0x2069000
|
||||||
|
|
||||||
# # Relocate to other debugger to 02048000 (after BL31, space in 0x020c0000 is no longer reachable -> dying debugger)
|
# # Relocate to other debugger to 02048000 (after BL31, space in 0x020c0000 is no longer reachable -> dying debugger)
|
||||||
debugger = open("../../dump/reloc_debugger_0x2048000.bin", "rb").read()
|
# debugger = open("../../dump/reloc_debugger_0x2048000.bin", "rb").read()
|
||||||
self.relocate_debugger(debugger=debugger, entry=0x02048000, storage=0x02051000, g_data_received=0x02052000)
|
# self.relocate_debugger(debugger=debugger, entry=0x02048000, storage=0x02051000, g_data_received=0x02052000)
|
||||||
DEBUGGER_ADDR = 0x02048000
|
# DEBUGGER_ADDR = 0x02048000
|
||||||
|
|
||||||
# # # Relocate to other debugger to 020c0000
|
# # # Relocate to other debugger to 020c0000
|
||||||
# debugger = open("../../dump/reloc_debugger.bin", "rb").read()
|
# debugger = open("../../dump/reloc_debugger.bin", "rb").read()
|
||||||
# self.relocate_debugger(debugger)
|
# self.relocate_debugger(debugger)
|
||||||
# DEBUGGER_ADDR = 0x020c0000
|
# DEBUGGER_ADDR = 0x020c0000
|
||||||
|
|
||||||
|
# Relocate debugger
|
||||||
|
debugger = open("../../dump/reloc_debugger_0x11200000.bin", "rb").read()
|
||||||
|
self.relocate_debugger(debugger=debugger, entry=0x11200000, storage=0x11201200, g_data_received=0x11201400)
|
||||||
|
DEBUGGER_ADDR = 0x11200000
|
||||||
|
|
||||||
# Test debugger connection
|
# Test debugger connection
|
||||||
self.cd.test_connection()
|
self.cd.test_connection()
|
||||||
|
|
||||||
@ -755,13 +726,14 @@ class ExynosDevice():
|
|||||||
TTBR0_EL3 = 0x02035600 # Zeroed out
|
TTBR0_EL3 = 0x02035600 # Zeroed out
|
||||||
|
|
||||||
# Modifies/disables setting up MMU (but is set up eventually) -> MMU says 0x0 instead of 0x1, but still little access (and proper USB recovyer boot!?)
|
# Modifies/disables setting up MMU (but is set up eventually) -> MMU says 0x0 instead of 0x1, but still little access (and proper USB recovyer boot!?)
|
||||||
|
self.cd.memwrite_region(0x020244e8, struct.pack('>I', 0x1f0c00f1)) # Change check to always false
|
||||||
# self.cd.memwrite_region(0x02032008, struct.pack('>I', 0x1f2003d5)) # Overwrite MAIR to NOP
|
# self.cd.memwrite_region(0x02032008, struct.pack('>I', 0x1f2003d5)) # Overwrite MAIR to NOP
|
||||||
# self.cd.memwrite_region(0x0202ee74, struct.pack('>I', 0x63650094)) # Return to debugger. (not working, it continues booting..)
|
# self.cd.memwrite_region(0x0202ee74, struct.pack('>I', 0x63650094)) # Return to debugger. (not working, it continues booting..)
|
||||||
|
|
||||||
# self.cd.memwrite_region(0x0202eb74, struct.pack('>I', 0x1f2003d5)) # Change check to always false
|
# self.cd.memwrite_region(0x0202eb7c, struct.pack('>I', 0x21650014)) # Change check to always false
|
||||||
|
|
||||||
# Jump back to debugger, after TTBR0 is no longer accessible
|
# Jump back to debugger, after TTBR0 is no longer accessible
|
||||||
self.cd.memwrite_region(0x020308a4, struct.pack('>I', 0xd75d0014)) # Change check to always false
|
# self.cd.memwrite_region(0x0202f288, struct.pack('>I', 0x5e630094)) # Change check to always false
|
||||||
|
|
||||||
# Jump into BL31 and execute it
|
# Jump into BL31 and execute it
|
||||||
self.cd.restore_stack_and_jump(0x02024010)
|
self.cd.restore_stack_and_jump(0x02024010)
|
||||||
@ -778,23 +750,26 @@ class ExynosDevice():
|
|||||||
# self.cd.arch_dbg.fetch_special_regs() # -> Does not work with original debugger (??). Only with relocated debugger.
|
# self.cd.arch_dbg.fetch_special_regs() # -> Does not work with original debugger (??). Only with relocated debugger.
|
||||||
VBAR_EL3 = self.cd.arch_dbg.state.VBAR_EL3
|
VBAR_EL3 = self.cd.arch_dbg.state.VBAR_EL3
|
||||||
|
|
||||||
# Disable MMU and branch to 0x02048000
|
# ================= WORKS TO DISABLE DEBUGGER. BUT UNNECESSARY =================
|
||||||
shellcode=f"""
|
# # Disable MMU and branch to 0x02048000
|
||||||
mrs x0, sctlr_el3
|
# shellcode=f"""
|
||||||
bic x0, x0, #1
|
# mrs x0, sctlr_el3
|
||||||
msr sctlr_el3, x0
|
# bic x0, x0, #1
|
||||||
ldr x0, =0x2048000
|
# msr sctlr_el3, x0
|
||||||
br x0
|
# ldr x0, =0x2048000
|
||||||
"""
|
# br x0
|
||||||
shellcode = ks.asm(shellcode, as_bytes=True)[0]
|
# """
|
||||||
self.cd.memwrite_region(0x02060000, shellcode)
|
# shellcode = ks.asm(shellcode, as_bytes=True)[0]
|
||||||
self.cd.jump_to(0x02060000)
|
# self.cd.memwrite_region(0x02060000, shellcode)
|
||||||
time.sleep(1)
|
# self.cd.jump_to(0x02060000)
|
||||||
self.usb_read(0x200) # GiAs
|
# time.sleep(1)
|
||||||
self.cd.arch_dbg.fetch_special_regs()
|
# self.usb_read(0x200) # GiAs
|
||||||
|
# self.cd.arch_dbg.fetch_special_regs()
|
||||||
|
|
||||||
# Print status of MMU
|
# # Print status of MMU
|
||||||
print(f'MMU is {hex(self.cd.arch_dbg.state.R_SCTLR_EL3.mmu)} (0x1=enabled, 0x0=disabled)')
|
# print(f'MMU is {hex(self.cd.arch_dbg.state.R_SCTLR_EL3.mmu)} (0x1=enabled, 0x0=disabled)')
|
||||||
|
|
||||||
|
# =================
|
||||||
|
|
||||||
# # Change the values of MAIR_EL3 to a different value
|
# # Change the values of MAIR_EL3 to a different value
|
||||||
# shellcode=f"""
|
# shellcode=f"""
|
||||||
@ -811,16 +786,36 @@ class ExynosDevice():
|
|||||||
# self.cd.arch_dbg.fetch_special_regs()
|
# self.cd.arch_dbg.fetch_special_regs()
|
||||||
# print(self.cd.arch_dbg.state.R_MAIR_EL3)
|
# print(self.cd.arch_dbg.state.R_MAIR_EL3)
|
||||||
|
|
||||||
|
self.test_write_execute(0x11207010)
|
||||||
|
|
||||||
|
# # Relocate debugger
|
||||||
|
# debugger = open("../../dump/reloc_debugger_0x2019e5c.bin", "rb").read()
|
||||||
|
# self.relocate_debugger(debugger=debugger, entry=0x11200000, storage=0x11201200, g_data_received=0x11201400)
|
||||||
|
# DEBUGGER_ADDR = 0x11200000
|
||||||
|
|
||||||
# Again restore bootflow
|
# Again restore bootflow
|
||||||
self.cd.memwrite_region(0x020200dc, p32(hijacked_fun))
|
# self.cd.memwrite_region(0x020200dc, p32(hijacked_fun))
|
||||||
self.cd.restore_stack_and_jump(hijacked_fun)
|
self.cd.restore_stack_and_jump(hijacked_fun)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
|
|
||||||
# ==== Stage 3 BL2 ====
|
# ==== Stage 3 BL2 ====
|
||||||
self.send_normal_stage(open("../S7/g930f_latest/g930f_sboot.bin.3.bin", "rb").read())
|
stage3 = open("../S7/g930f_latest/g930f_sboot.bin.3.bin", "rb").read()
|
||||||
|
# stage3_len = len(stage3)
|
||||||
|
# patch_len = len(b"MNGS_QUAD")
|
||||||
|
# patch = b"Patch" + (b"\x00" * (patch_len - len(b"Patch")))
|
||||||
|
# patch_offset = stage3.find(b"MNGS_QUAD")
|
||||||
|
# stage3 = stage3[:patch_offset] + patch + stage3[patch_len + patch_offset:]
|
||||||
|
# assert len(stage3) == stage3_len, "Invalid stage4 length"
|
||||||
|
|
||||||
|
self.send_normal_stage(stage3)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
self.connect_device()
|
self.connect_device()
|
||||||
|
self.usb_read(0x200) # GiAs
|
||||||
|
|
||||||
|
# Restore bootflow
|
||||||
|
self.cd.memwrite_region(0x020200dc, p32(hijacked_fun))
|
||||||
|
self.cd.restore_stack_and_jump(hijacked_fun)
|
||||||
|
|
||||||
# ==== Stage 4 ====
|
# ==== Stage 4 ====
|
||||||
stage4 = open("../S7/g930f_latest/g930f_sboot.bin.4.bin", "rb").read()
|
stage4 = open("../S7/g930f_latest/g930f_sboot.bin.4.bin", "rb").read()
|
||||||
|
Loading…
Reference in New Issue
Block a user