snort + barnyard2如何正确读取snort.unified2格式的数据集并且入库MySQL(图文详解)

不多说,直接上干货!

为什么,要写这篇论文?

   是因为,目前科研的我,正值研三,致力于网络安全、大数据、机器学习研究领域!

  论文方向的需要,同时不局限于真实物理环境机器实验室的攻防环境、也不局限于真实物理机器环境实验室的大数据集群平台。在此,为了需要的博友们,能在自己虚拟机里(我这里是CentOS6.5)来搭建部署snort+barnyard2+base的入侵检测系统。分享与交流是进步的阶梯!

  同时,本人还尝试过在Ubuntu14.04里搭建这入侵检测系统的环境。同时,还尝试过在win7win10里搭建这入侵检测系统的环境。

   同时,也欢迎做报警数据方向的烟酒僧留言评论加好友交流。欢迎指正!谢谢。

前期博客

基于CentOS6.5下snort+barnyard2+base的入侵检测系统的搭建(图文详解)(博主推荐)

   注意:看过我这篇前期博客的朋友们,我这里的主机名更改了,由datatest改为snort了。这个其实就是个主机名。

数据的准备

  我这里,数据集用的是,自己抓取采集到的数据集,即/root/data/guet/snort目录下。假设部分数据如下

[root@snort snort]# pwd
/root/data/guet/snort
[root@snort snort]# ll
total 316
-rw-r--r--. 1 root root  16540 Jan 16  2017 snort.unified2.1484570063
-rw-r--r--. 1 root root 302796 Jan 17  2017 snort.unified2.1484572750
[root@snort snort]# 

   切换到这个目录下,即把之前的什么,snort.log.***都给删除。

[root@snort snort]# ll
total 8192
-rw-r--r--. 1 root root    2056 Aug 11 15:01 barnyard2.waldo
[root@snort snort]# pwd
/var/log/snort
[root@snort snort]# 

 

  将snort.conf里

output unified2: filename snort.log,limit 128

改为

output unified2: filename snort.u2,limit 128

 或者不改

   我这里啊,为了表达我自己采集的数据,特意新建了个数据库guetsnort,来存储。

 

 

   对应,在/etc/snort/barnyard2.conf里将

   output database: log, mysql, user=snort password=snort dbname=snort host=localhost

 

   改为

   output database: log, mysql, user=snort password=snort dbname=guetsnort host=localhost

自定义规则local.rules

[root@snort rules]# pwd
/etc/snort/rules
[root@snort rules]# cat local.rules 
alert ip any any -> any any (msg: "IP Packet detected";sid:1000001;)

  

  得注释掉,/etc/snort下的barnyard2.conf配置文件。

#config waldo_file: /var/log/snort/barnyard2.waldo

执行顺序

  执行,启动barnyard2

[root@snort ~]# barnyard2 -c /etc/snort/barnyard2.conf -d /var/log/snort -f snort.u2 -w /var/log/snort/barnyard2.waldo 

  也许这个命令不行。

  得为如下。(下面这个操作是可行的)

[root@snort ~]# barnyard2 -c /etc/snort/barnyard2.conf -d /root/data/guet/snort -f snort.unified2

   

  这是,fast模式

  http://man.chinaunix.net/network/snort/Snortman.htm

  即,因为,是snort.fast模式,所以需要在/etc/snort下的barnyard2.conf里

output alert_fast: stdout

  则打印出如下。

  成功!

  或者

   或者

 

  那么, 对于,有时候,我们需要full模式呢,怎么来做?(这才是最重要和最关心的)

  http://man.chinaunix.net/network/snort/Snortman.htm

  因为,这里,其实数据是通过snort来产生得到的snort.unified2数据。

  所以,只需用到barnyard2即可。

 即,因为,是snort.full模式,所以需要在/etc/snort下的barnyard2.conf里

output alert_full: alert.full

[root@snort snort]# pwd
/root/data/guet/snort
[root@snort snort]# ll
total 20
-rw-r--r--. 1 root root 16540 Jan 16  2017 snort.unified2.1484570063
[root@snort snort]# barnyard2 -c /etc/snort/barnyard2.conf -d /root/data/guet/snort -f snort.unified2

  

  由

   变成

 

[root@snort barnyard2]# pwd
/var/log/barnyard2
[root@snort barnyard2]# ll
total 0
[root@snort barnyard2]# ll
total 4
-rw-r--r--. 1 root root 2930 Aug 13 14:42 alert.full
[root@snort barnyard2]# 

  成功!

   也就是说,这个alert.full就是snort.unified2.1484570063这个文件的内容。

  

  或者,比如,假设,我这目录下很多数据。

   则,可以这样来一次性收到一个txt里。则是

[root@snort snort]# barnyard2 -c /etc/snort/barnyard2.conf -d /root/data/guet/snort/nssa-sensor3 -f snort.unified2 > nssa-sensor3_snort.txt

[root@snort snort]# barnyard2 -c /etc/snort/barnyard2.conf -d /root/data/guet/snort/nssa-sensor4 -f snort.unified2 > nssa-sensor4_snort.txt

    这样也是可行。

output alert_full: stdout含义和output alert_full:  alert.full 

  前者stdout直接是打印到屏幕上

  后者alert.full是输出到/var/log/barnyard2下的alert.full文件里。

  barnyard2的github网站

https://github.com/firnsy/barnyard2

  或者以下也是可以的

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| snort              |
| test               |
+--------------------+
4 rows in set (0.01 sec)

mysql> create database guetsnort;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| guetsnort          |
| mysql              |
| snort              |
| test               |
+--------------------+
5 rows in set (0.00 sec)

mysql> 

   然后

   然后,注释掉/etc/snort/barnyard2.conf里

#config waldo_file: /var/log/snort/barnyard2.waldo

   以下是我数据放置的目录

    然后执行

[root@snort snort]# barnyard2 -c /etc/snort/barnyard2.conf -d /root/data/guet/snort/nssa-sensor3 -f snort.unified2 

  我这里,经多次尝试,依然还是无法用新建的数据库来导入。

  所以,我这就把导好的DARPA 1999数据库给删除掉了。

  这里教大家的是,如何在base界面里快速删除数据。

 

   成功删除。

   或者在base界面里快速清空里面的数据。

  操作如下:

   得到的

   成功!

  然后,继续尝试

[root@snort ~]# barnyard2 -c /etc/snort/barnyard2.conf -d /root/data/guet/snort/nssa-sensor3 -f snort.unified2 

   成功!

欢迎大家,加入我的微信公众号:大数据躺过的坑        人工智能躺过的坑
 
 
 

同时,大家可以关注我的个人博客

   http://www.cnblogs.com/zlslch/   和     http://www.cnblogs.com/lchzls/      http://www.cnblogs.com/sunnyDream/   

   详情请见:http://www.cnblogs.com/zlslch/p/7473861.html

  人生苦短,我愿分享。本公众号将秉持活到老学到老学习无休止的交流分享开源精神,汇聚于互联网和个人学习工作的精华干货知识,一切来于互联网,反馈回互联网。
  目前研究领域:大数据、机器学习、深度学习、人工智能、数据挖掘、数据分析。 语言涉及:Java、Scala、Python、Shell、Linux等 。同时还涉及平常所使用的手机、电脑和互联网上的使用技巧、问题和实用软件。 只要你一直关注和呆在群里,每天必须有收获

      对应本平台的讨论和答疑QQ群:大数据和人工智能躺过的坑(总群)(161156071) 

 

原文地址:https://www.cnblogs.com/zlslch/p/7347854.html