In this section

0.6 Execution Without a File

Module 0

Introduction

A growing share of malware never needs a file of its own on disk. It arrives as a command, runs inside a program Windows already trusts, builds its next stage in memory and runs that too. The usual name for this is fileless, and it is not quite accurate: something always starts the chain, and something always records parts of it. What changes is where the evidence is.

This lesson sets out how code runs without a file of its own: through PowerShell and script hosts, through signed system binaries used as proxies, through .NET loaded straight into memory, and through persistence that stores code rather than a path. It then shows what Windows records about all of it, AMSI and script block logging in particular, and decodes a three-layer PowerShell specimen to the command that finally runs.

1

What Fileless Means

And what it does not

The phrase describes the payload, not the whole attack. A ClickFix lure from lesson 0.1 ends with the user pasting a command into the Run dialog, and from then on the chain can run entirely in memory: a built-in program reads the command, decodes the next stage, runs it, and fetches or decodes the one after.

Microsoft's analysis of ClickFix found most of its payloads running in memory through built-in programs such as msbuild.exe, regasm.exe and powershell.exe.

Three things still exist. The command that started it is in a process command line, which endpoint telemetry records.

The script content passes through the engine that runs it, which is where AMSI scans and PowerShell logs. And the network carries whatever was fetched. So "fileless" means the evidence moved from a file an antivirus scanner can read to records the defender has to collect, and an analyst who looks only for files will find nothing.

The lab pack's specimen for this lesson is that kind of chain, built inert: a command line, as process telemetry would capture it, that runs PowerShell with an encoded argument. Its first line is all an alert usually shows:

$ tr ' ' '\n' < mw06-layers.ps1.txt | head -n 6 | cut -c1-60
powershell
-nop  # ◄ no profile
-w  # ◄ window style
hidden  # ◄ nothing on screen
-enc  # ◄ next argument is encoded
JABkAD0AWwBDAG8AbgB2AGUAcgB0AF0AOgA6AEYAcgBvAG0AQgBhAHMAZQA2

Four words carry the whole intent. No profile, so nothing the user has customized interferes. A hidden window, so nothing appears on screen. An encoded command, so the actual script is not readable in the command line. Every one of those is legitimate on its own; together, launched by an ordinary user's session, they are one of the most common signs of an attack in progress.

The sixth word is the start of the encoded argument itself, base64 text that runs on for several hundred characters. Its length is a clue too: a legitimate administrator's encoded command is usually short, written to avoid quoting problems, while an attack's is long because it carries a whole script, often with more encoded data inside.

2

PowerShell and the Script Hosts

Engines that run text

PowerShell is the most used tool in this kind of attack for reasons that have nothing to do with flaws in it. It is on every Windows machine, it can reach every part of the system through .NET, it can download and run code in one line, and it accepts its script as an encoded argument, which keeps the content off the command line.

Microsoft's ClickFix analysis names PowerShell as the most used native binary in those chains.

It is not alone. Windows ships other engines that run text: the Windows Script Host runs VBScript and JScript files, mshta runs HTML applications, and Office runs VBA macros, which lesson 0.1 showed being blocked by default for files from the internet. Each takes a script and executes it, so each is a place where code arrives as text and becomes behavior:

Windows engines that run text

powershell.exe

PowerShell script, including an encoded command line

wscript.exe, cscript.exe

VBScript and JScript files, through the Windows Script Host

mshta.exe

HTML applications

Office

VBA macros, blocked by default in files from the internet

The engine matters to the analyst because it decides the format of what has to be decoded and where its records are. A VBScript chain is read as VBScript and logged differently from a PowerShell one; a macro is extracted from the document before it can be read at all.

That shared design is what defenders use. Microsoft describes AMSI, the Antimalware Scan Interface, as open: any application can call it and any registered antimalware engine can process what is submitted. PowerShell and Windows' built-in script hosts call it, and Office passes the contents of a macro's buffer to it when high-risk calls are observed. Section 6 shows why the point at which they call it matters so much.

For the analyst, the practical rule is that a script host process with an encoded or heavily obfuscated argument is never the end of the investigation. It is the outer layer, and the questions are what it decoded, what it ran, and what that reached.

3

Living Off the Land

