This blog post series is a culmination of my learning experience in becoming a threat hunter. Over time this learning experience helped me develop a teaching philosophy to help novices go from zero to hero threat hunter, which is what I will be using to teach the threat hunting fundamentals. This series will have a strong focus on understanding the attacker mindset, how to interpret actions performed by an adversary from a defenders perspective, and how to transition findings from your hunts into future detections or environmental improvements. The content used here is a written adaptation of my DefCon 2020 Blue Team village workshop. It will utilize the same ideas and techniques used for that workshop reiterating specifics and points for the greater InfoSec community to use.
First, we will start by understanding the attacker mindset with the Mandiant Attack Lifecycle. To re-enforce this methodology there is a red team exercise utilizing Powershell Empire to perform an APT style attack. The outcome of this red team exercise is the creation of a story or, in this case, the creation of a fictious advanced persistent threat (APT) known as Goofball. Second, we will utilize the actions performed by Goofball to perform an informal threat hunting exercise that will hunt the artifacts generated by our fictious adversary using Sysmon and the Elastic stack.
Thirdly, we will use our informal threat hunting exercise as a foundational jumping off point to formally hunt our fictitious adversary using the Endgame threat hunting process. In addition to the Endgame threat hunting process, we will learn how to use the MITRE ATT&CK matrix to generate threat hunting hypotheses and use FleetDM + Osquery to confirm/deny our hypothesis. Lastly, we will end this blog post series with a retrospective and how to convert threat hunting findings into detections or environmental improvements.
Before we jump into these topics, we need an environment to perform our red team exercise and to collect logs from for our threat hunting exercises. This blog post contains Ansible playbooks and manual instructions to setup the Windows environment used for this series. Additionally, there is a “quick setup” to stand up an Elastic stack and import pre-collected logs from the red team exercise. This quick setup is for individuals who don’t have the hardware resources to spin up an entire network or would prefer to just utilize the logs. The take away from this blog post series should be an understanding of the attacker mindset, how to use the knowledge of attacker techniques and procedures to hunt for them, and finally how to transition successful hunts to detections.
DISCLAIMERS
The information contained in this blog post is for educational purposes ONLY! HoldMyBeerSecurity.com/HoldMyBeer.xyz and its authors DO NOT hold any responsibility for any misuse or damage of the information provided in blog posts, discussions, activities, or exercises.
The red team exercise performed in this blog post occurred in a home lab network. Therefore, the malicious activity performed was on machines that I own and have permission to perform these actions.
To prevent the weaponization of the content within this blog post there will be missing commands/instructions. The red team exercise is meant to simulate what an attacker may do on a network, NOT a step-by-step.
DISCLAIMERS
Goals
- Create a Windows environment for a red team exercise
- Intentionally make the environment vulnerable
- Choose your own SIEM adventure
- Setup Osquery + FleetDM to run ad-hoc queries on Windows environment
- Setup Sysmon + Winlogbeat + Elastic stack to perform real-time monitoring of Windows environment
Blog post series
- Part 1: Intro to Threat Hunting – Setting up the environment
- Part 2: Intro to Threat Hunting – Understanding the attacker mindset with Powershell Empire and the Mandiant Attack Lifecycle
My threat hunting teaching philosophy
This entire blog post series is how I learned threat hunting which turned into how I teach threat hunting. Back in college, I was interested in threat hunting and my professor did a post on his LinkedIn asking if people would like to mentor me. Thankfully the community came through and I started talking to a collection of threat hunters in the industry. Every one of them told me to understand the Mandiant Attack Lifecycle and the MITRE ATT&CK matrix.
Understanding the Mandiant Attack Lifecycle is really important because you need a good understanding of how the attacks are performed. The MITRE ATT&CK matrix can be used as a guide for threat hunters to create well scoped hypotheses for hunting. While all this is good, it didn’t quite give me that light bulb moment. During my college career, I heard about Mimikatz, malicious documents, and privilege escalation. What I had at the time was an independent concept of each of these things but not a concept of how all these things come together to perform an attack. Fast forward, I talked to @Devon who recommended that I perform a simulated attack with Powershell Empire and to hunt for it.
First, I set up a small Windows domain which is the network used in this post. Next, I performed an APT style attack following the phases of the attack lifecycle with Powershell Empire on the network. For the first time in my life, the words Mimikatz and privilege escalation were not just buzzwords. I came to an understanding of how an attacker uses these tools + techniques to accomplish their mission. Before I started this blog post series I had been helping the same professor do a re-design of the Windows DFIR class and I was reading the Incident Response & Computer Forensics book. This book is a GOLD MINE of DFIR knowledge for Windows. When I combined my DFIR knowledge with the understanding of how attacks are conducted, a HUGE light bulb went on for me on how to hunt. I knew how to apply my knowledge of how attackers operate and my DFIR knowledge to hunt for that activity.
Now, when I teach threat hunting, I always start with doing a 40 minute interactive session on the attack lifecycle. Basically, I write the attack lifecycle on a whiteboard and I take 10 mins to explain all the phases. Next, I turn to my peers and say: “y’all have been hypothetically hired to steal credit cards from XYZ“. Next, I walk them through the attack lifecycle having THEM build a hypothetical attack on the whiteboard. For example, I say: “Okay, if you want to do an initial recon on fake company XYZ what would you do?” They would typically say LinkedIn, Facebook, Github, NMAP scans, and etc. I do this because most of the time novices to threat hunting and infosec have never seen an attack from start to finish. Again, we discuss things like Mimikatz but not just from a functionality standpoint but how it “fits” into an attack. Next, I flip the script on them and say: “How would y’all detect your hypothetical attack?“. Unfortunately, most students had been taught to detect bad things but not how to stop and interpret what they found.
For example, typically (but not in all cases), if a defender detects an attacker using Mimikatz it usually indicates these three things: One, the attacker has gained a foothold within the network. Two, the attacker was able to escalate privileges to run Mimikatz (which means they have reached the privilege escalation phase of the attack lifecycle). Three, most likely they are using Mimikatz to obtain credentials in an attempt to move laterally in the environment. At this point the detection of Mimikatz can give you an idea of where the attacker is in the lifecycle and what they might do next. Again, this isn’t always true but I am trying to paint a picture.
Once students have a general concept of the attack lifecycle and what an attack looks like, we perform the simulated attack (linked above). The purpose of this is to allow students to experience an attack from the attacker’s perspective. Again, I do this because most students have never performed any red teaming from start to finish. But also for them to grasp an understanding of the capabilities and limitations of being an attacker. Giving a bit more background, I learned real quick that trying to teach other college students about defense isn’t sexy. I personally LOVE LOGGING and I would happily listen to a talk on logging for an hour but 99% of people would not. I found that teaching from the red team perspective first is more attention grabbing. Once I have performed all the red team stuff discussed above, I started talking about DFIR concepts.
Again, in my experience, most students didn’t want to learn Windows DFIR concepts/skills which are essential to hunting. I agree with students that reading about the AmCache is boring by itself but when you can apply that knowledge to a simulated attack it makes ALL the difference. So next I would say: “Now we will hunt our own simulated attack using Windows DFIR artifacts” and people are exponentially more interested. I would subtly teach them Windows forensics, something that is crucial to understand to perform hunting, but boring to learn. The hard part with threat hunting is you have to walk before you can run. Most people don’t want to walk because that is the boring content. But I promise you once you understand the basics really, really, really, really well, then you can run and you can run far. I hope this blog helps.
Choose your own SIEM adventure
This blog post will provide instructions on how to set up the Elastic stack as the SIEM of choice. However, this blog post series and the data generated from the red team exercise is compatible with the Elastic stack, Graylog, or Splunk. If you would like to use a different SIEM, you are encouraged to do so. The instructions to set up these SIEMs using Docker, Ansible, or a manual installation can be found here:
- IR Tales: The Quest for the Holy SIEM: Splunk + Sysmon + Osquery + Zeek
- IR Tales: The Quest for the Holy SIEM: Graylog + AuditD + Osquery
- IR Tales: The Quest for the Holy SIEM: Elastic stack + Sysmon + Osquery
Network diagram
docker-compose up -d – -no-wait
If you are not interested in setting up a Windows domain, deploying Osquery + FleetDM, and a SIEM of your choice, then continue reading. If you would like to setup the network in the diagram above please skip ahead to the following sections: “Install/Setup threat hunting environment with Ansible” or “Manual install/setup of threat hunting environment”. The instructions in this section are going to be setting up the Elastic stack version 7.10 using Docker and importing the logs from the red team exercise.
Spin up Elastic stack with Docker
git clone https://github.com/CptOfEvilMinions/ChooseYourSIEMAdventure
cd ChooseYourSIEMAdventure
- IR Tales: The Quest for the Holy SIEM: Elastic stack + Sysmon + Osquery – See this blog post for more information on how to modify setting up the Elastic stack such as setting up a different password. For this blog post we are going to accept the default username of
elastic
and password ofChangeme123!
.
- IR Tales: The Quest for the Holy SIEM: Elastic stack + Sysmon + Osquery – See this blog post for more information on how to modify setting up the Elastic stack such as setting up a different password. For this blog post we are going to accept the default username of
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout conf/tls/docker.key -out conf/tls/docker.crt
- Generate TLS public certificate and private key
docker-compose -f docker-compose-elastic.yml build
- Build Docker contains
docker-compose -f docker-compose-elastic.yml up -d
- Spin up the Elastic stack
Import logs from red team exercise
git clone https://github.com/CptOfEvilMinions/ThreatWaffle
cd ThreatWaffle/json_logs
unzip bg-logs.zip
- UNzip logs
cd ../../ChooseYourSIEMAdventure/siem_log_importer
virtualenv -p python3 venv
- Create Python virtual environment
source venv/bin/activate
- Active the Python virtual environment
pip3 install -r requirements.txt
- Install the required dependencies
python3 log_ingestor.py --platform=elasticsearch --server_host=<Elastic stack server IP addr> --server_port=<Elasticsearch port - default 9200> --index bg-sysmon --siem_username=elastic --siem_password=Changeme123! --log_file ../../ThreatWaffle/json_logs/bg-sysmon.json
- Import Sysmon logs into Elastic
python3 log_ingestor.py --platform=elasticsearch --server_host=10.150.100.210 --server_port=9200 --index bg-sysmon --siem_username=elastic --siem_password=Changeme123! --log_file ../../ThreatWaffle/json_logs/bg-sysmon.json
- Import Windows Event Logs into Elastic
Install/Setup threat hunting environment with Ansible
Step 0: Install Ansible on macOS
pip3 install pywinrm
pip3 install ansible
Step 1: Create VMs
Based on the table provided (screenshot below), create VMs using the following operating systems and versions listed. The Windows 10 VMs HAVE TO BE version 1511 because some of the red team techniques require an older version that is vulnerable. The following sections will provide instructions to set up each of these VMs with Ansible or with manual instructions.
Requirements
- Hardware/hypervisor with the following resources:
- CPU: Quad-core
- Ram: 16GBs
- HDD: 160GBs
- Some Ansible experience
- Some Linux experience
- Some Windows Group policy and server system administration experience
- ISOs
Step 2: Install/Setup Elastic stack v7.10 on Ubuntu 20.04
The instructions to run this Ansible playbook are copied from this blog post: IR TALES: THE QUEST FOR THE HOLY SIEM: ELASTIC STACK + SYSMON + OSQUERY
Setup playbook
git clone https://github.com/CptOfEvilMinions/ChooseYourSIEMAdventure
cd ChooseYourSIEMAdventure
openssl req -x509 -new -nodes -keyout conf/tls/tls.key -out conf/tls/tls.crt
- Generate TLS public certificate and private key
vim hosts.ini
add IP address of Elastic server under[elastic]
vim group_vars/all.yml
and set:base_domain
– Set the domain where the server residestimezone
– OPTIONAL – The default timezone is UTC+0siem_username
– Ignore this settingsiem_password
– Ignore this setting
vim group_vars/elastic.yml
and set:hostname
– Set the desired hostname for the serverelastic_repo_version
– Change the repo version to install the Elastic stack – best to leave as defaultelastic_version
– Set the version of the Elastic stack to install
- Save and exit
Run playbook
ansible-playbook -i hosts.ini deploy_elastic.yml -u <username> -K
- Monitor the Ansible output to record the username and passwords generated
- A temporary file containing the credentials is stored at
/tmp/elasticsearch-setup-passwords.txt
, which will be deleted on reboot
- A temporary file containing the credentials is stored at
- Skip ahead to “Setup Elastic via WebGUI” section to complete the setup
Step 3: Install/Setup FleetDM v3.9.0 on Ubuntu 20.04
The instructions to run this Ansible playbook are copied from this blog post: GETTING STARTED WITH FLEETDM V3.6.0
Setup playbook
git clone https://github.com/CptOfEvilMinions/FleetDM-Automation
cd FleetDM-Automation
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout conf/tls/fleet.key -out conf/tls/fleet.crt
- Generate TLS private key and public certificate
vim hosts.ini
and add IP address under[fleetdm]
vim group_vars/all.yml
and set:base_domain
– The domain for your network and the base domain of the FQDNtimezone
– OPTIONAL – Change the default timezone of UTC +0
openssl rand -base64 32
- Copy the output from the command
vim group_vars/fleetdm.yml
and set:fleetdm_jwt
– Set this to the random string generated by the OpenSSL commandmysql_root_password
– Set the root password for MySQLmysql_fleetdm_password
– Set the password for FleetDM MySQL user
Run playbook
ansible-playbook -i hosts.ini deploy_fleetdm.yml -u <user> -K
- Enter the password for the user
- Skip ahead to “Setup FleetDM via WebGUI” section to complete the setup
Step 4: Enable WinRM on Windows hosts
- On each Windows host login as Administrator
- Start Powershell as Administrator
powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1'))"
- Enable WinRM
Step 5: Deploy Windows Server 2016 domain controller
Setup Ansible playbook
git clone https://github.com/CptOfEvilMinions/ThreatWaffle
cd ThreatWaffle
vim group_vars/all.yml
and set:base_domain
– Set to the domain for the environmenttimezone
– Set the default timezone to use – default it UTC +0
cp group_vars/windows.yml.example group_vars/windows.yml
vim group_vars/windows.yml
and set:ansible_user
– Username to use to login into machines with WinRMansible_password
– Password to use to login into machines with WinRMwin_dc_hostname
– Set the hostname for the domain controllerad_safe_mode_password
– Set AD safe mode passworddomain_users_password
– Set domain administrator password
vim hosts.ini
and append IP address of Windows domain controller under[win_domain_controler]
- Append IP address of Elastic server under
[elastic]
- Append IP address of FleetDM server under
[fleetdm]
- Append IP address of Elastic server under
Run playbook
ansible-playbook -i hosts.ini deploy_windows_domain_controler.yml
Step 7: Deploy Windows clients
Set hostnames
- Login into each Windows 10 client
- Set the hostname of one machine to
saturn
and the other tojupiter
- Reboot both machines
Get FleetDM API token
export FLEETDM_TOKEN=$(curl -s -k -X POST https://fleetdm.hackinglab.beer/api/v1/kolide/login -d '{"Username": "<admin username>", "Password": "<password>"}' | jq -r '.token')
- Request an API token and save token to an environment variable
Setup playbook
vim group_vars/windows.yml
and set:ansible_user
– Change this value if the username for the Windows 10 machines is different than for the serveransible_password
– Change this value if the password for the Windows 10 machines is different than for the server
vim group_vars/sec_tools.yml
and set:osquery_version
– Set the version of Osquery to installfleetdm_host
– Set the FQDN of the FleetDM server – defaultfleetdm.<base_domain>
fleetdm_port
– Set the port the FleetDM + NGINX are listening on – default 443sysmon_version
– Set the version of Sysmon to installwinlogbeat_version
– Set the version of Winlogbeat to installlogstash_ip_addr
– Set this to the FQDN or IP address of the Elastic stack serverlogstash_port
– Set the port Logstash is ingesting logs – default 5044
vim conf/win_clients/sysmon/sysmonconfig.xml
edit the Symon config to your liking- The config in the repo was pulled from SwiftOn Security’s repo
vim hosts.ini
and add the IP addresses of the Windows 10 clients under[win_clients]
Run playbook
ansible-playbook -i hosts.ini deploy_windows_clients.yml
Manual install/setup of threat hunting environment
Step 1: Create VMs
Based on the table provided (screenshot below) create VMs using the following operating systems and versions listed. The Windows 10 VMs HAVE TO BE version 1511 because some of the red team techniques require an older version that is vulnerable. The following sections will provide instructions to set up each of these VMs with Ansible or with manual instructions.
Requirements
- Hardware/hypervisor with the following resources:
- CPU: Quad-core
- Ram: 16GBs
- HDD: 160GBs
- Some Ansible experience
- Some Linux experience
- Some Windows Group policy and server system administration experience
- ISOs
Step 2: Enable WinRM on Windows hosts
- On each Windows host login as Administrator
- Start Powershell as Administrator
powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1'))"
- Enable WinRM
Step 3: Install/Setup Elastic stack on Ubuntu 20.04
In order to keep this blog post short, I will not be including the manual instructions to setup the Elastic stack. If you would like manual instructions please go to my blog post: IR TALES: THE QUEST FOR THE HOLY SIEM: ELASTIC STACK + SYSMON + OSQUERY
Step 4: Install/Setup Fleet v3.9.0 on Ubuntu 20.04
In order to keep this blog post short, I will not be including the manual instructions to setup FleetDM. If you would like manual instructions please go to my blog post: GETTING STARTED WITH FLEETDM V3.6.0
Step 5: Install/Setup Windows Server 2016 domain controller
Install/setup Active Directory
- Open Powershell as Administrator
Rename-Compuer -NewName "windc"
- Set hostname of the domain controller
Restart-Computer
- Open Server Manager
- Select Manage > Add roles and features
- Installation type
- Select “Role-based or feature-based installation”
- Server selection
- Ensure the “windc” server is selected
- Server Roles
- Check “Active Directory Domain Services”
- Check “DNS Server”
- Leave the rest of the menus as default and select “Install”
- Exit the installation menu
- In the Server Manager window select the the flag icon with a yellow caution sign
- Select “Promote this server to a domain controller”
- Deployment configuration
- Select “Add a new forest” for deployment operation
- Enter “<domain>” into root domain name
- I am going to use the following domain:
hackinglab.beer
- I am going to use the following domain:
- Domain controller options
- Leave all settings as default
- Enter a password for DSRM
- For Additional options, Paths, Review options, Prereq checks
- Leave settings as default
- Select “Install”
Setup DNS server
- Login into domain controller
- Open Powershell as Administrator
Set-DnsClientServerAddress -InterfaceAlias * -ServerAddresses 127.0.0.1
- Set the default DNS server to itself
Create a DNS reverse zone
- Open Server Manager
- Select “Tools” then “DNS”
- Expand WinDC > Reverse Lookup Zone
- Right-Click “Reverse Lookup Zone” and select “New zone”
- Select “Primary zone” for the type of zone
- Select “To all DNS servers running on domain controllers in domain” for data replication
- Select “IPv4 reverse lookup zone” for the type of reverse zone
- Enter “<Local network ID>” for the Network ID in reverse
- Select “Allow only secure dynamic updates” for dynamic updates
- Select “Finish”
Add DNS A records
- Expand WinDC > Forward Lookup Zone >
hackinglab.beer
- Select “Action” then “New Host(A)”
- Enter
elastic
for Name - Enter
<IP addr of Elastic stack server>
for IP address - Check “Create associated pointer (PTR) record”, if UNchecked
- Select “Add host”
- Enter
- Repeat for “fleetdm”
Configure Group Policy
Enable RDP through the firewall
- Select “Tools” then “Group policy manager”
- Expand Group policy manager > Forest:
hackinglab.beer
> Domains >hackinglab.beer
- Right-click “Default Domain Policy”
- Expand Computer Configuration > Policies > Administrative Templates > Network > Network Connections > Windows Firewall > Domain Profile
- Enable “Allow inbound Remote Desktop exceptions” and enter
*
for IP addresses
- Enable “Allow inbound Remote Desktop exceptions” and enter
Enable SMB access for PSexec via firewall
- Expand Computer Configuration > Policies > Windows Settings > Security Settings > Windows Firewall with Advanced Security > Windows Firewall with Advanced Security LDAP
- Right-click “Inbound Rules” and select “New Rule”
- Rule type
- Select “Predefined” for type
- Select “File and Printer sharing”
- Predefined rules
- Accept defaults
- Action
- Select “Allow the connection”
- Rule type
Enable Powershell script block logging
- Expand Computer Configuration > Policies > Administrative Templates -> Windows Components -> Windows PowerShell
- Enable “Turn on PowerShell Script Block Logging”
Enable Process creation logging
- Computer Configuration > Windows Settings > Security Settings > Advanced Audit Policy Configuration > Audit Policies > Detailed Tracking
- Enable for successful “Audit Process Creation”
Create domain users (non-admin)
- Open server manager
- Select “Tools” then “Active Directory Users and Computers”
- Expand
hackinglab.beer
> Users - Select “Users” on the left
- Select “Action” then “New User”
- User info
- Enter
Bob
for First name - Enter
Gates
for the Last Name - Enter
Bgates
for logon
- Enter
- Password
- Enter a password for the user
- Uncheck “User must change password at next logon”
- User info
- Repeat this process for Sheldon Jobs with the username of “sjobs”
Step 6: Install/Setup Windows 10 clients
Initial setup
- Install trial of Office 365 – This is required for the red team exercise
Join Windows clients to the domain
- Open Powershell as Administrator
- Get the IP address of the Windows domain controller
Set-DnsClientServerAddress -InterfaceAlias * -ServerAddresses <Windows domain controller IP address>
Add-Computer -Domainname <domain> -Credential AD\Administrator -Restart –Force
- Enter password for domain admin
Install/Setup Osquery v4.8.0
- Open Powershell as Administrator
cd $ENV:TEMP
- Cd to user’s temp directory
Invoke-WebRequest -Uri https://pkg.osquery.io/windows/osquery-4.8.0.msi -OutFile osquery-4.8.0.msi -MaximumRedirection 3
- Download Osquery
Start-Process $ENV:TEMP\osquery-4.8.0.msi -ArgumentList '/quiet' -Wait
- Install Osquery
- Open a web browser and login into FleetDM
- Click “Add new host” in the top right
- Copy the enroll secret
Set-Content -Path 'C:\Program Files\osquery\osquery.key' -Value '<Osquery enroll key>'
- Write Osquery key to a file
Invoke-WebRequest -Uri https://raw.githubusercontent.com/CptOfEvilMinions/ThreatWaffle/main/conf/win_clients/osquery/osquery.flags -OutFile 'C:\Program Files\osquery\osquery.flags'
- Download Osquery.flags config
(Get-Content -Path 'C:\Program Files\osquery\osquery.flags' -Raw) -replace "{{ fleetdm_host }}","<FleetDM FQDN or IP addr>" | Set-Content -Path 'C:\Program Files\osquery\osquery.flags'
(Get-Content -Path 'C:\Program Files\osquery\osquery.flags' -Raw) -replace "{{ fleetdm_port }}","<FleetDM port - default 443>" | Set-Content -Path 'C:\Program Files\osquery\osquery.flags'
- Set FleetDM address and port
Restart-Service osqueryd
Install/Setup Sysmon v.13.10
- Open Powershell as Administrator
cd $ENV:TMP
$ProgressPreference = 'SilentlyContinue'
- Disable download status bar
Invoke-WebRequest -Uri https://download.sysinternals.com/files/Sysmon.zip -OutFile Sysmon.zip
- Download Sysmon
Expand-Archive .\Sysmon.zip -DestinationPath .
- Unzip Sysmon
Invoke-WebRequest -Uri https://raw.githubusercontent.com/olafhartong/sysmon-modular/master/sysmonconfig.xml -OutFile sysmonconfig.xml
- Download Sysmon config
.\Sysmon.exe -accepteula -i .\sysmonconfig.xml
- Install Sysmon driver and load Sysmon config
Install/Setup Winlogbeat
cd $ENV:TEMP
Invoke-WebRequest -Uri https://artifacts.elastic.co/downloads/beats/winlogbeat/winlogbeat-7.10.0-windows-x86_64.zip -OutFile winlogbeat-7.10.0-windows-x86_64.zip
- Download Winlogbeat
Expand-Archive .\winlogbeat-7.10.0-windows-x86_64.zip -DestinationPath .
- Unzip Winogbeat
mv .\winlogbeat-7.10.0-windows-x86_64 'C:\Program Files\winlogbeat'
- Move Winlogbeat to the Program Files directory
cd 'C:\Program Files\winlogbeat\'
- Change to the Program Files directory
Invoke-WebRequest -Uri https://raw.githubusercontent.com/CptOfEvilMinions/ThreatWaffle/main/conf/win_clients/winlogbeat/winlogbeat.yml -OutFile winlogbeat.yml
- Download Winglogbeat config
- Using your favorite text editor open
C:\Program Files\winlogbeat\winlogbeat.yml
- Open the document from the command line with Visual Studio Code:
code .\winlogbeat.yml
- Open the document from the command line with Notepad:
notepad.exe.\winlogbeat.yml
- Open the document from the command line with Visual Studio Code:
- Scroll down to the
output.logstash
:- Replace
logstash_ip_addr
with the IP address of FQDN of Logstash - Replace
logstash_port
with the port Logstash uses to ingest Beats (default 5044)
- Replace
powershell -Exec bypass -File .\install-service-winlogbeat.ps1
Set-Service -Name "winlogbeat" -StartupType automatic
Start-Service -Name "winlogbeat"
Get-Service -Name "winlogbeat"
Setup Elastic via WebGUI
Login into Elastic WebGUI
- Open a browser to
https://<IP addr or FQDN of Elastic>:443
and login- Username:
elastic
- Password:
<output for the Elastic user during setup>
- Select “Log in”
- Username:
Setup Sysmon index on Elastic
- Settings > Data > Index management
- Ensure that a Sysmon indices has been created like below
- Settings > Kibana > Index patterns
- Select “Create index pattern”
- Define an index pattern
- Enter
sysmon-*
int index pattern name
- Enter
- Configure settings
- Select “@timestamp” for timefield
- Select “Create index pattern”
- Define an index pattern
- Settings > Kibana > Discover
Setup FleetDM via WebGUI
- Open a web browser to FleetDM
- Setup user
- Enter a
<username>
into Username - Enter a
<password>
into Password - Enter an
<e-mail>
for the admin user - Select “Next”
- Enter a
- Organization details
- Enter organization name
- Enter the organization URL
- Select “Next”
- Set Fleet URL
- Accept the default Fleet URL, unless you need to change it
- Select “Submit”
- Select “Finish”
Test Osquery agents with a live query
- Select “Hosts” in the top right
- Select one of the Osquery agents from the list
- Select “Query” in the top right
- Enter the following query:
SELECT * FROM osquery_info
into SQL - Select “Run” in the bottom right
Future road map
In this blog post, we created a lab environment to perform red team activities for us to hunt. This environment is predominantly Windows machines with Windows clients Jupiter and Saturn as our primary targets. The Windows domain controller (WinDC) provides central authentication and Group Policy management for our Windows clients. In addition to our Windows machines we also have our Ubuntu servers running FleetDM which our Osquery agents are reporting too and the Elastic stack which Sysmon + Winlogbeat are reporting too. Using this environment we will focus on understanding the attack mindset, how to interpret actions performed by an adversary from a defenders perspective, and how to transition findings from your hunts into future detections or environmental improvements.
In the next blog post, I am going to introduce the attacker mindset with the Mandiant Attack Lifecycle. To do this I am going to utilize Powershell Empire to simulate an APT style attack to generate artifacts for us to hunt in the blog posts to follow.
In the third blog post we will see that Sysmon is monitoring the Windows clients in real time and reporting the activity to the Elastic stack. The Elastic stack will then be used to step through the phases of the attack life cycle hunting the malicious adversary activity in each phase. The goal will be to demonstrate common tools and techniques used by adversaries and how to hunt for artifacts generated by that activity using Elastic.
In the fourth blog post we will introduce the Endgame threat hunting process using the MITRE ATT&CK matrix. This will be done utilizing FleetDM as our fleet manager for Osquery agents, this provides the ability to run scheduled queries on a specified interval or ad-hoc queries to ask our environment a question. We will create threat hunting hypotheses and use FleetDM + Osquery to confirm or deny our hypothesis, aka the existence or absence of malicious activity in our environment. Lastly, we will collect and review our findings from the threat hunt exercises to create detections and/or recommend environment improvements.
DISCLAIMERS
The information contained in this blog post is for educational purposes ONLY! HoldMyBeerSecurity.com/HoldMyBeer.xyz and its authors DO NOT hold any responsibility for any misuse or damage of the information provided in blog posts, discussions, activities, or exercises.
The red team exercise performed in this blog post occurred in a home lab network. Therefore, the malicious activity performed was on machines that I own and have permission to perform these actions.
To prevent the weaponization of the content within this blog post there will be missing commands/instructions. The red team exercise is meant to simulate what an attacker may do on a network, NOT a step-by-step.
DISCLAIMERS
Lessons learned
I am currently reading a book called “Cracking the Coding Interview” and it is a great book. One interesting part of the book is their matrix to describe projects you worked on and the matrix contains the following sections which are: challenges, mistakes/failures, enjoyed, leadership, conflicts, and what would you do differently. I am going to try and use this model at the end of my blog posts to summarize and reflect on the things I learn. I don’t blog to post things that I know, I blog to learn new things and to share the knowledge of my security research.
New skills/knowledge
- How to configure Group Policy with Powershell
- Use the new version of Ansible v2.9
- Use the new version of FleetDM v3.9.0
- Using Sysmon v13.10
- Using the Python Elasticsearch library to import logs into Elasticsearch
- Using the Python Beats library to send logs to Logstash for ingestion
- How to setup a Windows domain
- How to setup a Windows domain that allows lateral movement
- How to interact/enable Windows Event Logs – process creation
Challenges
- Automate modifying the Group Policy with Ansible
- How to scale this workshop for DEFCON, especially as a remote workshop
Enjoyed
- Went to DEFCON for my first time even though it was virtual due to COVID
- My first security workshop – DEFCON
- Interacting with the community after my DEFCON workshop on Twitter
References
- Github: ThreatWaffle
- Managing Windows machines with Ansible
- Greater Visibility Through PowerShell Logging
- Kolide fleet documentation
- Enable Remote Desktop using Group Policy
- Powershell script block logging via Group Policy
- Process creation logging via Group Policy
- Allow PSexec on domain via Group Policy
- Change the computer name
- Ubuntu 20.04.1 LTS (Focal Fossa) ISO images
- Windows Server products & resources
- GETTING STARTED WITH FLEETDM V3.6.0
- POC: USING KSQL TO ENRICH ZEEK LOGS WITH OSQUERY AND SYSMON DATA
- IR TALES: THE QUEST FOR THE HOLY SIEM: ELASTIC STACK + SYSMON + OSQUERY
- Github: ThreatWaffle
- Managing Windows machines with Ansible
- Greater Visibility Through PowerShell Logging
- Kolide fleet documentation
- Enable Remote Desktop using Group Policy
- Powershell script block logging via Group Policy
- Process creation logging via Group Policy
- Allow PSexec on domain via Group Policy
Hi.
I am trying to follow your steps to deploy the osquery on Windows 10 and to enroll them to Kolide, however I do not understand what you mean in Deploy OSQuery agents -> Initial Setup -> Step 4 -> vim group_vars/agents -> set osquery_enroll_secret with string from Kolide.
Where is this group_vars? It is really confusing this Deployment steps, could you please clarify?
Thanks.
The directions have been updated to include:
4. mv group_vars/agents.example group_vars/agents
5. vim group_vars/agents
I have difficulty understanding the lingo here.
mv group_vars/all.example group_vars/all
mv group_vars/win_agents.example group_vars/win_agents
vim group_vars/win_agents
mv ==> move
group_vars/all.example ==> [folder/file.example] ==> group_vars/all [folder] ?
Do i make a file name group_vars with a file name all.example?
What is vim an editor. Do i create a file in folder groups_vars name
win_agents? My understanding of linux goes off the rails here. Can you please
provide some explanation. I would like to try your method in my personal lab.
Hey ralph23,
The move(mv) command within Linux can be used to move files OR rename files, like done above. The files within the current group_vars directory end with a “.example” extension. But Ansible is looking for a file called “group_vars/all”, which does not contain the extension. Continue reading if you want to know why I do this :).
Files within the “group_vars” directory may contain sensitive information. To avoid pushing code with potentially sensitive information, I make a copy of each group_var file and call it .example with fake/blank values. Next, I add “group_vars” files WITHOUT the “.example” extension to my “.gitignore” file. This ensures I don’t accidentally push code to Github with sensitive values such as a Slack token.
Happy Hunting!