Hunting with Splunk Lab 2
Hunting with Splunk Lab 2
Scenario
The IT Security manager has provided you with a Splunk instance that has ingested the Boss Of The SOC
v2 dataset. He tasked you with getting familiar with Splunk through the given hunting tasks, so that you
can create more complex Splunk hunting searches in the future.
All hunts of this lab build mostly on hypotheses derived from the MITRE ATT&CK framework.
• PowerShell
• Adversary Infrastructure
• Lateral Movement
Full credit goes to Ryan Kovar, David Herrald, James Brodsky, John Stoner, Jim Apger, and David
Veuve for sharing the Splunk detection tips this lab covers with the public.
That being said, the provided hunt solutions/searches in this lab are slightly different.
Goals
The learning objective of this lab is the rule generation ability and becoming more familiar with Splunk.
The learning objective of this lab is to not only get familiar with Splunk's architecture and detection
capabilities but also to learn effective Splunk search writing.
Specifically, you will learn how to use Splunk's capabilities in order to:
Report an issue
overview
tasks
solutions
SOLUTIONS
Below, you can find solutions for each task. Remember though, that you can follow your own strategy,
which may be different from the one explained in the following lab.
Kali Machine
Task 1. Hunt for PowerShell Empire
Once the query is completed, we can look at the src. The result should be similar to the one below.
The SSL subject/issuer value of "C = US" was seen on four internal systems
Bonus (for advanced hunting): You may have noticed that the SPL search above took some time to
complete. We could have accelerated our search by using the tstats command as follows.
| sort - count
The above search utilizes Splunk Datamodels and provides us with the same result but in considerably
less time.
Note the firstTime and lastTime entries as well as the common destination 45.77.65.211.
A data model is a hierarchically structured search-time mapping of semantic knowledge about one or
more datasets. It encodes the domain knowledge necessary to build a variety of specialized searches of
those datasets. These specialized searches are used by Splunk software to generate reports for Pivot
users.
Goals of a Datamodel:
• Make it easy to share/reuse domain knowledge [Admins/power users build data models]
• Provide an interface for 'non-technical users' interact with data via pivot UI [note: non-technical
== analyst with less "domain" knowledge]
To list all available datamodels in your environment, execute the search below.
| datamodel
| spath displayName
| stats values(displayName)
Information on the Certificates data model can be found below.
https://docs.splunk.com/Documentation/CIM/4.15.0/User/Certificates
Back to our hunt, let's see what data we have for the common destination we noticed, 45.77.65.211
We notice that we have web and Sysmon logs containing that indicator/IP. This means that this IP isn't
being blocked at the network level and that it has reached the system level.
The available firewall logs can indicate the workstations/servers that communicated with that IP the
most, as follows.
Once the search is completed click on 32 more fields and select the alert.signature field.
Unfortunately, if we click that (signature) newly-added field no interesting information appears.
Let's focus on another available sourcetype stream:http, to identify communication flows with the IP
indicator (45.77.65.211).
1. 172.31.4.249
The indicator IP (45.77.65.211) has a tremendous amount of events generated with a destination of
172.31.4.249. Note that 172.31.4.249 is a Linux server belonging to our organization.
Let's drill into the events where the source address is our indicator and the destination is our web server
172.31.4.249.
By searching online for w3af.org, we see that it is an open source web application security scanner. It
looks like the IP indicator has also been scanning a web server of ours in addition to being a destination
for some of our workstations/servers. Note that our web server that was scanned didn't appear in the
outbound communications.
1. 71.39.18.125
1. 10.0.2.109
Nothing that can advance our hypothesis about PowerShell Empire being executed comes up. We may
come back to investigate this further later.
It is about time we move our attention to host centric data through Microsoft Sysmon logs, as follows.
Let's use a wildcard on dest to ensure we get all of the values we saw in the previous search
index=botsv2 sourcetype="xmlwineventlog:microsoft-windows-sysmon/operational"
dest=45.77.65.211*
Once the search is completed, we notice that all returned events are running PowerShell. We also notice
a lot of Network Connect Sysmon events. It is not common to see PowerShell performing network
connections. Finally, some progress...
Let's analyze these Network Connection Sysmon events related with powershell.exe further, as follows.
index=botsv2 sourcetype="xmlwineventlog:microsoft-windows-sysmon/operational"
dest=45.77.65.211* | stats values(dest_port) as dest_port values(host) as host values(src_ip) as src_ip
values(src_port) as src_port by process,dest,user
The user executing these events are either the SYSTEM account or a frothly domain account called
service3.
By using the timechart command we can see that this network activity took place between 8/23 and
8/26. We are focusing on the service3 user.
index=botsv2 sourcetype="xmlwineventlog:microsoft-windows-sysmon/operational"
dest_ip=45.77.65.211* user=FROTHLY\\service3 | timechart count by src_ip
Let's dig deeper into what has been executing through the service3 account, as follows.
index="botsv2" sourcetype="xmlwineventlog:microsoft-windows-sysmon/operational"
user=FROTHLY\\service3 | stats values(CommandLine) by Computer,process,ParentImage
Not only we can see malicious PowerShell commands being executed but we also notice whoami.exe
and ftp.exe being executed by PowerShell(which is suspicious). These three suspicious processes appear
in both venus.frothly.local and wrk-klagerf.frothly.local.
How we know that these PowerShell commands are malicious you may ask. Let's Base64 decode them.
The output looks certainly malicious.
The output also contains /admin/get.php. Asking for this file is characteristic of PowerShell Empire!
Other strings may also exist that can indicate the existence of PowerShell Empire in our environment)
https://github.com/EmpireProject/Empire/blob/master/data/agent/agent.py
For the extra mile try to identify similar PowerShell commands on other workstations/servers. We
focused on the service3 account only. Maybe another account executed similar commands.
Let's start with the available sourcetypes for this hunt focusing on August 2017 (data obtained from the
previous Task).
or
We notice that two internal systems speaking to the same external destination address, 160.153.91.7.
If we look at Palo Alto data, we notice we have two sourcetypes, pan:traffic and pan:threat. The traffic
sourcetype has by far the greater volume of traffic, but interestingly, we see the vast majority of traffic
heading to the external interface of our firewall. So additional inspection of this data to learn more is
warranted.
We notice some curious-looking ftp activity! We will get back to this activity and investigate further.
Back to the network now, let's try to see inside the FTP traffic.
index=botsv2 ftp sourcetype=stream:ftp src_ip=* dest_ip=160.153.91.7
• flow_id
• reply_content
• method
• method_parameter
• filename
Make also sure you give reply_content a look for interesting information.
It is worth looking into each separate transmission. You can do that through the query below, clicking
into each green bar of the histogram and then pressing +Zoom to Selection.
Now you can view which files were uploaded/exfiltrated (do the below for each transmission) as follows.
Let's also not forget to search for the other files that were downloaded.
We have investigated FTP activity thoroughly enough. You should now have a good idea of how to hunt
for FTP exfiltration.
With the IP address of 160.153.91.7, we can leverage this indicator to determine if any exfiltration was
being attempted using DNS. stream:dns provides us with all DNS query and responses occurring within
Frothly (our domain).
Let's leverage URL Toolbox to refine our search. We will need to reference the mozilla list (part of URL
Toolbox) and then run the ut_parse_extended macro against the query field. This will chop the query
into finer pieces to analyze. We can then calculate the Shannon entropy score of the subdomain that
was extracted and then table the output.
As we review at our results, we can see that all of these subdomains have a high entropy score. Entropy
scores greater than 3 are considered high and can often be used to determine if domains or urls are
algorithmically generated. Entropy is not perfect, just look at an AWS subdomain name, but it is another
tool in the tool chest that can help indicate a DGA and that additional interrogation is needed.
| eval query{}=mvdedup(query)
| eval list="mozilla"
| `ut_parse_extended(query{},list)`
| `ut_shannon(ut_subdomain)`
Generally, a high average entropy, high subdomain length and low standard deviation of the length,
coupled with a high event count could be indicative of a DNS exfiltration attempt and we seem to have
met those metrics here.
| eval query{}=mvdedup(query)
| eval list="mozilla"
| `ut_parse_extended(query{},list)`
| `ut_shannon(ut_subdomain)`
We already know that our 10.0.2.107 endpoint communicated with the 45.77.65.211 IP indicator. We
also know that the communication was based on a SSL certificate of specific configuration. Let's extract
the certificate's sha256 hash and hunt for it in the wild as follows.
However, let's submit the IP Indicator to virustotal.com and see what the results are. The initial results
show as clean, but lets look at relations. You can see under Communicating Files that there are three
malicious files associated to the IP Address. By clicking on one or more of these files you now have an
opportunity to expand you indicators of compromise list and have a look at other assocaited IP
addresses and domains.
Based on the guidance provided in the JPCERT doc, we can craft a search using Sysmon and we find 11
events (between 8/23/2017 and 8/24/2017), all associated with wrk-klagef. Recall that we need escape
characters for \.
index=botsv2 sourcetype="xmlwineventlog:microsoft-windows-sysmon/operational" EventCode=1
ParentImage="C:\\Windows\\System32\\svchost.exe" CurrentDirectory="C:\\Windows\\system32\\"
CommandLine="C:\\Windows\\system32\\wbem\\wmiprvse.exe -secured -Embedding"
ParentCommandLine="C:\\Windows\\system32\\svchost.exe -k DcomLaunch" User="NT
AUTHORITY\\NETWORK SERVICE" Image="C:\\Windows\\System32\\wbem\\WmiPrvSE.exe" | stats
count by host
We didn't have any luck with the Network Connection event in Sysmon
The below is what we should see in Remote Execution via WMI at the destination side, but we don't
have all the needed data in our Sysmon logs.
Let's focus on Teymur Kheirklabarov's advice on hunting for remote execution via WMI (systems with
Network 4624 Event followed by Sysmon Process Creations).
index=botsv2 (sourcetype=wineventlog (EventCode=4624 Logon_Type=3)) OR
(sourcetype="xmlwineventlog:microsoft-windows-sysmon/operational"
ParentCommandLine!="*\\svchost.exe" EventCode=1)
| eval login=mvindex(Logon_ID,1)
| eval user_id=mvindex(Security_ID,1)
| eval session=lower(coalesce(login,LogonId))
| search eventcount>1
| eval Parent_Process=mvindex(ParentImage, 1)
To better see all the events that occurred and all processes that were running during the identified
sessions (LogonId) above on the venus and wrk-klagerf hosts, use the searches below.
You should now have a better idea of how to hunt for remote execution through WMI.
Not running
For the best experience, choose the region closest to you. Then, start the lab to begin.
US-East
Keyboard layout:🇺🇸 English (US)