Tuesday, August 25, 2015

Log Management Dengan Graylog2, MongoDB, Elasticsearch, Kibana (2)

Wihartoyo     Tuesday, August 25, 2015    

Bagian 2 dari 3 tulisan
Pada bagian ini diuraikan konfigurasi input dan ekstraktor serta menghubungkan Suricata ke Graylog2

Melanjutkan tulisan sebelumnya Log Management Dengan Graylog2, MongoDB, Elasticsearch, Kibana (1), pada tulisan ini akna sedikit menguraikan tentang beberapa konfigurasi dan pemanfaatannya.  Tentunya masih menggunakan Graylog2.

Input.

Konfiguras Input sangat penting mengingat ini adalah item konfigurasi yang memungkinkan Graylog2 untuk membuka port menangkap kiriman log. Ada beberapa jenis input.  Namun untuk sementara kita hanya menggunakan “Syslog TCP”  dan “Syslog UDP”.  Dan karena input nanti akan berhubungan dengan extractors, maka sebaiknya input dibuat spesifik untuk mesin log yang spesifik juga.  Misalkan kita akan menangkap log dari Suricata, kita buatkan 1 input khusus dengan protocol UDP misalnya, dan listening pada port 6160 misalkan.

Langkah pembuatan input

Untuk membuat input, setelah kita bisa memasuki interface Graylog2, silakan klik pada "System--Input" sebagaimana terlihat pada gambar:

System-->Input
Setelah kita klik input, maka kita akan dibawa ke layar berikut:

Layar Konfigurasi Input.
Dan, perhatikan gambar berikut:




Langkah-langkah:
  1. Pilih Syslog-UDP dan klik "Launch new Input" sehingga muncul pop-up.  Perhatikan judul pop-up harus sesuai dengan yang kita pilih.
  2. Tentukan nama Input
  3. Tentukan pada port berapa input akan dipasang (contoh 6061)
  4. Tentukan bind address (pada contoh 0.0.0.0 alias semua IP yang aktif)
  5. Klik "Launch"
Setelah kita klik Launch, maka input object aru akan di list pada layar Input dalam kondisi belum aktif. Untuk mengaktifkannya kita bisa klik "Start Input".


Namun, sebelum kita buatkan ekstraktorynya, ada baiknya jangan kita start dulu inputnya, karena ekstraktor berjalan saat ada log stream diterima oleh input.  Jadi bila input tidak dilengkapi oleh ektraktor, maka log stream yang disimpan adalah log stream apa adanya.

Manage Extractors

Untuk memanage ekstraktor, pada boks input kita klik tomnbol "Manage Extractors" sehingga kita akan dibawa ke layar berikut:
Layar Manage Extractors
Pada gambar, kita lihat belum ada satupun ektraktor yang bisa digunakan.  Untuk menambahkan, klik "Action" dan pilih "Impor Extractors". Dan masukkan text berikut (modifikasi ekstraktor untuk menghandle Log Suricata, sesuai kebutuhan saya).
#----------------------------------------------------------

