-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepub.c
77 lines (69 loc) · 1.57 KB
/
repub.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
#include <stdbool.h> // for bool type
#include <stdio.h> // for printf, etc
#include <stdlib.h>
#include <unistd.h> // for fork
#include <string.h> // for strlen, strcasecmp, etc
#include <ctype.h>
#include <signal.h> // for signal
#include <sys/types.h>
#include <sys/wait.h> // for wait, waitpid
#include <errno.h>
#define NUM_FUCK_YOUS 15
#define RECHARGE_TIME 2
#define BOMB_PAYLOAD "twilight.txt"
int main(int argc, char* argv[])
{
if (argc < 2)
{
return 0;
}
char* target = argv[1];
int fds[2];
pipe(fds);
pid_t pid = fork();
if (pid == 0)
{
dup2(fds[1], 1);
close(fds[0]);
close(fds[1]);
char* whoArgs[2] = {"who", NULL};
execvp(whoArgs[0], whoArgs);
}
waitpid(pid, NULL, 0);
bool targetFound = false;
char buf[101];
buf[100] = '\0';
close(fds[1]);
while(true)
{
int numRead = read(fds[0], buf, 100);
if (numRead <= 0)
break;
buf[numRead] = '\0';
if (strstr(buf, target) != NULL)
{
targetFound = true;
break;
}
}
if (!targetFound)
{
printf("0\n");
return 0;
}
printf("%d\n", (NUM_FUCK_YOUS - 1) * RECHARGE_TIME + 3);
for (int i = 0; i < NUM_FUCK_YOUS; i++)
{
pid = fork();
if (pid == 0)
{
dup2(fileno(fopen(BOMB_PAYLOAD, "r")), 0);
char* args[3] = {"write", target, NULL};
execvp(args[0], args);
}
waitpid(pid, NULL, 0);
if (i != NUM_FUCK_YOUS - 1)
sleep(RECHARGE_TIME);
}
return 0;
}