A few things on knox / rooting and bootloaders that need more testing / development

xclub_101

Senior Member
Oct 15, 2012
1,243
355
0
I've done a bit of reverse engineering, and I've discovered two very important pieces of information.

1. TrustZone appears to not be device specific, you could most likely flash any N3 TZ and possibly even S4/N2, as long as it is signed properly.

2. It appears rollback information is stored in the rpmb. I found a string in TZ.mbn directly indicating so.

Here's my idea; Since the only way to communicate with TrustZone is via TEE (Trusted Execution Environment) or in our case QSEE (Qualcomm Trusted Execution Environment) which is a proprietary stack. The device driver for QSEE is /dev/qseecom. I'm doing some experimenting on whether it'll accept commands or data, but this looks to be the most promising route. If it were possible to rollback the counters to 0, which I know now to be rpmb based so we can most likely reset them, we could flash an old aboot that exists from MHV or MG3 (I might be able to insert the certificates MG3 since it is not signed, but it's 4.2.2 based.) I'm able to see much lower level debug and logging information thanks to @Surge1223. The files in /firmware/image and /system/etc/firmware are elf images of TZ HLOS applications. Another place to start investigating more thoroughly. I would not be surprised to find Knox related things too.
...

1. TZ was known not to be device-specific and the overall protocol to talk to code in TZ and enter TEE was described using the privileged SMC instruction, for instance here:

http://blog.azimuthsecurity.com/2013/04/unlocking-motorola-bootloader.html

However it is product-family specific (I would expect Qualcomm to be different than Exynos) and I doubt there are any easy attacks left on the TZ direction itself (that must be crypto signed and so on, and the easy attacks have been already described and presumably patched already).



2. :good: Nice to see that somebody else confirmed that the rollback information is in rpmb - first that was mentioned by the z3x team (the guys selling the Easy-Jtag hardware solution) but since they will be using it for their product I do not think they will want to share anything they have learned about it :rolleyes:



3. Still IMHO attacks on knox could be done in theory easier by "rollback" rather than finding a new major exploit in the current TZ code.



4. Given that you provided the link to that Nokia PDF on TZ - what is IMHO the scenario that seems more credible to me regarding knox flag is that a value (we believe at least 2 bits, possibly more than that but unlikely to be more than 8-16 bits) from the qfuses is combined with the "device secret" mentioned and a one-way computation (hash?) of that is stored somewhere in rpmb. On boot the computation is done again and is compared to the value in rpmb - when there is a match you have knox 0, when there is no match you have knox 1. When something which is considered important is seen (like for instance during boot any kernel or recovery that is not signed by Samsung) the first free bit in the qfuse is blown; this automatically changes the computed value, and since it no longer matches the one in rpmb we see knox 1; when Samsung (or T-Mobile, see the 2 threads above) does a warranty repair they can "restore" knox - but not by "unblowing" the qfuse (which is not possible), but instead they look-up the (public) unique ID of the device, then probably do a look-up for the "device secret" (most likely somewhere at Samsung), calculate the new hash and write that new value in the rpmb, so on the next boot the computed value now matches again the (now different) value in rpmb. In this scenario if we want a solution to reset knox we "only" :rolleyes: need a way to calculate the secret and then a way to write it in rpmb. There is also the possibility that instead of calculating the new value outside the device (in that complex Samsung-involved way) they make a call inside the TZ, but that would be something to break any stupidity records since would by-pass the entire "device secret" effort.



5. One major mystery that remains in the above scenario is why N900W8 does not trigger the knox flag under certain conditions (like having TWRP as custom recovery) - still having the downgrade option is not anything special (probably the rollback restrictions are not added to the rpmb) but the TWRP recovery is certainly not signed by Samsung so at any boot knox should be set; possible explanations could be:
- the W8 boot process does not check recovery/kernel signatures on boot (?)
- the W8 boot process does the check but does not burn any other qfuse either on choice (??) or because they can not as a result of a bug (???) or as a result of already having all the qfuses blown (???? only makes sense if a very low number of bits of qfuses are dedicated to knox, 1 or at most 2).
 
Last edited:

ryanbg

Inactive Recognized Developer
Jan 3, 2008
855
1,734
0
movr0.com
1. TZ was known not to be device-specific and the overall protocol to talk to code in TZ and enter TEE was described using the privileged SMC instruction, for instance here:

