基于ubuntu-20.04.3的snort+Barnyard2+BASE的入侵检测系统安装时Barnyard2反编译时出错解决

本文详细讲述了在Ubuntu 20.04环境下安装Snort、Barnyard2及BASE入侵检测系统时,遇到的Barnyard2反编译过程中常见错误,包括po_alert_fwsam.c的类型声明错误、my_bool类型的替换,以及spo_database.h和spo_database_cache.c文件的修正。通过文本编辑器修改源代码,解决了编译问题并成功完成安装。
摘要由CSDN通过智能技术生成

基于ubuntu-20.04.3的snort+Barnyard2+BASE的入侵检测系统安装时Barnyard2反编译时出错解决

在按照https://www.modb.pro/db/159797大佬的博客安装IDS,在安装Barnyard2时

sudo apt-get install -y mysql-server libmysqlclient-dev mysql-client autoconf libtool
tar zxvf barnyard2-2-1.13.tar.gz

cd barnyard2-2-1.13

autoreconf -fvi -I ./

./configure --with-mysql --with-mysql-libraries=/usr/lib/x86_64-linux-gnu

sudo make

sudo make install

当进行sudo make到,报了很多错误,在网上冲了几个小时,并没有找到相应的解答,直到看到这位大佬的文章
其中提到了第一个报错:po_alert_fwsam.c:118:13: error: two or more data types in declaration specifiers是源代码的bug,醍醐灌顶,直接改代码不就行了!

错误一:spo_alert_fwsam.c文件语法错误

po_alert_fwsam.c:118:13: error: two or more data types in declaration specifiers
  118 | typedef int SOCKET;
      |             ^~~~~~
spo_alert_fwsam.c:118:1: warning: useless type name in empty declaration
  118 | typedef int SOCKET;
      | ^~~~~~~
In file included from /usr/local/include/pcap/pcap.h:130,
                 from /usr/local/include/pcap.h:43,
                 from ../barnyard2.h:46,
                 from spo_alert_fwsam.c:91:
spo_alert_fwsam.c:118:13: error: two or more data types in declaration specifiers
  118 | typedef int SOCKET;
      |             ^~~~~~
spo_alert_fwsam.c:118:1: warning: useless type name in empty declaration
  118 | typedef int SOCKET;
      | ^~~~~~~
spo_alert_fwsam.c: In function ‘FWsamReadLine’:
spo_alert_fwsam.c:620:9: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
  620 |         if(p>buf);
      |         ^~
spo_alert_fwsam.c:621:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
  621 |             strcpy(buf,p);
      |             ^~~~~~
spo_alert_fwsam.c: In function ‘FWsamReadLine’:
spo_alert_fwsam.c:620:9: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
  620 |         if(p>buf);
      |         ^~
spo_alert_fwsam.c:621:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
  621 |             strcpy(buf,p);
      |             ^~~~~~
spo_alert_fwsam.c: In function ‘AlertFWsam’:
spo_alert_fwsam.c:979:18: warning: variable ‘cn’ set but not used [-Wunused-but-set-variable]
  979 |     ClassType   *cn = NULL;
      |                  ^~
spo_alert_fwsam.c:978:18: warning: variable ‘sn’ set but not used [-Wunused-but-set-variable]
  978 |     SigNode     *sn = NULL;
      |                  ^~
spo_alert_fwsam.c: In function ‘AlertFWsam’:
spo_alert_fwsam.c:979:18: warning: variable ‘cn’ set but not used [-Wunused-but-set-variable]
  979 |     ClassType   *cn = NULL;
      |                  ^~
spo_alert_fwsam.c:978:18: warning: variable ‘sn’ set but not used [-Wunused-but-set-variable]
  978 |     SigNode     *sn = NULL;
      |                  ^~
spo_alert_fwsam.c:971:27: warning: variable ‘lastbsp’ set but not used [-Wunused-but-set-variable]
  971 |     static unsigned short lastbsp[FWSAM_REPET_BLOCKS];
      |                           ^~~~~~~
spo_alert_fwsam.c:971:27: warning: variable ‘lastbsp’ set but not used [-Wunused-but-set-variable]
  971 |     static unsigned short lastbsp[FWSAM_REPET_BLOCKS];
      |                           ^~~~~~~
make[3]: *** [Makefile:391:spo_alert_fwsam.o] 错误 1
make[3]: 离开目录“/home/isis/barnyard2-2-1.13/src/output-plugins”
make[2]: *** [Makefile:497:all-recursive] 错误 1
make[2]: 离开目录“/home/isis/barnyard2-2-1.13/src”
make[1]: *** [Makefile:412:all-recursive] 错误 1
make[1]: 离开目录“/home/isis/barnyard2-2-1.13”
make: *** [Makefile:344:all] 错误 2
make[2]: *** [Makefile:391:spo_alert_fwsam.o] 错误 1
make[2]: 离开目录“/home/isis/barnyard2-2-1.13/src/output-plugins”
make[1]: *** [Makefile:497:install-recursive] 错误 1
make[1]: 离开目录“/home/isis/barnyard2-2-1.13/src”
make: *** [Makefile:412:install-recursive] 错误 1
[2]-  退出 2                sudo make

