使用Packetbeat+Elasticsearch+Kibana将DNS日志可视化

首先

最近有一些消息,来自株式会社ラック公司,关于使用DNS协议的病毒的警告。

■遠隔操作ウイルスの制御にDNSプロトコルを使用する事案への注意喚起
http://www.lac.co.jp/security/alert/2016/02/01_alert_01.html

記事中にそのウィルスへの対応法について記載があり、その1つに「内部DNSのアクセスログから不正なリクエストを発見する(ログを取得する)」があげられています。
本事案以外でも、多くのマルウェアは名前解決を行いC&Cサーバとやり取りを行うため、DNS通信のログを取得することは、調査において重要な情報になると考えます。

即使说是获取DNS通信的日志,如果仅仅使用简单的数据包捕获,会有一些问题,比如查看困难(追溯信息时会花费时间)等。

我想使用以下的开源产品来创建一个易于浏览的系统。

    • Packetbeat

 

    • Elasticsearch

 

    Kibana

产品说明

“Packetbeat”是由elastic公司提供的一种包监控工具。
它是”Beats”产品系列中的一员,其他还有”Filebeat”、”Metricbeat”、”Topbeat”和”Winlogbeat”。

“Elasticsearch”、”Kibana”もelastic社のプロダクトで、”Elasticsearch”は全文検索エンジン、”Kibana”はログ可視化ツールです。

https://www.elastic.co/zh-cn/products/elasticsearch
https://www.elastic.co/zh-cn/products/kibana

构成

Packetbeat_構成.png

蓝色箭头:DNS查询、响应通信
红色箭头:Packetbeat将日志传输到Elasticsearch通信
绿色箭头:客户端PC访问Kibana(WebUI)通信

●DNS 服务器
CentOS 7.2
Packetbeat 版本 1.2.3

● Elasticsearch/Kibana 服务器
CentOS 7.2 操作系统
Elasticsearch 版本 2.3.5
Kibana 版本 2.5.4

Packetbeat_構成_ミラーポート.png

安装

・ 今回はインストールして動作させることを目的としているため、細かなパラメータの調整は割愛しています。
・ Firewalldは停止させている想定です。(systemctl stop firewalld)

网络封包追踪器

在“DNS 服务器”上执行以下命令。

sudo yum install libpcap
curl -L -O https://download.elastic.co/beats/packetbeat/packetbeat-1.2.3-x86_64.rpm
sudo rpm -vi packetbeat-1.2.3-x86_64.rpm

インストール完了後、以下の設定ファイルを編集します。

/etc/packetbeat/packetbeat.yml

Protocolsセクションで、” ports: [53]”がコメントアウトされていないことを確認します。
今回はDNS以外のログは取得しないので、その他のポート番号行はコメントアウトします。
※ports: [80, 8080, 8000, 5000, 8002]等

<略>
############################# Protocols #######################################
protocols:
  dns:
    # Configure the ports where to listen for DNS traffic. You can disable
    # the DNS protocol by commenting out the list of ports.
    ports: [53]
<略>
  http:
    # Configure the ports where to listen for HTTP traffic. You can disable
    # the HTTP protocol by commenting out the list of ports.
    #ports: [80, 8080, 8000, 5000, 8002]
<略>
  memcache:
    # Configure the ports where to listen for memcache traffic. You can disable
    # the Memcache protocol by commenting out the list of ports.
    #ports: [11211]
<略>
  mysql:
    # Configure the ports where to listen for MySQL traffic. You can disable
    # the MySQL protocol by commenting out the list of ports.
    #ports: [3306]

  pgsql:
    # Configure the ports where to listen for Pgsql traffic. You can disable
    # the Pgsql protocol by commenting out the list of ports.
    #ports: [5432]

  redis:
    # Configure the ports where to listen for Redis traffic. You can disable
    # the Redis protocol by commenting out the list of ports.
    #ports: [6379]

  thrift:
    # Configure the ports where to listen for Thrift-RPC traffic. You can disable
    # the Thrift-RPC protocol by commenting out the list of ports.
    #ports: [9090]

  mongodb:
    # Configure the ports where to listen for MongoDB traffic. You can disable
    # the MongoDB protocol by commenting out the list of ports.
    #ports: [27017]