http://blog.azimuthsecurity.com/2013/04/unlocking-motorola-bootloader.html

However it is product-family specific (I would expect Qualcomm to be different than Exynos) and I doubt there are any easy attacks left on the TZ direction itself (that must be crypto signed and so on, and the easy attacks have been already described and presumably patched already).



2. :good: Nice to see that somebody else confirmed that the rollback information is in rpmb - first that was mentioned by the z3x team (the guys selling the Easy-Jtag hardware solution) but since they will be using it for their product I do not think they will want to share anything they have learned about it :rolleyes:



3. Still IMHO attacks on knox could be done in theory easier by "rollback" rather than finding a new major exploit in the current TZ code.



4. Given that you provided the link to that Nokia PDF on TZ - what is IMHO the scenario that seems more credible to me regarding knox flag is that a value (we believe at least 2 bits, possibly more than that but unlikely to be more than 8-16 bits) from the qfuses is combined with the "device secret" mentioned and a one-way computation (hash?) of that is stored somewhere in rpmb. On boot the computation is done again and is compared to the value in rpmb - when there is a match you have knox 0, when there is no match you have knox 1. When something which is considered important is seen (like for instance during boot any kernel or recovery that is not signed by Samsung) the first free bit in the qfuse is blown; this automatically changes the computed value, and since it no longer matches the one in rpmb we see knox 1; when Samsung (or T-Mobile, see the 2 threads above) does a warranty repair they can "restore" knox - but not by "unblowing" the qfuse (which is not possible), but instead they look-up the (public) unique ID of the device, then probably do a look-up for the "device secret" (most likely somewhere at Samsung), calculate the new hash and write that new value in the rpmb, so on the next boot the computed value now matches again the (now different) value in rpmb. In this scenario if we want a solution to reset knox we "only" :rolleyes: need a way to calculate the secret and then a way to write it in rpmb. There is also the possibility that instead of calculating the new value outside the device (in that complex Samsung-involved way) they make a call inside the TZ, but that would be something to break any stupidity records since would by-pass the entire "device secret" effort.



5. One major mystery that remains in the above scenario is why N900W8 does not trigger the knox flag under certain conditions (like having TWRP as custom recovery) - still having the downgrade option is not anything special (probably the rollback restrictions are not added to the rpmb) but the TWRP recovery is certainly not signed by Samsung so at any boot knox should be set; possible explanations could be:
- the W8 boot process does not check recovery/kernel signatures on boot (?)
- the W8 boot process does the check but does not burn any other qfuse either on choice (??) or because they can not as a result of a bug (???) or as a result of already having all the qfuses blown (???? only makes sense if a very low number of bits of qfuses are dedicated to knox, 1 or at most 2).
I found a very interesting log file on my device that was hidden pretty deep...

init_ddi_data: usable ddi data.
<LP> ODIN MODE
<LP> PRODUCT NAME: SM-N900V
<LP> CURRENT BINARY: Samsung Official
<LP> SYSTEM STATUS: Official
KL: API Status 0x0
KNOX KERNEL LOCK: 0x0
<LP> KNOX KERNEL LOCK: 0x0
WV: API Status 0x0
KNOX WARRANTY VOID: 0x0
<LP> KNOX WARRANTY VOID: 0x0
QFPROM oem_config1: 0x00000f03
<LP> QUALCOMM SECUREBOOT: ENABLE (CSB)
anti_en 0xf
QFPROM_RAW_AP_ANTI_ROLLBACK_ROW0_LSB: 0x10001
QFPROM_RAW_AP_ANTI_ROLLBACK_ROW1_LSB: 0x3
QFPROM_RAW_SPARE_REG19_ROW0_LSB: 0x0
<LP> RP SWREV: S1, T1, R1, A2, P0
<LP> WRITE PROTECTION: Enable
odin3_init()
udc_start()
 

ant456

Senior Member
Apr 16, 2013
71
86
0
Where did you find that bootloader log file I've only had my phone for a week so I still have the 14 day warranty so I can just exchange it at the store if you have any tests you want me to do
 

ryanbg

