1 /* author: Kacper Wysocki <kwy@redpill-linpro.com> */
3 #include "../sys_func.h"
8 #include "log_stdout.h"
10 output_plugin p_stdout
= {
11 .init
= &init_output_stdout
,
14 .service
= &stdout_service
,
16 .denit
= &end_log_stdout
,
20 output_plugin
*init_log_stdout()
25 int init_output_stdout(output_plugin
*p
, const char *f
, int flags
)
27 if(flags
& (CONFIG_CXWRITE
| CONFIG_CONNECT
)){
28 p
->connection
= &stdout_connection
;
29 if(!(flags
& CONFIG_VERBOSE
)){
38 int end_log_stdout (output_plugin
*log
)
44 void stdout_arp (output_plugin
*unused
, asset
*main
)
46 static char ip_addr_s
[INET6_ADDRSTRLEN
];
48 if (memcmp(main
->mac_addr
, "\0\0\0\0\0\0", 6)) {
49 u_ntop(main
->ip_addr
, main
->af
, ip_addr_s
);
50 printf("%s", ip_addr_s
);
51 if (main
->vlan
!= 0) printf(",[vlan:%u]", ntohs(main
->vlan
));
53 hex2mac(main
->mac_addr
));
54 if(main
->macentry
) printf(",%s", main
->macentry
->vendor
);
60 void stdout_os (output_plugin
*unused
, asset
*main
, os_asset
*os
, connection
* c
)
62 static char ip_addr_s
[INET6_ADDRSTRLEN
];
65 u_ntop(main
->ip_addr
, main
->af
, ip_addr_s
);
66 printf("%s", ip_addr_s
);
67 if (main
->vlan
!= 0) printf(",[vlan:%u]", ntohs(main
->vlan
));
70 if (os
->detection
== CO_SYN
) printf("syn");
71 if (os
->detection
== CO_SYNACK
) printf("synack");
72 if (os
->detection
== CO_ACK
) printf("ack");
73 if (os
->detection
== CO_RST
) printf("rst");
74 if (os
->detection
== CO_FIN
) printf("fin");
75 if (os
->detection
== CO_UDP
) printf("udp");
76 if (os
->detection
== CO_ICMP
) printf("icmp");
79 if (os
->raw_fp
!= NULL
) {
80 printf("%s]", (char *)bdata(os
->raw_fp
));
82 bstring b
= gen_fp_tcp(&os
->fp
, os
->uptime
, os
->detection
);
84 printf("%s]", (char *)bdata(os
->raw_fp
));
86 if (os
->fp
.os
!= NULL
) printf(",[%s", os
->fp
.os
);
87 else printf(",[unknown");
88 if (os
->fp
.desc
!= NULL
) printf(":%s]", os
->fp
.desc
);
89 else printf(":unknown]");
91 if (os
->fp
.mss
) printf(",[link:%s]",lookup_link(os
->fp
.mss
,1));
94 if (os
->uptime
) printf(",[uptime:%dhrs]",os
->uptime
/360000);
96 tmp_ttl
= normalize_ttl(os
->ttl
);
97 printf(",[distance:%d]",tmp_ttl
- os
->ttl
);
103 void stdout_service (output_plugin
* unused
, asset
*main
, serv_asset
*service
, connection
*c
)
105 static char ip_addr_s
[INET6_ADDRSTRLEN
];
108 u_ntop(main
->ip_addr
, main
->af
, ip_addr_s
);
109 printf("%s", ip_addr_s
);
110 if (main
->vlan
!= 0) printf(",[vlan:%u]", ntohs(main
->vlan
));
112 if (service
->role
== SC_SERVER
) {
113 printf(",[service:%s:%u:%u]",
114 (char *)bdata(service
->application
),
115 ntohs(service
->port
),service
->proto
);
117 printf(",[client:%s:%u:%u]",
118 (char*)bdata(service
->application
),
119 ntohs(service
->port
),service
->proto
);
122 tmp_ttl
= normalize_ttl(service
->ttl
);
123 printf(",[distance:%d]",tmp_ttl
- service
->ttl
);
129 void stdout_excessive(connection
*cxt
)
131 static char src_s
[INET6_ADDRSTRLEN
];
132 static char dst_s
[INET6_ADDRSTRLEN
];
133 if(!inet_ntop(cxt
->af
, (cxt
->af
== AF_INET6
? (void*) &cxt
->s_ip
: (void*) cxt
->s_ip
.s6_addr32
), src_s
, INET6_ADDRSTRLEN
))
135 if(!inet_ntop(cxt
->af
, (cxt
->af
== AF_INET6
? (void*) &cxt
->d_ip
: (void*) cxt
->d_ip
.s6_addr32
), dst_s
, INET6_ADDRSTRLEN
))
137 printf("conn[%4lu] %s:%u -> %s:%u\n", cxt
->cxid
,
138 src_s
, ntohs(cxt
->s_port
),
139 dst_s
, ntohs(cxt
->d_port
));
142 void stdout_connection (output_plugin
*plugin
, connection
*cxt
, int outputmode
)
144 char stime
[80], ltime
[80];
146 static char src_s
[INET6_ADDRSTRLEN
];
147 static char dst_s
[INET6_ADDRSTRLEN
];
148 if(outputmode
== CX_EXCESSIVE
){
149 stdout_excessive(cxt
);
153 strftime(stime
, 80, "%F %H:%M:%S", gmtime(&cxt
->start_time
));
154 strftime(ltime
, 80, "%F %H:%M:%S", gmtime(&cxt
->last_pkt_time
));
155 tot_time
= cxt
->last_pkt_time
- cxt
->start_time
;
157 fprintf(fd
, "%ld%09ju|%s|%s|%ld|%hhu|",
158 cxt
->start_time
, cxt
->cxid
, stime
, ltime
, tot_time
,
160 if(!inet_ntop(cxt
->af
, (cxt
->af
== AF_INET6
? (void*) &cxt
->s_ip
: (void*) cxt
->s_ip
.s6_addr32
), src_s
, INET6_ADDRSTRLEN
))
162 if(!inet_ntop(cxt
->af
, (cxt
->af
== AF_INET6
? (void*) &cxt
->d_ip
: (void*) cxt
->d_ip
.s6_addr32
), dst_s
, INET6_ADDRSTRLEN
))
164 fprintf(fd
, "%s|%u|%s|%u|",
165 src_s
, ntohs(cxt
->s_port
),
166 dst_s
, ntohs(cxt
->d_port
));
167 fprintf(fd
, "%ju|%ju|",
168 cxt
->s_total_pkts
, cxt
->s_total_bytes
);
169 fprintf(fd
, "%ju|%ju|%u|%u",
170 cxt
->d_total_pkts
, cxt
->d_total_bytes
,
171 cxt
->s_tcpFlags
, cxt
->d_tcpFlags
);
172 // hack to distinguish output paths
174 switch (outputmode
) {
185 if(o
) fprintf(fd
, "|%s", o
);