log management with elastic search technology · 2017-01-20 · elastic search technology....

56
Information Technology School of Informatics Walailak University Log Management with Elastic Search Technology

Upload: others

Post on 04-Jul-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Information Technology School of Informatics

Walailak University

Log Management with Elastic Search Technology

Page 2: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Information Technology School of Informatics

Walailak University

System Preparation

Page 3: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

ติดตั้ง Ubuntu บน VirtualBox• สร้าง Virtual

• Single Core CPU • 2GB RAM (2048 MB in VirtualBox) • 16 GB Hardisk • 2 Ethernet

• 1st NAT • 2nd Host Only

• Ubuntu Server DVD is attached to DVD Drive • Ubuntu-Server-16.04-i386.iso

3

Page 4: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

Install Ubuntu on VirtualBox• Install Ubuntu with default settings • PLEASE

• remember your username & password • for this workshop

• username : wunca • password : 1q2w3e4r

• Wait until Installation is completed

4

Page 5: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

กำหนดค่าเริ่มต้น• หลังจากที่ Boot Linux แล้ว ให้ Login ด้วย Username และ Password ที่กำหนดไว้ • ทดสอบการเชื่อมต่อเครือข่าย $ host www.wu.ac.th

• update และ upgrade ไลบรารี $ sudo apt-get update$ sudo apt-get upgrade

5

Page 6: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

กำหนดค่าเริ่มต้น• กำหนด IP Address $ sudo nano /etc/network/interfaces

• append auto enp0s8iface enp0s8 inet dhcp

• รีสตาร์ท Ubuntu $ sudo reboot

6

Page 7: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

Secured Remote Log in ด้วย Putty• ตรวจสอบ IP Address

$ ifconfig -a | grep inet

• เลือก 192.168.56.x • ในที่นี้ใช้ 192.168.56.101

• เปิดโปรแกรม web browser • เข้าเว็บ http://192.168.56.101

7

192.168.56.101

Page 8: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Information Technology School of Informatics

Walailak University

Software Installation

Page 9: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

Download • ดาวน์โหลดไฟล์ netmon-2.0.tgz จาก https://goo.gl/N5vkX3 • ดาวโหลดโปรแกรม winscp จาก • อัพโหลดไฟล์เข้าในระบบปฏิบัติการ ไว้ใน home directory • รีโมทเข้าสู่ระบบ ด้วย putty

9

Page 10: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

ติดตั้งโปรแกรม$ cd $ tar -zxvf netmon-2.0.tgz $ cd netmon$ sudo sh setup [IP_ADDRESS]

10

และ คอยครับ

Page 11: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Information Technology School of Informatics

Walailak University

Basic Concept of Network Monitoring System

Page 12: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

General Network Architecture

12

Page 13: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

Software Architecture

13

Page 14: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

1. Data Logger

14

Page 15: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

1. Data Logger• Record of events

• OS - syslog services, window log • Application - database, user application • Network services - Authentication, SNMP, WMI, Network monitoring system • Network Traffic - packet sniffer

15

Page 16: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

1. Data Logger

16

Page 17: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

2. Data Analysis

17

Page 18: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

3.Data Visualisation

18

Page 19: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

3.Data Visualisation

19

Page 20: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

การติดตั้งแบบ Mannual• ติดตั้ง java sdk $ sudo apt-get -y install openjdk-8-jdk-headless

• ดาวโหลดไฟล์ และ ติดตั้งโปรแกรมที่เกี่ยวข้อง $ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.1.2.deb$ wget https://artifacts.elastic.co/downloads/kibana/kibana-5.1.1-i386.deb$ wget https://artifacts.elastic.co/downloads/logstash/logstash-5.1.2.deb$ wget https://artifacts.elastic.co/downloads/beats/packetbeat/packetbeat-5.1.2-i386.deb$ wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.1.2-i386.deb$ wget https://download.elastic.co/beats/topbeat/topbeat_1.3.1_i386.deb$ sudo dpkg -i *.deb

20

Page 21: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

ElasticSearch• แก้ไขไฟล์ configure $ sudo -s# nano /etc/elasticsearch/elasticsearch.ymlแก้ไขnetwork.host: 192.168.56.101

• สั่งรัน Service # service elasticsearch start

