1 /* author: Kacper Wysocki <kwy@redpill-linpro.com> */
5 #include "../sys_func.h"
8 output_plugin p_sguil
= {
9 .init
= &init_output_sguil
,
13 .connection
= &sguil_connection
,
15 .rotate
= &sguil_rotate
,
19 output_plugin
*init_log_sguil(){
23 int init_output_sguil(output_plugin
*p
, const char* log_prefix
, int check_time
)
26 static char filename
[PATH_MAX
];
27 struct log_sguil
*sguil_data
;
29 elog("sguil plugin on but no output directory!");
33 check_time
= (int) time(NULL
);
34 snprintf(filename
, PATH_MAX
, "%s.%d", log_prefix
, check_time
);
35 cxtfile
= fopen(filename
, "w");
36 if (cxtfile
== NULL
) {
37 elog("[*] ERROR: Cant open file %s\n", filename
);
40 dlog("Opened file: %s\n", filename
);
41 sguil_data
= calloc(1, sizeof(*sguil_data
));
42 sguil_data
->prefix
= log_prefix
;
43 sguil_data
->filename
= filename
;
44 sguil_data
->file
= cxtfile
;
50 int sguil_end(output_plugin
*p
)
52 struct log_sguil
*d
= (struct log_sguil
*) p
->data
;
59 void sguil_rotate(output_plugin
*plugin
, time_t check_time
)
61 struct log_sguil
*d
= (struct log_sguil
*) plugin
->data
;
62 const char* prefix
= d
->prefix
;
63 /* end_(all)_sessions - make a new logfile
64 * check_time is some time(NULL) */
66 init_output_sguil(plugin
, prefix
, check_time
);
70 void sguil_connection (output_plugin
*plugin
, connection
*cxt
, int outputmode
)
74 char stime
[80], ltime
[80];
76 uint32_t s_ip_t
, d_ip_t
;
77 static char src_s
[INET6_ADDRSTRLEN
];
78 static char dst_s
[INET6_ADDRSTRLEN
];
86 struct log_sguil
*d
= (struct log_sguil
*) plugin
->data
;
88 strftime(stime
, 80, "%F %H:%M:%S", gmtime(&cxt
->start_time
));
89 strftime(ltime
, 80, "%F %H:%M:%S", gmtime(&cxt
->last_pkt_time
));
90 tot_time
= cxt
->last_pkt_time
- cxt
->start_time
;
92 if ( cxt
->af
== AF_INET
) {
93 s_ip_t
= ntohl(cxt
->s_ip
.s6_addr32
[0]);
94 d_ip_t
= ntohl(cxt
->d_ip
.s6_addr32
[0]);
97 fprintf(fd
, "%ld%09ju|%s|%s|%ld|%hhu|",
98 cxt
->start_time
, cxt
->cxid
, stime
, ltime
, tot_time
,
100 if(cxt
->af
== AF_INET6
) {
101 if(!inet_ntop(cxt
->af
, (cxt
->af
== AF_INET6
? (void*) &cxt
->s_ip
: (void*) cxt
->s_ip
.s6_addr32
), src_s
, INET6_ADDRSTRLEN
))
103 if(!inet_ntop(cxt
->af
, (cxt
->af
== AF_INET6
? (void*) &cxt
->d_ip
: (void*) cxt
->d_ip
.s6_addr32
), dst_s
, INET6_ADDRSTRLEN
))
105 fprintf(fd
, "%s|%u|%s|%u|",
106 src_s
, ntohs(cxt
->s_port
),
107 dst_s
, ntohs(cxt
->d_port
));
109 fprintf(fd
, "%u|%u|%u|%u|",
110 s_ip_t
, ntohs(cxt
->s_port
),
111 d_ip_t
, ntohs(cxt
->d_port
));
113 fprintf(fd
, "%ju|%ju|",
114 cxt
->s_total_pkts
, cxt
->s_total_bytes
);
115 fprintf(fd
, "%ju|%ju|%u|%u",
116 cxt
->d_total_pkts
, cxt
->d_total_bytes
,
117 cxt
->s_tcpFlags
, cxt
->d_tcpFlags
);