Libnids在Ubuntu下的安装
来源:互联网 发布:结婚证照片制作软件 编辑:程序博客网 时间:2024/05/30 13:43
Libnids在Linux下安装
Libnids下载:http://download.csdn.net/download/u013074465/8596159
官方地址:http://libnids.sourceforge.net/
Libnids需要libpcap和libnet库的支持,因此首先确保自己的linux主机安装了这两个开发包,没有提前安装。
进入解压的Libnids的目录,依次执行:
./configure
make
sudo make install
在我的Ubuntu下安装中如果上面没有sudo会出错:
输出TCP连接信息的例子
//文件:tcp.c#include "./src/nids.h" /* Libnids的头文件,必须包含 */ char ascii_string[10000]; char *char_to_ascii(char ch) /* 此函数的功能主要用于把协议数据进行显示 */ { char *string; ascii_string[0] = 0; string = ascii_string; if (isgraph(ch)) /* 可打印字符 */ { *string++ = ch; } else if (ch == ' ') /* 空格 */ { *string++ = ch; } else if (ch == '\n' || ch == '\r') /* 回车和换行 */ { *string++ = ch; } else /* 其它字符以点"."表示 */ { *string++ = '.'; } *string = 0; return ascii_string; } /* ====================================================================================下面的函数是回调函数,用于分析TCP连接,分析TCP连接状态,对TCP协议传输的数据进行分析 ==================================================================================== */ void tcp_protocol_callback(struct tcp_stream *tcp_connection, void **arg) { int i; char address_string[1024]; char content[65535]; char content_urgent[65535]; struct tuple4 ip_and_port = tcp_connection->addr; /* 获取TCP连接的地址和端口对 */ strcpy(address_string, inet_ntoa(*((struct in_addr*) &(ip_and_port.saddr)))); /* 获取源地址 */ sprintf(address_string + strlen(address_string), " : %i", ip_and_port.source); /* 获取源端口 */ strcat(address_string, " <---> "); strcat(address_string, inet_ntoa(*((struct in_addr*) &(ip_and_port.daddr)))); /* 获取目的地址 */ sprintf(address_string + strlen(address_string), " : %i", ip_and_port.dest); /* 获取目的端口 */ strcat(address_string, "\n"); switch (tcp_connection->nids_state) /* 判断LIBNIDS的状态 */ { case NIDS_JUST_EST: /* 表示TCP客户端和TCP服务器端建立连接状态 */ tcp_connection->client.collect++; /* 客户端接收数据 */ tcp_connection->server.collect++; /* 服务器接收数据 */ tcp_connection->server.collect_urg++; /* 服务器接收紧急数据 */ tcp_connection->client.collect_urg++; /* 客户端接收紧急数据 */ printf("%sTCP连接建立\n", address_string); return ; case NIDS_CLOSE: /* 表示TCP连接正常关闭 */ printf("--------------------------------\n"); printf("%sTCP连接正常关闭\n", address_string); return ; case NIDS_RESET: /* 表示TCP连接被RST关闭 */ printf("--------------------------------\n"); printf("%sTCP连接被RST关闭\n", address_string); return ; case NIDS_DATA: /* 表示有新的数据到达 */ { struct half_stream *hlf; /* 表示TCP连接的一端的信息,可以是客户端,也可以是服务器端 */ if (tcp_connection->server.count_new_urg) { /* 表示TCP服务器端接收到新的紧急数据 */ printf("--------------------------------\n"); strcpy(address_string, inet_ntoa(*((struct in_addr*) &(ip_and_port.saddr)))); sprintf(address_string + strlen(address_string), " : %i", ip_and_port.source); strcat(address_string, " urgent---> "); strcat(address_string, inet_ntoa(*((struct in_addr*) &(ip_and_port.daddr)))); sprintf(address_string + strlen(address_string), " : %i", ip_and_port.dest); strcat(address_string, "\n"); address_string[strlen(address_string) + 1] = 0; address_string[strlen(address_string)] = tcp_connection->server.urgdata; printf("%s", address_string); return ; } if (tcp_connection->client.count_new_urg) { /* 表示TCP客户端接收到新的紧急数据 */ printf("--------------------------------\n"); strcpy(address_string, inet_ntoa(*((struct in_addr*) &(ip_and_port.saddr)))); sprintf(address_string + strlen(address_string), " : %i", ip_and_port.source); strcat(address_string, " <--- urgent "); strcat(address_string, inet_ntoa(*((struct in_addr*) &(ip_and_port.daddr)))); sprintf(address_string + strlen(address_string), " : %i", ip_and_port.dest); strcat(address_string, "\n"); address_string[strlen(address_string) + 1] = 0; address_string[strlen(address_string)] = tcp_connection->client.urgdata; printf("%s", address_string); return ; } if (tcp_connection->client.count_new) { /* 表示客户端接收到新的数据 */ hlf = &tcp_connection->client; /* 此时hlf表示的是客户端的TCP连接信息 */ strcpy(address_string, inet_ntoa(*((struct in_addr*) &(ip_and_port.saddr)))); sprintf(address_string + strlen(address_string), ":%i", ip_and_port.source); strcat(address_string, " <--- "); strcat(address_string, inet_ntoa(*((struct in_addr*) &(ip_and_port.daddr)))); sprintf(address_string + strlen(address_string), ":%i", ip_and_port.dest); strcat(address_string, "\n"); printf("--------------------------------\n"); printf("%s", address_string); memcpy(content, hlf->data, hlf->count_new); content[hlf->count_new] = '\0'; /*printf("客户端接收数据\n"); for (i = 0; i < hlf->count_new; i++) { printf("%s", char_to_ascii(content[i])); //输出客户端接收的新的数据,以可打印字符进行显示 } printf("\n"); */ } else { /* 表示服务器端接收到新的数据 */ hlf = &tcp_connection->server; /* 此时hlf表示服务器端的TCP连接信息 */ strcpy(address_string, inet_ntoa(*((struct in_addr*) &(ip_and_port.saddr)))); sprintf(address_string + strlen(address_string), ":%i", ip_and_port.source); strcat(address_string, " ---> "); strcat(address_string, inet_ntoa(*((struct in_addr*) &(ip_and_port.daddr)))); sprintf(address_string + strlen(address_string), ":%i", ip_and_port.dest); strcat(address_string, "\n"); printf("--------------------------------\n"); printf("%s", address_string); memcpy(content, hlf->data, hlf->count_new); content[hlf->count_new] = '\0'; /* printf("服务器端接收数据:\n"); for (i = 0; i < hlf->count_new; i++) { printf("%s", char_to_ascii(content[i])); // 输出服务器接收到的新的数据 } printf("\n"); */ } } default: break; } return ; } void main() { if (!nids_init()) /* Libnids初始化 */ { printf("出现错误:%s\n", nids_errbuf); exit(1); } nids_register_tcp(tcp_protocol_callback); /* 注册回调函数 */ nids_run(); /* Libnids进入循环捕获数据包状态 */ }
(1)编译该程序的命令:gcc tcp.c -lnids -lpcap -lnet -lgthread-2.0
因为libnids 1.22以后使用了,glib2库中的gthread-2.0来实现多线程提高效率,因此在编译除了-lnids -lpcap -lnet 以外还要加上 -lgthread-2.0
(2)执行程序出错“./a.out”:
将执行命令改为“sudo ./a.out”:出现此问题原因仍然是权限不够,进程无权使用网卡捕获数据包。
0 0
- Libnids在Ubuntu下的安装
- Ubuntu下Libnids的安装详解
- libnids在Windows下的安装
- linux下libnids的安装
- linux下libnids的安装
- ubuntu下安装libnet、libpcap、libnids等环境
- ubuntu下安装libnet、libpcap、libnids等环境
- ubuntu 安装 libpcap、libnet、libnids
- Libnids安装过程以及存在的问题
- Synergy在Ubuntu下的安装
- 关于libpcap在ubuntu下的安装
- QtCreator4.5在Ubuntu下的安装
- Python3在ubuntu环境下的安装
- GCC在Ubuntu Linux下的安装
- bochs在ubuntu下的安装心得
- wxWidgets 2.8 在ubuntu 下的安装
- freetds在UBUNTU下的安装
- QtCreator4.5在Ubuntu下的安装
- RFC3261 sip协议------cancel请求
- IOS开源库一览表
- 关于srcollTop+clientTop+offsetTop的总结
- 渣蜀黍 - iOS 个人笔记(四)_极光推送使用步骤
- 创建job让oracel自动运行存储过程
- Libnids在Ubuntu下的安装
- java笔试面试题(二)
- “创客”进政府工作报告 创业迎来黄金时代
- jsp之javabean快捷赋值
- 09年 ZZUPC校赛第四题 多重背包 最大杀伤力
- wince Gridview 设置样式添加数据
- C++string类常用函数
- iOS数据存储的四种方案对比
- js版本导致的CSS紊乱