1 Description: The mod_if module monitors various aspects of network
2 interfaces for change, including IP, Hardware Address,
3 broadcast, MTU, metric, and promiscuous mode.
6 diff -ruN osiris-4.1.9-old/src/osirisd/modules/mod_if/Makefile osiris-4.1.9-new/src/osirisd/modules/mod_if/Makefile
7 --- osiris-4.1.9-old/src/osirisd/modules/mod_if/Makefile 1970-01-01 01:00:00.000000000 +0100
8 +++ osiris-4.1.9-new/src/osirisd/modules/mod_if/Makefile 2005-10-07 02:19:17.000000000 +0200
16 +module: ${SRCS} ${OBJS}
18 +INCS=-I../.. -I../../../libosiris -I../../../libfileapi -I../../../..
20 +# meta-rule for compiling any "C" source file.
22 + $(CC) $(DEFS) $(DEFAULT_INCLUDES) ${INCLUDES} ${INCS} $(AM_CPPFLAGS) \
23 + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $(SRCS)
26 diff -ruN osiris-4.1.9-old/src/osirisd/modules/mod_if/README osiris-4.1.9-new/src/osirisd/modules/mod_if/README
27 --- osiris-4.1.9-old/src/osirisd/modules/mod_if/README 1970-01-01 01:00:00.000000000 +0100
28 +++ osiris-4.1.9-new/src/osirisd/modules/mod_if/README 2005-10-07 02:19:17.000000000 +0200
32 +Author: Brian Wotring (brian@hostintegrity.com)
38 +The mod_if module is designed originally to monitor the promisc flag
39 +on network interfaces, but quickly turned into being able to monitor
40 +various aspects of network interfaces including hardware address,
41 +IP address, broadcast, MTU, and metric.
43 +This module is somewhat different in that each record is an element
44 +about a network interface as opposed to one record per interface. This
45 +will make it easier to add more elements to be monitored, easier to
46 +filter, and easier to understand alerts.
50 +To use this module, all that is needed is to include it in the Modules
51 +block of a scan configuration, e.g.:
62 +There are no parameters for this module.
66 +Currently, this module is only implemented for Linux.
72 diff -ruN osiris-4.1.9-old/src/osirisd/modules/mod_if/mod_if.c osiris-4.1.9-new/src/osirisd/modules/mod_if/mod_if.c
73 --- osiris-4.1.9-old/src/osirisd/modules/mod_if/mod_if.c 1970-01-01 01:00:00.000000000 +0100
74 +++ osiris-4.1.9-new/src/osirisd/modules/mod_if/mod_if.c 2005-10-07 02:19:17.000000000 +0200
77 +/******************************************************************************
79 +** Copyright (C) 2005 Brian Wotring.
81 +** This program is free software; you can redistribute it and/or
82 +** modify it, however, you cannot sell it.
84 +** This program is distributed in the hope that it will be useful,
85 +** but WITHOUT ANY WARRANTY; without even the implied warranty of
86 +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
88 +** You should have received a copy of the license attached to the
89 +** use of this software. If not, view a current copy of the license
92 +** http://www.hostintegrity.com/osiris/LICENSE
94 +******************************************************************************/
96 +/*****************************************************************************
99 +** Date: September 23, 2005
101 +** Author: Brian Wotring
102 +** Purpose: platform specific methods for monitoring network devices.
104 +******************************************************************************/
107 +/* CODE USED IN THIS MODULE WAS ORIGINALLY TAKEN FROM:
109 +* http://mail.nl.linux.org/kernelnewbies/2003-05/msg00090.html
112 +static const char *MODULE_NAME = "mod_if";
127 +#include <sys/socket.h>
128 +#include <sys/types.h>
132 +#include <sys/ioctl.h>
133 +#include <net/if_arp.h>
134 +#include <arpa/inet.h>
137 +#include "libosiris.h"
138 +#include "libfileapi.h"
139 +#include "rootpriv.h"
141 +#include "version.h"
143 +#include "scanner.h"
144 +#include "logging.h"
147 +#define inaddrr(x) (*(struct in_addr *) &ifr->x[sizeof sa.sin_port])
148 +#define IFRSIZE ((int)(size * sizeof (struct ifreq)))
150 +void process_if_unix( SCANNER *scanner )
153 + int sockfd, size = 1;
156 + struct sockaddr_in sa;
158 + SCAN_RECORD_TEXT_1 record;
160 + /* Make sure we are able to create sockets */
162 + if ( (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0 )
164 + log_error( "mod_if unable to create socket!" );
168 + ifc.ifc_len = IFRSIZE;
169 + ifc.ifc_req = NULL;
175 + /* realloc buffer size until no overflow occurs */
177 + if ((ifc.ifc_req = realloc(ifc.ifc_req, IFRSIZE)) == NULL )
179 + log_error( "out of memory!!!" );
183 + ifc.ifc_len = IFRSIZE;
185 + if (ioctl(sockfd, SIOCGIFCONF, &ifc))
187 + log_error("ioctl failure: SIOCFIFCONF");
191 + } while (IFRSIZE <= ifc.ifc_len);
195 + for (;(char *) ifr < (char *) ifc.ifc_req + ifc.ifc_len; ++ifr)
197 + if (ifr->ifr_addr.sa_data == (ifr+1)->ifr_addr.sa_data)
199 + continue; /* duplicate, skip it */
202 + if (ioctl(sockfd, SIOCGIFFLAGS, ifr))
204 + continue; /* failed to get flags, skip it */
207 + initialize_scan_record( (SCAN_RECORD *)&record,
208 + SCAN_RECORD_TYPE_TEXT_1 );
210 + osi_strlcpy( record.module_name, MODULE_NAME,
211 + sizeof( record.module_name ) );
213 + osi_snprintf( record.name, sizeof( record.name ),
214 + "if:%s:IP", ifr->ifr_name );
216 + osi_snprintf( record.data, sizeof( record.data ),
217 + "%s", inet_ntoa(inaddrr(ifr_addr.sa_data)));
219 + send_scan_data( scanner, (SCAN_RECORD *)&record );
222 + * This won't work on HP-UX 10.20 as there's no SIOCGIFHWADDR ioctl. You'll
223 + * need to use DLPI or the NETSTAT ioctl on /dev/lan0, etc (and you'll need
224 + * to be root to use the NETSTAT ioctl. Also this is deprecated and doesn't
227 + * On Digital Unix you can use the SIOCRPHYSADDR ioctl according to an old
228 + * utility I have. Also on SGI I think you need to use a raw socket, e.g. s
229 + * = socket(PF_RAW, SOCK_RAW, RAWPROTO_SNOOP)
233 + * From: David Peter <dave.peter@eu.citrix.com>
236 + if ( ioctl(sockfd, SIOCGIFHWADDR, ifr) == 0 )
238 + /* Select which hardware types to process.
240 + ** See list in system include file included from
241 + ** /usr/include/net/if_arp.h (For example, on
242 + ** Linux see file /usr/include/linux/if_arp.h to
246 + switch (ifr->ifr_hwaddr.sa_family)
251 + case ARPHRD_NETROM:
254 + case ARPHRD_EETHER:
255 + case ARPHRD_IEEE802:
259 + u = (unsigned char *) &ifr->ifr_addr.sa_data;
261 + /* send record for MAC for this interface */
263 + if (u[0] + u[1] + u[2] + u[3] + u[4] + u[5])
265 + initialize_scan_record( (SCAN_RECORD *)&record,
266 + SCAN_RECORD_TYPE_TEXT_1 );
268 + osi_strlcpy( record.module_name, MODULE_NAME,
269 + sizeof( record.module_name ) );
271 + osi_snprintf( record.name, sizeof( record.name ),
272 + "if:%s:MAC", ifr->ifr_name );
274 + osi_snprintf( record.data, sizeof( record.data ),
275 + "%2.2x.%2.2x.%2.2x.%2.2x.%2.2x.%2.2x",
276 + u[0], u[1], u[2], u[3], u[4], u[5]);
278 + send_scan_data( scanner, (SCAN_RECORD *)&record );
282 + if ( ioctl(sockfd, SIOCGIFNETMASK, ifr) == 0 &&
283 + strcmp("255.255.255.255", inet_ntoa(inaddrr(ifr_addr.sa_data))))
285 + initialize_scan_record( (SCAN_RECORD *)&record,
286 + SCAN_RECORD_TYPE_TEXT_1 );
288 + osi_strlcpy( record.module_name, MODULE_NAME,
289 + sizeof( record.module_name ) );
291 + osi_snprintf( record.name, sizeof( record.name ),
292 + "if:%s:NETMASK", ifr->ifr_name );
294 + osi_snprintf( record.data, sizeof( record.data ),
295 + "%s", inet_ntoa(inaddrr(ifr_addr.sa_data)));
297 + send_scan_data( scanner, (SCAN_RECORD *)&record );
300 + if (ifr->ifr_flags & IFF_BROADCAST)
302 + if ( ioctl(sockfd, SIOCGIFBRDADDR, ifr) == 0 &&
303 + strcmp("0.0.0.0", inet_ntoa(inaddrr(ifr_addr.sa_data))))
306 + initialize_scan_record( (SCAN_RECORD *)&record,
307 + SCAN_RECORD_TYPE_TEXT_1 );
309 + osi_strlcpy( record.module_name, MODULE_NAME,
310 + sizeof( record.module_name ) );
312 + osi_snprintf( record.name, sizeof( record.name ),
313 + "if:%s:BROADCAST", ifr->ifr_name );
315 + osi_snprintf( record.data, sizeof( record.data ),
316 + "%s",inet_ntoa(inaddrr(ifr_addr.sa_data)));
318 + send_scan_data( scanner, (SCAN_RECORD *)&record );
322 + /* Added by David Vasil to check for Promiscuous mode */
324 + initialize_scan_record( (SCAN_RECORD *)&record,
325 + SCAN_RECORD_TYPE_TEXT_1 );
327 + osi_strlcpy( record.module_name, MODULE_NAME,
328 + sizeof( record.module_name ) );
331 + osi_snprintf( record.name, sizeof( record.name ),
332 + "if:%s:PROMISC", ifr->ifr_name );
334 + if ( ioctl(sockfd, SIOCGIFFLAGS, ifr) == 0 &&
335 + ifr->ifr_flags & IFF_PROMISC)
337 + osi_strlcpy( record.data, "ENABLED", sizeof( record.data ) );
342 + osi_strlcpy( record.data, "DISABLED", sizeof( record.data ) );
345 + send_scan_data( scanner, (SCAN_RECORD *)&record );
348 + if ( ioctl(sockfd, SIOCGIFMTU, ifr) == 0 )
350 + initialize_scan_record( (SCAN_RECORD *)&record,
351 + SCAN_RECORD_TYPE_TEXT_1 );
353 + osi_strlcpy( record.module_name, MODULE_NAME,
354 + sizeof( record.module_name ) );
356 + osi_snprintf( record.name, sizeof( record.name ),
357 + "if:%s:MTU", ifr->ifr_name );
359 + osi_snprintf( record.data, sizeof( record.data ),
360 + "%u", ifr->ifr_mtu );
362 + send_scan_data( scanner, (SCAN_RECORD *)&record );
365 + if ( ioctl(sockfd, SIOCGIFMETRIC, ifr) == 0 )
367 + initialize_scan_record( (SCAN_RECORD *)&record,
368 + SCAN_RECORD_TYPE_TEXT_1 );
370 + osi_strlcpy( record.module_name, MODULE_NAME,
371 + sizeof( record.module_name ) );
373 + osi_snprintf( record.name, sizeof( record.name ),
374 + "if:%s:METRIC", ifr->ifr_name );
376 + osi_snprintf( record.data, sizeof( record.data ),
377 + "%u", ifr->ifr_metric );
379 + send_scan_data( scanner, (SCAN_RECORD *)&record );
386 +void mod_if( SCANNER *scanner )
388 +#if defined(SYSTEM_LINUX)
389 + process_if_unix( scanner );