-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.c
58 lines (46 loc) · 1.15 KB
/
code.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
//
// gcc -m32 code.c -o binary-test
//
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#define BUFFER_SIZE 64
#pragma weak check_credentials
int check_credentials(unsigned long matricule, char* password) {
return 0;
}
#pragma weak get_flag
char* get_flag(unsigned long matricule, char* password) {
return "flag-is-not-me";
}
void ask_credentials() {
char* flag;
unsigned long matricule;
char password[BUFFER_SIZE];
printf("Username: ");
if(scanf("%lu", &matricule) != 1) {
printf("Error\n");
return;
}
printf("Password: ");
if(scanf("%s", password) != 1) {
printf("Error\n");
return;
}
flag = get_flag(matricule, password);
char msg[BUFFER_SIZE];
snprintf(msg, BUFFER_SIZE, "Username: %lu\nPassword: %s\n", matricule, password);
dprintf(1, msg);
if(!check_credentials(matricule, password)) {
dprintf(1, "Invalid credentials.\n");
return;
}
snprintf(msg, BUFFER_SIZE, "Login successful, here's the flag: %s\n", flag);
dprintf(1, msg);
}
#pragma weak main
int main() {
ask_credentials();
return 0;
}