十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
部署参考:http://blog.csdn.net/qq_29277155/article/details/53205582
部分参考:https://linux.cn/article-6985-1.html
https://suricata-ids.org/download/
http://suricata.readthedocs.io/en/latest/index.html
http://www.cnblogs.com/piaolingzxh/p/4217480.html
成都创新互联公司专注于营山企业网站建设,自适应网站建设,商城网站建设。营山网站建设公司,为营山等地区提供建站服务。全流程按需求定制设计,专业设计,全程项目跟踪,成都创新互联公司专业和态度为您提供的服务
Suricata是一个高性能的网络IDS,IPS和网络安全监控引擎。Suricata是一个网络***检测和防护引擎,由开放信息安全基金会及其支持的厂商开发。该引擎是多线程的,内置支持IPV6。可加载现有的Snort规则和签名,支持Barnyard 和 Barnyard2 工具.
IDS:英文“Intrusion Detection Systems”的缩写,中文意思是“***检测系统”。依照一定的安全策略,通过软、硬件,对网络、系统的运行状况进行监视,尽可能发现各种***企图、***行为或者***结果,以保证网络系统资源的机密性、完整性和可用性。
Barnyard:知名的开源IDS的日志工具,具有快速的响应速度,优异的数据库写入功能,是做自byebug定义的***检测系统不可缺少的插件。
IPS:***预防系统(IPS: Intrusion Prevention System)是电脑网络安全设施,是对防病毒软件(Antivirus Programs)和防火墙(Packet Filter, Application Gateway)的补充。 ***预防系统(Intrusion-prevention system)是一部能够监视网络或网络设备的网络资料传输行为的计算机网络安全设备,能够即时的中断、调整或隔离一些不正常或是具有伤害性的网络资料传输行为。是新一代的侵入检测系统(IDS)。
IDS和IPS的区别:IDS只是发现***、产生报警,而IPS不但可以发现***,更重要的是针对***采取行动。
一、部署Suricata、Barnyard 2、Snorby服务器
1、MySQL安装
yum install -y mysql-community-server
启动mysql
systemctl start mysqld.service
给mysql赋权限,设置密码,允许登录的主机,省略,
2、安装相关的依赖
yum install epel-release
#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
#yum clean all
#yum makecache
安装依赖包
yum -y install ImageMagickgcc-c++ patch readline readline-devel zlib zlib-devel git-core libyaml-devel libffi-devel openssl-devel make libpcap-devel pcre-devel libyaml-devel file-devel jansson-devel nss-devel libcap-ng-devel libnet-devel tar libnetfilter_queue-devel lua-devel mysql-devel fontconfig-devel libX11-devel libXrender-devel libxml2-devel libxslt-devel qconf
cd /opt/
wget -O libhtp-0.5.20.tar.gz https://codeload.github.com/OISF/libhtp/tar.gz/0.5.20
tar zxvf libhtp-0.5.20.tar.gz && cd libhtp-0.5.20
./autogen.sh
./configure && make && make install
3、安装Ruby on rails
curl -L get.rvm.io | bash -s stable
command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -#导入证书
source /etc/profile.d/rvm.sh
rvm install 2.0.0
rvm use 2.0.0--default 如果有多个ruby 版本,才使用这条语句。
ruby -v
gem install bundler # 安装bundler
cd /opt/
git clone git://github.com/Snorby/snorby.git
cd /opt/snorby
创建snorby_config.yml和database.yml两个文件
cp config/snorby_config.yml.example config/snorby_config.yml
cp config/database.yml.example config/database.yml
修改文件参考:https://linux.cn/article-6985-1.html
修改文件Gemfile,把gem 'rake', '0.9.2' 改成 gem 'rake', '> 0.9.2'
sed -i '/dm-postgres-adapter/d' Gemfile
设置iptables
/etc/init.d/iptables stop #关闭防火墙,其他主机可以访问http://ip:3000
iptables -I INPUT -p tcp --dport 3000 -mstate --state=NEW,ESTABLISHED,RELATED -j ACCEPT
初始化rails
bundle install
cd /opt/snorby
rake snorby:setup
启动服务snory:
rails server -e production &
[1] 1519
[david-dai@dep006 snorby]$ syck has been removed, psych is used instead
=> Booting Thin
=> Rails 3.2.22 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
4、安装suricata
yum install suricata
编辑suricata.yaml文件
touch /var/log/suricata/suricata.waldo
修改日志格式文件:
sed -i -e '/default-log-format/a\ default-log-format: "[%i] %t -(%f:%l) <%d> (%n) -- "' /etc/suricata/suricata.yaml
开启syslog 功能, 在/etc/suricata/suricata.yaml , 找到:
sed -i -e '\/var\/log\/suricata\/suricata.log/,/Step 4/s/no/yes/g' /etc/suricata/suricata.yaml
开启unified2 logging in the suricata yaml:
sed -i -e '/unified2-alert/,/unified2.alert/s/no/yes/g' /etc/suricata/suricata.yaml
找到#pid-file: /var/run/suricata.pid把前面的#号去掉
sed -i -e '/pid-file/a\pid-file: /var/run/suricata.pid' /etc/suricata/suricata.yaml
找到rule-files,把下面的emerging-icmp.rules 和emerging-virus.rules删除掉。(unfinished)
启用 threshold,找到#threshold-file: /etc/suricata/threshold.config
sed -i -e '/threshold-file/a\threshold-file: /etc/suricata/threshold.config' /etc/suricata/suricata.yaml
首次配置 Suricata IDS 参考:https://linux.cn/article-6985-1.html
vim /etc/suricata/suricata.yaml
(1)所有的interface:etho 修改为:interface:em2 因为我只有em1和em2 网卡,这里监测公网ip的em2网卡流量,ye可以监测em1网卡流量。
(2)现在到了配置 Suricata 的时候了。配置文件的位置是 /etc/suricata/suricata.yaml。参照以下命令,用文本编辑器打开这个文件。
为default-log-dir关键字指定 Suricata 日志文件所在的位置。
default-log-dir: /var/log/suricata/
(3)在vars部分下方,你会发现几项对 Suricata 来说很重要变量。HOME_NET变量需要指定 Suricata 检查的网络。被分配给 EXTERNAL_NET 变量的 !$HOME_NET 代表除本地网络之外的其他网络。XXX_PORTS变量用来辨别不同服务所用到的端口号。需要注意的是无论使用什么端口,Suricata 都可以自动检测 HTTP 流量。所以是不是正确指定端口就显得没那么重要了。
vars:
address-groups:
HOME_NET: "[221.228.208.0/24,172.22.66.0/24]"
(4)host-os-policy 部分用于防御利用操作系统网络栈的自身行为来逃避检测的一些知名***手段(例如:TCP reassembly)。作为对策,通过针对目标操作系统而对检测引擎算法进行微调,现代 IDC 提供了“基于目标”的检测手段。因此,如果你知道某台主机运行了什么操作系统的话,将这个信息提供给 Suricata 就可以大幅提高检测的成功率。这就是 host-os-policy 存在的意义。本例中,默认的 IDC 策略是 Linux 系统。如果针对某个 IP 地址没有指定操作系统信息,Suricata 会默认应用基于 Linux 系统的检测策略。如下,当捕获到对 192.168.122.0/28 和 192.168.122.155通讯时,Suricata 就会应用基于 Windows 系统的检测策略。
host-os-policy:
windows: [0.0.0.0/0]
bsd: []
bsd-right: []
old-linux: []
linux: [0.0.0.0/0]
old-solaris: []
solaris: []
hpux10: []
hpux11: []
irix: []
macos: []
vista: []
windows2k3: []
按照以下方法关闭 em 接口的 LRO/GRO 功能。
sudo ethtool -K em1 gro off lro off
sudo ethtool -K em2 gro off lro off
Suricata 支持许多运行模式。运行模式决定着 IDC 会使用何种线程。以下命令可以查看所有 可用的运行模式。
sudo /usr/local/bin/suricata --list-runmodes
安装规则,也可以从其他服务器上拷贝过来到/etc/suricata/rules目录即可:
root@deptest34:/home/david/suricata-2.0.8# make install-rules
install -d "/etc/suricata/rules"
/usr/bin/wget -qO - http://rules.emergingthreats.net/open/suricata-2.0/emerging.rules.tar.gz | tar -x -z -C "/etc/suricata/" -f -
You can now start suricata by running as root something like '/usr/local/bin/suricata -c /etc/suricata//suricata.yaml -i eth0'.
If a library like libhtp.so is not found, you can run suricata with:
'LD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/suricata -c /etc/suricata//suricata.yaml -i eth0'.
While rules are installed now, it's highly recommended to use a rule manager for maintaining rules.
The two most common are Oinkmaster and Pulledpork. For a guide see:
https://redmine.openinfosecfoundation.org/projects/suricata/wiki/Rule_Management_with_Oinkmaster
root@deptest34:/home/david/suricata-2.0.8# echo $?
0
更新规则命令:
suricatasc -c reload-rules
启动suricata:
LD_LIBRARY_PATH=/usr/local/lib /usr/sbin/suricata -c /etc/suricata/suricata.yaml -i em2 -D &
tailf /var/log/suricata/stats.log
5、安装barnyard2
cd /opt/
wget https://codeload.github.com/firnsy/barnyard2/tar.gz/v2-1.13
tar xvfz barnyard2-2-1.13.tar.gz && cd barnyard2-2-1.13/
./autogen.sh
./configure --with-mysql-libraries=/usr/lib64/mysql/ --with-mysql=/usr/bin/mysql
make && make install
vim /etc/suricata/barnyard2.conf
配置Barnyard 2
#把Barnyard 2安装源文件中的etc/barnyard2.conf文件拷贝到Suricata的配置目录下
cd /opt/barnyard2-2-1.13
cp ./etc/barnyard2.conf /etc/suricata/
#创建barnyard2日志目录/var/log/barnyard2
mkdir /var/log/barnyard2
修改barnyard2.conf
把 默认的snort文件配置改成 suricata
sed -i 's/snort/suricata/g' /etc/suricata/barnyard2.conf
sed -i 's/gen-msg.map/\/rules\/gen-msg.map/g' /etc/suricata/barnyard2.conf
sed -i 's/sid-msg.map/\/rules\/sid-msg.map/g' /etc/suricata/barnyard2.conf
把数据库信息添加到barnyard2.conf
sed -i '$a output database: log, mysql, user=root password=1q2w3e4r dbname=snorby host=localhost' /etc/suricata/barnyard2.conf
#找到“config hostname”和“config interface”,em2是镜像端口所在的网卡,按照你的实际情况修改
sed -i -e '/#config hostname: thor/\a/config hostname: $hostname/' /etc/suricata/barnyard2.conf
sed -i -e '/#config interface: eth0/\a/config interface: em2/' /etc/suricata/barnyard2.conf
sed -i -e '/config waldo_file/a\config waldo_file: /var/log/suricata/suricata.waldo' /etc/suricata/barnyard2.conf
启动barnyard2:
sudo /usr/local/bin/barnyard2 -c /etc/suricata/barnyard2.conf -d /var/log/suricata -f unified2.alert -w /var/log/suricata/suricata.waldo –D &
到目前为止,一台服务器ids/ips 监测部署好监测客户端和展示服务端,如果需要监测其他服务器,怎么办?
好像网络上把流量镜像拷贝到这台服务器上,是一种方法。这里采用C/S方法,部署suricata客户端。
二、ubuntu 服务器上安装Suricata、Barnyard 2客户端
这里在每台服务器上部署Suricata,保存为waldo格式,Barnyard2把日志全部推送到snorby服务器上,统一展示。
1、安装依赖包
apt-get install libpcre3 libpcre3-dbg libpcre3-dev libpcap*\
build-essential autoconf automake libtool pkg-config\
libpcap-dev libnet1-dev mysql-client libmysqlclient16 flex software-properties-common python-software-properties
2、这里采用ppa方式安装suricata,也可以使用编译安装suricata,编译安装barnyard2
sudo add-apt-repository ppa:oisf/suricata-stable
sudo apt-get update
sudo apt-get install suricata
wget http://www.tcpdump.org/release/libpcap-1.2.1.tar.gz
tar -zxvf libpcap-1.2.1.tar.gz
cd libpcap-1.2.1
apt-get install flex
./configure && make && make install
root@TS-DEP-CENTER01:/tmp/barnyard2-2-1.13# /sbin/ldconfig
cd /tmp/
wget https://www.openinfosecfoundation.org/download/suricata-3.2.4.tar.gz
tar -zxvf suricata-3.2.4.tar.gz
cd suricata-3.2.4
make clean
./configure --prefix=/usr/ --sysconfdir=/etc/ --localstatedir=/var/
make
make install
mkdir -p /var/log/barnyard2
mkdir -p /var/log/suricata
cd /tmp/
wget https://codeload.github.com/firnsy/barnyard2/tar.gz/v2-1.13
mv v2-1.13 barnyard2-2-1.13.tar.gz
cd /tmp/barnyard2-2-1.13
./configure --with-mysql && make && make install
cp ./etc/barnyard2.conf /etc/suricata/
3、修改barnyard2 和 suricata的配置文件
可以拷贝之前的配置,我直接用salt同步。
参考上文,省略
barnyard2配置示例:
vim /etc/suricata/barnyard2.conf
root@TS-DEP-CENTER01:/opt# grep -v '^#' /etc/suricata/barnyard2.conf | grep -v '^$'
config reference_file: /etc/suricata/reference.config
config classification_file: /etc/suricata/classification.config
config gen_file: /etc/suricata//rules/gen-msg.map
config sid_file: /etc/suricata//rules/sid-msg.map
config hostname: TS-DEP-CENTER01-172.22.66.41
config interface: em2
input unified2
output alert_fast: stdout
output database: log, mysql, user=root password=1q2w3e4r dbname=snorby host=172.22.66.6
4、启动suricata:
suricata -c /etc/suricata/suricata.yaml -i em1 -D &
5、启动barnyard2
sudo /usr/local/bin/barnyard2 -c /etc/suricata/barnyard2.conf -d /var/log/suricata -f unified2.alert -w /var/log/suricata/suricata.waldo –D &
打印出来的日志会告诉你是否连接数据库成功,上报的host和网卡信息。
然后到系统上查看sensor(host)信息:
问题:
depshlt02(ubuntu14.04)
The following packages have unmet dependencies:
libpcre3-dbg : Depends: libpcrecpp0 (= 1:8.31-2ubuntu2.1) but 1:8.31-2ubuntu2.3 is to be installed
libpcre3-dev : Depends: libpcrecpp0 (= 1:8.31-2ubuntu2.1) but 1:8.31-2ubuntu2.3 is to be installed
问题解决:
vim /etc/apt/source.list 添加:
deb http://cn.archive.ubuntu.com/ubuntu/ trusty main universe multiverse restricted
deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main universe multiverse restricted
然后执行:
apt-get update
apt-get install libpcre3 libpcre3-dbg libpcre3-dev build-essential autoconf automake libtool libpcap-dev libnet1-dev mysql-client
最终在snorby系统上可以看event统计信息和sensors主机信息。
三、salt批量在服务器上安装:
1、定义两个salt组
一个组包含两个ip (一个内网,一个公网),另一个组仅仅包含一个内网ip
root@TS-OP03:/home/david-dai# vim /etc/salt/master.d/group.conf
nodegroups:
suricata_two_ip: 'S@172.22.66.8 or S@172.22.66.9 or S@172.22.66.10 or S@172.22.66.11 or S@172.22.66.12 or S@172.22.66.13 or S@172.22.66.22 or S@172.22.66.23
or S@172.22.66.24 or S@172.22.66.29 or S@172.22.66.30 or S@172.22.66.41 or S@172.22.66.42 or S@172.22.66.43 or S@172.22.66.44 or S@172.22.66.45 or S@172.22.
66.46 or S@172.22.66.47 or S@172.22.66.50'
suricata_one_ip: 'S@172.22.66.21 or S@172.22.66.25 or S@172.22.66.26 or S@172.22.66.27 or S@172.22.66.28 or S@172.22.66.48 or S@172.22.66.49 or S@172.22.66.
51 or S@172.22.66.52 or S@172.22.66.53 or S@172.22.66.54 or S@172.22.66.55 or S@172.22.66.56 or S@172.22.66.57 or S@172.22.66.58'
2、针对第一个组two ip,em1是内网ip,em2是公网ip,双网卡只监测公网ip的em2网卡流量。
安装依赖包:
salt -N suricata_two_ip cmd.run "apt-get install -y bison flex libpcap*"
salt -N suricata_two_ip cmd.run 'apt-get install -y --force-yes libpcre3 libpcre3-dbg libpcre3-dev build-essential autoconf automake libtool pkg-config libpcap-dev libnet1-dev mysql-client libmysqlclient16 flex software-properties-common python-software-properties'
3、同步一些必要的配置(suricata.yaml&barnyard.con)
salt -N suricata_two_ip cmd.run 'sudo add-apt-repository ppa:oisf/suricata-stable'
salt -N suricata_two_ip cmd.run 'sudo apt-get update '
salt -N suricata_two_ip cmd.run 'sudo apt-get install -y suricata '
salt -N suricata_two_ip cmd.run 'dpkg -l | grep suricata'
root@TS-OP03:/home/david-dai# cp suricata.yaml /srv/salt/chinadep/
salt -N suricata_two_ip cp.get_file salt://chinadep/suricata.yaml /etc/suricata/suricata.yaml
root@TS-OP03:/home/david-dai# cp barnyard2.conf /srv/salt/chinadep/
root@TS-OP03:/home/david-dai# cp -pr barnyard2-2-1.13 /srv/salt/chinadep/
root@TS-OP03:/home/david-dai# ls -ld /srv/salt/chinadep/
salt -N suricata_two_ip cp.get_dir salt://chinadep/barnyard2-2-1.13 /tmp/
salt -N suricata_two_ip cp.get_file salt://chinadep/barnyard2.conf /etc/suricata/barnyard2.conf
4、安装suricata&barnary
root@TS-OP03:/home/david-dai# vim /srv/salt/chinadep/barnyard.sh
#!/bin/bash
sed -i 's/^config hostname./config hostname: '$(hostname)'/g' /etc/suricata/barnyard2.conf
apt-get install -y --force-yes libmysqlclient libdbd-mysql-perl mysql-common mysql-client libmysql
apt-get install -y --force-yes bison flex libpcap
apt-get install -y --force-yes libpcre3 libpcre3-dbg libpcre3-dev build-essential autoconf automake libtool pkg-config libpcap-dev libnet1-dev mysql-client
t libmysqlclient16 flex software-properties-common python-software-properties
cd /tmp
tar -zxvf libpcap-1.2.1.tar.gz
cd /tmp/libpcap-1.2.1
./configure
make
make install
/sbin/ldconfig
echo $? >/tmp/barnyard_two_ip.txt
cd /tmp/barnyard2-2-1.13/
chmod +x autogen.sh
make clean
./autogen.sh
ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient* /usr/include/mysql/
./configure --with-mysql-libraries=/usr/include/mysql --with-mysql=/usr/bin/mysql
make
make install
echo $? >>/tmp/barnyard_two_ip.txt
salt -N suricata_two_ip cp.get_file salt://chinadep/barnyard.sh /tmp/barnyard.sh
salt -N suricata_two_ip cmd.run 'chmod +x /tmp/barnyard.sh'
salt -N suricata_two_ip cmd.run 'sh -x /tmp/barnyard.sh'
5、检查配置
root@TS-OP03:/home/david-dai# salt -N suricata_two_ip cmd.run "grep ^'config hostname' /etc/suricata/barnyard2.conf "
CK749X1:
config hostname: TS-DEP-CENTER05
8K649X1:
config hostname: TS-DEP-CENTER06
插入一句话:如果登录服务器,想在单台服务器上sed修改hostname,请执行如下命令:
sed -i 's/^config hostname./config hostname: 'hostname
'/g' /etc/suricata/barnyard2.conf"或者:"sed -i 's/^config hostname./config hostname: '$(hostname)'/g' /etc/suricata/barnyard2.conf"
6、启动suricata和barnary,必须登录单台服务器才能执行启动。
root@TS-OP03:/home/david-dai# vim /srv/salt/chinadep/barnyard_start.sh
sudo ps aux | grep -v grep | grep suricata | awk -F' ' '{print $2}' | xargs kill
sleep 5
sudo mv /var/run/suricata.pid /tmp/
#启动suricata
sudo nohup suricata -c /etc/suricata/suricata.yaml -i em2 -D & > nohup.out
sleep 5
#启动barnyard2
sudo nohup /usr/local/bin/barnyard2 -c /etc/suricata/barnyard2.conf -d /var/log/suricata -f unified2.alert -w /var/log/suricata/suricata.waldo –D & > nohup.
out
salt -N suricata_two_ip cp.get_file salt://chinadep/barnyard_start.sh /tmp/barnyard_start.sh
salt -N suricata_two_ip cmd.run 'chmod +x /tmp/barnyard_start.sh'
#salt -N suricata_two_ip cmd.run 'sh -x /tmp/barnyard_start.sh'
salt执行失败,必须登录服务器后执行:sh -x /tmp/barnyard_start.sh
手动执行:
suricata -c /etc/suricata/suricata.yaml -i em1 -D &
/usr/local/bin/barnyard2 -c /etc/suricata/barnyard2.conf -d /var/log/suricata -f unified2.alert -w /var/log/suricata/suricata.waldo –D &