8. Why ELK?
Old School
● grep/sed/awk/cut/sort
● manually analyze the output
ELK
● define endpoints(input/output)
● correlate patterns
● store data(search and visualize)
10. History of ElasticSearch!
- Developed by Shay banon
- Version 1 was called as Compass -2004
- Fully Developed over apache Lucene!
- Necessity to scale Compass resulted in rewriting
most of its code and renaming it to ElasticSearch!
- Version 1 was released in 2010
- Raised first Funding in 2014 !
11. Apache Lucene!
- Free open source search engine library written in
java
- Author : Doug Cutting
- Were mostly used or still in use by many ecom
websites.
- Useful in optimizing speed and performance in
finding relevant docs on every search query.
- An index of 10K documents can be queried within
milliseconds
13. Overview of Elasticsearch
•Open source search server written in Java, over Apache lucene library.
•Used to index any kind of heterogeneous data
•Enables real-time ability to search through index
•Has a REST API web-interface with JSON output
14. Terminologies of Elasticsearch!
Cluster
● A cluster is a collection of one or more nodes (servers) that together
holds your entire data and provides federated indexing and search
capabilities across all nodes
● A cluster is identified by a unique name which by default is
"elasticsearch"
15. Terminologies of Elasticsearch!
Node
● It is an elasticsearch instance (a java process)
● A node is created when a elasticsearch instance is started
● A random Marvel Charater name is allocated by default
16. Terminologies of Elasticsearch!
Index
● An index is a collection of documents that have somewhat similar
characteristics. eg:customer data, product catalog
● Very crucial while performing indexing, search, update, and delete
operations against the documents in it
● One can define as many indexes in one single cluster
17. Document
● It is the most basic unit of information which can be indexed
● It is expressed in json (key:value) pair. ‘{“user”:”nullcon”}’
● Every Document gets associated with a type and a unique id.
Terminologies of Elasticsearch!
18. Terminologies of Elasticsearch!
Shard
● Every index can be split into multiple shards to be able to distribute data.
● The shard is the atomic part of an index, which can be distributed over the cluster if you
add more nodes.
● By default 5 primary shards and 1 replica shards are created while starting elasticsearch
____ ____ | 1 | | 2 | | 3 | | 4 | | 5 | |____| |____|
● Atleast 2 Nodes are required for replicas to be created
19. edit elasticsearch.yml
$ sudo nano /etc/elasticsearch/elasticsearch.yml
ctrl+w search for ”cluster.name”
Change the cluster name to elastic_yourname
ctrl+x Y
Now start ElasticSearch sudo service elasticsearch restart
22. Restful API’s over http -- !help curl
curl -X<VERB> '<PROTOCOL>://<HOST>/<PATH>?<QUERY_STRING>' -d '<BODY>'
● VERB-The appropriate HTTP method or verb: GET, POST, PUT, HEAD, or DELETE.
● PROTOCOL-Either http or https (if you have an https proxy in front of Elasticsearch.)
● HOST-The hostname of any node in your Elasticsearch cluster, or localhost for a node on your
local machine.
● PORT-The port running the Elasticsearch HTTP service, which defaults to 9200.
● QUERY_STRING-Any optional query-string parameters (for example ?pretty will pretty-print
the JSON response to make it easier to read.)
● BODY-A JSON encoded request body (if the request needs one.)
23. !help curl
Simple Index Creation with XPUT:
curl -XPUT 'http://IP:9200/twitter/'
Add data to your created index:
curl -XPUT 'http://IP:9200/twitter/tweet/1' -d '{"user":"nullmeet"}'
Now check the Index status:
curl -XGET 'http://IP:9200/twitter/?pretty=true'
List all Indices in ES Instance:
curl -XGET 'http://IP:9200/_cat/indices?v'
Check the shard status:
curl -XGET 'http://IP:9200/twitter/_search_shards'
24. !help curl
Automatic doc creation in an index with XPOST:
curl -XPOST 'http://IP:9200/twitter/tweet/' -d '{"user":"nullcon"}'
Creating a user profile doc:
curl -XPUT 'http://IP:9200/twitter/tweet/9' -d '{"user":"admin", "role":"tester", "sex":"male"}'
curl -XPOST 'http://IP:9200/twitter/tester/' -d '{"user":"abcd", "role":"tester", "sex":"male"}'
curl -XPOST 'http://IP:9200/twitter/tester/' -d '{"user":"abcd", "role":"admin", "sex":"male"}'
25. Searching in ElasticSearch:
$ curl -XGET 'http://IP:9200/twitter/_search?q=user:abcd&pretty=true'
The Power of “Explain”
$ curl -XGET 'http://IP:9200/twitter/_search?q=user:abcd&explain&pretty=true'
!help curl
26. !help curl
Deleting an doc in an index:
$curl -XDELETE 'http://IP:9200/twitter/tweet/1'
Deleting the whole Index:
$curl -XDELETE 'http://IP:9200/index_name/'
Cluster Health: (yellow to green)/ Significance of colours (green/yellow/red)
$curl -XGET 'http://IP:9200/_cluster/health?pretty=true'
$./elasticsearch -D es.config=../config/elasticsearch2.yml &
27.
28. Overview of Logstash
•Framework for managing logs
•Founded by Jordan Sissel
•Mainly consists of 3 components:
● input : passing logs to process them into machine understandable
format(file,lumberjack,beat).
● filters: set of conditionals to perform specific action on a event(grok,
geoip).
● output: decision maker for processed event/log(elasticsearch,file)
29. Logstash Configuration
● Managing events and logs
● Collect data
● Parse data
● Enrich data
● Store data (search and
visualizing)
} input
} filter
} output
40. •Powerful front-end dashboard for visualizing indexed information from
elastic cluster.
•Capable to providing historical data in form of graphs,charts,etc.
•Enables real-time search of indexed information.
Overview of Kibana
46. Grok 101
•Understanding grok nomenclature.
•The syntax for a grok pattern is %{SYNTAX:SEMANTIC}
•SYNTAX is the name of the pattern that will match your text.
● E.g 1337 will be matched by the NUMBER pattern, 254.254.254
will be matched by the IP pattern.
•SEMANTIC is the identifier you give to the piece of text being
matched.
● E.g. 1337 could be the count and 254.254.254 could be a client
making a request
%{NUMBER:count} %{IP:client}
47. Grok 101…(continued)
• Common Grok Patterns:
• %{WORD:alphabet} e.g Nullcon
• %{INT:numeric} e.g. 1337
•%{NOTSPACE:pattern_until_space} e.g. Nullcon Goa
•%{GREEDYDATA:anything} e.g. $Nullcon@Goa_2016
48. Grok 101…(continued)
Let’s work out GROK for below:
● 192.168.1.101
● 192.168.1.101:8080
● [15:30:00]
● [03/08/2016]
● [08/March/2016:14:12:13 +0000]
49. Playing with grok filters
•Apache access.log event:
123.249.19.22 - - [08/Mar/2016:14:12:13 +0000] "GET /manager/html HTTP/1.1" 404 448
"-" "Mozilla/3.0 (compatible; Indy Library)"
•Matching grok:
%{IPV4} %{USER:ident} %{USER:auth} [%{HTTPDATE:timestamp}] "(?:%{WORD:verb} %
{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?)" %{NUMBER:response} (?:%
{NUMBER:bytes}|-)
•Things can get even more simpler using grok:
%{COMBINEDAPACHELOG}
59. Identifying DoS patterns
-Identifying DoS patterns is trivial.
- Any traffic that tends to exhaust your connection pool
would result in DoS.
- Traffic need not be volumetric
68. Logtash grok to rescue!
https://github.com/bitsofinfo/logstash-modsecurity
69.
70. Kibana Overview
● Queries ES instance
● Visualization capabilities on top of the content
indexed on an Elasticsearch cluster.
● create bar, line and scatter plots, or pie charts
and maps on top of large volumes
74. Tabs
Discover - Overview of all Data pumped into ES Instance
Visualize - Setup cool graphs
Dashboard - Arrange all visualizations, and make a sorted dashboard.
Settings
- Configure
● ES Instance
● Indices
● Fields
88. Overview
•Alerting Framework for ElasticSearch Events
•Queries ES instance periodically
•Checks for a Match
•If match { create Alert;}
•Supports Alerts on Kibana, Email, Command, JIRA, etc.
•Highly Scalable
91. Config.yaml – The backbone
Main configuration file for multiple settings.
Key Value pair based configuration.
● ES_host
● Buffer_time
● Use_terms_query
● Rules_folder
● Run_every
92. Rules
Different Rule Types available
● Frequency - X events in Y time.
● Spike - rate of events increases or decreases.
● Flatline - less than X events in Y time.
● Blacklist / Whitelist - certain field matches a blacklist/whitelist.
● Any - any event matching a given filter
● Change - if field has two different values within some time.
93. Rules Config
● All rules reside in a folder.
● Rules_folder in config.yaml
● Important Configurations
○ type: Rule type to be used (eg. Frequency / spike / etc.)
○ index: (eg. Logstash-*)
○ filter: (eg. term: n host:’xyzhostname’)
○ num_events: (eg. 10)
○ timeframe: [hours / minutes / seconds / days] (eg. Hours: 3)
○ alert: (eg. Email / JIRA / Command / etc.)
94. So far we discussed about “external threats”, but
what about “internal threats”?
95.
96. Understanding osquery
● Open source project from Facebook Security Team.
● osquery exposes an operating system as a lightweight, high-performance relational database.
● With osquery, your system acts as “database” and “tables” represents concepts as running
process, packages installed, open network connections, etc...
● Two operational modes:
○ osqueryi - CLI interface
○ sudo service osquery restart - daemon service
100. osqueryd - Run scheduled queries of tables
$ sudo service osquery restart
$ cat /etc/osquery/osquery.conf
{
"schedule": {
"debpackages": {
"query": "select name,version from deb_packages;",
"interval": 10
},
"total_processes": {
"query": "select name,pid from processes;",
"interval": 10
},
"ports_listening": {
"query": "select pid,port,address from listening_ports;",
"interval": 10
}
}
}
101. Verify your osquery is working
Open a terminal and type below:
$ sudo tailf /var/log/osquery/osqueryd.results.log
Open a new terminal and type below:
$ python -m SimpleHTTPServer
Go to your first terminal and verify the event from second terminal.