Inactive Recognized Developer
Jan 3, 2008
855
1,734
0
movr0.com
Would be interesting to know whether https://www.fsf.org/blogs/community/replicant-developers-find-and-close-samsung-galaxy-backdoor could be used to access stuff on knox devices (and patch the system that way) that Samsung would us not want to do ...
I've been looking into it the past couple of days. It may be possible to use an older modem and a hacked-together ServiceMode.apk to issue AT/DM/FTM commands directly to the modem. Decompile HiddenMenu.apk, there's all sorts of goodies in there. It's a little more complicated than I'd like to think, but it seems plausible. They have their own custom firmware/RIL library though, we don't have the luxury of using that to take advantage of the exploit, so we'll have to find another way.
 

E:V:A

Inactive Recognized Developer
Dec 6, 2011
1,449
2,212
0
-∇ϕ
I found a very interesting log file on my device that was hidden pretty deep...
And where is that? (Do you know what wrote it?)

I've been looking into it the past couple of days. It may be possible to use an older modem and a hacked-together ServiceMode.apk to issue AT/DM/FTM commands directly to the modem. Decompile HiddenMenu.apk, there's all sorts of goodies in there. It's a little more complicated than I'd like to think, but it seems plausible. They have their own custom firmware/RIL library though, we don't have the luxury of using that to take advantage of the exploit, so we'll have to find another way.
Any progress? I did something similar for the SGS3, found tons of goodies. I'd like to see what you have if anything new.
 

ryanbg

Inactive Recognized Developer
Jan 3, 2008
855
1,734
0
movr0.com
And where is that? (Do you know what wrote it?)



Any progress? I did something similar for the SGS3, found tons of goodies. I'd like to see what you have if anything new.
Rollback protection information isn't stored in 'actual' QFPROM, but rather the RPMB. Both on Snapdragon and Exynos devices. The warranty bit is controlled by an actual hardware fuse in the MCU, while the Exynos warranty bit is also stored in the RPMB. I believe the RPMB may serve as a shadow register for all fuses also. I'm looking into the patches and ioctl for RPMB. I was dissecting an old unsigned RPMB from a Note 3 engineering build and found an 'SSD Keystore Encryption Key' and 'SSD Auth Key' within the TrustZone blob. Note I have a 160 bit key for both in plaintext, not a .key file. I'm not exactly sure if SSD is referring to the RPMB or the NAND chip itself, but it may be possible to send authenticated messages to TZ kernel/keystore. I can explain more in-depth via gtalk. We've got several theories.
 

david515

Member
May 18, 2013
26
14
0
Ames
Don't know if this helps anybody wth MJE to MI9...

