john Profile picture
29 May, 19 tweets, 4 min read
Here is my little thread about yet another bug I found in A6 bootrom (and probably any other that boots from H2FMI PPN NAND)

As always, absolutely useless on its own
Look at this picture. The bootrom has just read LLB from a bootpage and is now ready to create a Memz structure out of it. Address - 0x10000000, size - 0x24C00, flags - IMAGE_OPTION_LOCAL_STORAGE
Since the size was 0x24C00, we expect to see nothing on range of 0x10024C00 - 0x10060000 (the end of load area), right? Wrong!
As you can see, we have controllable custom data beyond the range nand_read_bootblock() reports to main()
The first question you ask now is can we write beyond load area on devices where [unlike A6] load area is shorter than NAND space for LLB (for example A5 - 0x2F400 vs 0x2C000)?
Nope. This works only because nand_read_bootblock() checks ECC of newly read page BEFORE adding its size to a counter, and when ECC is bad it returns, and under certain circumstances it even returns success
As result, we can have up to one page of data beyond the size nand_read_bootblock() reports to the caller (and it stays unaware), BUT only if it doesn’t overflow the limits of load area
(Remark - I’m a shit reverse engineer, so better verify the last bit yourself)
How to achieve this on practice and have something we want to see there? Well, the boot block consists of pages and pages consist of sectors. A sector is 0x200 bytes in size, and there’re 3 in one page (so a page is 0x600)
We can write just 2 sectors instead of 3 - this way first 2 sectors will contain our arbitrary data, and the third will have some nonsense and broken ECC. Lame way, and it limits size of the meaningful data to 0x400, but that's the best I could do
I’ve implemented this technique in my iBoot payload - StarInjector - and will push the updated branch a little bit later. Stay tuned (omg, who the hell cares)

As stated in the top tweet, it’s absolutely useless without something else. But since Image3 routines won’t consider this data as part of an image, it will survive a lot of memset()s on the way, except for the one in main() which is only called when boot_image() returns
And upon successful load of an Image3, the data will persist to the very end. Here you can see the bootrom ready to boot an image (0x5F80 is prepare_and_jump()) and our data still there
Useful resources:

1) Stolen iBoot source code - still contains the code for booting from H2FMI NAND, even though it’s not used by SecureROM from that era

2) My thread about bugs I’ve found in Image3 stack of A4/A6 bootrom
3) StarInjector - mentioned above, the payload to write to boot block (and more!)
One more thing. I initially thought that the ECC failures on the device I discovered the whole thing on were caused by the fact StarInjector violates standard procedure of writing to NAND boot block a little bit
The procedure is like this:

1) Save the page 0 - partition map
2) Erase the whole block (0)
3) Put the map back on pages 0 and 1
4) Write your LLB page by page
5) The rest of the pages must written as “full” (for whatever it means - look at the screenshot)
StarInjector skips the step 5
But apparently this bug happens even on fresh normal restores. Either they skip the step too, or that’s just not the cause

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with john

john Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @nyan_satan

5 Jul 20
As promised, here’s my little thread about my experience of repairing 1st-gen KongSWD (all-white)
Although that’s most likely not your case if you got such a cable, but I did manage to break firmware on mine completely. So let’s start with restoring it
Both generations of Kong make use of NXP LPC1768 MCU (Cortex-M3) (along with Xilinx Spartan 6 FPGA, by the way), that can be reflashed over SWD Image
Read 18 tweets
5 Feb 20
Here is my little thread about bugs I’ve found in Image3 parsers of various SecureROMs (well, A4 and A6)

None of them are exploitable, but all of them can cause a crash and/or denial-of-service

Why am I posting this? Just for lulz and from hopelessness

Image
1) memsetting the whole address space

That’s only for A4 (and maybe lower)

Back in February 2019, someone told me about “SHSH tag length underflow”, that allows “arbitrary memset”. The person failed to tell me which ROM it’s for
But for A4 ROM I found something similar. Look at this line of code:

github.com/NyanSatan/Imag… Image
Read 23 tweets
8 Oct 19
@chronic 1/ there’s no such bootloader as BSS, there’s iBSS (iBoot Single Stage) instead

2/ LLB cannot enter recovery mode, it enters DFU-like mode

3/ boot-command upgrade makes it boot new iBEC, not iBSS

4/ SecureROM versions do NOT match iBoot version at the time of device release
@chronic 5/ there’s console on production iBoot too, although very limited

6/ there’re more iBoot flags than he shows

7/ demotion to 01 is enough to get JTAG (I’d even say SWD). Demotion of Security status isn’t even possible according to @s1guza

@chronic @s1guza 8/8 limera1n isn’t the only bootrom exploit of the past times. There also were Pwnage 1/2, steaks4uce, 24kpwn, SHAtter and alloc8

That was just brief view, by the way
Read 4 tweets
17 Aug 19
Here is my little thread about Power NVRAM — another persistent key-value storage, located right on PMU chip. Only talking about iBoot context
Modifying certain key there allows to enable debug UART on any boot loader (including DFU ones) very early and without touching normal NVRAM

Both keys and values are unsigned 8-bit integers

Now let’s talk about known keys and values for them:
Read 17 tweets
27 Jul 19
Here is my little thread about Lightning video adapters – also known as Haywire – which are actually computers that feature Apple Secure Boot and run Darwin kernel
There’re 2 kinds of Haywire:

1. Lightning Digital AV Adapter (b137ap/iAccy1,1) – Lightning to HDMI adapter, supports both video and audio
2. Lightning to VGA Adapter (b165ap/iAccy1,2) – doesn’t support audio output for obvious reason
Read 20 tweets
31 Jan 19
I was planning to keep this knowledge private, but damn it. This is a thread about Apple SWD cables, some things they can do and how to use them
For now I only have got KongSWD, so everything below applies to this type of cable first of all
f you’re reading this thread, you’ve most likely seen many photos with these weird Apple internal cables posted here, on Twitter, — Gorilla, Kong, Kanzi, Chimp, Flamingo, etc.

Read 29 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(