21

Page 22: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

ElasticSearch• ทดสอบ $ curl 192.168.56.101:9200{ "name" : "aoduRoo", "cluster_name" : "elasticsearch", "cluster_uuid" : "9NDw8Xg_Rn2akl2dnXCkOA", "version" : { "number" : "5.1.1", "build_hash" : "5395e21", "build_date" : "2016-12-06T12:36:15.409Z", "build_snapshot" : false, "lucene_version" : "6.3.0" }, "tagline" : "You Know, for Search"}

22

Page 23: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

ElasticSearch• หากไม่สามารถรันได้ ให้ตรวจสอบ log ของ service # tail -f tail /var/log/elasticsearch/elasticsearch.log

• ปัญหาของ vm.max_map_count ไม่พอ # sysctl -w vm.max_map_count=262144

23

Page 24: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

LogStash• สร้างไฟล์ configuration ของ LogStash เพื่อทดสอบ $ mkdir config$ cd config$ sudo nano simple-log.confinput { stdin { }

}output{stdout{

codec => rubydebug}

}

24

Page 25: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

LogStash• รัน service ของ LogStash เพื่อ ทดสอบ $ /usr/share/logstash/bin/logstash -f simple-log.conf06:44:37.577 [Api Webserver] INFO logstash.agent - Successfully started Logstash API endpoint {:port=>9600}

hello world{ "@timestamp" => 2017-01-12T16:44:16.775Z, "@version" => "1", "host" => "ubuntu", "message" => "hello world", "tags" => []}

25

Page 26: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

LogStash• ส่งข้อมูลจาก logstashไปยัง elasticsearch • ไฟล์ configure $ nano simple-log.conf

input { stdin { }

}output{

elasticsearch { hosts => “192.168.56.101:9200” manage_template => false index => "logstash-%{+YYYY.MM.dd}" document_type => "%{[@metadata][type]}" }

stdout{codec => rubydebug

}}

26

Page 27: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

LogStash• รัน service ของ LogStash เพื่อ ทดสอบ $ /usr/share/logstash/bin/logstash -f simple-log.conf

07:07:13.383 [Api Webserver] INFO logstash.agent - Successfully started Logstash API endpoint {:port=>9600}hello{ "@timestamp" => 2017-01-13T00:07:20.722Z, "@version" => "1", "host" => "ubuntu", "message" => "hello"}

27

Page 28: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

LogStash & ElasticSearch• ตรวจสอบการสร้าง index ของ elasticsearch $ curl -XGET ‘192.168.56.101:9200/_cat/indices?v&pretty'

health status index uuid pri rep docs.count docs.deleted store.size pri.store.sizeyellow open logstash-2017.01.12 TfGDKDvoQxiywrNignCC8w 5 1 2 0 10.4kb 10.4kbyellow open .kibana V62ANqzAQraSU7QBL9_v_w 1 1 2 0 8.6kb 8.6kbyellow open logstash-2017.01.13 pW8oHakZRQ-qZNEEz9nB3A 5 1 3 0 14.9kb 14.9kb

28

Page 29: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

LogStash & ElasticSearch• อ่านข้อมูลใน Index ชื่อ logstash-2017.01.13 $ curl -XGET '192.168.56.101:9200/logstash-2017.01.13/_search?pretty' -d'{ "query": { "match_all": {} }}'

{ "_index" : "logstash-2017.01.13", "_type" : "%{[@metadata][type]}", "_id" : "AVmVJoyQIRcak5HWwy4q", "_score" : 1.0, "_source" : { "@timestamp" : "2017-01-13T00:07:28.639Z", "@version" : "1", "host" : "ubuntu", "message" : "hello world" } }

29

ตัวอย่าง

Page 30: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

Kibana• แก้ไขไฟล์ configure $ sudo -s# nano /etc/kibana/kibana.ymlแก้ไขserver.host: “192.168.56.101"elasticsearch.url: "http://192.168.56.101:9200"

• สั่งรัน Service # service kibana start

30

Page 31: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

Kibana• ทดสอบ โดยใช้ web browser http://192.168.56.101:5601/status

31

Page 32: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

Kibana

32

1

2

3

4

Page 33: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

Kibana

33

1

2