Downgrading is limited to the flag fuse counter values. On MJE, I can downgrade to MI9 boot image and recovery. I was able to downgrade to some pre-release engineering SBL1, RPM, and TZ because they're signed and fuse counter is only 1 for those 3. It's very benign and basic to downgrade. Just use heimdall and try downgrading an individual image. If I figure out what P is, I'll be able to test if I can flash anything related to that flag. For some reason, I can downgrade to MI9 boot and recovery, but not the system.img. I'm just starting to learn a lot about the flags/fuse counters after dissecting aboot further. If you've got any more specific questions, feel free to PM me :)
I was able to flash from MJE Modem down to MI9, but system Image still on MJE but ever thing else says MI9- ( don't know if that helps anyone)
 

david515

Member
May 18, 2013
26
14
0
Ames
I'm planning on investing in JTAG...

The modem actually has rollback protection, but all modems seem to be '1' value.
I may be of some better help after I get a Jtag set up hopefully this next week. Thank you everyone for your efforts. J TAG has been something I've been meaning to invest in for a while.
 

siraltus

Senior Member
Jan 26, 2010
1,997
1,733
0
Rollback protection information isn't stored in 'actual' QFPROM, but rather the RPMB. Both on Snapdragon and Exynos devices. The warranty bit is controlled by an actual hardware fuse in the MCU, while the Exynos warranty bit is also stored in the RPMB. I believe the RPMB may serve as a shadow register for all fuses also. I'm looking into the patches and ioctl for RPMB. I was dissecting an old unsigned RPMB from a Note 3 engineering build and found an 'SSD Keystore Encryption Key' and 'SSD Auth Key' within the TrustZone blob. Note I have a 160 bit key for both in plaintext, not a .key file. I'm not exactly sure if SSD is referring to the RPMB or the NAND chip itself, but it may be possible to send authenticated messages to TZ kernel/keystore. I can explain more in-depth via gtalk. We've got several theories.
SSD could stand for System Software Debug, part of the JTAG specification.
 
  • Like
Reactions: HEXC

evilpotatoman

Senior Member
Jan 29, 2010
135
654
133
Charlotte
Rollback protection information isn't stored in 'actual' QFPROM, but rather the RPMB. Both on Snapdragon and Exynos devices. The warranty bit is controlled by an actual hardware fuse in the MCU, while the Exynos warranty bit is also stored in the RPMB. I believe the RPMB may serve as a shadow register for all fuses also. I'm looking into the patches and ioctl for RPMB. I was dissecting an old unsigned RPMB from a Note 3 engineering build and found an 'SSD Keystore Encryption Key' and 'SSD Auth Key' within the TrustZone blob. Note I have a 160 bit key for both in plaintext, not a .key file. I'm not exactly sure if SSD is referring to the RPMB or the NAND chip itself, but it may be possible to send authenticated messages to TZ kernel/keystore. I can explain more in-depth via gtalk. We've got several theories.
Create folder /sdcard/ks.license and place key files there.

May need to invoke factory mode (here's how I did it):

Boot into safe strap
advanced->terminal command
navigate to /dev/block/platform/msm_sdcc.1/by-name
open terminal
mount ./efs /efs
echo OFF > /efs/FactoryApp/factorymode
echo OFF > /efs/FactoryApp/keystr
mount ./system /system
sed -i 's/build.type=user/build.type=eng/g' /system/build.prop
sed -i 's/ship=true/ship=false/g' /system/build.prop
 

ryanbg

Inactive Recognized Developer
Jan 3, 2008
855
1,734
0
movr0.com
Create folder /sdcard/ks.license and place key files there.

May need to invoke factory mode (here's how I did it):

Boot into safe strap
advanced->terminal command
navigate to /dev/block/platform/msm_sdcc.1/by-name
open terminal
mount ./efs /efs
echo OFF > /efs/FactoryApp/factorymode
echo OFF > /efs/FactoryApp/keystr
mount ./system /system
sed -i 's/build.type=user/build.type=eng/g' /system/build.prop
sed -i 's/ship=true/ship=false/g' /system/build.prop
Where did you get this ks.license business? You can't tell me all this without giving me more clues ;)
Should I just paste plaintext key and save as .key? Also, why factory mode? There's an easier way to get into it too.

update: Not quite sure what I'm looking for or doing.
 
Last edited:

david515

Member
May 18, 2013
26
14
0
Ames
Where did you get this ks.license business? You can't tell me all this without giving me more clues ;)
Should I just paste plaintext key and save as .key? Also, why factory mode? There's an easier way to get into it too.

update: Not quite sure what I'm looking for or doing.
This is encouraging check this post -- Evilpotatomans post http://forum.xda-developers.com/showthread.php?t=2721505
I hope this helps you guys out.
Thank you!!
 
Last edited:
  • Like
Reactions: RuggedHunter

E:V:A

Inactive Recognized Developer
Dec 6, 2011
1,449
2,212
0
-∇ϕ
This is encouraging check this post -- Evilpotatomans post http://forum.xda-developers.com/showthread.php?t=2721505
I hope this helps you guys out. Thank you!!
That thread was DMCA yanked faster than you can say "yank".

May need to invoke factory mode (here's how I did it):

Boot into safe strap
advanced->terminal command
navigate to /dev/block/platform/msm_sdcc.1/by-name
open terminal
mount ./efs /efs
echo OFF > /efs/FactoryApp/factorymode
echo OFF > /efs/FactoryApp/keystr
mount ./system /system
sed -i 's/build.type=user/build.type=eng/g' /system/build.prop
sed -i 's/ship=true/ship=false/g' /system/build.prop
This is weird. Any idea what this does?
It surely seem like you turn OFF Factory Mode and turn ON Engineering mode,
but I always though they'd be the same. I wonder what is different.
 

Grompy

Senior Member
Oct 30, 2009
500
190
0
Noblesville, IN
That thread was DMCA yanked faster than you can say "yank".



This is weird. Any idea what this does?
It surely seem like you turn OFF Factory Mode and turn ON Engineering mode,
but I always though they'd be the same. I wonder what is different.

FYI google has the cached version before it was mod editted and all the stuff is still in his google drive account available for download.