libnids api

来源:互联网 发布:javaajax请求json数据 编辑:程序博客网 时间:2024/05/16 05:03

libnids(3) - Linux man page

Name

libnids - network intrusion detection system E-box library

Synopsis

#include <nids.h>extern struct nids_prm nids_params;extern char nids_errbuf[];intnids_init(void);
voidnids_register_ip_frag(void (*ip_frag_func)(struct ip *pkt, int len));
voidnids_unregister_ip_frag(void (*ip_frag_func)(struct ip *pkt, int len));voidnids_register_ip(void (*ip_func)(struct ip *pkt, int len));voidnids_unregister_ip(void (*ip_func)(struct ip *pkt, int len));voidnids_register_udp(void (*udp_func)(struct tuple4 *addr, u_char *data, intlen, struct ip *pkt));voidnids_unregister_udp(void (*udp_func)(struct tuple4 *addr, u_char *data,int len, struct ip *pkt));voidnids_register_tcp(void (*tcp_func)(struct tcp_stream *ts, void **param));voidnids_unregister_tcp(void (*tcp_func)(struct tcp_stream *ts, void **param));voidnids_killtcp(struct tcp_stream *ts);voidnids_discard(struct tcp_stream *ts, int numbytes);voidnids_run(void);intnids_dispatch(int cnt);intnids_next(void);intnids_getfd(void);intnids_register_chksum_ctl(struct nids_chksum_ctl *, int);voidnids_pcap_handler(u_char *par, struct pcap_pkthdr *hdr, u_char *data);struct tcp_stream *nids_find_tcp_stream(struct tuple4 *addr);

Description

libnids provides the functionality of a network intrusion detection system (NIDS) E-box component. It currently performs:
    1. IP defragmentation    2. TCP stream reassembly    3. TCP port scan detection
libnids performs TCP/IP reassembly in exactly the same way as Linux 2.0.36 kernels, and correctly handles all of the attacks implemented in fragrouter(8) (plus many other attacks as well).

Routines

nids_init() initializes the application for sniffing, based on the values set in the global variable nids_params, declared as follows:

struct nids_prm {    int    n_tcp_streams;    int    n_hosts;    char    *device;    char    *filename;    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;    int    pcap_timeout;    int    multiproc;    int    queue_limit;    int    tcp_workarounds;    pcap_t    *pcap_desc;} nids_params;
The members of this structure are:
n_tcp_streams
Size of the hash table used for storing TCP connection information ( a maximum of 3/4 * n_tcp_streams TCP connections will be followed simultaneously). Default value: 1024


n_hosts

Size of the hash table used for storing IP defragmentation information. Default value: 256


filename

It this variable is set, libnids will call pcap_open_offline with this variable as the argument (instead of pcap_open_live()). Default value: NULL


device

Interface to monitor. Default value: NULL (in which case an appropriate device is determined automatically). If this variable is assigned value all, libnids will attempt to capture packets on all interfaces (which works on Linux only)


sk_buff_size

Size of struct sk_buff (used for queuing packets), which should be set to match the value on the hosts being monitored. Default value: 168


dev_addon

Number of bytes in struct sk_buff reserved for link-layer information. Default value: -1 (in which case an appropriate offset if determined automatically based on link-layer type)


syslog

Syslog callback function, used to report unusual conditions, such as port scan attempts, invalid TCP header flags, etc. Default value: nids_syslog (which logs messages via syslog(3) without regard for message rate per second or free disk space)


syslog_level

