-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathhard_coded_credential1.c
More file actions
39 lines (33 loc) · 1.18 KB
/
Copy pathhard_coded_credential1.c
File metadata and controls
39 lines (33 loc) · 1.18 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
/*
This program demonstrates the use of a hardcoded password to access a
system-critical file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char inputPassword[50];
const char *hardcodedPassword = "secret123"; // Hardcoded password
printf("Enter password to access the system file: ");
fgets(inputPassword, sizeof(inputPassword), stdin);
inputPassword[strcspn(inputPassword, "\n")] = 0; // Remove newline character
if (strcmp(inputPassword, hardcodedPassword) == 0) {
printf("Access granted. Reading system file...\n");
// Attempting to read a system-critical file (with a fake filename)
const char *criticalFilePath = "/etc/fake_critical_file.conf";
FILE *file = fopen(criticalFilePath, "r");
if (file == NULL) {
perror("Error opening file");
} else {
// Read and print the contents of the file (hypothetical)
char buffer[256];
while (fgets(buffer, sizeof(buffer), file) != NULL) {
printf("%s", buffer);
}
fclose(file);
}
} else {
printf("Access denied.\n");
}
return 0;
}