27 #include <sys/types.h>
28 #include <sys/socket.h>
29 #include <netinet/in.h>
30 #include <netinet/in_systm.h>
31 #include <arpa/inet.h>
40 #include "../common/packet_dump.h"
41 #include "../common/packet_functions.h"
42 #include "../common/packet_types.h"
43 #include "../common/PyRep.h"
44 #include "../common/EVEUnmarshal.h"
45 #include "../common/PyPacket.h"
46 #include "../common/PyVisitor.h"
47 #include "../common/logsys.h"
48 #include "../common/StreamPacketizer.h"
49 #include "../common/CachedObjectMgr.h"
50 #include "../common/PyXMLGenerator.h"
51 #include "../common/PyDumpVisitor.h"
52 #include "../common/PyLookupDump.h"
56 #include "../packets/General.h"
61 #define int_ntoa(x) inet_ntoa(*((struct in_addr *)&x))
71 sprintf (buf + strlen (buf),
",%i,", addr.source);
73 sprintf (buf + strlen (buf),
",%i", addr.dest);
88 void tcp_callback (
struct tcp_stream *a_tcp,
void ** this_time_not_needed) {
90 strcpy (buf,
adres (a_tcp->addr));
92 if (a_tcp->nids_state == NIDS_JUST_EST) {
95 if(a_tcp->addr.source != 26000 && a_tcp->addr.dest != 26000 &&
96 a_tcp->addr.source != 26001 && a_tcp->addr.dest != 26001)
99 a_tcp->client.collect++;
100 a_tcp->server.collect++;
101 _log(COLLECT__TCP,
"%s established", buf);
104 if (a_tcp->nids_state == NIDS_CLOSE) {
106 _log(COLLECT__TCP,
"%s closing", buf);
109 if (a_tcp->nids_state == NIDS_RESET) {
111 _log(COLLECT__TCP,
"%s reset", buf);
115 if (a_tcp->nids_state == NIDS_DATA) {
119 struct half_stream *hlf;
122 if (a_tcp->client.count_new) {
124 hlf = &a_tcp->client;
127 strcat (buf,
"(<-)");
130 hlf = &a_tcp->server;
131 strcat (buf,
"(->)");
134 _log(COLLECT__TCP,
"Data %s (len %d)", buf, hlf->count_new);
138 sp->InputBytes((
const byte *) hlf->data, hlf->count_new);
140 StreamPacketizer::Packet *p;
144 uint32 body_len = p->length;
145 const byte *body = p->data;
147 _log(COLLECT__RAW_HEX,
"Raw Hex Dump of len %d:", body_len);
148 _hex(COLLECT__RAW_HEX, body, body_len);
150 PyRep *rep = InflateAndUnmarshal(body, body_len);
152 printf(
"Failed to inflate or unmarshal!");
162 _log(COLLECT__PYREP_DUMP,
"Unmarshaled PyRep:");
163 PyLookupDump dumper(&CollectDispatcher->
lookResolver, COLLECT__PYREP_DUMP);
168 if(!packet->
Decode(rep)) {
169 _log(COLLECT__ERROR,
"Failed to decode packet rep");
177 _log(COLLECT__PACKET_DUMP,
"Decoded message:");
178 PyLookupDump dumper(&CollectDispatcher->
lookResolver, COLLECT__PACKET_DUMP);
179 packet->
Dump(COLLECT__PACKET_DUMP, &dumper);
198 fprintf(stderr,
"NULL dispatcher provided to NIDS, not running\n",nids_errbuf);
201 CollectDispatcher = disp;
206 nids_params.filename =
strdup(argv[1]);
208 nids_params.device =
strdup(argv[2]);
210 fprintf(stderr,
"%s\n",nids_errbuf);
215 printf(
"Starting NIDS loop...\n");
char * adres(struct tuple4 addr)
StreamPacketizer serverPacketizer
#define _log(type, fmt,...)
static EVECollectDispatcher * CollectDispatcher
std::string sprintf(const char *fmt,...)
sprintf for std::string.
void ProcessCallRequest(PyPacket *packet)
#define is_log_enabled(type)
void Dump(LogType type, PyVisitor &dumper)
void tcp_callback(struct tcp_stream *a_tcp, void **this_time_not_needed)
#define _hex(type, data, len)
StreamPacketizer clientPacketizer
bool Decode(PyRep **packet)
PyLookupResolver lookResolver
bool visit(PyVisitor &v) const
Visits object.
bool DispatchPacket(PyPacket *packet)
virtual bool visit(PyVisitor &v) const =0
Visits object.
int EVE_NIDS_main(EVECollectDispatcher *disp, int argc, char *argv[])