-
Notifications
You must be signed in to change notification settings - Fork 5
/
impossible_v2.c
79 lines (58 loc) · 1.86 KB
/
impossible_v2.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
// gcc -no-pie -Wno-format-security -o impossible_v2 impossible_v2.c aes.c
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "aes.h"
#define MSG_SIZE 40
// AES implem source : https://github.com/noahp/aes_c
unsigned char* expected = "\xde\xad\xbe\xef\xde\xad\xbe\xef\xca\xfe\xba\xbe\xca\xfe\xba\xbe" ;
unsigned char key[16];
unsigned char message[MSG_SIZE];
int main(void){
FILE* fd;
unsigned char tmp_message[MSG_SIZE];
char c;
printf("I've implemented a 1-block AES ECB 128 cipher that uses a random key.\n"
"Try to give me a message such as AES_Encrypt(message, key) = 0xdeadbeefdeadbeefcafebabecafebabe.\n"
"(don't try too much, this is impossible).\n\n");
fflush(stdout);
fd = fopen("/dev/urandom", "rb");
fread(key, 16, 1, fd);
fclose(fd);
printf("Enter your message: ");
fflush(stdout);
fgets(tmp_message, MSG_SIZE, stdin);
sprintf(message, tmp_message);
printf("Do you want to change it ? (y/n) ");
fflush(stdout);
c = getc(stdin);
// get the "\n"
getc(stdin);
if(c == 'y'){
printf("Enter your message (last chance): ");
fflush(stdout);
fgets(tmp_message, MSG_SIZE, stdin);
sprintf(message, tmp_message);
}
printf("So, this is your final message: ");
for(int i=0 ; i < MSG_SIZE ; i++){
printf("%02x", message[i]);
}
puts("\n");
fflush(stdout);
AES_Encrypt(message, key);
if(memcmp(message, expected, 16) == 0){
puts("WHAT ?! THIS IS IMPOSSIBLE !!!");
fd = fopen("flag.txt", "r");
while((c = getc(fd)) != EOF){
printf("%c", c);
}
fflush(stdout);
fclose(fd);
} else {
puts("Well, I guess you're not this smart :)");
fflush(stdout);
}
return EXIT_SUCCESS;
}