Log level used by nids_syslog for reporting events via syslog(3). Default value: LOG_ALERT
scan_num_hosts
Size of hash table used for storing portscan information (the maximum number portscans that will be detected simultaneously). If set to 0, portscan detection will be disabled. Default value: 256
scan_num_ports
Minimum number of ports that must be scanned from the same source host before it is identifed as a portscan. Default value: 10
scan_delay
Maximum delay (in milliseconds) between connections to different ports for them to be identified as part of a portscan. Default value: 3000
no_mem
Out-of-memory callback function, used to terminate the calling process gracefully.
ip_filter
IP filtering callback function, used to selectively discard IP packets, inspected after reassembly. If the function returns a non-zero value, the packet is processed; otherwise, it is discarded. Default value: nids_ip_filter (which always returns 1)
pcap_filter
pcap(3) filter string applied to the link-layer (raw, unassembled) packets. Note: filters like ''tcp dst port 23'' will NOT correctly handle appropriately fragmented traffic, e.g. 8-byte IP fragments; one should add "or (ip[6:2] & 0x1fff != 0)" at the end of the filter to process reassembled packets. Default value: NULL
promisc
If non-zero, libnids will set the interface(s) it listens on to promiscuous mode. Default value: 1
one_loop_less
Disabled by default; see comments in API.html file
pcap_timeout
Sets the pcap read timeout, which may or may not be supported by your platform. Default value: 1024.
multiproc
If nonzero, creates a separate thread for packets processing. See API.html. Default value: 0.
queue_limit
If multiproc is nonzero, this is the maximum number of packets queued in the thread which reads packets from libpcap. Default value: 20000
tcp_workarounds
Enables extra checks for faulty implementations of TCP such as the ones which allow connections to be closed despite the fact that there should be retransmissions for lost packets first (as stated by RFC 793, section 3.5). If non-zero, libnids will set the NIDS_TIMED_OUT state for savagely closed connections. Default value: 0
pcap_desc
It this variable is set, libnids will call neither pcap_open_live nor pcap_open_offline, but will use a pre-opened PCAP descriptor; use this with nids_pcap_handler() in order to interactively feed packets to libnids. Default value: NULL

Returns 1 on success, 0 on failure (in which case nids_errbuf contains an appropriate error message).

nids_register_ip_frag() registers a user-defined callback function to process all incoming IP packets (including IP fragments, packets with invalid checksums, etc.).

nids_unregister_ip_frag() unregisters a user-defined callback function to process all incoming IP packets.

nids_register_ip() registers a user-defined callback function to process IP packets validated and reassembled by libnids.

nids_unregister_ip() unregisters a user-defined callback function to process IP packets.

nids_register_udp() registers a user-defined callback function to process UDP packets validated and reassembled by libnids.

nids_unregister_udp() unregisters a user-defined callback function to process UDP packets.

nids_register_tcp() registers a user-defined callback function to process TCP streams validated and reassembled by libnids. The tcp_stream structure is defined as follows:

struct 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;    ...    void            *user;};
The members of the tuple4 structure identify a unique TCP connection:
sourcedest
Client and server port numbers
saddrdaddr
Client and server IP addresses

The members of the half_stream structure describe each half of a TCP connection (client and server):

state
Socket state (e.g. TCP_ESTABLISHED).
collect
A boolean which specifies whether to collect data for this half of the connection in the data buffer.
collect_urg
A boolean which specifies whether to collect urgent data pointed to by the TCP urgent pointer for this half of the connection in the urgdata buffer.
data
Buffer for normal data.
urgdata
One-byte buffer for urgent data.
count
The number of bytes appended to data since the creation of the connection.
offset
The current offset from the first byte stored in the data buffer, identifying the start of newly received data.
count_new
The number of bytes appended to data since the last invocation of the TCP callback function (if 0, no new data arrived).
count_new_urg
The number of bytes appended to urgdata since the last invocation of the TCP callback function (if 0, no new urgent data arrived).

The value of the nids_state field provides information about the state of the TCP connection, to be used by the TCP callback function:

NIDS_JUST_EST
Connection just established. Connection parameters in the addr structure are available for inspection. If the connection is interesting, the TCP callback function may specify which data it wishes to receive in the future by setting non-zero values for the collect or collect_urg variables in the appropriate client or server half_stream structure members.
NIDS_DATA
New data has arrived on a connection. The half_stream structures contain buffers of data.
NIDS_CLOSE, NIDS_RESET, NIDS_TIMED_OUT
Connection has closed. The TCP callback function should free any resources it may have allocated for this connection.