3

1

Page 34: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

Kibana

34

1

2

Page 35: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

Kibana• พิมพ์ ข้อความ $ /usr/share/logstash/bin/logstash -f simple-log.conf

Hello Kibana{ "@timestamp" => 2017-01-13T00:32:42.343Z, "@version" => "1", "host" => "ubuntu", "message" => "Hello Kibana"}

35

Page 36: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

Kibana

36

1

Page 37: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

Beat to LogStash• โปรแกรมที่จัดเก็บข้อมูลจากเครื่องคอมพิวเตอร์ที่ได้รับการติดตั้งโปรแกรมในกลุ่มของ beat ซึ่งประกอบด้วยโปรแกรมต่างๆ ได้แก่ packetbeat, topbeat และ filebeat ซึ่งแต่ละโปรแกรมมีหน้าที่ในการจัดเก็บข้อมูลจากแหล่งต่างๆ ดังนี้

• packetbeat จัดเก็บข้อมูลผ่าน libpcap โดยจัดดักจับแพ็คอกตและกรองเฉพาะโพรโตคอลต่างๆ ที่กำหนดในไฟล์ configuration

• topbeat จัดเก็บข้อมูลผ่านโปรแกรม top โดยเน้นข้อมูลในส่วนของประสิทธิภาพของเครื่องคอมพิวเตอร์ที่ติดตั้งโปรแกรม

• filebeat อ่านข้อมูลจากไฟล์ที่กำหนด เพื่ออ่านข้อมูลต่างๆ เหล่านั้นส่งต่อไปยังแหล่งเก็บข้อมูล

37

Page 38: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

Beat to LogStash• ส่งข้อมูลจาก *Beat ไปยัง LogStast • ไฟล์ configure $ nano simple-log.conf

input { stdin { } beats{ port => 5044 }}

