-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbomb.c
97 lines (88 loc) · 1.92 KB
/
bomb.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
// Hi {{ github_username }}, this is your challenge
void print_flag()
{
system("cat flag.txt");
}
void goBoom()
{
printf("BOOM!\n\nYou failed.\n");
exit(0);
}
void functionZero(char *buffer)
{
if (strcmp(buffer, "{{ foo0_sol }}") != 0) {
goBoom();
}
}
void functionOne(char *buffer)
{
int magicNumber = {{ rand_scanf_safe_int() | saveas('foo1_sol') }};
if (*(int *) buffer != magicNumber) {
goBoom();
}
}
void functionTwo(char *buffer)
{
int i = 0;
char string[] = "{{ rand_str(10,15, alpha_uppercase) | saveas('foo2_sol') }}";
const size_t len = strlen(string);
for (i = 0; i < len; i++) {
if (string[i] != buffer[i]) {
goBoom();
}
}
}
void functionThree(char *buffer)
{
if (strlen(buffer) > 3)
goBoom();
int one = atoi(buffer);
if ({{ IntPolynomial(foo3_sol).to_str('one') }} == 0) {
printf("You're getting better!\n");
} else {
goBoom();
}
}
void functionFour(char *buffer)
{
char buffer2[10];
strncpy(buffer2, buffer, 10);
printf("Validating Input 4\n");
if (buffer2[0] + buffer2[8] == {{ foo4_sol[0]+foo4_sol[8] }}) {
if (buffer2[1] + buffer2[7] == {{ foo4_sol[1]+foo4_sol[7] }}) {
if (buffer2[2] + buffer2[6] == {{ foo4_sol[2]+foo4_sol[6] }}) {
if (buffer2[3] + buffer2[5] == {{ foo4_sol[3]+foo4_sol[5] }}) {
if (buffer2[4] == {{ foo4_sol[4] }})
printf("Good job.\n");
} else
goBoom();
} else
goBoom();
} else
goBoom();
} else
goBoom();
}
int main()
{
char buffer[64];
void (*functionArray[])(char *) =
{ &functionZero, &functionOne, &functionTwo, &functionThree,
&functionFour };
void (*func)(char *);
int i;
setvbuf(stdout, NULL, _IONBF, 0);
printf("Hi!\nI am a BOMB!\nGive me the right inputs or I'll explode.\n");
for (i = 0; i < 5; i++) {
printf("Enter input #%d: ", i + 1);
scanf("%s", buffer);
func = functionArray[i];
func(buffer);
}
print_flag();
return 0;
}