The param pointer passed by libnids as argument to the TCP callback function may be set to save a pointer to user-defined connection-specific data to pass to subsequent invocations of the TCP callback function (ex. the current working directory for an FTP control connection, etc.).

The user pointer in the tcp_stream structure has the same purpose except it is global to the stream, whereas the param pointer is different from one callback function to the other even though they were called for the same stream.

nids_unregister_tcp() unregisters a user-defined callback function to process TCP streams.

nids_killtcp() tears down the specified TCP connection with symmetric RST packets between client and server.

nids_discard() may be called from the TCP callback function to specify the number of bytes to discard from the beginning of the data buffer (updating the offset value accordingly) after the TCP callback function exits. Otherwise, the new data (totalling count_new bytes) will be discarded by default.

nids_run() starts the packet-driven application, reading packets in an endless loop, and invoking registered callback functions to handle new data as it arrives. This function does not return.

nids_dispatch() attempts to process cnt packets before returning, with a cnt of -1 understood as all packets available in one pcap buffer, or all packets in a file when reading offline. On success, returns the count of packets processed, which may be zero upon EOF (offline read) or upon hitting pcap_timeout (if supported by your platform). On failure, returns -1, putting an appropriate error message in nids_errbuf.

nids_next() process the next available packet before returning. Returns 1 on success, 0 if no packet was processed, setting nids_effbuf appropriately if an error prevented packet processing.

nids_getfd() may be used by an application sleeping in select(2) to snoop for a socket file descriptor present in the read fd_set. Returns the file descriptor on success, -1 on failure (in which case nids_errbuf contains an appropriate error message).

nids_register_chksum_ctl() takes as arguments an array of struct nids_chksum_ctl elements and the number of elements in the array. A nids_chksum_ctl element is defined as follows:

struct nids_chksum_ctl {    u_int netaddr;    u_int mask;    u_int action;    /* private members */};
Internal checksumming functions will first check elements of this array one by one, and if the source ip SRCIP of the current packet satisfies condition
(SRCIP&chksum_ctl_array[i].mask)==chksum_ctl_array[i].netaddr

then if the action field is NIDS_DO_CHKSUM, the packet will be checksummed; if the action field is NIDS_DONT_CHKSUM, the packet will not be checksummed. If the packet matches none of the array elements, the default action is to perform checksumming.

nids_pcap_handler() may be used by an application already running a capture with libpcap, in order to pass frames to libnids interactively (frame per frame) instead of having libnids itself do the capture.

nids_find_tcp_stream() returns a pointer to the tcp_stream structure corresponding to the tuple passed as argument if libnids knows about this TCP connection already, otherwise it returns NULL.

nids_free_tcp_stream() removes the given tcp_stream from the list of streams tracked by libnids. Warning: its usage can result in crashes! See comments in the API.html file.

See Also

pcap(3)libnet(3)fragrouter(8)

Author

Rafal Wojtczuk <nergal@icm.edu.pl>

Manpage by Dug Song <dugsong@monkey.org>, minor updates by Michael Pomraning <mjp@pilcrow.madison.wi.us>

Referenced By

dsniff(8)



一、当日工作(或学习)内容及进展情况(以条目式陈述,必要时配图说明)

Libnids读书笔记:

Libnids(Library Network Intusion Detection System)网络入侵检测开发包,基于libpcap和libnet开发,是仿照linux内核中的TCP/IP协议部分而实现的。

 