output{ elasticsearch { hosts => "192.168.56.101:9200" manage_template => false index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}" document_type => "%{[@metadata][type]}" } stdout{ codec => rubydebug}}

38

Page 39: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

TopBeat• แก้ไขไฟล์ /etc/topbeat/topbeat.yml $ sudo nano /etc/topbeat/topbeat.yml

ให ้comment บรรทัดนี้# elasticsearch:# hosts: [“localhost:9200"] Gin Feng FD3033

ให้แก้ไขบรรทัดนี้ logstash: hosts: [“192.168.56.101:5044"]

• สั่งสตาร์ท Service $ sudo service topbeat start

39

Page 40: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

TopBeat

40

1

2 3

4

topbeat-*

Page 41: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

PacketBeat• แก้ไขไฟล์ /etc/packetbeat/packetbeat.yml $ sudo nano /etc/packetbeat/packetbeat.yml

ให ้comment บรรทัดนี้#output.elasticsearch:# hosts: ["localhost:9200"]

ให้แก้ไขบรรทัดนี้output.logstash: hosts: [“192.168.56.101:5044"]

• สั่งสตาร์ท Service $ sudo service packetbeat start

41

Page 42: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

PacketBeat

42

1

2 3

4

packetbeat-*

Page 43: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

FileBeat• แก้ไขไฟล์ /etc/filebeat/filebeat.yml $ sudo nano /etc/filebeat/filebeat.yml

43

Page 44: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

FileBeat• แก้ไขไฟล์ /etc/filebeat/filebeat.yml $ sudo nano /etc/filebeat/filebeat.yml

44

Page 45: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

FileBeat• สั่งสตาร์ท Service $ sudo service filebeat start

45

Page 46: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

Dr. Chanankorn Jandaeng —To push the student over the boundary—

FileBeat

46

1

2 3

4

filebeat-*

Page 47: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

1. การปรับแต่งกราฟตามความต้องการของผู้ดูแลระบบ บางครั้งผู้ใช้ต้องการใช้งาน dashboard ของผู้ใช้แบบจำเพาะเจาะจง ระบบวิเคราะห์ข้อมูลจราจร

เครือข่ายนี้สามารถสร้าง dashbord ใหม่ได้เอง และสามารถเพิ่มเข้าสู่ระบบได้โดยเพิ่มกราฟใน kibana และเพิ่ม key ของกราฟไว้ในไฟล์ configure ของเว็บไซต์ ตามขั้นตอนดังนี้

สร้างกราฟด้วย kibana 1. เข้าเว็บไซต์ http://192.168.56.101:5601 หลังจากนั้นเลือก Discover เพื่อเลือกข้อมูล โดยเลือก

แหล่งข้อมูลดิบ ระบบที่พัฒนานี้ ประกอบด้วยแหล่งข้อมูล 3 ไฟล์ ได้แก่ 1.1. packetbeat เก็บข้อมูลของข้อมูลจราจรที่จับโดย packbeat ซึ่งเป็น Service ของ

ElasticSearch โดยมีข้อมูลหลัก โดยดูรูปแบบของข้อมูลได้จากเมนู Settings --> Indics --> packbeat 1.2. topbeat เก็บข้อมูลจากประสิทธิภาพของเครื่อง Network Monitoring นั้นโดยตรง ซึ่งเป็น

Service ของ ElasticSearch โดยมีข้อมูลหลัก โดยดูรูปแบบของข้อมูลได้จากเมนู Settings --> Indics --> topbeat

1.3. filebeat เก็บข้อมูลที่มากไฟล์ล็อกเป็นหลัก โดยข้อมูลล็อกที่นำเข้ามาประมวลผลนั้นเก็บไว้ในไฟล์ /var/log/netmon.log ข้อมูลแต่ละบรรทัดจะถูกสกัดเป็นฟิล์ดต่างๆ โดยโปรแกรม gork (ซึ่งจะอธิบายในหัวข้อที่ 4)

T

2. เลือก กลุ่มของข้อมูลที่ต้องการโดยกรองข้อมูล 2.1. เลือกแหล่งที่มาของข้อมูล ในที่นี้เลือกเป็น filebeat 2.2. เมนูทางซ้ายมือ แสดงรายชื่อของฟิล์ดที่บันทึกในฐานข้อมูล หลังจากนั้นให้เลือก data (ซึ่ง

กำหนดแหล่งที่มาของข้อมูล) ในที่นี้ มีค่าที่เป็นไปได ้ จำนวน 2 ค่าได้แก่ traffic และ snmp ในที่นี้ให้เลือก snmp

T

�1

Page 48: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

2.3. ผลการเลือก data:”snmp”

T

2.4. เลือก label เป็น ifInOctets.1001 เพื่อแสดงจำนวนของ จำนวนแพ็คเก็ตขาเข้าของ 192.168.36.1

T

2.5. ให้บันทึกข้อมูลการสืบค้นชื่อ snmp_gateway_in

T

�2

Page 49: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

3. เลือก visualization เพื่อกำหนดรูปแบบของกราฟ 3.1. เลือก Area Chart

T 3.2. เลือก From a saved search หลังจากนั้นเลือก snmp_gateway_in

T หลักการเลือก ชนิดของ Chart นั้น พิจารณาจากภาพประกอบต่อไปนี้

T

4. ปรับแต่งค่าของ Area Chart 4.1. Y-Axis หากใช้ค่า default เป็นการนับ (Count) จำนวนของ record ที่มีในฐานข้อมูล 4.2. ในที่นี้ให้กำหนด Aggregation เป็น Sum และ กำหนด Field เป็น value (จำนวนข้อมูลหน่วย

เป็นไบต์) 4.3. X-Axis กำหนดค่าแกน X เป็นเวลา โดยเลือก Aggregation เป็น Date Histogram

�3

Page 50: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

4.4. หลังจากนั้นกดปุ่ม Apply Changes

T

5. บันทึก Chart ที่ได้ กำหนดชื่อเป็น Gateway Packet In

T

6. สร้าง Dashboard 6.1. เลือกโหมด Dashboard แล้วเพิ่ม Chart เข้าสู่ระบบ โดยเลือก Gatway Packet In

T

6.2. ปรับแต่ง ตำแหน่ง และชนาดของ Chart แล้ว บันทึกเป็น Gateway Traffic

�4

Page 51: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

T

6.3. แชร์ dashboard ข้างต้นไว้ใน เว็บไซต์ 7. แก้ไขไฟล์ /var/log/www/conf/dashboard.php โดยเพิ่ม dashboard ใหม่ต่อไปนี้

<?php$dashboard = array(

"gateway"=>array( "width" => "99%", "height" => "690", "title" => "Gateway", "key" => "502a39e17e92404f3c54f4fa1e573c59"), // cut "custom1"=>array( "width" => "99%", "height" => "690",

"title" => "Gateway Packet In", "key" => "c4dd115d71a288070dc3892dc890a056"), );?>

8. แก้ไขไฟล์ /var/log/www/conf/menu.php โดยเพิ่มเมนูใหม่ต่อไปนี้

<?php$navbar=array(

"dashboard" => array("title"=> array("Dashboard","#"),"sub_menu" => array(

array("Gateway", "index.php?page=gateway"),array("Core Switch", "index.php?page=traffic"),array("Monitoring", "index.php?page=monitor"),

),),"statistic" => array(

"title"=> array("Statistics","#"),"sub_menu" => array(

array("IP Statistics", "index.php?page=ip"),array("TCP Statistics", "index.php?page=tcp"),array("UDP Statistics", "index.php?page=udp"),

),

�5

Page 52: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

),"security" => array(

"title"=> array("Attack","#"),"sub_menu" => array(

array("New menu", "index.php?page=variable"),),

),"customized" => array(

"title"=> array("Custom Chart","#"),"sub_menu" => array(

array("Gateway Packet In", "index.php?page=custom1"),),

),);?>

4. การเพิ่มแหล่งที่มาของข้อมูล เอกสารฉบับนี้แสดงตัวอย่างของการเพิ่มแหล่งที่มาของข้อมูลล็อก โดยเพิ่มข้อมูลล็อกจาก iptables 1. ปรับแต่ง iptable ให้ drop packet ของโพรโตคอล ICMP เมื่อมีการโจมตีด้วย ping of death

# iptables -N syn_flood# iptables -A INPUT -p tcp --syn -j syn_flood# iptables -A syn_flood -m limit --limit 1/s --limit-burst 3 -j RETURN# iptables -A syn_flood -j DROP# iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j ACCEPT# iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j LOG --log-prefix PING-DROP:# iptables -A INPUT -p icmp -j DROP# iptables -A OUTPUT -p icmp -j ACCEPT

2. ตัวอย่างข้อมูลล็อกใน /var/log/netmon.log

Sep 12 03:46:34 gateway kernel: PING-DROP:IN=enp0s8 OUT= MAC=08:00:27:b8:07:92:08:00:27:00:9a:e9:08:00 SRC=192.168.56.109 DST=192.168.56.108 LEN=84 TOS=0x00 PREC=0x00 TTL=64 ID=46656 DF PROTO=ICMP TYPE=8 CODE=0 ID=2341 SEQ=0

3. การสกัดข้อมูลด้วย grok 3.1. เข้าเว็บไซต์ http://grokdebug.herokuapp.com 3.2. คัดลอกข้อมูลล็อกวางในช่องแรก และเขียน grok pattern ในช่องที่สอง

�6

Page 53: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

T

3.3. หากการตัดข้อมูลถูกต้องแล้ว ผลการสกัดจะแสดงในภาพต่อไปนี้

T

4. การเพิ่ม กฎของ grok ในโปรแกรม Logstash โดยแก้ไขไฟล์ /etc/logstash/conf.d/logstash.conf

input { stdin{} beats { port => 5044 }}

filter {grok {

break_on_match => truematch => [ "message", "%{DATESTAMP:timestamp} %{BASE10NUM:user:int}

%{DATA:process}: data=%{DATA:data} dstmac=%{MAC:dstmac} srcmac=%{MAC:srcmac} ethtype=%{BASE16NUM:ethtype} ip=%{BASE10NUM:ip:int} hl=%{BASE10NUM:hl:int} tos=%{BASE10NUM:tos:int} len=%{BASE10NUM:len:int} ident=%{BASE10NUM:ident:int} dstip=%{IP:dstip} srcip=%{IP:srcip} protocol=%{BASE16NUM:protocol} sport=%{BASE10NUM:sport:int} dport=%{BASE10NUM:dport:int} udplen=%{BASE10NUM:udplen:int} chksum=%{BASE10NUM:chksum:int}"]

match => [ "message", "%{DATESTAMP:timestamp} %{BASE10NUM:user:int} %{DATA:process}: data=%{DATA:data} dstmac=%{MAC:dstmac} srcmac=%{MAC:srcmac}

�7

Page 54: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

ethtype=%{BASE16NUM:ethtype} ip=%{BASE10NUM:ip:int} hl=%{BASE10NUM:hl:int} tos=%{BASE10NUM:tos:int} len=%{BASE10NUM:len:int} ident=%{BASE10NUM:ident:int} dstip=%{IP:dstip} srcip=%{IP:srcip} protocol=%{BASE16NUM:protocol} sport=%{BASE10NUM:sport:int} dport=%{BASE10NUM:dport:int} seqno=%{BASE10NUM:seqno:int} ackno=%{BASE10NUM:ackno:int} hlen=%{BASE10NUM:hlen:int} urg=%{BASE10NUM:urg:int} ack=%{BASE10NUM:ack:int} psh=%{BASE10NUM:psh:int} rst=%{BASE10NUM:rst:int} syn=%{BASE10NUM:syn:int}"]

match => [ "message", "%{DATESTAMP:timestamp} %{BASE10NUM:user:int} %{DATA:process}: data=%{DATA:data} dstmac=%{MAC:dstmac} srcmac=%{MAC:srcmac} ethtype=%{BASE16NUM:ethtype} ip=%{BASE10NUM:ip:int} hl=%{BASE10NUM:hl:int} tos=%{BASE10NUM:tos:int} len=%{BASE10NUM:len:int} ident=%{BASE10NUM:ident:int} dstip=%{IP:dstip} srcip=%{IP:srcip} protocol=%{BASE16NUM:protocol} icmptype=%{BASE10NUM:icmptype:int} icmpcode=%{BASE10NUM:icmpcode:int}"]match => [ "message", "%{DATESTAMP:timestamp} %{BASE10NUM:user} %{DATA:process}: data=%{DATA:data} dstmac=%{MAC:dstmac} srcmac=%{MAC:srcmac} ethtype=%{BASE16NUM:ethtype} arptype=%{BASE16NUM:arptype}"]

match => [ "message", "data=%{DATA:data} snmp_type=%{DATA:snmp_type} label=%{DATA:label} oid=%{DATA:oid} accvalue=Counter32: %{BASE10NUM:accvalue:int} host=%{IP:snmpagent} timestamp=%{DATA:timetick:int} value=%{BASE10NUM:value:int}"]

match => [ "message", "%{COMBINEDAPACHELOG}"]

match => [ "message", "%{SYSLOGBASE2} PING-DROP:IN=%{DATA:in_nic} OUT= MAC=%{MAC:victim_mac}:%{MAC:attack_mac}:%{DATA} SRC=%{IP:attack_ip} DST=%{IP:victim_ip} LEN=%{BASE10NUM:ping_len} %{DATA} PROTO=%{DATA:ping_proto}"]

match => [ "message", "%{DATA:simple}"] }}

output {elasticsearch {

hosts => "localhost:9200" manage_template => false index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}" document_type => "%{[@metadata][type]}" } stdout { codec => rubydebug }}

5. การเพิ่มกราฟเพื่อแสดงข้อมูลการโจมตีด้วย ping of death 5.1. เมื่อมีการเปลี่ยนแปลง configure ของ logstash ให้ update ฐานข้อมูลใน kibana ด้วย

โดยเข้าเว็บไซต์ http://192.168.56.101:5601 หลังจากนั้นเลือก Settings --> Indics หลังจากนั้นเลือก Index Patterns : filebeat-* แล้วกดปุ่ม Refresh fild list ให้สังเกตจำนวนฟิล์ดที่เปลี่ยนแปลงไป

�8

Page 55: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

T

5.2. กรองข้อมูลเฉพาะ PING-DROP โดยพิมพ์ “message: *PING-DROP*” ในช่อง filter

T

5.3. บันทึกผลการสืบค้นไว้ในชื่อ ping_of_death

T

�9

Page 56: Log Management with Elastic Search Technology · 2017-01-20 · Elastic Search Technology. Information Technology School of Informatics Walailak University System Preparation. Dr

5.4. สร้าง Dashboard ของ Ping of Death

T

�10