This repository was archived by the owner on Sep 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput_count.c
More file actions
136 lines (127 loc) · 3.6 KB
/
Copy pathinput_count.c
File metadata and controls
136 lines (127 loc) · 3.6 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <stdio.h>
#include <stdlib.h>
// Process functions
int syn_process(char **syn_data, FILE *outp);
int ack_process(char **ack_data, FILE *outp);
void print_usage();
int main(int argc, char *argv[]) {
FILE *outp;
printf("# of Args %d \n",argc);
printf("argv[1] %s\n", argv[1]);
// printf("argv[2] %s\n\n", argv[2]);
// printf("argv[3] %s\n", argv[3]);
// printf("argv[4] %s\n\n", argv[4]);
if (argc < 2) {
printf("Fatal Usage Error\n");
print_usage();
//printf("Usage:\n-S for SYN processing\n-A for SYN-ACK processing\n\n");
return 0;
}
if (strcmp(argv[1], "-S") == 0) {
printf("SYN function\n");
//outp = fopen("syn.log", "a");
//send argv[2] to SYN stream capture
}
else if (strcmp(argv[1], "-A") == 0) {
printf("SYN-ACK function\n");
//outp = fopen("syn-ack.log", "a");
//send argv[2] to SYN-ACK stream capture
}
else {
printf("Fatal Usage Error\n");
print_usage();
return 0;
}
/*
if (strcmp(argv[3], "-S") == 0) {
printf("SYN function\n");
//send argv[4] to SYN stream capture
}
else if (strcmp(argv[3], "-A") == 0) {
printf("SYN-ACK function\n");
//send argv[4] to SYN-ACK stream capture
}
else {
printf("Fatal Usage Error\n");
print_usage();
//printf("Usage:\n-S for SYN processing\n-A for SYN-ACK processing\n\n");
return 0;
}
*/
int count = 1;
char *readin = NULL;
int exit_char = 0;
size_t slen = 0;
// Actually daemonize
// Check existence of DB and initialize if it does not
// table: ip; syn-print; sack-print; (mac? maybe...)
printf("OPENING A STREAM!\n");
if (stdin == NULL) { printf("OH NOES!\n"); exit(1); }
printf("STREAM OPEN, ENTERING LOOP!\nTo exit daemon type \"Ctrl-D\"\n");
while(1) {
/*scanf("%c", exit_char);*/
//printf("Exit Character: %s \n", exit_char);
//printf("Exit Character: %s \n", exit_char);
while((exit_char=getchar()) == EOF) {
printf("Exiting input count daemon\n");
//fclose(outp);
return 0;
}
// POTENTIAL BUG: getline returns -1 in EOF, but also on other errors
// clear all variables changed in loop every loop
//
if(getline(&readin, &slen, stdin) != -1) {
//printf("FOUND A LINE! NUMBER: %d\n", count);
//process info collected process();
//printf("Processing %s \n", readin);
//printf("size_t %zd \n", slen);
if (strcmp(argv[1], "-S") == 0) {
//printf("SYN function\n");
syn_process(&readin, outp);
}
else if (strcmp(argv[1], "-A") == 0) {
//printf("SYN-ACK function\n");
ack_process(&readin, outp);
//send argv[2] to SYN-ACK stream capture
}
// grab source and fingerprint (with regex)
// existing_syn=(SELECT syn FROM table WHERE IP=$ip)
// if existing_syn == NULL => new_node alert; print to found nodes file
// elsif existing_sys != greped_sys => rouge node alert
// else {}
count++;
}
// Another if group to cover the SYN-ACK
else {
printf("NO LINE FOUND, WAITING 10secs\n");
sleep(10);
}
}
}
void print_usage()
{
printf("Print Usage Function\n");
printf("Usage:\n-S for SYN processing\n-A for SYN-ACK processing\n\n");
return;
}
int syn_process(char **syn_data, FILE *outp)
{
//print p0f data to syn.log file
//printf("SYN_process() function. \n");
outp = fopen("syn.log", "a");
fprintf(outp, "Data: %s", *syn_data);
fclose(outp);
//printf("Data: %s \n", *syn_data);
//fclose(outp);
return;
}
int ack_process(char **ack_data, FILE *outp)
{
//print p0f data to syn-ack.log file
//printf("ACK_process() function. \n");
outp = fopen("syn-ack.log", "a");
fprintf(outp, "Data: %s", *ack_data);
fclose(outp);
//printf("Data: %s \n", *ack_data);
return;
}