libnids主要功能包括捕获网络数据包、IP碎片重组、TCP数据流重组以及端口扫描攻击检测和异常数据包检测等。IP碎片重组是libnids的一个重要内容,是仿照linux内核中的IP重组而实现的,所以非常可靠。libnids提供了TCP数据流重组功能,这是libpcap所不具备的,利用TCP数据流重组,可以分析基于TCP协议的各种应用层协议。另外,LIBNIDS还提供了检测TCP端口扫描攻击的功能,检测异常数据包的功能,这是入侵检测系统(IDS)最基本的功能。

 

LIBNIDS的使用范围:

  1. 入侵检测系统
  2. 网络协议分析
  3. 网络嗅探(网络监视)

除此之外利用LIBSNIDS还可以重现网络内容,还原网络数据,如重现HTTP协议中传输的网页、POP3协议中传输的电子邮件等。

 

LIBNIDS数据结构

基本常量

1.报警类型

下面是在LIBSNIDS中定义的警告描述常量

 

2. LIBNIDS状态

在对TCP数据流进行重组时,必须考虑到TCP的连接状态,在LIBNIDS中为了方便开发而定义了LIBNIDS状态,共有如下6种:

LIBNIDS描述的是连接的逻辑状态。真正的TCP连接状态有11种,它们对应于TCP协议的状态变迁图中的各个状态,定义如下:

 

3.校验和

实现了关于是否计算校验和的功能

 

 

 

tuple4

是LIBNIDS中最基本的一种数据结构

 

 

half_stream

用来描述TCP连接中一端的所有信息,客户端或服务器端。

 

 

tcp_stream

是一个TCP连接的所有信息

 

 

nids_prm

描述了LIBNIDS的一些全局参数信息

 

其中ip_filter函数指针,当IP数据包到达时,默认函数nids_ip_filter被调用,如果此函数返回非零值,此数据包就被处理;如果返回零,就被丢弃。nids_ip_filter函数定义如下:

 

在LIBNIDS中用nids_prm数据结构定义了一个全部变量nids_params,其定义和初始值如下:

在使用LIBNIDS开发程序时,可以首先对nids_params全局变量的值进行修改,这样对整个libnids就全部有效。

 

nids_chksum_ctl

描述的是计算检验和

 

 

LIBNIDS函数

1.基本函数

int nids_init(void);

函数返回值:函数调用成功返回1,失败返回0

对LIBNIDS进行初始化,主要内容包括打开网络接口、打开文件、编译过滤规则、设置过滤规则、判断网络链路类型、进行必要的初始化工作。

 

void nids_run(void);

欲行LIBNIDS,进入循环捕获数据包状态。实际上是调用LIBPCAP函数pcap_loop()来循环捕获数据包。

 

int nids_getfd(void);

函数返回值:执行成功就返回文件描述符,失败就返回-1。

获得文件描述符号

 

int nids_dispatch(int cnt);

函数返回值:函数执行成功就返回个数、失败就返回负数

参数描述:参数cnt表示捕获的数据包的个数

功能是调用LIBPCAP中的捕获数据包函数pcap_dispatch();

 

int nids_next(void);

函数返回值:成功1,失败0

调用LIBPCAP中捕获数据包函数pcap_next();

 

void nids_register_chksum_ctl(struct nids_chksum_ctl *ptr, int nr)

参数描述:参数ptr表示nids_chksum_ctl列表,参数nr表示列表中的个数

决定是否计算检验和。是根据数据结构nids_chjsum_ctl中的action进行决定的,如果所要计算的对象不在列表中,则必须都要计算检验和。

 

 

2.IP碎片函数

void nids_register_ip_frag(void(*));

参数描述:参数应该是一个回调函数的名字

注册一个能够检测所有IP数据包的回调函数,包括IP碎片。例如可用如下方式调用:

nids_register_ip_frag(ip_frag_function);

这样就注册了一个回调函数ip_ftag_function的定义类型如下:

void ip_frag_function(struct ip *a_packet, int len);

其中a_packet表示接受的IP数据包,参数len表示接受的数据包的长度。

此回调函数中可以检测所有的IP数据包,包括IP碎片。

 