然后,在Output部分进行设置以指定信息发送到目标地(Elasticsearch)。
作为发送目标,填写Elasticsearch/Kibana服务器的IP地址。

<略>
############################# Output ##########################################

# Configure what outputs to use when sending the data collected by the beat.
# Multiple outputs may be used.
output:

  ### Elasticsearch as output
  elasticsearch:
    # Array of hosts to connect to.
    # Scheme and port can be left out and will be set to the default (http and 9200)
    # In case you specify and additional path, the scheme is required: http://localhost:9200/path
    # IPv6 addresses should always be defined as: https://[2001:db8::1]:9200
    #hosts: ["localhost:9200"]
    hosts: ["192.168.1.18:9200"]

<略>

设置完成后,启动”Packetbeat”。

sudo systemctl start packetbeat

Elasticsearch 弹性搜索

在”Elasticsearch/Kibana服务器”上执行以下命令。

sudo yum install -y java
sudo cat <<EOF> /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-2.x]
name=Elasticsearch repository for 2.x packages
baseurl=http://packages.elastic.co/elasticsearch/2.x/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
EOF
sudo yum install elasticsearch-2.3.5

安装完成后,将编辑以下设置文件。

/etc/elasticsearch/elasticsearch.yml

在网络部分,将”Elasticsearch/Kibana Server”的IP地址填写到”network.host”选项中。

<略>
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 192.168.1.18
#
# Set a custom port for HTTP:
#
# http.port: 9200
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
<略>

配置完成后,启动”Elasticsearch”。

sudo systemctl start elasticsearch

Kibana 可视化工具

在”Elasticsearch/Kibana服务器”上执行以下命令。

sudo cat <<EOF> /etc/yum.repos.d/kibana.repo
[kibana-4.5]
name=Kibana repository for 4.5.x packages
baseurl=http://packages.elastic.co/kibana/4.5/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
EOF
sudo yum install kibana-4.5.4

安装完成后,需要编辑以下配置文件。

/opt/kibana/config/kibana.yml

将”Elasticsearch/Kibana Server” 的 IP 地址填写到 “elasticsearch.url” 中。

<略>
# The Elasticsearch instance to use for all your queries.
elasticsearch.url: "http://192.168.1.18:9200"

# preserve_elasticsearch_host true will send the hostname specified in `elasticsearch`. If you set it to false,
# then the host you use to connect to *this* Kibana instance will be sent.
# elasticsearch.preserveHost: true
<略>

在设置完成后,我们将启动”Kibana”。

sudo systemctl start kibana

Elasticsearch模板的定义

为了处理Packetbeat在Elasticsearch中获取到的信息,我们需要定义一个模板。

在“DNS服务器”上执行以下命令。

curl -XPUT 'http://192.168.1.18:9200/_template/packetbeat' -d@/etc/packetbeat/packetbeat.template.json

{"acknowledged":true}

确认执行命令后的结果为”{“acknowledged”:true}”。

Kibana仪表板定义

使用Kibana定义用于日志可视化的仪表板。

在”Elasticsearch/Kibana Server”上执行以下命令。

※安装Elastic公司提供的仪表板。

curl -L -O http://download.elastic.co/beats/dashboards/beats-dashboards-1.2.3.zip
unzip beats-dashboards-1.2.3.zip
cd beats-dashboards-1.2.3/
./load.sh

除了Packetbeat之外,还会安装其他Beats系列的仪表盘。

访问Kibana

我要使用Kibana进行访问。

http://192.168.1.18:5601/

请打开以下界面,并从左侧菜单中选择”packetbeat-*”,在右侧菜单中找到该界面并点击星形图标。

Kibana_2.5.4.jpg
Kibana_2.5.4..jpg

接下来,点击上方菜单栏的“Dashbord”,然后点击显示屏幕右上方的文件夹图标。

スクリーンショット_081516_072415_PM.jpg
スクリーンショット_081516_072505_PM.jpg

Dashbordの選択メニューが表示されるので、”Packetbeat Dashboard”をクリックします。

Kibana_2.5.4.jpg

创建专用于DNS的仪表板

由于“Packetbeat Dashboard”并不是专用于DNS的仪表板,因此我们需要创建一个专用的仪表板。

我想在下一篇文章中写下续篇。

bannerAds