-
Notifications
You must be signed in to change notification settings - Fork 0
/
decrypt_luks.c
79 lines (62 loc) · 1.87 KB
/
decrypt_luks.c
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
#include <stdio.h>
#include <string.h>
#include <libcryptsetup.h>
int main(int argc, char **argv)
{
struct crypt_device *cd = NULL;
const char *data_device = NULL;
const char *activated_name = "cryptsetup_mount_name";
const char* header_device;
uint32_t flags = 0;
int r;
if (argc < 2)
{
printf("Usage: ./decrypt_luks device_name wordlist_file_name\n\n");
return 0;
}
header_device = argv[1];
if ((r = crypt_init(&cd, header_device)))
goto out;
if ((r = crypt_load(cd, CRYPT_LUKS1, NULL)))
goto out;
if (!data_device && (crypt_get_data_offset(cd) < 8)) {//crypt_get_data_offset(cd)=4096
goto out;
}
crypt_set_timeout(cd, 0); // 0
crypt_set_password_retry(cd, 3); //3
crypt_set_password_verify(cd, 0); //0
crypt_set_iteration_time(cd, 100);
do{
char *key_file_name = argv[2];
FILE *key_file;
int len;
char pass[256];
key_file = fopen(key_file_name, "r");
if(!key_file){
printf("File open error\n");
goto out;
}
for (;;)
{
memset(pass,0,sizeof(pass));
fscanf(key_file,"%s",pass);
len = strlen(pass);
if(len < 1)
break;
printf("pass= %s len= %d\n",pass,len);
r = crypt_activate_by_passphrase(cd, /* crypt context */
activated_name, /* device name to activate */
CRYPT_ANY_SLOT,/* which slot use (ANY - try all) */
pass, len, /* passphrase */
flags); /* flags */
if (r >= 0) {
printf("\nFound Passphase! %s\n\n",pass);
break;
}
}
fclose(key_file);
} while(0);
out:
crypt_free(cd);
return r;
}