Nesse post irei estar abordando a instalação e configuração do Snort inline como IDS assim como a integração do mesmo com a Dashboard Snorby.
Introdução
Snort é um Sistema de Detecção de Intrusos(IDS) open source e free criado em 1998 por Martin Roesch. Snort atualmente é desenvolvido pela Cisco que propos o SourceFire em 2013.
Em 2009, Snort entrou para o InforWorld’s Open Source Hall of Fame como um dos maiores pedaços de código livre de todos os tempos.
Snort como IDS tem a capacidade de realizar uma analise de tráfego em tempo real assim como registrar os logs dos pacotes em redes IP. Snort realiza analise de procolo, busca por conteúdo e verificação por assinaturas.
O programa também pode ser utilizado para detectar scaners ou ataques, incluindo mas não limitando à tentativas de fingerprint de Sistema operacional, ataques de semantica em URL’s, buffer overflows, SMB scanners e port scanners em modo stealth.
Snort can be runned in 4 modes:
- sniffer mode: snort will read the network traffic and print them to the screen.
- packet logger mode: snort will record the network traffic on a file
- IDS mode: network traffic matching security rules will be recorded (mode used in our tutorial)
- IPS mode: also known as snort-inline (IPS = Intrusion prevention system)
Porém a implementação como IPS não será abordada aqui, será abordado apenas o modo IDS.
Pré Instalação:
Pacotes necessários
sudo apt install -y gcc flex bison make libpcap-dev libdnet-dev libdumbnet-dev libpcre3-dev libghc-zlib-dev
sudo apt-get install flex bison build-essential checkinstall libpcap-dev libnet1-dev libpcre3-dev libnetfilter-queue-dev iptables-dev libdumbnet-dev zlib1g-dev -y
sudo apt-get install -y liblzma-dev openssl libssl-dev cpputest libsqlite3-dev uuid-dev
mkdir ~/snort_src && cd ~/snort_src
Instalação do DAQ.
wget https://www.snort.org/downloads/snort/daq-2.0.6.tar.gz
tar -xvzf daq-2.0.6.tar.gz
cd daq-2.0.6
./configure && make && sudo make install
Instalação do Snort
cd ~/snort_src
Verifique no website do snort se o pacote ainda é a versão 2.9.12, caso não for pegue o mais atualizado, talvez dẽ algum pau de alguma nova dependencia que nessa versão não tinha, mas é melhor você começar com um software atualizado do que começar com uma versão desatualizada e depois ter que migrar ou coisas do gênero.
wget https://www.snort.org/downloads/snort/snort-2.9.12.tar.gz
tar -xzvf snort-2.9.12.tar.gz
cd snort-2.9.12/
./configure --enable-sourcefire && make && sudo make install
Pós Instalação:
ldconfig
Então vamos verificar a versão do snort:
root@srv-web:~/snort_src/snort-2.9.12# snort --version
,,_ -*> Snort! <*-
o" )~ Version 2.9.12 GRE (Build 325)
'''' By Martin Roesch & The Snort Team: http://www.snort.org/contact#team
Copyright (C) 2014-2018 Cisco and/or its affiliates. All rights reserved.
Copyright (C) 1998-2013 Sourcefire, Inc., et al.
Using libpcap version 1.8.1
Using PCRE version: 8.39 2016-06-14
Using ZLIB version: 1.2.8
Criando um usuário e grupo para executar o snort para que ele não execute com usuário administrativo:
groupadd snort
useradd snort -r -s /sbin/nologin -c SNORT_IDS -g snort
Preparando a estrutura do Snort.
mkdir /etc/snort
mkdir /etc/snort/rules
mkdir /etc/snort/preproc_rules
touch /etc/snort/rules/white_list.rules /etc/snort/rules/black_list.rules /etc/snort/rules/local.rules
Criando o diretório onde será armazenado os logs
mkdir /var/log/snort
Criando o diretório onde será dicionado regras dinamicas:
mkdir /usr/local/lib/snort_dynamicrules
Definindo as permissões dos diretórios:
sudo chmod -R 5775 /etc/snort
sudo chmod -R 5775 /var/log/snort
sudo chmod -R 5775 /usr/local/lib/snort_dynamicrules
sudo chown -R snort:snort /etc/snort
sudo chown -R snort:snort /var/log/snort
sudo chown -R snort:snort /usr/local/lib/snort_dynamicrules
Preparando os arquivos de configuração:
cp /root/snort_src/snort*/etc/*.conf /etc/snort
cp /root/snort_src/snort*/etc/*.map /etc/snort
Configurando os arquivos de configuração:
cd /etc/snort
vim snort.conf
Defina a sua rede:
ipvar HOME_NET 10.10.50.0/24
Then, you’ll have to set the EXTERNAL_NET variable to: any
Which just turns EXERNAL_NET into whatever your HOME_NET is not.
Ainda no snort.conf, vá até o bloco 6 e defina o output para unified2:
output unified2: filename unifiedsnort.log, limit 128
Configurando as regras:
Linha 104 do snort.conf
var RULE_PATH /etc/snort/rules
var SO_RULE_PATH /etc/snort/so_rules
var PREPROC_RULE_PATH /etc/snort/preproc_rules
var WHITE_LIST_PATH /etc/snort/rules
var BLACK_LIST_PATH /etc/snort/rules
Procure pela string “decompress_depth 65535” e adicione ao final da mesma linha:
max_gzip_mem 104857600
Tenha certeza que as seguintes configurações não estão comentadas:
preprocessor normalize_ip4
preprocessor normalize_tcp: ips ecn stream
preprocessor normalize_icmp4
preprocessor normalize_ip6
preprocessor normalize_icmp6
Ao final do segundo passo, adicione:
config policy_mode:inline
Configurando o DAQ:
config daq:afpacket
config daq_dir:/usr/local/lib/daq
config daq_mode:inline
config daq_var:buffer_size_mb=1024
Então comente as regras na linha 548 para baixo
Testando se está operacional:
O jeito mais fácil de testar o snort é habilitando as regras local.rules. Arquivo qual contém as suas regras customizadas.
Certifique-se de incluir o arquivo de regras local.rules no snort.conf:
include $RULE_PATH/local.rules
Vamos então adicionar uma regra no arquivo local.rules para identificar pacotes icmp:
alert icmp any any -> $HOME_NET any (msg:"ICMP test"; sid:10000001; rev:001;)
A composição de uma regra é composta dos seguintes elementos:
- action for traffic matching the rule, alert in this case
- traffic protocol like TCP, UDP or ICMP like here
- the source address and port, simply marked as any to include all addresses and ports
- the destination address and port, $HOME_NET as declared in the configuration and any for port
- some additional bits
- log message
- unique rule identifier (sid) which for local rules needs to be 1000001 or higher
- rule version number.
Iniciando o Snort:
/usr/local/bin/snort -A console -q -u snort -g snort -c /etc/snort/snort.conf -i eth0:eth1
Sendo:
- -A Saída dos logs, no caso vai mostrar na própria console
- -q quiet, não vai exibir aquelas mensagens quando o snort iniciar.
- -u Usuário que irá executar o programa
- -g Grupo quer irá executar o programa
- -c Arquivo de configuração do snort.
Então de uma máquina de fora da rede, vamos disparar 3 pacotes ICMP para o snort e verificar como ele reage:
ping -c 3 apache
Então na console ssh do snort:
root@srv-web:/etc/snort# /usr/local/bin/snort -A console -q -u snort -g snort -c /etc/snort/snort.conf -i eth0
10/14-19:49:58.336307 [**] [1:10000001:1] ICMP test [**] [Priority: 0] {ICMP} 192.168.1.111 -> 10.0.0.18
10/14-19:49:59.337211 [**] [1:10000001:1] ICMP test [**] [Priority: 0] {ICMP} 192.168.1.111 -> 10.0.0.18
10/14-19:50:00.339291 [**] [1:10000001:1] ICMP test [**] [Priority: 0] {ICMP} 192.168.1.111 -> 10.0.0.18
Beleza, está funcional.
Rules
Vamos adicionar umas regras ao Snort então! A própria comunidade do Snort tem um repositório de regras, são três categorias:
- Community -> Regras abertas à comunidade.
- Registered -> Regras apenas para usuários registrados.
- Subscription -> Regras apenas para usuáiros inscritos.
Você pode acessar o site nesse link: https://snort.org/downloads/#rule-downloads
Eu to com preguiça de me registrar, então vamos realizar o download da Community mesmo!
Só se atende à versão do snort que a regra é compativel, eu não faço ideia se elas dariam pau se eu colocasse a do v2.9 no 3.0 ou o contrário, mas não é algo que eu quero descobrir agora.
Então vamos lá, realizando o downlaod:
wget https://snort.org/downloads/community/community-rules.tar.gz
root@srv-web:~# tar -xzvf community-rules.tar.gz
community-rules/
community-rules/community.rules
community-rules/VRT-License.txt
community-rules/LICENSE
community-rules/AUTHORS
community-rules/snort.conf
community-rules/sid-msg.map
Como você pode ver, ele vem com um novo arquivo map, um snort.conf e um community.rules os outros não importam agora.
Verificando quantas regras existem no community.rules:
root@srv-web:~/community-rules# wc -l community.rules
3789 community.rules
São então 3789 regras, mas a maioria delas está comentada. Vamos então copiar essas regras para dentro do /etc/snort/rules e depois dar um include nelas para dentro do snort.conf.
include /etc/snort/rules/community.rules
Vamos nos registrar no Snort e pegando as rules registered, quando registrado, ele vai te exibir 5 arquivos tar.gz para download.
snortrules-snapshot-2990.tar.gz
snortrules-snapshot-2983.tar.gz
snortrules-snapshot-29120.tar.gz
snortrules-snapshot-29111.tar.gz
snortrules-snapshot-29110.tar.gz
Para realizar o download dos arquivos você precisa utilizar um token chamado oinkcode da seguinte forma:
https://www.snort.org/rules/?oinkcode=
Lembre-se de baixar a regra que seja equivalente à versão do seu Snort.
wget https://snort.org/rules/snortrules-snapshot-29120.tar.gz?oinkcode=[CENSURADO]
mv snortrules-snapshot-29120.tar.gz?oinkcode=[CENSURADO] snortrules-snapshot-29120.tar.gz
mkdir registered_rules
tar -xzvf snortrules-snapshot-29120.tar.gz -C registered_rules/
As regras registered são bem mais organizadas, não é um arquivo só com tudo jogando dentro por exemplo, ele separa por sistema operacional, tipos de regras etc:
root@srv-web:~/snortrules-snapshot# ls -l so_rules/
total 536
-rw-r--r-- 1 1210 root 1025 Oct 10 17:18 browser-ie.rules
-rw-r--r-- 1 1210 root 4131 Oct 10 17:18 browser-other.rules
-rw-r--r-- 1 1210 root 2149 Oct 10 17:18 exploit-kit.rules
-rw-r--r-- 1 1210 root 2959 Oct 10 17:18 file-executable.rules
-rw-r--r-- 1 1210 root 1256 Oct 10 17:18 file-flash.rules
-rw-r--r-- 1 1210 root 44890 Oct 10 17:18 file-image.rules
-rw-r--r-- 1 1210 root 407 Oct 10 17:18 file-java.rules
-rw-r--r-- 1 1210 root 8295 Oct 10 17:18 file-multimedia.rules
-rw-r--r-- 1 1210 root 40220 Oct 10 17:18 file-office.rules
-rw-r--r-- 1 1210 root 54789 Oct 10 17:18 file-other.rules
-rw-r--r-- 1 1210 root 25687 Oct 10 17:18 file-pdf.rules
-rw-r--r-- 1 1210 root 686 Oct 10 17:18 indicator-shellcode.rules
-rw-r--r-- 1 1210 root 5381 Oct 10 17:18 malware-cnc.rules
-rw-r--r-- 1 1210 root 1326 Oct 10 17:18 malware-other.rules
-rw-r--r-- 1 1210 root 3091 Oct 10 17:18 netbios.rules
-rw-r--r-- 1 1210 root 756 Oct 10 17:18 os-linux.rules
-rw-r--r-- 1 1210 root 5972 Oct 10 17:18 os-other.rules
-rw-r--r-- 1 1210 root 20337 Oct 10 17:18 os-windows.rules
-rw-r--r-- 1 1210 root 17447 Oct 10 17:18 policy-other.rules
-rw-r--r-- 1 1210 root 817 Oct 10 17:18 policy-social.rules
drwxr-xr-x 29 1210 root 4096 Oct 14 21:07 precompiled
-rw-r--r-- 1 1210 root 6430 Oct 10 17:18 protocol-dns.rules
-rw-r--r-- 1 1210 root 368 Oct 10 17:18 protocol-nntp.rules
-rw-r--r-- 1 1210 root 3038 Oct 10 17:18 protocol-other.rules
-rw-r--r-- 1 1210 root 2757 Oct 10 17:18 protocol-scada.rules
-rw-r--r-- 1 1210 root 5740 Oct 10 17:18 protocol-snmp.rules
-rw-r--r-- 1 1210 root 2794 Oct 10 17:18 protocol-tftp.rules
-rw-r--r-- 1 1210 root 12150 Oct 10 17:18 protocol-voip.rules
-rw-r--r-- 1 1210 root 262 Oct 10 17:18 pua-p2p.rules
-rw-r--r-- 1 1210 root 417 Oct 10 17:18 server-apache.rules
-rw-r--r-- 1 1210 root 421 Oct 10 17:18 server-iis.rules
-rw-r--r-- 1 1210 root 2654 Oct 10 17:18 server-mail.rules
-rw-r--r-- 1 1210 root 458 Oct 10 17:18 server-mysql.rules
-rw-r--r-- 1 1210 root 1572 Oct 10 17:18 server-oracle.rules
-rw-r--r-- 1 1210 root 69579 Oct 10 17:18 server-other.rules
-rw-r--r-- 1 1210 root 95818 Oct 10 17:18 server-webapp.rules
drwxr-xr-x 2 1210 root 16384 Oct 14 21:07 src
Então vamos copiar algumas regras pra dentro do diretório onde estão nossas regras do snort:
cd os_rules
cp os-linux.rules server-apache.rules exploit-kit.rules file-executable.rules indicator-shellcode.rules malware-cnc.rules malware-other.rules protocol-dns.rules protocol-snmp.rules server-mail.rules /etc/snort/rules
Você pode refinar as regras também removendo regras de serviços que não existem na sua rede ou até mesmo criando novas regras para serviços especificos.
Depois que vocẽ refinar as regras, basta você ir até o arquivo de configuração do snort e dar os respectivos includes das novas regras, não esqueça de remover o include que faz referente às regras da community.
# Rules
include /etc/snort/rules/local.rules
#include /etc/snort/rules/community.rules
include /etc/snort/rules/exploit-kit.rules
include /etc/snort/rules/file-executable.rules
include /etc/snort/rules/indicator-shellcode.rules
include /etc/snort/rules/malware-cnc.rules
include /etc/snort/rules/malware-other.rules
include /etc/snort/rules/os-linux.rules
include /etc/snort/rules/protocol-dns.rules
include /etc/snort/rules/protocol-snmp.rules
include /etc/snort/rules/server-apache.rules
include /etc/snort/rules/server-mail.rules
Bom, agora vamos fazer um teste!
O comando abaixo vai testar se as regras estão carregando normalmente:
snort -c /usr/local/etc/snort/snort.lua -R /usr/local/etc/snort/rules/snort3-community.rules
Snort records the alerts to a log under /var/log/snort/snort.log., where the time stamp is the point in time when Snort was started marked in Unix time. You can read the logs with the command underneath. Since you have only run Snort once, there is only one log, complete your command by pressing TAB.
snort -r /var/log/snort/snort.log.
The log shows a warning for each ICMP call with source and destination IPs, time and date, plus some additional info as shown in the example below.
Executando o snort no background:
vim /lib/systemd/system/snort.service
[Unit]
Description=Snort NIDS Daemon
After=syslog.target network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/snort -q -u snort -g snort -c /etc/snort/snort.conf -i eth0
[Install]
WantedBy=multi-user.target
Controlando o Daemon:
systemctl daemon-reload
systemctl start snort
systemctl status snort
Instalação do Snorby
Barnyard
Barnyard2 is an open source interpreter for Snort unified2 binary output files.
Its primary use is allowing Snort to write to disk in an efficient manner and
leaving the task of parsing binary data into various formats to a separate
process that will not cause Snort to miss network traffic.
Barnyard2 has 3 modes of operation:
1. batch (or one-shot),
2. continual, and
3. continual w/ bookmark.
apt install libtool autoconf mysql-server default-mysql-client
wget http://ftp.psu.ac.th/pub/snort/libdnet-1.12.tgz
cd /usr/src
root@srv-web:/usr/src# git clone https://github.com/firnsy/barnyard2.git
1. *** Make sure you have libpcap HEADERS installed!!! ***
2. ./autogen.sh
3. ./configure
4. make
5. make install
6. Create a sample rules file (eg. look at etc/barnyard2.conf)
7. barnyard2 -?
8. HAVE FUN!
wget https://github.com/binf/barnyard2/tree/bug-fix-release
./autogen.sh
autoreconf -fvi -I ./m4 && ./configure --with-mysql --with-mysql-libraries=/usr/lib/x86_64-linux-gnu
make && make install
cp etc/barnyard2.conf
mkdir /var/log/barnyard2
chown snort:snort /var/log/barnyard2/
vim barnyard2.conf
Instalação do Ruby e as caralha chata pra caralho q da pau pra porra
apt-get install ruby-full postgresql-server-dev-9.6
root@srv-web:~# ruby -v
ruby 2.3.3p222 (2016-11-21) [x86_64-linux-gnu]
Rails:
curl -L https://get.rvm.io | bash -s stable --rails
oot@srv-web:/var/www/snorby# rvm install ruby-1.9.3
rvm use ruby-1.9.3
root@srv-web:/var/www/snorby# vim Gemfile
root@srv-web:/var/www/snorby# vim Gemfile.lock
root@srv-web:/var/www/snorby# gem install rails bundler passenger
pdfkit --install-wkhtmltopdf
Run the Snorby Setup:
rake snorby:setup
root@srv-web:/var/www/snorby# rake snorby:start_worker
Para executar o Snorby:
RAILS_ENV=production bundle exec rake snorby:start_worker
Default User Credentials
E-mail: snorby@example.com
Password: snorby
Outros comandos do Snorby:
root@srv-web:/var/www/snorby# rake snorby:
dbupdate hard_reset refresh restart_worker setup soft_reset start_worker update
Notas:
For barnyard2 to work, your unified2 output file created by snort must contain alert AND PCAP data.
So, in /etc/snort/snort.conf (or wherever your snort configuration is), you need to specify output unified2: (I recommend NOT using “snort.log” for the filename).
Review the barnyard2 global variable file /etc/default/barnyard2 or /etc/sysconfig/barnyard2 comment out the BINARY_LOG Setting, and also make sure the log filename matches the one you used in snort.conf.
Restart snort, and then restart barnyard2 to see if you are up and running.
output unified2: filename snortunified.log, limit 128
/usr/local/bin/barnyard2 -c /etc/snort/barnyard2.conf -d /var/log/snort -f snortunified.log -w /var/log/snort/barnyard2.waldo -g snort -u snort
snort -d -A full -u snort -g snort -c /etc/snort/snort.conf -i eth0:eth1
https://techanarchy.net/2015/01/home-ids-with-snort-and-snorby/
https://blog.snort.org/2011/01/guis-for-snort.html
https://github.com/Snorby/snorby
https://techanarchy.net/2015/01/home-ids-with-snort-and-snorby/
https://github.com/Snorby/snorby