具体解决方法如下:
用ubuntu自带的文本编辑器打开文件/barnyard2-2-1.13/src/output-plugins/spo_alert_fwsam.c
修改以下内容:

1. 用Barnyard2_SOCKET替换SOCKET

118 - typedef int SOCKET;				//用Barnyard2_SOCKET替换SOCKET
    + typedef int Barnyard2_SOCKET;
    ……
964 - SOCKET stationsocket;
    + BARNYARD2_SOCKET stationsocket;
    ……
1390 - SOCKET stationsocket;
     + BARNYARD2_SOCKET stationsocket;
1541 - SOCKET stationsocket;
     + BARNYARD2_SOCKET stationsocket;

2. 删除if语句后的分号

620  if(p>buf);			//删除分号
621     strcpy(buf,p);

3. 其他错误应该是误报,可以忽视。

再次sudo make时,问题一就解决了,但这只是一个开始!再次运行sudo make时,又出现了错误

问题二:spo_database.h文件出错

In file included from spo_database.c:103:
../output-plugins/spo_database.h:360:5: error: unknown type name ‘my_bool’
  360 |     my_bool mysql_reconnect; /* We will handle it via the api. */
      |     ^~~~~~~
In file included from spo_database.c:103:
../output-plugins/spo_database.h:360:5: error: unknown type name ‘my_bool’
  360 |     my_bool mysql_reconnect; /* We will handle it via the api. */

出现这个错误是因为在 MySQL 8 中,my_bool 被重命名为 bool。
解决方法很简单:用ubuntu自带的文本编辑器打开文件/barnyard2-2-1.13/src/output-plugins/spo_database.h

bool替换my_bool

再次运行sudo make,依旧报错

问题三:spo_database_cache.c文件报错

spo_database_cache.c: In function ‘SignatureReferenceCacheUpdateDBid’:
spo_database_cache.c:5270:6: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
 5270 |      memset(sigRefArr,'\0',MAX_REF_OBJ);
      |      ^~~~~~
spo_database_cache.c: In function ‘SignatureReferenceCacheUpdateDBid’:
spo_database_cache.c:5270:6: warning: ‘memset’ used with length equal to number of elements without multiplication by element size [-Wmemset-elt-size]
 5270 |      memset(sigRefArr,'\0',MAX_REF_OBJ);

函数解释:
memset:作用是在一段内存块中填充某个给定的值,它是对较大的结构体或数组进行清零操作的一种最快方法 。

void *memset(void *s, int ch, size_t n); //将s中当前位置后面的n个字节 (typedef unsigned int size_t )用 ch 替换并返回 s 

在此文件中的memset是多余的. 因为这块内存马上就被全部覆盖,清零没有意义.
解决方法很简单

用/**/注释memset(sigRefArr,'\0',MAX_REF_OBJ);,忽略此函数

最后在运行sudo make && sudo make install,就成功啦

barnyard2-1.9.tar是一个软件包,用于与Snort(一个开源的入侵检测系统)一起使用。它可以将Snort的日志输出转换为可读性更好的格式,并将其存储在数据库中,以便进行分析和管理。这个软件包提供了一个灵活的框架,允许用户配置各种不同的输出和存储选项。 barnyard2-1.9.tar可以通过以下步骤安装和配置: 1. 下载barnyard2-1.9.tar软件包文件,并将其解压缩到一个目录中。 2. 打开终端或命令提示符窗口,并切换到解压缩后的目录。 3. 执行configure命令来配置软件包。根据系统的需求和用户的偏好,可以添加一些额外的参数来自定义安装选项。 4. 运行make命令来编译软件包。 5. 运行make install命令以将编译后的软件包安装到系统中。 6. 打开配置文件(通常是barnyard2.conf)并根据需要进行修改。配置文件包含了各种设置,例如日志输出目标、数据库连接信息和日志格式。 7. 启动barnyard2进程,可以使用以下命令:barnyard2 -c barnyard2.conf。 在运行期间,barnyard2将读取Snort的日志输出,并将其转换为可读性更好的格式。这些日志可以存储在本地或远程数据库中,以便后续分析和查询。此外,barnyard2还可以将警报发送到其他系统,如SIEM(安全信息和事件管理系统)或日志收集器。 总之,barnyard2-1.9.tar是一个与Snort配合使用的软件包,使得Snort日志的处理和管理更加方便和灵活。通过安装和配置barnyard2,用户可以获得更好的安全日志分析和管理功能。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值