|
|
Overview
This is a description of how the secpack header can be decrypted and what it contains.
I. secpack .bin file structure
- 0x000 - 0x07F RSA-encrypted header
- 0x080 - 0x1FF zeros
- 0x200 - 0x7FF secpack payload
II. RSA-encrypted header
The 0x80-byte header is encrypted by Apple's private RSA key and can be decrypted using one (the first one) of Apple's two unique public RSA keys (modulus and exponent, discussed later). It contains the SHA-1 sums of the secpack payload and also of the firmware image it is authorized to upload to iPhone.
It can be broken down into sections H,I,0,J,K,L:
000: HH HH II II II II II II II II II II II II II II 010: II II II II II II II II II II II II II II II II 020: II II II II II II II II II II II II II II II 00 030: JJ JJ JJ JJ JJ JJ JJ JJ JJ JJ JJ JJ JJ JJ JJ JJ 040: JJ JJ JJ JJ KK KK KK KK KK KK KK KK KK KK KK KK 050: KK KK KK KK KK KK KK KK LL LL LL LL LL LL LL LL 060: LL LL LL LL LL LL LL LL LL LL LL LL LL LL LL LL 070: LL LL LL LL LL LL LL LL LL LL LL LL LL LL LL LL
* H: Length 2 (0x02) PKCS1v1.5 values. Always 00 01 * I: Length 45 (0x2D) Padding. In 4.02.13 it's all FF's, but in other releases it isn't * 0: Length 1 (0x01) End of padding marker. Always 00 * J: Length 20 (0x14) SHA-1 sum of firmware this secpack is authorized for * K: Length 20 (0x14) SHA-1 sum of secpack from 0x200-0x800 of secpack.bin * L: Length 40 (0x28) Extra bytes that aren't checked by either the 3.9 or 4.6 Apple bootloader (thanks, geohot!)
For example, secpack40213.bin's header decrypts into this:
000: 00 01 ff ff ff ff ff ff ff ff ff ff ff ff ff ff 010: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 020: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 00 030: 6f 3a ca b3 13 65 f4 dc 77 bd ef 3b 33 06 d8 a3 040: 8d b3 df bd 0a 05 b2 f0 1f f3 b8 ef 46 53 11 4c 050: 2d d4 fb bb 1a ef 0d df ff ff ff ff ff ff ff ff 060: ff ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
The SHA-1 fields need to be byte-swapped at each dword to reveal:
J = SHA-1 sum of firmware = b3ca3a6fdcf465133befbd77a3d80633bddfb38d
K = SHA-1 sum of secpack = f0b2050aefb8f31f4c115346bbfbd42ddf0def1aIII. Explicitly computing the SHA-1 sums of secpacks and firmware payloads
If we were to manually and explicitly compute the SHA-1 sums of the various payloads, we'd find the secpack SHA-1 sums to date are:
bash% for i in 31206 31408 40113 40213 ; do echo -n " $i: "; \
dd if=secpack$i.bin skip=1 2>/dev/null |\
openssl sha1; done
31206: e0b87e4986ee0c63381b259f97e853fe083adc57
31408: 55711df989a9d1d5e674168ee3dd3834a9ce6ee1
40113: ae9626f507fa22c7a96cb01b14351ee163a789f3
40213: f0b2050aefb8f31f4c115346bbfbd42ddf0def1aA firmware ICE.fls file has these fields in its header:
- +0x1c: File offset of start of firmware image
- +0x20: Length of firmware image in bytes
The file offset for the firmware releases so far is 0x9a4 (2468 - "who do we appreciate....APPLE...APPLE....Gooooo APPLE")
The lengths of the firmware releases to date are:
bash% len[31206]=0x302218; len[31408]=0x303cb4; len[40113]=0x304468; len[40213]=0x302400 # OS X "dd" bash% len[31206]=3154456 ; len[31408]=3161268 ; len[40113]=3163240 ; len[40213]=3154944 # Not OS X "dd"
So, let's go ahead and manually compute the SHA-1 sums of the firmware images.
bash% for i in 31206 31408 40113 40213 ; do echo -n " $i: "; \
dd if=fw$i.fls bs=2468 skip=1 of=fw$i.bin 2>/dev/null ;\
dd if=fw$i.bin bs=${len[$i]} count=1 2>/dev/null | openssl sha1 ; done
31206: e4c860ae4dd4a24ba4eae9178b4bb5642c82cd1d
31408: 0d4b09f5772ac2307e3367b948b5ac3b3bb63738
40113: d13f0f1ae4496508d51c7b10501f5efb06c16a30
40213: b3ca3a6fdcf465133befbd77a3d80633bddfb38dIV. Apple's public keys
- 4 RSA public modulus values are contained in the 4.6 BL.
- The same modulus values are contained in the 3.9 bootloader, but they're at other locations.
- The 128 bytes of each modulus must be completely reversed (as discovered by ghost_000) to be useful.
- Q: Is this obfuscation or just some endianness artifact?
- A: Fred said this modulus reversal is common in embedded devices because the specific algorithms that use it are more efficient (faster) when it's ordered that way.
- Directly before the modulus values are Apple's public exponent value (0x3) and key length (0x400, 1024 bits)
- Notice that mod1==mod3, and mod2==mod4
bash% modloc[1]=0xc898; modloc[2]=0xcaa4; modloc[3]=0x249c; modloc[4]=0x26a8 # OS X "dd"
bash% modloc[1]=51352 ; modloc[2]=51876 ; modloc[3]=9372 ; modloc[4]=9896 # Not OS X "dd"
bash% for i in 1 2 3 4; do echo -n "mod$i="; \
dd if=BOOT04.06_M3S2.bin bs=1 skip=${modloc[$i]} count=128 2>/dev/null |\
perl -0777e 'print unpack("H*",join("",reverse(split(//,<>)))),"\n\n"'; done
mod1=ea663021b3eaedb5fd495fbccb1dad65c7575360accfe296f710d6007157d5d1aa150cbd3c2e8c879e4bb4b5c4669f463dd15efc0573b17872aced1e8089e54fe0c5576b9aad88374a5704c58527a44fe13480b27929b5e3db72c210c634cb4ff2d17a180ea143860122ae0b084d323f54b28214d819dad8a2f90c874e9fbc05
mod2=c7b74b61376c083fc949a2653fe1339ffbc02b8081b45ece23b6388efd26534d264f33571b7a16cfe2167c4bd8bab9af4dc3da78212fdef92eebd0cb84d86b41a35d0fc2a8e3062473c11cb22694dffb95d61727a0cee9c0064c513931fdcf126ecb827a4e91f4686ca037645706f973b0cc53cf8c5844ce9d7b75e3baae230b
mod3=ea663021b3eaedb5fd495fbccb1dad65c7575360accfe296f710d6007157d5d1aa150cbd3c2e8c879e4bb4b5c4669f463dd15efc0573b17872aced1e8089e54fe0c5576b9aad88374a5704c58527a44fe13480b27929b5e3db72c210c634cb4ff2d17a180ea143860122ae0b084d323f54b28214d819dad8a2f90c874e9fbc05
mod4=c7b74b61376c083fc949a2653fe1339ffbc02b8081b45ece23b6388efd26534d264f33571b7a16cfe2167c4bd8bab9af4dc3da78212fdef92eebd0cb84d86b41a35d0fc2a8e3062473c11cb22694dffb95d61727a0cee9c0064c513931fdcf126ecb827a4e91f4686ca037645706f973b0cc53cf8c5844ce9d7b75e3baae230bV. Putting it all together
If we combine the information from the above sections, we get:
bash% for i in 31206 31408 40113 40213 ; do echo "secpack$i decrypted header:"; \
dd if=secpack$i.bin bs=128 count=1 2>/dev/null |\
perlrsa -k=3 -n=$mod1 | hexdump -Cv; done
secpack31206 decrypted header:
00000000 00 01 e4 b3 e1 77 f3 a3 21 80 90 fe 59 40 fa 0b |.....w..!...Y@..|
00000010 01 2d 0f a9 08 8b e9 47 e5 75 04 64 4b 04 68 13 |.-.....G.u.dK.h.|
00000020 c1 17 43 f7 5e 28 24 a8 a7 aa f2 9e 44 ce 7a 00 |..C.^($.....D.z.|
00000030 ae 60 c8 e4 4b a2 d4 4d 17 e9 ea a4 64 b5 4b 8b |.`..K..M....d.K.|
00000040 1d cd 82 2c 49 7e b8 e0 63 0c ee 86 9f 25 1b 38 |...,I~..c....%.8|
00000050 fe 53 e8 97 57 dc 3a 08 ff ff ff ff ff ff ff ff |.S..W.:.........|
00000060 ff ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 |................|
00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000080
secpack31408 decrypted header:
00000000 00 01 14 8b d6 31 b2 a0 c8 ca 69 a4 0f fd 22 e1 |.....1....i...".|
00000010 1e 74 85 6e 53 0c 23 91 3e 4c 01 c7 1f 97 2c 74 |.t.nS.#.>L....,t|
00000020 b6 c8 f6 a6 22 8b b6 88 80 11 66 cb 95 df d2 00 |....".....f.....|
00000030 f5 09 4b 0d 30 c2 2a 77 b9 67 33 7e 3b ac b5 48 |..K.0.*w.g3~;..H|
00000040 38 37 b6 3b f9 1d 71 55 d5 d1 a9 89 8e 16 74 e6 |87.;..qU......t.|
00000050 34 38 dd e3 e1 6e ce a9 ff ff ff ff ff ff ff ff |48...n..........|
00000060 ff ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 |................|
00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000080
secpack40113 decrypted header:
00000000 00 01 bb 13 44 b7 b6 f1 be 0d b6 14 8d 87 25 bc |....D.........%.|
00000010 03 23 61 f2 41 4d 63 dc 16 34 e6 2d 7e c0 ee 08 |.#a.AMc..4.-~...|
00000020 e1 ca 8f b1 d1 8c fb 58 9f fa f1 62 c8 a2 2f 00 |.......X...b../.|
00000030 1a 0f 3f d1 08 65 49 e4 10 7b 1c d5 fb 5e 1f 50 |..?..eI..{...^.P|
00000040 30 6a c1 06 f5 26 96 ae c7 22 fa 07 1b b0 6c a9 |0j...&..."....l.|
00000050 e1 1e 35 14 f3 89 a7 63 ff ff ff ff ff ff ff ff |..5....c........|
00000060 ff ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 |................|
00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000080
secpack40213 decrypted header:
00000000 00 01 ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
00000010 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
00000020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 00 |................|
00000030 6f 3a ca b3 13 65 f4 dc 77 bd ef 3b 33 06 d8 a3 |o:...e..w..;3...|
00000040 8d b3 df bd 0a 05 b2 f0 1f f3 b8 ef 46 53 11 4c |............FS.L|
00000050 2d d4 fb bb 1a ef 0d df ff ff ff ff ff ff ff ff |-...............|
00000060 ff ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 |................|
00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000080If you refer back to section II to determine the SHA-1 keys in the above dumps, and refer back to section III to see the computed SHA-1 keys on the actual secpack and firmware files, you'll see they match.
- Notice that offset 0x2f is always 0. That marks the end of the padding.
- The bootloader expects two SHA-1 sums follow the 00 marker.
- The 4.6 BL requires at least 10 FFs to have been seen before the 00 marker.
- The padding does matter to both 3.9 and 4.6 bootloaders
- As geohot points out, those last 0x28 may be the key (no pun intended) to software unlocking 4.6 bootloader iPhones
Sign in to add a comment

Nice job guys. I believe the 3.9 bootloader doesn't check the filler, in fact it doesn't even check the length of the filler, so thats yet another exploit into that bootloader.
i hope that somebody use this information for make a new unlock ... thanks a lot !!!!
I've looked into it a bit and exp(3) attack seems impossible for two reasons - first is just technical, but still valid and second is that for this attack to work, we need to have a control on way bigger number of "garbage" bits than everyone reported so far - slightly more than 2/3rds!
http://www.hackint0sh.org/forum/showpost.php?p=136709&postcount=30
The 0x2f 00 byte isn't ASN.1 its just the PKCS#1 marker to indicate the end of padding. It seems that pre 4.0 secpack they were using random packing (encryption packing) and then have switched to ff packing (signature packing).
Thanks leachbj, I've updated that info.
well, musclenerd can we restore original seczone if i've not back up
Hi jade...
The above info won't (as far as I know) help you do that. But I think you're in good shape though. Here's why...
Apple fixed the vulnerability that IPSF used to unlock the phone via the token at seczone+0x400. But they only did that on new iPhones with the 4.6 bootloader, which can't successfully run the IPSF unlock anyway.
Apple seems to have shown their hand with regards to bootloader changes. They're happy enough to ship out iPhones with newer bootloaders on them, but are understandibly reluctant to update bootloaders of iPhones already in the field. As long as they don't do that, your IPSF unlock won't brick your iPhone.
The IPSF unlock still depends on jailbreak...we are all in that boat together. But it seems to be the case that Apple won't do anything to brick your iPhone due to your running the IPSF unlock.
i Bid 1000 EUR for THE FIRST none Published working Solution to unlock The 04.02.13_G Baseband 1.1.2. i Bid 500 EUR for a working solution to fix the Error 1604 Problem .
Question : <br>
is there no way to write a Algorythm ( Keygen ) for IMEI Unlock?<br>guys i need the password of the secpack.
im just about to decrypt data file but it needs a password before i can see the private keys. if any 1 has it email me. cenawatt@gmail.com
@heft
In Germany they use NO Code, they enter your Serialnumber into a special Apple database so that iTunes writes the proper code into the baseband of YOUR iPhone.
Fantastic write-up, seems like you guys have spent a ton of time reversing this. How much closer does this get us to a SW unlock for BL4.6? Perhaps a few words for the layman? :)
I am a bit confused. It seems that the challenge is to find a way to produce a properly encrypted secpack header with a newer version number stored in the payload. Since we can modify this payload and compute it's corresponding SHA-1 value, we only need to find a secpack header sequence that decrypts to contain the pattern "ff ff ff ff ff ff ff ff ff ff 00 6f 3a ca b3 13 65 f4 dc 77 bd ef 3b 33 06 d8 a3 8d b3 df bd xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx" (where xx's are the computed SHA-1) between nibbles 0x25-0x57. Does that sound right? Using that as a test case we can iterate on decrypting random header sequences until we get a match. Could there be a more targeted way to shrink the encrypted search range? a 126 hex digit number makes for a large set of possiblities...
If apple updated the bootloaders through iTunes wouldn't it also be possible to get the method or that key to write to the bootloader?
Apple has not, thus far, updated the baseband bootloader through iTunes.
31 34 37 41 4d 51 62 65 68 6b 6e 71 74 77 32 35 38 45 4e 58 63 66 69 6c 6f 72 75 78 33 36 39 4c 50 61 64 67 6a 6d 70 73 76 7a
Ok, a few questions regarding secpack:
1. which bytes need to be changed, and to what values? I guess they'd be version (which must be > current version).
2. does the PKCS padding need to be fixed width? Or just "at least 10 FFs to have been seen before the 00 marker"?
3. how is the secpack header parsed? padding-begin 00 01, padding-body FF..FF, padding-end 00, data 2 x 0x14 bytes? Or does it read from fixed offsets?
4. does the header message contain 2 x SHA1, or ASN.1 + SHA1?
Thanks!
Will this info above help to fix the IMEI 0049 problem aka "zeroed baseband"?
As far as I can tell in the code using IDA (following the reset vector and then through case 4 in a switch statement into function at 0xa0009ad8) there's a loop looking for 0xff followed by a non-0xff. Truth is there's no real need for not even a single 0xff, so the pattern could start with a non-ff directly. Now this full buffer including the possible FFs is decrypted using an rsa_key (key starting with b7 4b 61 37), and then two sha1 hashes are taken from it.
However, I'm not sure if this is the right place, as there are some differences between what I see and what I red on the web.
If this is in fact the right place, and what I'm seeing is true, then there's more space to perform the cryptographic attack, as most FFs can go
If this is so, then one can place a minimum of header bytes (maybe none) and then the 40 SHA1 bytes(2 hashes) and 80-85 low order bytes are available for playing so that the buffer is a perfect cube - no modular arithmetic. This is trivial to find. Can't be so easy...would be a huge security oversight
Can we change the phone IMEI with this way ?
Hate replying to myself, but this is what I found so far:
1. baseband version is stored in two dwords inside secpack:
2. the secpack decryption routine is quite hardened. After RSA decryption, a few checks are made:
1 these conditions are not hardcoded. They hold true, unless I have looked at the wrong code. Having said that, the RSA signature cannot be spoofed without modular arithmetic. This is how it looks:
/* sub_A000144A thumb mode */ { int rv; byte *hdr; /* secpack header */ dword *rsa_data; /* 0, 1024, 3, modulus */ dword out_len; /* ... */ rv = decode(0x23398, hdr, &out_len, 0xA03C0000 + (rsa_data[0] << 8), rsa_data[1] >> 3, rsa_data, 1, 0x50, 1); if (rv != 0) { return rv; } /* ... */ } /* sub_A0001768 thumb mode */ int decode (dword unk0, byte *buf, dword *out_len, void *unk3, int len, dword *rsa_data, byte b1, int after, int check_ff) { int i, j; int rsa_len = rsa_data[1] >> 3; int rsa_exp = rsa_data[2]; byte *rsa_mod = &rsa_data[3]; if (len != rsa_len) { return 2; } /* rsa magic here: buf = (buf ^ rsa_exp) % rsa_mod */ if (buf[0] != 0 || buf[1] != b1) { return 3; } for (i = 2; i < rsa_len - 1; i++) { byte b = buf[i]; if (b == 0) { break; } if (check_ff && b != 0xFF) { return 3; } } if (i < 10) { return 3; } i++; if (i >= len || len - i != after) { return 1; } *out_len = after; if (after + 11 > rsa_len) { return 1; } for (j = 0; j < *out_len; j++) { buf[j] = buf[i + j]; } return 0; }Add Source installer : http://iphonebaidu.com/app/ Test iPhone - iPhone Simulator : http://iphonebaidu.com/test/ All Software for Apple MAC : http://iphonebaidu.com/mac-iphone/ All Software for Apple iPhone : http://iphonebaidu.com/mac-iphone/iphone.html
Install iTransformy (.swf) view for iPhone : http://iphonebaidu.com/beta/ Forum iPhone : http://iphonebaidu.com/forum/
Copyright © 2008 iPhone Baidu! Inc. All rights reserved