void nids_register_ip(void(*));

参数描述:参数应该是一个回调函数的名字。

注册一个回调函数,可以接受正常的IP数据包。可以使用如下方式调用:

nids_register_ip(ip_function);

注册一个回调函数ip_function,此回调函数的定义类型如下:

void ip_function(struct ip *a_packet);

其中a_packet表示的是所捕获的IP数据包。

 

 

3.TCP数据流重组函数

void nids_register_tcp(void(*));

参数是一个回调函数

注册一个TCP连接的回调函数。定义如下:

void tcp_callback(struct tcp_stream *ns,  void **param);

其中参数ns表示一个TCP连接的所有信息,它的类型是tcp_stream数据结构;参数param表示要传递的连接参数信息,可以指向一个TCP连接的私有数据。

此回调函数接受的TCP数据存放在half_stream的缓存中,应该马上取出来,一旦此回调函数返回,此数据缓存中存储的数据就不存在了。half_stream成员offset描述了呗丢地的数据字节数。如果不想马上取出来,而是等到存储一定数量的数据之后再取出来,那么可以使用函数nids_discard(struct tcp_stream *a_tcp, int num_bytes);来处理。这样回调函数返回时,LIBNIDS将丢弃缓存数据之前的num_bytes字节的数据。如果不调用nids_discard()函数,那么缓存数据的字节应该为count_new字节。一般情况下,缓存中的数据应该是count_offset字节。

 

void nids_killtcp(struct tcp_stream * a_tcp)

a_tcp表示一个TCP连接

终止TCP连接。实际上是调用LIBNET的函数进行构造数据包,然后发送出去。

 

void nids_discard(struct tcp_stream *a_tcp, int num)

a_tcp表示一个TCP连接,参数num表示个数

丢弃num字节TCP数据,用于存储更多的数据。

 

 

4. UDP注册函数

LIBNIDS也提供了对UDP协议的分析,其注册函数定义如下:

void nids_register_udp(void(*))

参数是一个回调函数

注册一个分析UDP协议的回调函数,定义如下:

void udp_callback(struct tuple4 *addr,  char  * buf,  int  len,  struct  ip *iph)

addr表示地址端口信息,包括UDP发送端的IP地址和端口,以及UDP接收端额IP地址和端口;buf表示UDP协议负载数据内容;len表示UDP负载数据的长度;iph表示一个IP数据包,包括IP首部、UDP首部以及UDP负载内容。

定以后,在此回调函数中就可以对UDP数据包进行分析了。

 

 

 

LIBNIDS的使用

1.显示TCP连接

见附件

次程序的功能是重组TCP数据流,显示它们的连接状态以及传输的详细数据。利用此程序可以分析使用LIBNIDS的开发流程。首先用函数nids_init()进行初始化,然后注册相应的回调函数,最后让调用函数nids_run()进入循环捕获数据包的状态。不同的回调函数实现不同的功能,主要的工作都是在回调函数中实现的。

编译:gcc –o show_tcp_connection tcp.c –lnids –lpcap –lnet

结果如下:

 

 

2.显示UDP数据包

在LIBNIDS中,函数nids_register_udp()提供了捕获UDP协议的接口,在此函数中注册回调函数,然后在回调函数中对UDP协议进行分析。其回调函数类型如下:

void udp_callback(struct tuple4 *addr, char *buf, int len, struct ip *iph)

addr一对协议地址和端口;buf表示UDP协议的负载内容;len为buf长度;

代码见附件;

ping了一下suda网站,结果如下:

 

 

3.HTTP协议分析

HTTP协议用来实现WEB服务器和WEB浏览器之间的通信,其设计简单而灵活,它是基于客户端、服务器模型的,使用HTTP可以传输任何类型的数据,它是一个无连接的协议,每次连接只限处理一个请求。HTTP

