📄 libnids.3
字号:
.\" libnids manpage by Dug Song <dugsong@monkey.org>.\" tmac.an sux, tmac.doc rules.TH LIBNIDS 3.SH NAMElibnids \- network intrusion detection system E-box library.SH SYNOPSIS.nf#include <nids.h>extern struct nids_prm \fInids_params\fR;extern char \fInids_errbuf\fR[];int\fBnids_init\fR(void);void\fBnids_register_ip_frag\fR(void (*ip_frag_func)(struct ip *pkt));void\fBnids_register_ip\fR(void (*ip_func)(struct ip *pkt));void\fBnids_register_udp\fR(void (*udp_func)(struct tuple4 *addr, u_char *data, int len, struct ip *pkt));void\fBnids_register_tcp\fR(void (*tcp_func)(struct tcp_stream *ts, void **param));void\fBnids_killtcp\fR(struct tcp_stream *ts);void\fBnids_discard\fR(struct tcp_stream *ts);void\fBnids_run\fR(void);int\fBnids_next\fR(void);int\fBnids_getfd\fR(void);.fi.SH DESCRIPTION.B libnidsprovides the functionality of a network intrusion detection system(NIDS) E-box component. It currently performs:.LP.nf 1. IP defragmentation 2. TCP stream reassembly 3. TCP port scan detection.fi.PP.B libnidsperforms TCP/IP reassembly in exactly the same way as Linux2.0.36 kernels, and correctly handles all of the attacks implementedin fragrouter(8) (plus many other attacks as well)..SH ROUTINES.PP.BR nids_init ()initializes the application for sniffing, based on the values set in theglobal variable \fInids_params\fR, declared as follows:.LP.nfstruct nids_prm { int n_tcp_streams; int n_hosts; char *device; int sk_buff_size; int dev_addon; void (*syslog)(int type, int err, struct ip *iph, void *data); int syslog_level; int scan_num_hosts; int scan_num_ports; int scan_delay; void (*no_mem)(void); int (*ip_filter)(struct ip *iph); char *pcap_filter; int promisc; int one_loop_less;} nids_params;.fi.PPThe members of this structure are:.TP.I n_tcp_streamsSize of the hash table used for storing TCP connection information (a maximum of 3/4 * \fIn_tcp_streams\fR TCP connections will befollowed simultaneously). Default value: 1024.TP.I n_hostsSize of the hash table used for storing IP defragmentationinformation. Default value: 256.TP.I filenameIt this variable is set, libnids will call pcap_open_offline with thisvariable as the argument (instead of pcap_open_live()). Default value: NULL.TP.I deviceInterface to monitor. Default value: NULL (in which case anappropriate device is determined automatically). If this variable is assigned value \fBall\fR, libnids will attempt to capture packets on all interfaces (which works on Linux only).TP.I sk_buff_sizeSize of \fIstruct sk_buff\fR (used for queuing packets), which shouldbe set to match the value on the hosts being monitored. Default value: 168.TP.I dev_addonNumber of bytes in \fIstruct sk_buff\fR reserved for link-layerinformation. Default value: -1 (in which case an appropriate offset ifdetermined automatically based on link-layer type).TP.I syslogSyslog callback function, used to report unusual conditions, such asport scan attempts, invalid TCP header flags, etc. Default value:\fInids_syslog\fR (which logs messages via syslog(3) without regardfor message rate per second or free disk space).TP.I syslog_levelLog level used by \fInids_syslog\fR for reporting events viasyslog(3). Default value: LOG_ALERT.TP.I scan_num_hostsSize of hash table used for storing portscan information (the maximumnumber portscans that will be detected simultaneously). If set to 0,portscan detection will be disabled. Default value: 256.TP.I scan_num_portsMinimum number of ports that must be scanned from the same sourcehost before it is identifed as a portscan. Default value: 10.TP.I scan_delayMaximum delay (in milliseconds) between connections to differentports for them to be identified as part of a portscan. Default value:3000.TP.I no_memOut-of-memory callback function, used to terminate the calling processgracefully..TP.I ip_filterIP filtering callback function, used to selectively discard IPpackets, inspected after reassembly. If the function returns anon-zero value, the packet is processed; otherwise, it isdiscarded. Default value: \fInids_ip_filter\fR (which always returns1).TP.I pcap_filterpcap(3) filter string applied to the link-layer (raw, unassembled)packets. \fBNote\fR: filters like ``tcp dst port 23'' will NOTcorrectly handle appropriately fragmented traffic, e.g. 8-byte IPfragments. Default value: NULL.TP.I promiscIf non-zero, libnids will set the interface(s) it listens on topromiscuous mode. Default value: 1.TP.I one_loop_lessdisabled by default; see comments in API.html file.PPReturns 1 on success, 0 on failure (in which case \fBnids_errbuf\fRcontains an appropriate error message)..PP.BR nids_register_ip_frag ()registers a user-defined callback function to process all incoming IPpackets (including IP fragments, packets with invalid checksums, etc.)..PP.BR nids_register_ip ()registers a user-defined callback function to process IP packetsvalidated and reassembled by \fBlibnids\fR..PP.BR nids_register_udp ()registers a user-defined callback function to process UDP packetsvalidated and reassembled by \fBlibnids\fR..PP.BR nids_register_tcp ()registers a user-defined callback function to process TCP streamsvalidated and reassembled by \fBlibnids\fR. The \fItcp_stream\fRstructure is defined as follows:.LP.nfstruct tcp_stream { struct tuple4 { u_short source; u_short dest; u_int saddr; u_int daddr; } addr; char nids_state; struct half_stream { char state; char collect; char collect_urg; char *data; u_char urgdata; int count; int offset; int count_new; char count_new_urg; ... } client; struct half_stream server; ...};.fi.PPThe members of the \fItuple4\fR structure identify a unique TCPconnection:.TP\fIsource\fR, \fIdest\fRClient and server port numbers.TP\fIsaddr\fR, \fIdaddr\fRClient and server IP addresses.PPThe members of the \fIhalf_stream\fR structure describe each half of aTCP connection (client and server):.TP.I stateSocket state (e.g. TCP_ESTABLISHED)..TP.I collectA boolean which specifies whether to collect data for this half of theconnection in the \fIdata\fR buffer..TP.I collect_urgA boolean which specifies whether to collect urgent data pointed to bythe TCP urgent pointer for this half of the connection in the\fIurgdata\fR buffer..TP.I dataBuffer for normal data..TP.I urgdataOne-byte buffer for urgent data..TP.I countThe number of bytes appended to \fIdata\fR since the creation of theconnection..TP.I offsetThe current offset from the first byte stored in the \fIdata\fRbuffer, identifying the start of newly received data..TP.I count_newThe number of bytes appended to \fIdata\fR since the last invocationof the TCP callback function (if 0, no new data arrived)..TP.I count_new_urgThe number of bytes appended to \fIurgdata\fR since the lastinvocation of the TCP callback function (if 0, no new urgent dataarrived)..PPThe value of the \fInids_state\fR field provides information about thestate of the TCP connection, to be used by the TCP callback function:.TPNIDS_JUST_ESTConnection just established. Connection parameters in the \fIaddr\fRstructure are available for inspection. If the connection isinteresting, the TCP callback function may specify which data itwishes to receive in the future by setting non-zero values for the\fIcollect\fR or \fIcollect_urg\fR variables in the appropriate\fIclient\fR or \fIserver\fR half_stream structure members..TPNIDS_DATANew data has arrived on a connection. The \fIhalf_stream\fR structurescontain buffers of data..TPNIDS_CLOSE, NIDS_RESET, NIDS_TIMEOUTConnection has closed. The TCP callback function should free anyresources it may have allocated for this connection..PPThe \fIparam\fR pointer may be set to save a pointer to user-definedconnection-specific data to pass to subsequent invocations of the TCPcallback function (ex. the current working directory for an FTPcontrol connection, etc.)..PP.BR nids_killtcp ()tears down the specified TCP connection with symmetric RST packetsbetween client and server..PP.BR nids_discard ()may be called from the TCP callback function to specify the number ofbytes to discard from the beginning of the \fIdata\fR buffer (updatingthe \fIoffset\fR value accordingly) after the TCP callback functionexists. Otherwise, the new data (totalling \fIcount_new\fR bytes) willbe discarded by default..PP.BR nids_run ()starts the packet-driven application, reading packets in an endlessloop, and invoking registered callback functions to handle new data asit arrives. This function does not return..PP.BR nids_next ()sleeps until a packet arrives, and then processes a single packetbefore returning. This allows the program to perform other tasks evenwhen no packets arrive. Returns 1 on success, 0 on failure (in whichcase \fBnids_errbuf\fR contains an appropriate error message)..PP.BR nids_getfd ()may be used by an application sleeping in select(2) to snoop for asocket file descriptor present in the read fd_set. Returns the filedescriptor on success, -1 on failure (in which case \fBnids_errbuf\fRcontains an appropriate error message)..SH SEE ALSOpcap(3), libnet(3), fragrouter(8).SH AUTHORRafal Wojtczuk <nergal@icm.edu.pl>.PPManpage by Dug Song <dugsong@monkey.org>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -