📘
CAS Cybersecurity
  • Start
  • Reconnaissance
    • Opensource Intelligence
  • Docker basics and Images
    • Damn Vulnerable Webapp
    • bWAPP
    • Juice Webshop
    • Webgoat
    • Metasploitable 2
    • Metasploitable 3
    • MISP Docker (old)
    • MISP Docker (new)
  • Scanning and Enumeration
    • Scanning with zenmap
    • Scanning with nmap
    • Scanning with msf auxiliary
  • Vulnerability Scanning and Analysis
    • OpenVAS
    • nmap vulnerability scan
    • MSF Auxiliary Modules
  • Exploitation
    • Metasploitable 2
    • Redis Server
    • Print Nightmare
    • Baron Samedit
    • Polkit
    • Heartbleed
  • Man in the Middle
    • ARP Cache poisoning
    • RDP MitM Exercise
  • Windows Hacking
    • Throwback Network
      • Entering the breach
      • Exploring the caverns
      • Webshells and you!
      • First Contact
    • WinAttack LAB
      • Module 01
      • Module 02
      • Module 03
      • Module 04
      • Module 05
      • Module 06
      • Module 07
      • Module 08
      • Module 09
      • Module 10
  • Web Application Security
    • Burp Proxy Introduction
    • DVWA
      • DVWA Exercises 1
      • DVWA Exercises 2
      • DVWA Exercises 3
      • DVWA Exercises 4
      • DVWA Exercises 5
      • DVWA Exercises 6
      • DVWA Exercises 7
      • DVWA Exercises 8
  • CTF and Crypto Exercises
    • Cyberchef Challenge
    • HTB Invite Challenge
    • BSides London 2019 Challenge
    • Ninja Sec Challenge
  • Threat Intelligence
    • MISP Exercise 1
    • MISP Exercise 2
    • MISP Exercise 3
    • MISP Exercise 4
    • MISP Exercise 5
    • MISP Exercise 6
    • MISP Exercise 7
    • MISP Exercise 8
    • Virus Total Graph Exercise
    • RFI Incoming!
  • Forensic Exercises
    • Disk Forensics
      • The Sleuth Kit Intro
      • Filecarving with Foremost
      • Filecarving with scalpel
      • Bulk extractor
      • Disk acquisition with dd
      • Disk acquisition with dcfldd
      • Disk acquisition with ewftools
      • Disk acquisition with FTK Imager
      • Mount disk image (raw)
      • Unknown USB Stick
      • USB Stick Filecarving
      • Autopsy Exercise
    • Windows Forensics
      • Bitunlocker
      • Alternate Datastreams
    • Memory Forensics
      • Volatility2 Basics (Linux)
      • Volatility2 Exercise 1
      • Volatility3 Exercise 1
      • Volatility3 Exercise 2
      • Volatility3 Exercise 3
    • Image Forensics
      • Unswirl Image
      • Manual Filecarving 1
      • Manual Filecarving 2
    • Browser Forensics
    • Mail Header Analysis
    • Timestomping Exercise
    • Network Forensics
      • Tshark Exercise
  • Malware Analysis
    • Ransomware
      • General Introduction
      • Ryuk
      • RansomEXX
      • REvil
      • BlackMatter
      • Hades
      • Egregor
      • DoppelPaymer
    • YARA
      • YARA Install
      • yarGen
      • YARA with Cyberchef
      • TCP dump analysis
      • Memory dump analysis
    • Dosfuscated Scripts
  • Android Malware
    • LAB Setup 1
    • LAB Setup 2
    • Android Manifest
    • Android Permissions
    • APP Tracing with Frida
    • AES Key decryption
    • RedAlert
    • BlackRoseLucy
    • Crackme RE Challenge
  • Forensic Readiness
    • Windows Event Logs
    • Windows Sysmon
    • Sysmon: Capture Clipboard
    • Sysmon: Process Injection
    • Ransomware Detection
      • Signature based
  • Live Response
    • Velociraptor P1
    • Velociraptor P2
    • Velociraptor P3
    • Windows Response LAB
      • Lateral Movement Detection
      • Detect persistence
      • Volatility Analysis
Powered by GitBook
On this page
  • 1. Introduction
  • 2. Locate the infected process
  • 3. Investigate the infected process
  • 4. Stop the infected process
  • 5. Configure Sysmon
  • 6. Find second infected process
  • 7. Security Questions
  • Answers

Was this helpful?

  1. Forensic Readiness

Sysmon: Process Injection

PreviousSysmon: Capture ClipboardNextRansomware Detection