Signed binaries as proxies

PowerShell is the best known of a larger set. MITRE ATT&CK describes system binary proxy execution, where adversaries run malicious content through signed or otherwise trusted binaries, many of them signed by Microsoft and shipped with Windows, so they are trusted by default where signature validation is enforced. The technique lists fourteen such binaries and families. A few account for most of what analysts meet:

Signed binaries and what they are abused to run

powershell.exe

Script, often encoded, as in this lesson

mshta.exe

HTML applications and inline script

rundll32.exe

An exported function from any DLL

regsvr32.exe

Registration code in a DLL it is pointed at

msiexec.exe

An installer package

regasm.exe, msbuild.exe

.NET code loaded by a trusted tool

The attraction is the same for each. The process that runs is genuine and signed, so allow lists permit it and a quick look at the process name finds nothing wrong. What gives it away is context: the parent that started it, the arguments it was given, the network connection it made, and the file or address those arguments point to.

This is why process lineage matters more than process names. rundll32.exe starting under explorer.exe when a user opens a control panel item is routine. rundll32.exe starting under a script host, pointed at a DLL in a temporary folder that was written a minute earlier, is not. The binary is the same in both cases; the chain of parents, arguments and files around it is the evidence that tells them apart.

The community LOLBAS project catalogs these binaries with the abuse each one allows. For a defender, the useful question about any one of them is narrower: in this environment, who legitimately runs it, from where, and with what arguments. Anything outside that answer is worth a look.

That answer is also what makes a detection usable. A rule that alerts on every rundll32.exe launch drowns the SOC; a rule that alerts on rundll32.exe started by a script host or an Office application, or pointed at a DLL outside the system folders, fires rarely and means something when it does. Lesson 0.10 builds detections in that shape, from the behavior around a binary rather than the binary's name.

4

Code Loaded Straight Into Memory

Reflective loading and .NET

The deepest form of in-memory execution loads a whole program without writing it anywhere. MITRE ATT&CK calls this reflective code loading: adversaries load code into a process to conceal the execution of malicious payloads, avoiding files and other artifacts on disk, with the payload often staying encrypted until the moment it runs:

Reflective code loading

In memory

Technique

MITRE ATT&CK T1620

What it does

loads code into a process from memory

What it avoids

files and other artifacts on disk

Seen in

FIN7, Cobalt Strike, Lumma Stealer

The call to look for

  • Reflection.Assembly::Load, the .NET method FIN7 used

.NET makes it easy. A script can hold a compiled .NET program as a byte array, often base64-encoded, and hand it to the runtime's assembly loading method, which runs it inside the current process. MITRE records FIN7 loading a .NET assembly this way and Cobalt Strike running .NET programs in the memory of a sacrificial process, and lists Lumma Stealer among the families that use the technique.

For an analyst, the byte array is the find. A script that decodes a large blob and passes it to an assembly loading call is carrying a program, and that program can be carved out exactly as lesson 0.2 carved a stage from a loader: decode the blob, check that it is a valid executable, hash it and analyze it like any other file.

It never existed on disk on the victim's machine, but it can exist on the analyst's.

Memory forensics is the other route, when the script is gone and only the running process remains. The loaded program sits in the process's memory, readable with the right tools, and it is often the only copy of the real payload anywhere. That route belongs to a later module; the point here is that "never written to disk" does not mean unrecoverable.

The record for in-memory code keeps the same three things as for an unpacked stage in lesson 0.2: what arrived, the script that carried the program; what was analyzed, the program carved from it; and how one came from the other, the offset or variable, the encoding and the hash of the result.

5

Persistence That Carries Code

Surviving a reboot without a file

Code that lives only in memory disappears when the machine restarts, so attackers who want to stay store the code somewhere Windows will run it again. Some places hold a path to a file; others can hold the code itself, which keeps the chain fileless across reboots. WMI event subscriptions are a standard example:

Persistence that carries code: WMI event subscriptions

Persistence

Technique

MITRE ATT&CK T1546.003

Parts

filter, consumer, binding

Runs

code when the event occurs

Where it shows

  • Creation of EventFilter, EventConsumer and FilterToConsumerBinding objects
  • mofcomp.exe on a command line, Register-WmiEvent in PowerShell
  • Unexpected child processes of WmiPrvSE.exe

