My favorites
▼
|
Sign in
chronicdev
Chronic Dev public projects, tools, source code, information, and more
Project Home
Downloads
Wiki
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
Genpass
/
genpass.c
r213
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// genpass
// get asr key for 3.x firmware
//
// by posixninja, geohot, chronic, and #iphone-rce
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <openssl/sha.h>
#include <openssl/evp.h>
#define BUF_SIZE 0x100000
#define SHA256_DIGEST_LENGTH 32
typedef unsigned char uint8;
typedef unsigned int uint32;
typedef unsigned long long uint64;
uint64 u32_to_u64(uint32 msq, uint32 lsq) {
uint64 ms = (uint64)msq;
uint64 ls = (uint64)lsq;
return ls | (ms << 32);
}
uint64 hash_platform(const char* platform) {
uint8* md = malloc(SHA_DIGEST_LENGTH);
SHA1(platform, strlen(platform), md);
uint64 hash = u32_to_u64(
((md[0] << 24) | (md[1] << 16) | (md[2] << 8) | md[3]),
((md[4] << 24) | (md[5] << 16) | (md[6] << 8) | md[7])
);
free(md);
return hash;
}
uint64 ramdisk_size(const char* ramdisk) {
struct stat filestat;
if(stat(ramdisk, &filestat) < 0) {
return 0;
}
return (uint64)filestat.st_size;
}
void keydump(uint8* passphrase,int l) {
int i=0;
for(i=0; i<l; i++) {
printf("%02x", passphrase[i]);
} printf("\n");
}
int compare(const uint32* a, const uint32* b) {
if(*a < *b) return -1;
if(*a > *b) return 1;
return 0;
}
const char platform[]="s5l8900x";
const char ramdisk[]="ramdisk.dmg";
int main(int argc, char* argv[]) {
if(argc<3) {printf("%s: <platform> <ramdisk> <main>\n", argv[0]); return -1;}
uint32 saltedHash[4];
uint64 salt[4];
salt[0] = 0xad79d29de5e2ac9e;
salt[1] = 0xe6af2eb19e23925b;
salt[2] = 0x3f1375b4bd88815c;
salt[3] = 0x3bdff4e5564a9f87;
FILE* fd = fopen(argv[2], "rb");
int i = 0;
int x = 0;
SHA256_CTX ctx;
uint8* buffer = NULL;
uint8* passphrase = NULL;
uint64 totalSize = ramdisk_size(argv[2]);
uint64 platformHash = hash_platform(argv[1]);
/*printf("size: %I64x plat: %s plathash %I64x\n", totalSize,
platform,platformHash);*/
for(i=0;i<4;i++)
{
salt[i]+=platformHash;
//printf("%d: %I64x\n", i, salt[i]);
}
for(i = 0; i < 4; i++) {
saltedHash[i] = ((uint32)(salt[i] % totalSize)) & 0xFFFFFE00;
}
qsort(&saltedHash, 4, 4, &compare);
SHA256_Init(&ctx);
SHA256_Update(&ctx, salt, 32);
int r=0;
i=0; //hash count
buffer = malloc(BUF_SIZE);
passphrase = malloc(SHA256_DIGEST_LENGTH);
while(r<totalSize) {
x = fread(buffer, 1, BUF_SIZE, fd);
SHA256_Update(&ctx, buffer, x);
if(i<4) //some salts remain
{
if(r >= (saltedHash[i]+0x4000)) i++;
else if( r < saltedHash[i] && saltedHash[i] < (r+x) )
{
if( (saltedHash[i]+0x4000) < r )
SHA256_Update(&ctx, buffer, saltedHash[i]-r);
else SHA256_Update(&ctx, buffer+(saltedHash[i]-r),
( (x-(saltedHash[i]-r))<0x4000) ? (x-(saltedHash[i]-r)) : 0x4000 );
}
}
r+=x;
}
fclose(fd);
SHA256_Final(passphrase, &ctx);
printf("passphrase: ");
keydump(passphrase, SHA256_DIGEST_LENGTH);
if(buffer) free(buffer);
if(argc==4) //do main as well
{
fd=fopen(argv[3],"rb");
EVP_CIPHER_CTX ctx;
int offset=0x1D4;
uint8 data[0x30];
uint8 out[0x30]; int outlen,tmplen;
int a;
for(a=0;a<7;a++)
{
fseek(fd, offset, SEEK_SET); offset+=0x268;
fread(data, 1, 0x30, fd);
EVP_CIPHER_CTX_init(&ctx);
EVP_DecryptInit_ex(&ctx, EVP_des_ede3_cbc(),
NULL, passphrase, &passphrase[24]);
EVP_DecryptUpdate(&ctx, out, &outlen, data, 0x30);
if(!EVP_DecryptFinal_ex(&ctx, out + outlen, &tmplen))
printf("not block %d\n", a);
else
break;
}
printf("vfdecryptk: ");
keydump(out, 0x24);
}
if(passphrase) free(passphrase);
return 0;
}
Show details
Hide details
Change log
r208
by will.chronicdev on Apr 6, 2009
Diff
pushing Genpass to public repo
Go to:
/trunk/Genpass
/trunk/Genpass/build-mac
/trunk/Genpass/build-mac/genpass
/trunk/Genpass/genpass.c
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 3628 bytes, 168 lines
View raw file
Powered by
Google Project Hosting