协议是一个无状态的协议,其系统运行效率高,服务器应答速度快,但如果后续处理需要用到前面的信息,则必须重传,这样可能导致每次连接传送的数据量增大。

HTTP协议的运行基本过程主要有四步:首先浏览器与服务器建立连接;其次浏览器向服务器发送请求信息;然后服务器对请求做出应答,并发送给浏览器;最后数据传送完毕,关闭浏览器和服务器之间的连接。

其中最重要的是浏览器发送请求消息给服务器。请求消息包括的内容非常广泛,其中一般有请求行、普通头、HTTP请求头、实体头和实体。所有请求消息都由1个请求行、0个或多个头部行和1个回车换行组成。其中头部行可以是普通头、HTTP请求头或实体头,头部行之后是回车换行,回车换行之后可能有一个实体,也可以没有实体。回车换行表示实体的开始。

HTTP请求头中包括请求方法,HTTP请求方法有GET,HEAD,POST,PUT,DELETE,TRACE,CONNECT。但是最常用的方法是GET,HEAD和POST。

浏览器向服务器发送一个请求,称为请求行,使用方式如下:

Method SP Request-URI SP HTTP-Version CRLF

其中Method表示请求方法。例如,GET表示请求指定的页面信息,并返回实体主体;HEAD表示只请求页面的首部;从客户机到服务器传送数据,在要求服务器和CGI做进一步处理时会用到POST方法,它主要用于HTML文本中FORM的内容,让CGI程序处理。Request-URI表示资源。HTTP-Version表示HTTP的版本。

请求头的内容有很多,在这里就不一一列举了。

浏览器发送给服务器请求信息后,服务器及时做出应答。服务器应答向浏览器返回的应答小异一般包括状态行、普通头、响应头、实体头和实体。

状态行的格式如下:

HTTP-Version SP Status-Code SP Reason-Phrase CRLF

其中Status-Code表示状态码,是3个数字码,分为五类,以1开头的表示信息响应类,以2开头的表示请求被成功处理,以3开头的表示请求被重定向,以4开头的表示客户的请求有错,以5开头的表示服务器不能满足要求。其详细描述也不一一列举了。

无论是客户端的请求信息还是服务器端的应答信息,都可能包括普通头、实体头和实体。其中普通头内容如下。见书。实体头内容也见书。

实体是传输的资源内容,是整个HTTP协议所要传输的真正内容。实体和头部用一个空行分隔开。

在理解了HTTP协议的格式和运行机理之后,可利用LIBNIDS的TCP数据流重组机制来分析HTTP协议的内容。要实现的目标是把HTTP协议中的所有信息都进行详细分析。其完整源代码见附件。

结果如下:

 

 

4.FTP协议分析

待看

 

5.Telnet协议分析

待看

 

6.POP3协议分析

POP3(Post Office Protocol 3)是适用于客户-服务器结构的脱机模型的电子邮件协议。它规定了怎样将个人计算机连接到Internet邮件服务器和下载电子邮件的电子协议,允许用户从服务器上把邮件存储到本地主机上,同时删除保存在邮件服务器上的邮件。POP3服务器是遵循POP3协议的接收邮件服务器,用来接收电子邮件。

在POP3协议中有三种状态:认可状态、处理状态和更新状态。

当客户机和服务器建立联系时,一旦客户机提供了自己身份并成功确认,即由认可状态转入处理状态,在完成相应的操作后客户机发出QUIT命令,则进入更新状态,更新之后重返认可状态。大多数现有的POP3客户机与服务器执行采用ASCII明文发送用户名和口令,在认可状态等待用户连接的情况下,客户发出连接,并由命令user/pass对在网络上发送明文用户名和口令给服务器进行身份确认。一旦确认成功,便转入处理状态。