MITRE ATT&CK describes WMI being used to install event filters, consumers and bindings that execute code when a defined event occurs, such as the system starting or a time of day arriving. The detection advice is concrete: watch for the creation of those three objects, for mofcomp.exe compiling a subscription, for Register-WmiEvent in PowerShell, and for unexpected child processes of WmiPrvSE.exe, the process that runs triggered actions.

Registry values and scheduled tasks are used the same way. A run key or a task whose command is a PowerShell line with an encoded argument stores the whole first layer of a chain in the configuration of the system itself. The analyst decodes it exactly as the specimen in this lesson is decoded, because it is the same kind of text.

The common thread is that persistence leaves a definition behind, and the definition is readable. Whatever the mechanism, the record to keep is where it was stored, what triggers it, and the decoded content it runs.

Removal follows the same logic. Deleting a file a run key points to leaves the key, which then fails quietly at every boot; deleting a subscription's consumer and leaving its filter and binding leaves parts that a later attacker can reuse. Each part of the definition is listed, removed and recorded, and the host is checked again after a restart to confirm nothing ran.

6

What Windows Records

AMSI and script block logging

Obfuscation hides code from anything that reads it before it runs. It cannot hide code from the engine that runs it, because the engine needs plain text, and that is where Windows looks. Microsoft's explanation of AMSI is explicit: script might go through several passes of de-obfuscation, but the engine has to be supplied with plain, un-obfuscated code, and that is the point at which the AMSI APIs are called:

1. Encoded commandwhat the process command line shows2. Layer 1 reaches the engineAMSI scans it; script block logging records it3. Layer 2 reaches the enginerun by iex: scanned and recorded again4. Layer 3 reaches the engineplain text, scanned and recorded5. Outputwhatever the final layer doesProcess telemetrythe outer layerInside PowerShellevery layer

Where the defenses look. However many layers an attacker adds, each one has to reach the engine as plain text, and that is where AMSI scans and script block logging records.

Every layer of a chain that decodes the next one and passes it to the engine is therefore scanned in plain text, once per layer. Microsoft's own illustration of this is a script typed at the command line, so that there is no file at all, and AMSI still catching the content at the point it ran.

Script block logging records at the same point. With it turned on, PowerShell records the content of every script block it processes, as event 4104 in its Operational log, as lesson 0.1 showed. A script built at run time and handed to iex is a script block like any other, so a three-layer chain produces three records, each in plain text, in order.

Set side by side, the records a defender can collect for a chain like this one hold very different amounts of it:

What each record holds for this chain

Process command line

The outer layer only: the encoded argument

AMSI

Each layer in plain text, offered to the antimalware engine as it runs

Script block logging, 4104

Each layer in plain text, kept in the PowerShell log, if turned on

Network records

Anything a layer fetched, and from where

The two inside PowerShell are complementary. AMSI is a chance to block the content as it runs, if the antimalware engine recognizes it; script block logging is the record of what ran, whether or not anything recognized it.

The process command line, the third record, shows only the outer layer. An analyst with all three has the chain; one with only the command line has to decode it by hand, which is what the rest of this lesson does.

Whether script block logging was on is itself a finding to record. Many estates enable it only on servers, or not at all, and an investigation that discovers the gap mid-incident has found a control to fix as well as an infection to scope.

The decode by hand gives the same text the log would have held; what it cannot give is the time each layer ran, which only the log records.

7

Decoding the Specimen

Layer by layer, to the command that runs

The specimen's encoded argument is base64 of UTF-16LE text, as PowerShell's encoded commands always are. Decoding it, and splitting the result at its statement separators so it can be read, gives the first layer:

$ awk '{print $NF}' mw06-layers.ps1.txt | base64 -d \
    | iconv -f UTF-16LE -t UTF-8 > layer1.ps1