{
  "extractors": [
    {
      "condition_type": "none",
      "condition_value": "event_type",
      "converters": [],
      "cursor_strategy": "copy",
      "extractor_config": {
        "regex_value": "\"event_type\"[:]([^,]+)"
      },
      "extractor_type": "regex",
      "order": 1,
      "source_field": "message",
      "target_field": "event_type",
      "title": "suricata Event Type"
    },
    {
      "condition_type": "none",
      "condition_value": "src_ip",
      "converters": [],
      "cursor_strategy": "copy",
      "extractor_config": {
        "regex_value": "\"src_ip\"[:]([^,]+)"
      },
      "extractor_type": "regex",
      "order": 1,
      "source_field": "message",
      "target_field": "src_ip",
      "title": "Source IP"
    },
    {
      "condition_type": "none",
      "condition_value": "src_port",
      "converters": [],
      "cursor_strategy": "copy",
      "extractor_config": {
        "regex_value": "\"src_port\"[:]([^,]+)"
      },
      "extractor_type": "regex",
      "order": 1,
      "source_field": "message",
      "target_field": "src_port",
      "title": "Soource Port"
    },
    {
      "condition_type": "none",
      "condition_value": "dest_ip",
      "converters": [],
      "cursor_strategy": "copy",
      "extractor_config": {
        "regex_value": "\"dest_ip\"[:]([^,]+)"
      },
      "extractor_type": "regex",
      "order": 1,
      "source_field": "message",
      "target_field": "dest_ip",
      "title": "Destination IP"
    },
    {
      "condition_type": "none",
      "condition_value": "dest_port",
      "converters": [],
      "cursor_strategy": "copy",
      "extractor_config": {
        "regex_value": "\"dest_port\"[:]([^,]+)"
      },
      "extractor_type": "regex",
      "order": 1,
      "source_field": "message",
      "target_field": "dest_port",
      "title": "Destination Port"
    },
    {
      "condition_type": "none",
      "condition_value": "hostname",
      "converters": [],
      "cursor_strategy": "copy",
      "extractor_config": {
        "regex_value": "\"hostname\"[:]([^,]+)"
      },
      "extractor_type": "regex",
      "order": 1,
      "source_field": "message",
      "target_field": "hostname",
      "title": "Destination Host name"
    },
    {
      "condition_type": "none",
      "condition_value": "url",
      "converters": [],
      "cursor_strategy": "copy",
      "extractor_config": {
        "regex_value": "\"url\"[:]([^,]+)"
      },
      "extractor_type": "regex",
      "order": 1,
      "source_field": "message",
      "target_field": "url",
      "title": "URL"
    },
    {
      "condition_type": "none",
      "condition_value": "http_user_agent",
      "converters": [],
      "cursor_strategy": "copy",
      "extractor_config": {
        "regex_value": "\"http_user_agent\"[:]([^,]+)"
      },
      "extractor_type": "regex",
      "order": 1,
      "source_field": "message",
      "target_field": "http_user_agent",
      "title": "HTTP User Agent"
    },
    {
      "condition_type": "none",
      "condition_value": "http_content_type",
      "converters": [],
      "cursor_strategy": "copy",
      "extractor_config": {
        "regex_value": "\"http_content_type\"[:]([^,]+)"
      },
      "extractor_type": "regex",
      "order": 1,
      "source_field": "message",
      "target_field": "http_content_type",
      "title": "HTTP Content Type"
    },
    {
      "condition_type": "none",
      "condition_value": "http_method",
      "converters": [],
      "cursor_strategy": "copy",
      "extractor_config": {
        "regex_value": "\"http_method\"[:]([^,]+)"
      },
      "extractor_type": "regex",
      "order": 1,
      "source_field": "message",
      "target_field": "http_method",
      "title": "HTTP Method"
    },
    {
      "condition_type": "none",
      "condition_value": "signature",
      "converters": [],
      "cursor_strategy": "copy",
      "extractor_config": {
        "regex_value": "\"signature\"[:]([^,]+)"
      },
      "extractor_type": "regex",
      "order": 1,
      "source_field": "message",
      "target_field": "signature",
      "title": "Signature"
    },
    {
      "condition_type": "none",
      "condition_value": "payload",
      "converters": [],
      "cursor_strategy": "copy",
      "extractor_config": {
        "regex_value": "\"payload\"[:]([^,]+)"
      },
      "extractor_type": "regex",
      "order": 1,
      "source_field": "message",
      "target_field": "payload",
      "title": "Payload"
    },
    {
      "condition_type": "none",
      "condition_value": "payload_printable",
      "converters": [],
      "cursor_strategy": "copy",
      "extractor_config": {
        "regex_value": "\"payload_printable\"[:]([^,]+)"
      },
      "extractor_type": "regex",
      "order": 1,
      "source_field": "message",
      "target_field": "payload_printable",
      "title": "Payload Printable"
    },
    {
      "condition_type": "none",
      "condition_value": "severity",
      "converters": [
        {
          "config": {},
          "type": "numeric"
        }
      ],
      "cursor_strategy": "copy",
      "extractor_config": {
        "regex_value": "\\\"severity\\\"[:]([^\\}|\\]]+)"
      },
      "extractor_type": "regex",
      "order": 1,
      "source_field": "message",
      "target_field": "severity",
      "title": "Severity"
    },
    {
      "condition_type": "none",
      "condition_value": "signature_id",
      "converters": [],
      "cursor_strategy": "copy",
      "extractor_config": {
        "regex_value": "\"signature_id\"[:]([^,]+)"
      },
      "extractor_type": "regex",
      "order": 1,
      "source_field": "message",
      "target_field": "signature_id",
      "title": "Signature ID"
    },
    {
      "condition_type": "none",
      "condition_value": "bytes_toclient",
      "converters": [
        {
          "config": {},
          "type": "numeric"
        }
      ],
      "cursor_strategy": "copy",
      "extractor_config": {
        "regex_value": "\\\"bytes_toclient\\\"[:]([^\\,]+)"
      },
      "extractor_type": "regex",
      "order": 1,
      "source_field": "message",
      "target_field": "bytes_toclient",
      "title": "Bytes to Client"
    },
    {
      "condition_type": "none",
      "condition_value": "bytes_toserver",
      "converters": [
        {
          "config": {},
          "type": "numeric"
        }
      ],
      "cursor_strategy": "copy",
      "extractor_config": {
        "regex_value": "\"bytes_toserver\"[:]([^\\,]+)"
      },
      "extractor_type": "regex",
      "order": 1,
      "source_field": "message",
      "target_field": "bytes_toserver",
      "title": "Bytes to Server"
    }
  ],
  "version": "1.1.6 (2e264c2)"
}
#----------------------------------------------------------