POP3命令你刚由1个命令和一些参数组成。所有命令以一个回车换行CRLF结束。命令和参数由可打印的ASCII字符组成,它们之间由空格隔开。命令一般是3到4个字母,每个参数却可达40个字符长。POP3响应是由1个状态码和1个可能有附加信息的命令组成。所有响应也是由回车换行CRL结束的。有两周年高状态码,状态码”+OK”表示成功,状态码“-ERR”表示失败。

对POP3命令进行详细介绍,请参考书。

代码见附件

 

7.SMTP和ESMTP协议分析

简单邮件传输协议(SMTP, Simple Mail Transfer Protocol)是一组用于由源地址到目的地址传送邮件的协议,用以控制新建的中转方式。SMTP协议用于TCP/IP协议族,它帮助每台计算机在发送或中转信件时找到下一个目的地。通过SMTP协议所指定的服务器,可以把E-mail寄到收信人的服务器上。SMTP服务器则是遵循SMTP协议的邮件发送服务商,用来发送或中转电子邮件。SMTP工作再两种情况下,一是电子邮件从客户机传输到服务器,二是从某一个服务器传输到另一个服务器。SMTP提供了一种邮件传输机制,当收件方和发件方都在一个网络上时,可以把邮件直接传给对方。当双方不在同一个网络上时,需要通过一个或几个中间服务器转发。SMTP首先由发件方提出申请,要求与接收方SMTP建立双向的通信渠道。收件方可以是最终收件人,也可以是中间转发的服务器。收件方服务器确认可以建立连接后,双方就可以开始通信。

SMTP协议的基本流程如下:首先,建立连接;其次,客户端发送命令,以标识发件人自己的身份,然后发送邮件命令,服务器端做出响应,表明是否准备接受;再次,客户端发送邮件,以标识该电子邮件的计划接收人,服务器端则表示是否愿意为收件人接收邮件,如果协商成功,则发送邮件;最后,结束此次发送,退出连接。

在SMTP协议中,最重要的内容是SMTP命令和响应状态,这是STMP运行的基础。SMTP命令都以回车换行作为结束标志,下面对它们做详细描述。(见书)

SMTP客户端向SMTP服务器发送命令之后,SMTP服务器就会返回一个应答码。应答码的每一个数字都有特定含义,第一个数字为2时表示命令成功,为5时表示失败,3时表示没有完成。详细描述应答码的含义(见书)

ESMTP待看。

用LIBNIDS分析SMTP的操作过程,代码见附件。

 

8.IP数据包的捕获和分析

LIBNIDS不仅可以捕获正常的IP数据包,也可以捕获异常的IP数据包和IP碎片。LIBNIDS提供了捕获IP碎片的接口,可对IP碎片进行重组。

代码见附件

 

9.检测攻击的一个例子

使用LIBNIDS可以检测网络攻击,它是入侵检测系统的开发包。在LIBNIDS中提供了一些基本的检测技术,如对网络扫描攻击的检测,以及对异常IP数据包、异常TCP数据包和异常UDP数据包的检测。

在LIBNIDS提供的所有功能的基础上还可以进行更深入的开发,以检测更多的入侵行为,它为进一步的开发提供了最基本的功能,其中最镇南关要的就是TCP数据流重组功能。在此基础上,可以检测更多的网络攻击行为,另外LIBNIDS已经为开发者提供了一些检测攻击的功能,如上述的端口扫描检测功能,数据包异常检测功能。

检测端口扫描攻击,主要功能来自LIBNIDS中提供的默认函数sys_log()

代码见附件

 

二、存在问题及分析(以条目式陈述,必要时配图说明)

       

三、明日工作计划(以条目式陈述)

将对下列例程序的源代码进行分析和改写,着重HTTP协议分析,SMTP和POP3协议分析

1.显示TCP连接

2.显示UDP数据报

3.HTTP协议分析

4.FTP协议分析

5.TELNET协议分析

6.POP3协议分析

7.SMTP和ESMTP协议分析

8.IP数据包的捕获和分析

9.检测攻击的一个例子


0 0
原创粉丝点击