Detection: PowerShell WebRequest Using Memory Stream

Description

The following analytic detects the use of .NET classes in PowerShell to download a URL payload directly into memory, a common fileless malware staging technique. It leverages PowerShell Script Block Logging (EventCode=4104) to identify suspicious PowerShell commands involving system.net.webclient, system.net.webrequest, and IO.MemoryStream. This activity is significant as it indicates potential fileless malware execution, which is harder to detect and can bypass traditional file-based defenses. If confirmed malicious, this technique could allow attackers to execute code in memory, evade detection, and maintain persistence in the environment.

1`powershell` EventCode=4104  ScriptBlockText IN ("*system.net.webclient*","*system.net.webrequest*") AND ScriptBlockText="*IO.MemoryStream*" 
2| eval Path = case(isnotnull(Path),Path,true(),"unknown") 
3| stats count min(_time) as firstTime max(_time) as lastTime list(ScriptBlockText) as command values(Path) as file_name values(UserID) as user by ActivityID, Computer, EventCode 
4| rename Computer as dest, EventCode as signature_id 
5| `security_content_ctime(firstTime)` 
6| `security_content_ctime(lastTime)` 
7| `powershell_webrequest_using_memory_stream_filter`

Data Source

Name Platform Sourcetype Source
Powershell Script Block Logging 4104 Windows icon Windows 'xmlwineventlog' 'XmlWinEventLog:Microsoft-Windows-PowerShell/Operational'

Macros Used

Name Value
powershell (source=WinEventLog:Microsoft-Windows-PowerShell/Operational OR source="XmlWinEventLog:Microsoft-Windows-PowerShell/Operational")
powershell_webrequest_using_memory_stream_filter search *
powershell_webrequest_using_memory_stream_filter is an empty macro by default. It allows the user to filter out any results (false positives) without editing the SPL.

Annotations

- MITRE ATT&CK
+ Kill Chain Phases
+ NIST
+ CIS
- Threat Actors
ID Technique Tactic
T1059.001 PowerShell Execution
T1105 Ingress Tool Transfer Command And Control
T1027.011 Fileless Storage Defense Evasion
KillChainPhase.COMMAND_AND_CONTROL
KillChainPhase.EXPLOITAITON
KillChainPhase.INSTALLATION
NistCategory.DE_CM
Cis18Value.CIS_10
APT19
APT28
APT29
APT3
APT32
APT33
APT38
APT39
APT41
APT5
Aquatic Panda
BRONZE BUTLER
Blue Mockingbird
CURIUM
Chimera
Cinnamon Tempest
Cobalt Group
Confucius
CopyKittens
Daggerfly
DarkHydrus
DarkVishnya
Deep Panda
Dragonfly
Earth Lusca
Ember Bear
FIN10
FIN13
FIN6
FIN7
FIN8
Fox Kitten
GALLIUM
GOLD SOUTHFIELD
Gallmaker
Gamaredon Group
Gorgon Group
HAFNIUM
HEXANE
Inception
Indrik Spider
Kimsuky
Lazarus Group
LazyScripter
Leviathan
Magic Hound
Molerats
MoustachedBouncer
MuddyWater
Mustang Panda
Nomadic Octopus
OilRig
Patchwork
Play
Poseidon Group
RedCurl
Saint Bear
Sandworm Team
Sidewinder
Silence
Stealth Falcon
TA2541
TA459
TA505
TeamTNT
Threat Group-3390
Thrip
ToddyCat
Tonto Team
Turla
Volt Typhoon
WIRTE
Winter Vivern
Wizard Spider
menuPass
APT-C-36
APT18
APT28
APT29
APT3
APT32
APT33
APT37
APT38
APT39
APT41
Ajax Security Team
Andariel
Aquatic Panda
BITTER
BRONZE BUTLER
BackdoorDiplomacy
Chimera
Cinnamon Tempest
Cobalt Group
Confucius
Daggerfly
Darkhotel
Dragonfly
Elderwood
Evilnum
FIN13
FIN7
FIN8
Fox Kitten
GALLIUM
Gamaredon Group
Gorgon Group
HAFNIUM
HEXANE
INC Ransom
IndigoZebra
Indrik Spider
Ke3chang
Kimsuky
Lazarus Group
LazyScripter
Leviathan
LuminousMoth
Magic Hound
Metador
Molerats
Moonstone Sleet
Moses Staff
MuddyWater
Mustang Panda
Mustard Tempest
Nomadic Octopus
OilRig
PLATINUM
Patchwork
Play
Rancor
Rocke
Sandworm Team
SideCopy
Sidewinder
Silence
TA2541
TA505
TA551
TeamTNT
Threat Group-3390
Tonto Team
Tropic Trooper
Turla
Volatile Cedar
Volt Typhoon
WIRTE
Whitefly
Windshift
Winnti Group
Winter Vivern
Wizard Spider
ZIRCONIUM
menuPass
APT32
Turla

Default Configuration

This detection is configured by default in Splunk Enterprise Security to run with the following settings:

Setting Value
Disabled true
Cron Schedule 0 * * * *
Earliest Time -70m@m
Latest Time -10m@m
Schedule Window auto
Creates Notable Yes
Rule Title %name%
Rule Description %description%
Notable Event Fields user, dest
Creates Risk Event True
This configuration file applies to all detections of type TTP. These detections will use Risk Based Alerting and generate Notable Events.

Implementation

The following analytic requires PowerShell operational logs to be imported. Modify the powershell macro as needed to match the sourcetype or add index. This analytic is specific to 4104, or PowerShell Script Block Logging.

Known False Positives

Unknown, possible custom scripting.

Associated Analytic Story

Risk Based Analytics (RBA)

Risk Message Risk Score Impact Confidence
Powershell webrequest to memory stream behavior. Possible fileless malware staging on $dest$ by $user$. 80 100 80
The Risk Score is calculated by the following formula: Risk Score = (Impact * Confidence/100). Initial Confidence and Impact is set by the analytic author.

References

Detection Testing

Test Type Status Dataset Source Sourcetype
Validation Passing N/A N/A N/A
Unit Passing Dataset XmlWinEventLog:Microsoft-Windows-PowerShell/Operational XmlWinEventLog
Integration ✅ Passing Dataset XmlWinEventLog:Microsoft-Windows-PowerShell/Operational XmlWinEventLog

Replay any dataset to Splunk Enterprise by using our replay.py tool or the UI. Alternatively you can replay a dataset into a Splunk Attack Range


Source: GitHub | Version: 3