Splunk
Splunk
Splunk
Hands-On Labs
1. Downloading Splunk
1.1. Splunk Portal Registration
By registering and creating an account on splunk.com you are able to benefit from downloading for free the Splunk software
and also other applications and add-ons that you are able to benefit from right out of the box.
Follow the steps outlined below in order to register you on the www.splunk.com website and login in with your new Splunk
username.
Step 1 & 2. Navigate to www.splunk.com with your favorite browser and & sign-up.
1
Step 3 & 4. Fill in the required fields that has the * in front of them and after you have completed the mandatory questions
press the submit button.
Page 2
3
Page 3
Step 5 & 6. After you click submit, you receive a confirmation email from Splunk which you will have to click on the link located
in the body of the email in order to activate your account.
Step 7 & 8. Wait until your email is validated and then you can log-in.
Page 4
1.2. Let’s get some free goodies
Step 1 & 2. Click on the free Splunk link to download the software – Splunk Enterprise
Step 3 & 4. Choose the platform that you want to download and install the splunk-7.3.0-657388c7a488-Linux-x86_64.tgz
package (if required login with the credentials that you used to register with above).
Page 5
4
Step 5 & 6. As a next step we will NOT download the Splunk tgz package but we will COPY the wget link which we will then
paste into the virtual instance’s terminal windows to automatically download it locally
Note: For now paste it into your notepad and keep it until it is needed in the steps below.
Page 6
Splunk main Installation & Configuration
Step 1 & 2. Launch your SSH client and login to the CentOS operating system with the details that have been provided to you
and when prompted login with the username/password assigned to you.
Enter username/password
2
assigned to you.
Step 3. Download the rpm package using wget and install it (use the url command you copied before in section 1.2/step 6).
$ cd /tmp
$ sudo adduser splunk
Page 7
$ wget -O splunk-7.3.0-657388c7a488-Linux-x86_64.tgz
'https://www.splunk.com/bin/splunk/DownloadActivityServlet?architecture=x86_64&platform=linux&version=7.3.0&produ
ct=splunk&filename=splunk-7.3.0-657388c7a488-Linux-x86_64.tgz&wget=true'| use the link you copied before
$ sudo tar-zxvf /tmp/splunk-7.3.0-657388c7a488-Linux-x86_64.tgz –C /opt | install the splunk software
$ sudo chown -R splunk:splunk /opt/splunk
$ /opt/splunk/bin/splunk start | start the splunk daemon & accept license agreement
$ sudo /opt/splunk/bin/splunk enable boot-start -systemd-managed 0 -user splunk | start the splunk daemon on every
reboot
http://<amazon_publc_ip_address>:8000
Step 2. Log into the splunk web console and change the default changeme password.
Page 8
5
Note: You will have to restart the web server for the settings to take effect. Also it is strongly recommended that you replace
the default certificates with those provided by the client.
Page 9
Step 8-10 – Set Search Preferences – Configure Search Default time to All Time
8
10
11
Note – Its note recommended to change Default Search time to All Time in production. This setting is being configured for ease
of use in Lab/educational environments.
Page 10
1
NOTE: This step is only necessary for this lab exercise to easily locate your configuration stanza. By selecting the Search &
Reporting app, you are changing the app context. The app context determines where the specific configuration files get saved.
Step 2 & 3. Click Settings > Data inputs > Add data
Page 11
3
Page 12
Step 6. Configure the correct input settings in order to insure that the data gets correctly ingested and with the correct
parameters; when finished press Review.
Input Settings
App Context Search & Reporting
Host field Identifier Constant value
Host field Value www1
Index Default
Step 7. Check to ensure that the data has been correctly indexed, in order to do so, go to the Search page.
Page 13
Step 10. Click on the selected field names to see the assigned host and source type.
Page 14
2.1.2. Searching & Reporting for web access logs >Splunk SH
Working with Tables
Step 1. Type in index=* and press enter, you should see all the logs that your instance is receiving. [Do you want to know of a
different way to search all indexes?]
Step 2. Try looking only for apache access logs (Hint: access_combined).
Page 15
Step 3. Search for a Page Not Found status code (Do you know what a Page Not Found request code is?) -
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
Step 4. Next step will be to represent in a tabular format the following fields: _time, clientip, status.
Step 5. To represent the columns in a more “meaningful” way, we will rename the fields (Hint: Pay attention to the | symbol).
Note: Let’s get the time the job needed in order to finish go to Job > Inspect Job. / Search for This search has completed and has
returned 4 results by scanning 4 events in 0.083seconds.
Step 2. You can also exclude specific fields from searches, for example I want to exclude the action field.
Page 16
Before excluding fields
index=* sourcetype=access_combined
Tip: The more specific you are in your searches the faster they run (i.e. specifying the exact index).
Page 17
Step 2. Get all the data about the methods being used (Hint: keyword method) and the client IP (Hint: clientip) and represent
them in a table (as done above).
Do you see something below that catches your eye? Something repetitive?
Step 3. We need to find a way so we can get a summary about each clientip and the method they have used to login to our
website; The key here are statistical functions, more precisely a command called stats.
Step 5. The above would look a lot nicer in a more graphical representation such as a pie chart (don’t you agree?)
Page 18
Nice Pie Chart with a few simple steps.
Step 4. How about we start creating a nice dashboard with our web data?
Note: Do not view the dashboard; we will add one table before seeing what we have accomplished.
Page 19
Step 4. But this is not what we are looking for; we also wanted to see the clientip, so we will modify our search to include just
that!
Task: Try on your own and rename both the clientip and method fields to “Client IP” and “HTTP Method”.
Step 5. The next step will be to sort based on the new field that stats has created, which is called count.
Note: This will put the lowest number on top, in order to reverse the order you will have to put -count
| sort by count
Page 20
Sorting by descending order.
| sort by -count
Step 6. Save the above as a dashboard under the existing one we created named “Apache Logs” with the title “Client IP Access
Details”.
Page 21
Step 2. How would you create a search for the rare values? (Hint: keyword rare)
What I want from you is to create a search that will show me the number of successful logins that are greater than five (5) and
present it by clientip and sort it in a descending manner. In order to write this query use the following hints: [sourcetype, stats,
action, clientip, where, sort].
Step 2. Next step will be to count the number of failed logins by src.
Step 3. Show only the IPs that have successfully connected more than five (5) times.
Page 22
a
Step 6. As a last step, you will have a report and name it “Top Access IPs”
Page 23
a
Step 1. Let’s take into consideration the apache access logs and perform a search again, this time focusing on the Client IP which
in our case are the external client IPs hitting our website.
Page 24
Have a look at the fields that are generated.
1 Task: Create some nice searches based on the new
interesting fields (use what you have learnt so far).
Step 2. Wouldn’t this type of data be best represented on a map? (Hint: keyword geostats) – Represent the method data on the
map by Country.
Page 25
2.2. Indexing syslog events from a Linux OS (no UF)
Step 1. SSH into the Linux/Unix machine that has been assigned to you and follow the commands are they are shown below.
$ssh splunk@linux_machine
$sudo vim /etc/rsyslog.conf
Add the following lines in the end of the file and save the file.
Note: Replace the IP with the one of your own Splunk instance; keep in mind the Private IP
Step 1. Go to Settings > Data Inputs in order to configure your input type.
Step 2. Choose Add New next to UDP in order to create a UDP listener.
Page 26
Step 3. Choose the UDP option, enter port 514 and input the IP that you will be sending the data from, and press Next.
Step 4. Configure the correct input settings; here you will choose for sourcetype linux_secure (under operating Systems), the
Searching & Reporting application as App Context and Method IP. Lastly, you will choose the Default Index; Press Next.
Step 5. Review the Settings in the existing page and press Submit. Do you see an error? [why?] Go back to Select Source and
modify the port from 514 to 5514; Press Next until done.
Page 27
5
Step 2. Go to the Search Application (you may need to generate some login data in the Linux machine).
Page 28
Step 5. By Downloading the UNIX & Linux add-on, it will help us to generate the interesting fields – Go to App > Find More Apps
Step 6. Search for the “Splunk Add-on for Unix and Linux” (just type in unix in the search box) and press search.
Step 7. Enter your Splunk credentials that you created in section 1 and proceed with the download and installation.
Page 29
Step 8. Restart Splunk in order for the changes to take effect and login again.
Step 9. Search for the linux access logs again and see the difference in the interesting fields.
Page 30
2.3. Indexing a scripted input on a Linux OS (with UF)
Step 1. You would normally download the Splunk UF from the Splunk website (www.splunk.com), but for the sake of not
wasting time, we have done that for you, and have placed it under /home/splunk/software.
$cd /home/splunk/software
$sudo rpm -i splunkforwarder-6.3.2-aaff59bb082c-linux-2.6-x86_64.rpm
Step 2. The next step after installing splunk is starting it up the daemon.
$/opt/splunkforwarder/bin/splunk start | start the splunk daemon and accept the license
$sudo /opt/splunkforwarder/bin/splunk enable boot-start -user splunk | start the splunk daemon on every start-up
$/opt/splunkforwarder/bin/splunk add forward-server <private_SH_IP>:9997 -auth admin:changeme | forward all data to
SH
$/opt/splunkforwarder/bin/splunk restart
Note: Do not forget to replace the IP with the Private IP of your Splunk SH.
Find the line that starts with [script://./bin/ps.sh] and modify the following:
disabled = 1 → disabled = 0
$/opt/splunkforwarder/bin/splunk restart
Page 31
2
Step 1. For this exercise we will be using the sourcetype ps that we indexed in section 3.3.1.
index=* sourcetype=ps
Page 32
Step 2. Manipulating data coming in with a tabular format can be done with the multikv command.
index=* sourcetype=ps
| multikv fields USER, cpu_load_percent, ELAPSED, COMMAND, ARGS
| table USER, cpu_load_percent, ELAPSED, COMMAND, ARGS
| sort -cpu_load_percent
Task: Modify your search and rename USER as “User”, CPUTIME as “CPU Time”, COMMAND as “Command Used”, and ARGS as
“Argument”.
Connect via RDP with the Public IP (If you have a MAC use the Microsoft Remote Desktop).
Note: For the ease of this exercise we have already downloaded the UF and have placed it under c:\software\
Step 1. Locate the software under c:\Software\ and double on the splunkforwarder-6.3.2-aaff59bb082c-x64-release to initiate
the installation.
Step 2. Check the appropriate settings as shown below & choose “Customize Options”.
Page 33
Step 3. Choose the installation path (unless you have explicit requirements leave default) and press Next.
Step 4. For our training purposes leave the settings empty and press Next.
Page 34
Step 6. For this lab we will monitor Application, Security & System Logs.
Step 7. Tell the installer to install the Windows TA together with the forwarder (Do you remember what a TA is?).
Step 8. Skip this step and press Next. [would you like to know what a deployment server does?]
Page 35
Page 36
Step 9. Input the IP and port of your assinged instance (or in Splunk terminology an indexer).
Enter Private IP of SH
9
Step 10. Install & Check the installation directory.
10
Note: All Splunk log files are stored under C:\Program Files\SplunkUniversalForwarder\var\log\splunk.
Page 37
2.5. Searching & Representing with Windows > Splunk
Step 0. Do you see any errors under Messages? Before you begin indexing data from the windows UF you will first have to
create an index that Splunk is expecting “wineventlog”.
Page 38
Step 1. Having some good searching fun – Type in index=* and press enter, you should see all the logs that your instance is
receiving. [Do you want to know of a different way to search all indexes?]
Step 2. Try looking only for Security Windows Event Logs (Hint: Sourcetype=WinEventLog:Security).
Page 39
Step 3. Search for Windows Logons (Hint: EventCode=4624) – Do you know what these codes mean?
(https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/Default.aspx).
Step 4. Next step will be to represent in a tabular format the following fields: src, Account_Name, dest.
Spaces between searches represent a
4
logical AND
Step 5. Represent the fields in a more “meaningful” way, thus we will rename the fields (Hint: Pay attention to the | symbol).
Step 6. We are not interested in seeing any account names that end with a $ sign, thus we will filter those out.
Page 40
Step 7. Identify multiple failed login attempts by a single username (modify the search and try from a single source IP).
Task:
a. Add the data to a dashboard named “Windows Failed Logins”.
b. Create a Bar chart with the top 10 failed login IPs (hint: keyword top or maybe a sub command within sort) –
docs.splunk.com
c. Sort this data in a descending manner
Page 41