-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwinlock.c
More file actions
248 lines (210 loc) · 6.28 KB
/
winlock.c
File metadata and controls
248 lines (210 loc) · 6.28 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <openssl/evp.h>
/*****************************************************************************
* use this tool, to test wordlist files against files encrypted with
* 'MyWinLocker' from egistec. the software is usually bundled to acer
* products and is also know as 'eDataSecurity'
*
* written by defa
* no license at all, do what you want
*
* compile: gcc -lcrypto -o winlock winlock.c
*
****************************************************************************/
void hexdump (void *ptr, int buflen);
int16_t makekey (unsigned char *key, const unsigned char *pass,
int32_t length);
int32_t tryKey (const unsigned char *key, const unsigned char *crypted,
int32_t * cryptedl, const unsigned char *challenge);
const unsigned char iv[] = "1631330216313302";
int
main (int argc, char *argv[])
{
int iRet = 0;
unsigned char key[0x20];
// check wether we have all parmeters
if (argc < 3)
{
printf ("Usage: %s crypted_file wordlist\n", argv[0]);
goto exitProgram;
}
// we open the file
FILE *fh = fopen (argv[1], "r");
if (!fh)
{
printf ("Crypted file %s not found. Terminating.\n", argv[1]);
iRet = -1;
goto exitProgram;
}
fseek (fh, 4, SEEK_CUR); // jump over first 4 bytes
/* i did not reverse this enough, sometimes it's there, sometimes not
int32_t hintlength = 0;
fread (&hintlength, sizeof (int32_t), 1, fh);
printf ("Hint is %d (%#x) long - jumping over it\n", hintlength, hintlength);
fseek (fh, hintlength, SEEK_CUR);
*/
int32_t origfilenamelength = 0;
fread (&origfilenamelength, sizeof (int32_t), 1, fh);
printf ("Original filename is %d (%#x)long - jumping over it\n",
origfilenamelength, origfilenamelength);
fseek (fh, origfilenamelength + sizeof (int32_t), SEEK_CUR);
int32_t challengel = 0x14; // length of sha1 hash
// i previously thought this was the challenge length, but i was wrong
// fread (&challengel, sizeof (int32_t), 1, fh);
fseek (fh, sizeof (int32_t), SEEK_CUR);
printf ("Challenge is %d long - reading it\n", challengel);
unsigned char challenge[100];
memset (challenge, 0, 100);
fread (challenge, 1, challengel, fh);
printf ("challenge:\n");
hexdump (challenge, challengel);
unsigned char crypted[100];
int32_t cryptedl = 0x18;
memset (crypted, 0, 100);
fread (crypted, 1, cryptedl, fh);
printf ("crypted:\n");
hexdump (crypted, cryptedl);
fclose (fh);
FILE *wlh;
wlh = fopen (argv[2], "r");
printf("Trying to open wordlist %s\n", argv[2]);
if (NULL == wlh)
{
printf ("No wordlist given. Usage: %s <wordlist>\n", argv[0]);
iRet = -2;
goto exitProgram;
}
unsigned char* pass = malloc(100);
unsigned char* tmpass = malloc(100);
uint32_t i = 0;
while (fgets (pass, 100, wlh))
{
uint32_t passl = strlen (pass);
pass[passl - 1] = 0;
passl--;
char number[3];
uint32_t numberl = passl + 2;
int j = 0;
for (j = 0; j <= 100; j++)
{
if (0 == j)
{
strncpy (tmpass, pass, 100);
makekey (key, tmpass, passl);
j += 120;
}
else
{
number[0] = j / 10 + 0x30;
number[1] = j % 10 + 0x30;
number[2] = 0;
strncpy (tmpass, pass, 100);
strcat (tmpass, number);
//printf ("%s\n", tmpass);
makekey (key, tmpass, numberl);
}
if (0 == tryKey (key, crypted, &cryptedl, challenge))
{
printf ("found pass! its: %s\n", tmpass);
return 0;
}
// if (!(i % 10000))
// {
printf ("%d passwords tested. current try: %s\n", i, tmpass);
// }
i++;
}
}
exitProgram:
return iRet;
}
int16_t
makekey (unsigned char *key, const unsigned char *pass, int32_t length)
{
EVP_MD_CTX mdctx;
EVP_CIPHER_CTX cictx;
EVP_MD_CTX_init (&mdctx);
EVP_CIPHER_CTX_init (&cictx);
unsigned char key2[24];
unsigned char out[100];
int outl = 0x10;
int keyl = 0x18;
#ifdef DEBUG
printf ("%s\n", pass);
#endif
// initialize SSL
EVP_MD_CTX_init (&mdctx);
EVP_CIPHER_CTX_init (&cictx);
memset (key2, 0x01, 24);
OpenSSL_add_all_digests ();
// create the md5 hash of the password
EVP_DigestInit_ex (&mdctx, EVP_md5 (), NULL);
EVP_DigestUpdate (&mdctx, pass, length);
EVP_DigestFinal_ex (&mdctx, out, &outl);
EVP_MD_CTX_cleanup (&mdctx);
//copy the md5 hash to the beginning of the key, leave the rest filled with 0x01
memcpy (key2, out, 0x10);
// printf("%s line %d\n", __FUNCTION__, __LINE__);
//encrypt the key2 with itself
OpenSSL_add_all_ciphers ();
EVP_EncryptInit_ex (&cictx, EVP_aes_192_cfb (), 0, key2, iv);
EVP_EncryptUpdate (&cictx, key, &keyl, key2, 0x18);
EVP_EncryptFinal_ex (&cictx, key, &keyl);
EVP_CIPHER_CTX_cleanup (&cictx);
// now we have the key in 'result'
// printf ("key:\n");
// hexdump (key, 0x18);
EVP_cleanup ();
return keyl;
}
int32_t
tryKey (const unsigned char *key, const unsigned char *crypted,
int32_t * cryptedl, const unsigned char *challenge)
{
EVP_MD_CTX mdctx;
EVP_CIPHER_CTX cictx;
EVP_MD_CTX_init (&mdctx);
EVP_CIPHER_CTX_init (&cictx);
int32_t randdatal = 0x18;
unsigned char randdata[0x24];
EVP_DecryptInit_ex (&cictx, EVP_aes_192_cfb (), NULL, key, iv);
EVP_DecryptUpdate (&cictx, randdata, &randdatal, crypted, *cryptedl);
EVP_DecryptFinal_ex (&cictx, randdata, &randdatal);
EVP_CIPHER_CTX_cleanup (&cictx);
//printf ("randdata (%p):\n", randdata);
//hexdump (randdata, 0x18);
unsigned char sha1[0x18];
int32_t sha1l = 0x14;
// create the sha1 hash of the decrypted randdata
memset (&mdctx, 0, sizeof (EVP_MD_CTX));
EVP_DigestInit_ex (&mdctx, EVP_sha1 (), NULL);
EVP_DigestUpdate (&mdctx, randdata, 0x18);
EVP_DigestFinal_ex (&mdctx, sha1, NULL);
EVP_MD_CTX_cleanup (&mdctx);
//printf ("sha1:\n");
//hexdump (sha1, sha1l);
EVP_cleanup ();
return strncmp (sha1, challenge, sha1l);
}
void
hexdump (void *ptr, int buflen)
{
unsigned char *buf = (unsigned char *) ptr;
int i, j;
for (i = 0; i < buflen; i += 16)
{
printf ("%06x: ", i);
for (j = 0; j < 16; j++)
if (i + j < buflen)
printf ("%02x ", buf[i + j]);
else
printf (" ");
printf (" ");
for (j = 0; j < 16; j++)
if (i + j < buflen)
printf ("%c", isprint (buf[i + j]) ? buf[i + j] : '.');
printf ("\n");
}
}