$ tr ';' '\n' < layer1.ps1 | cut -c1-56
$d=[Convert]::FromBase64String("H4sIAAAAAAAC/z1Oyw7CMAz7  # ◄ more base64 inside
$s=New-Object IO.Compression.GzipStream((New-Object IO.M  # ◄ and it is compressed
(New-Object IO.StreamReader($s)).ReadToEnd()|iex  # ◄ then run as code

The first layer is a decoder for the second. It converts another base64 string to bytes, decompresses them as gzip, reads the result as text and passes that text to iex, which runs a string as code. Repeating its steps on the command line gives the second layer:

$ grep -o 'FromBase64String("[^"]*")' layer1.ps1 | cut -d'"' -f2 \
    | base64 -d | gunzip > layer2.ps1
$ cut -c1-48 layer2.ps1
[string]::Join("", ([char[]](87,114,105,116,101,  # ◄ numbers that are characters
$ tail -c 24 layer2.ps1
10,101,114,116,34)))|iex  # ◄ run as code again

The second layer is another wrapper: a list of numbers converted to characters, joined into a string and run with iex again. Each number is a character code, so turning them back into characters gives the third layer:

$ grep -o '([0-9,]*)' layer2.ps1 | tr -d '()' | tr ',' '\n' \
    | awk '{printf "%c", $1}' > final.ps1

The third layer is plain PowerShell, with nothing left to decode:

Write-Output "RIDGELINE-SPECIMEN mw06 final layer: inert"

That is the command the chain exists to run, and in this specimen it prints the lab pack's marker. In a real chain it would be the download, the reflective load or the persistence the earlier sections described, and it is the layer every later question is about. Counting the iex calls confirms the structure, and the sizes show each layer unwrapping the next:

$ grep -c 'iex' layer1.ps1 layer2.ps1 final.ps1
layer1.ps1:1
layer2.ps1:1
final.ps1:0  # ◄ nothing left to unwrap
$ wc -c < layer1.ps1
419
$ wc -c < layer2.ps1
230

Drawn as a chain, the structure is three wrappers around one line:

Command line-nop -w hidden-enc ...decodesLayer 1base64, thengzip, then iexunzips, runsLayer 2character codesjoined, then iexjoins, runsLayer 3Write-Outputthe marker

The specimen's layers. Each one is code that builds the next and runs it, so each is a separate script block when PowerShell executes the chain.

The same decode is a short recipe in CyberChef, the tool most analysts reach for first: From Base64, Decode text as UTF-16LE, then for the inner string From Base64 and Gunzip, then From Charcode. Whatever the tool, the record is the same: each layer's encoding, what ran it, and the final text, with the hash of the original command line so the chain can be tied back to the alert.

8

Working With the Assistant

Prompt, session, record

Deobfuscation is one of the tasks assistants are best at, and one where the question decides whether the answer stops at the right layer. Asked what the command does, it describes commands like it:

OpenCode in REMnux, file namedPrepared example
What does this PowerShell do?
It is an obfuscated downloader:
  1. It decodes a base64 payload, decompresses it and runs it in memory.
  2. Payloads like this usually download a second stage from a remote server.
Numbered for checking against the tool output

Nothing in that answer was decoded, and the second line is the usual next step of a chain, not this one's. The prompt that works asks for the decode itself, sets the boundary, and gives the assistant the test that tells a wrapper from the command that ran:

PromptThe prompt that works
mw06-layers.ps1.txt holds a PowerShell command line captured on a host. Decode it layer by layer, writing each layer to a file to read and never running it. A layer that still has a decoding call or an iex is a wrapper; stop at the first layer with neither, and show me the start of each layer on the way. One command at a time.
  1. captured on a hostsays this is evidence of something that ran, so the answer is what ran
  2. writing each layer to a file to read and never running itthe boundary, and a habit that keeps every layer
  3. still has a decoding call or an iex is a wrappergives it the test for a wrapper, so it cannot stop early
  4. show me the start of each layerputs every layer in front of you as well as its conclusion
  5. One command at a timekeeps each step on output you have seen

The session decodes all three layers, and the test in the prompt is what the analyst points back to when the assistant stops one layer short:

What ran, in orderOpenCode in REMnux, mw06-layers.ps1.txtPrepared example
  1. You
    mw06-layers.ps1.txt holds a PowerShell command line captured on a host. Decode it layer by layer, writing each layer to a file to read and never running it. A layer that still has a decoding call or an iex is a wrapper; stop at the first layer with neither, and show me the start of each layer on the way. One command at a time.
  2. Assistant
    Split the command line into words first to see the flags.
  3. REMnux
    $ tr ' ' '\n' < mw06-layers.ps1.txt | head -n 5 | cut -c1-40
    powershell
    -nop
    -w
    hidden
    -enc
  4. Assistant
    Hidden, no profile, and -enc: base64 of UTF-16LE text. Decode it to l1.ps1 and list the calls that decode or run code.
  5. REMnux
    $ awk '{print $NF}' mw06-layers.ps1.txt | base64 -d \
        | iconv -f UTF-16LE -t UTF-8 > l1.ps1
    $ grep -o -E 'FromBase64String|GzipStream|iex' l1.ps1 | sort -u
    FromBase64String
    GzipStream
    iex
  6. Assistant
    Layer 1 decodes more base64, decompresses it with gzip and runs the result with iex: a wrapper. Extract the base64, decompress it to l2.ps1 and show the start.
  7. REMnux
    $ grep -o 'FromBase64String("[^"]*")' l1.ps1 | cut -d'"' -f2 \
        | base64 -d | gunzip > l2.ps1
    $ cut -c1-40 l2.ps1
    [string]::Join("", ([char[]](87,114,105,
  8. Assistant
    Layer 2 is an array of character codes; the numbers spell Write-Output and a marker, so that is the payload: it prints a line.
  9. You
    Does layer 2 end in iex? By the test in my prompt that makes it a wrapper. Decode it.
  10. Assistant
    You are right: it joins the codes and pipes them to iex, so it is layer 2 of 3. Check its end, convert the codes to text as l3.ps1, and count iex in every layer.
  11. REMnux
    $ tail -c 12 l2.ps1
    16,34)))|iex
    $ grep -o '([0-9,]*)' l2.ps1 | tr -d '()' | tr ',' '\n' \
        | awk '{printf "%c", $1}' > l3.ps1
    $ grep -c iex l1.ps1 l2.ps1 l3.ps1
    l1.ps1:1
    l2.ps1:1
    l3.ps1:0
  12. Assistant
    Layer 3 has no iex and no decoding call. It is the command that ran; read it before anything else.
  13. REMnux
    Write-Output "RIDGELINE-SPECIMEN mw06 final layer: inert"
REMnux turns are the commands as run, with their output

Stopping a layer early is the most common deobfuscation slip, by people as well as assistants, because the inner wrapper often carries readable fragments of the payload. The prompt had already stated the test, so the correction was one line that quoted it, and the assistant applied it and went on to count iex in every layer, which is the check that proves the last layer is the end.

The time saved is in the decoding steps: the UTF-16LE detail, the gzip inside base64, and the awk that turns character codes into text. Each is a short lookup by hand. Writing each layer to its own file, which the prompt asked for, is the other gain, because the layers are what a detection is written against and what a host's logs will show.

The answer goes into the record on three lines:

What the answer rests on

Three layers

iex once in layers 1 and 2, and none in layer 3

What ran

l3.ps1: one Write-Output line

What stays open

whether the host recorded the layers: its script block logging decides it

The open line goes to the host owner with something specific to look for: three script blocks in event 4104, in the order the session decoded them, if logging was on.

Do

Practice

What ran, in order?
prepared evidence

The scenario below holds the working session, the decoded layers and the command line from this lesson. Decide how to steer the assistant, then say what ran and where a host would have recorded it.

In the lab, decode mw06-layers.ps1.txt with the same commands in your REMnux machine, then again in CyberChef with the recipe from section 7, and decode it in OpenCode, started in the pack's lab folder, using the prompt above, holding it to the wrapper test at every layer. The pack's answers.json lists the layers and the final command.

Execution without a file moves the evidence rather than removing it. The outer layer is in the process command line, every layer that reaches a script engine is scanned by AMSI and, with logging on, recorded in plain text, and code loaded straight into memory can still be carved out as a file or read from the process.

Signed system binaries run attackers' content because they are trusted, so their context, not their names, is the evidence. Decoding a chain is mechanical once each layer is treated as text that builds the next: decode, read, repeat, and stop at the first layer with nothing left to run.

Resources

Vendors and projects revise these pages; where a page and this lesson disagree, the page is newer.