forked from NoraCodes/crackmes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrackme07.c
57 lines (46 loc) · 1.08 KB
/
crackme07.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
// Checks that the password is correct and that the time is between 0500 and 0659 local
#define PASSWORD "password1"
#define PASSLEN 9
void succeed() {
printf("Access granted!\n");
exit(0);
}
void fail() {
printf("Access denied.\n");
exit(1);
}
int cur_hour() {
time_t rawtime;
time(&rawtime);
if (errno != 0) {
printf("ERROR: Could not get time: %s", strerror(errno));
return(-1);
}
struct tm *current_time = localtime(&rawtime);
if (errno != 0) {
printf("ERROR: Could not get time: %s", strerror(errno));
return(-1);
}
return current_time->tm_hour;
}
int main(int argc, char** argv) {
if (argc != 2) {
printf("Need exactly one argument.\n");
return -1;
}
int hour = cur_hour();
char* input = argv[1];
if (strncmp(input, PASSWORD, PASSLEN) != 0) {
fail();
}
// Fail if not between 0500 and 0659
if (hour < 5 || hour > 6) {
fail();
}
succeed();
}