Copy text di atas, dan paste ke layar berikut:


Setelah selesai, klik "Add extractors to input" dan kita akan dibawa ke layar berikut:

Daftar Ekstrator yang terbentuk
Penyesuaian Konfigurasi Syslog mesin Suricata

Pada tulisan Install Suricata IDS Pada Ubuntu 14.04, telah diuraikan tentang konfigurasi Suricata agar menuliskan outputnya ke syslog.  Di sini kita akan merubah konfigurasi syslog agar log dari suricata bisa di'lempar' ke Graylog2 pada protokol UDP dengna port 6061.

Pada Ubuntu 14.04, kita merubah konfigura syslog pada /etc/rsyslog.d/50-default.conf, sedangkan pada Centos 7.0 kita sesuaikan file /etc/rsyslog.conf dengan menambahkan baris berikut pada baris terakhir.

suricata                                 @graylog2-host:6061
Catatan: @@ menunjukkan penggunaan protokol TCP, @ menunjukkan penggunaan protokol UDP
Kemudian restart service rsyslog dengan perintah.


[root@suricatahost~]#service rsyslog restart


Setelah syslognya aktif, kita jalankan input pada graylog.  Tunggu beberapa saat sampai cukup log item untuk ditampilkan.

Setelah kira-kira akumulasi event dirasa cukup, maka kita bisa coba dengan klik "Seacrh" dan memasukkan "source:[suricatahost]" (dengan kurung siku menandakan variable, misal suricatahost = surids, maka
querynya adalah "source:surids").  Setelah menuliskan query dengan benar, tekan enter.

Layar "Search" untuk meng-query event.
Kita bisa melakukan analisa instan melalui box fields. Dalam contoh berikut kita ingin detil signature dengan mengklik "Quick View" di bawah signature.

Interaktif screen pada menu "Search"

Ok, sekarang suricata sudah ngobrol dengan Graylog2. Silakan dieksplore lebih lanjut, termasuk pembentukan Dashboard.  Dan, karena data tersimpan dalam elasticsearch, maka syntax untuk searching atau filtering data harus mengikuti kaidah yang berlaku pada elasticsearch.

,

Recommended