Last updated 3 years ago

Was this helpful?

1. Introduction

There is a cat infestation problem in the Contoso.Azure domain. The senior feline control specialist in Contoso reported that process injection is used to download cat pictures. He suggested using Sysmon to track it down. Let's delve into the event log and track down the latest offender.

2. Locate the infected process

In this case, it is Event ID 11: FileCreate.

We can use the -FilterHashtable parameter to filter out all FileCreate events @{logname='Microsoft-Windows-Sysmon/Operational'; id=11}.

Since this query will give us all file creation events across the system, it will likely be too verbose. We can pipe the previous command to filter down the event log messages based on file path and type: | ?{ if ($.Message -like 'TargetFilename: C:\Users\Administrator\Desktop*.jpg') { $ }}

Run the following command in powershell:

(((Get-WinEvent -LogName Microsoft-Windows-Sysmon/Operational -FilterXPath '*/*/EventID=11') | Where-Object { If ($PSItem.Message -Like '*TargetFilename: C:\users\ContosoAdmin\Desktop\*.jpg*') { $PSItem }})[0].message | Select-String -Pattern 'Image: (.*)').matches.groups.value[1]

Powershell output:

3. Investigate the infected process

Check process ID of spoolsv.exe

Once you have identified the process writing the files, you can determine that this behavior is abnormal. In the hopes of understanding this anomaly, you will need to gather more information. To query all events that Sysmon recorded for this process, you can use the following command:

Get-WinEvent -LogName Microsoft-Windows-Sysmon/Operational -FilterXPath ('*/*/Data[@Name="ProcessId"]="1148"') | sort -Property id -Unique | ft -Wrap

This queries the Sysmon log file using the Get-WinEvent cmdlet and filters out all log events where the key is equal to process ID 1148 that we are looking for. To reduce the output, you can sort the results by unique event ID and then wrap the output, so that PowerShell shows the entire line.

From the list of Sysmon event IDs 3 and 11, you can determine that the suspicious process spent most of its time making network connections to a specific host and writing files to disk. Let's find all files the process created.

(Get-WinEvent -LogName Microsoft-Windows-Sysmon/Operational -FilterXPath ('*/*/Data[@Name="ProcessId"]="7228"')).Message | findstr 'TargetFilename'

Let's also check the powershell log for the identified process id 1148

(Get-WinEvent -LogName Microsoft-Windows-PowerShell/Operational -FilterXPath '*[System[Execution[@ProcessID="1148"]]]').Message

4. Stop the infected process

tasklist /svc
Stop-Service -Name Spooler

5. Configure Sysmon

You stopped the hording for the moment. Now, you need to install a more extensive Sysmon template to track down the source.

The senior specialist mentioned that he put together a new Sysmon template based on an open source from SwiftOnSecurity.

6. Find second infected process

For a process to run a PowerShell script, it would have to use System.Management.Automation.dll to communicate with the .NET framework. In theory, any binary could host the System.Management.Automation.dll to execute PowerShell, but very few do. Find processes (other than powershell.exe) that have loaded System.Management.Automation to narrow down the potentially infected processes.

((Get-Process | Where-Object {$PSItem.ProcessName -ne "powershell"}) | ForEach-Object { If (($PSItem.Modules.ModuleName | Select-String -Pattern "System.Management.Automation*") | Tee-Object -Variable a ) {$PSItem.ProcessName; $a ; $infectedProcessId=$_.Id}})[0]

7. Security Questions

  1. What are the two most common Sysmon event IDs created by the infected process?

  2. What was the ParentImage: of the infected process?

  3. What is the file extension for the file type other than .jpg that the infected process writes to the disk?

  4. What is the event ID of the "IPC listening thread on process" event in the Microsoft-Windows-PowerShell/Operational log?

Answers

  1. Event ID 11 and 3

  2. Services.exe

  3. ps1 fileextension

  4. 53504

As Sysmon is set up, we can query the Windows event log using the PowerShell Get-WinEvent cmdlet. To figure out what we need to filter for, we can use the to find the event ID that we are interested in.

Here we can see that PowerShell starts an IPC listening thread from the given process PID 1148. This also indicates that the given process is executing PowerShell. To confirm your suspicion, see if the process is using System.Management.Automation.dll. For a process to run a PowerShell script, it would have to load System.Management.Automation.dll to communicate with the .NET framework. In theory, any binary could host the System.Management.Automation.dll to execute PowerShell, but very few actually do. You can use to confirm this.

Sysmon page
Process Explorer
Partent Process of Spooler SubSystem App
Event ID for IPC listening thread