Prerequisites
- Target system, dependencies and environment configured.
Usage
Purpose
A large share of real-world attacks start not with a compiled binary but with a script — a malicious Office macro, an obfuscated PowerShell command, a JavaScript dropper in an email. These are the initial-access and dropper stages, and they're heavily obfuscated to evade detection and human eyes. This skill covers analysing and deobfuscating script-based malware to reveal what it actually does — usually download and run the next stage.
When to use it
Analysing phishing attachments and droppers (the most common thing a SOC/IR analyst faces), or any script-based sample. It's often more immediately relevant than binary reversing, because scripts are where most intrusions begin. Do it in the isolated lab, and read scripts statically rather than running them where you can.
Procedure
- Extract the script from its container. Office documents are containers — macros live inside the OLE/OOXML structure.
oletools (olevba) pulls VBA macros out without opening the document in Office (which would run them):olevba suspicious.docm # extract + flag VBA macros, no Office needed
oleid suspicious.docm # quick risk indicators
For other types: extract the script from the email, HTML, or archive.
- Read it statically first — don't run it. The whole point is to understand it without execution. Malicious scripts are obfuscated but ultimately have to deobfuscate themselves to run, so the logic is there to be followed.
- Deobfuscate in layers. Script obfuscation is usually layered: base64/hex encoding, string concatenation and reversal, character-code arithmetic, and
eval/Invoke-Expression of a reconstructed string. Peel each layer:
- decode base64/hex (CyberChef is ideal for chaining decode operations);
- resolve string concatenation and reversal;
- substitute variables to see the reconstructed command.
# CyberChef: chain From Base64 -> decode -> etc. to unwrap layers
- Find the payload action. After deobfuscation, most droppers reveal the same thing: a URL to download the next stage, a command to run it, and often a persistence step. That downloaded URL and the executed command are your key indicators.
- For PowerShell specifically, watch for
-EncodedCommand (base64), IEX/Invoke-Expression, download cradles (New-Object Net.WebClient).DownloadString, and -WindowStyle Hidden -NoProfile — the hallmarks of a download-and-execute cradle. Decode the encoded command to read it.
- Extract indicators and pivot — the URLs, dropped filenames, and commands feed IoC extraction and detection; the downloaded next stage (if retrievable safely) becomes the next sample to analyse.
Cheatsheet
extract WITHOUT opening/running
Office macros: olevba doc.docm / oleid doc.docm (oletools)
other: pull script from email / HTML / archive
read STATICALLY, deobfuscate in LAYERS (CyberChef chains the steps)
base64 / hex decode
string concat + reversal
char-code arithmetic
eval / Invoke-Expression of the rebuilt string -> the real command
PowerShell red flags
-EncodedCommand (base64) | IEX / Invoke-Expression
(New-Object Net.WebClient).DownloadString (download cradle)
-WindowStyle Hidden -NoProfile -ExecutionPolicy Bypass
the payload is usually: download URL (next stage) + run command + persistence
-> these are your key IoCs (feeds extracting-iocs)
Reading the script
- A deobfuscated download-and-execute cradle = the classic dropper; the URL it fetches and the command it runs are your primary indicators and the pivot to the next stage. This is the payoff of deobfuscation.
- Heavy layered obfuscation (base64 inside string-reversal inside char-code math) = intentional evasion, not complexity for its own sake; peel it layer by layer — CyberChef makes chaining the decodes manageable.
Invoke-Expression/eval of a reconstructed string = the moment the script runs its real payload; whatever is passed to it, deobfuscated, is the actual command.
- A macro with
AutoOpen/Document_Open = auto-execution on document open — how the macro fires without further user action beyond enabling macros.
- A URL and a dropped filename = the indicators IR needs to block and hunt, often obtainable without ever running the script.
- A fully deobfuscated script = you understand the initial-access stage and have its IoCs — frequently more actionable, faster, than reversing a binary.
Pitfalls
- Opening the document in Office to "see the macro". That runs it. Extract with olevba/oletools instead, statically.
- Running the script to deobfuscate it. Tempting (let it decode itself), but that's execution — do it in the lab only, and prefer manual/CyberChef deobfuscation. Never run a dropper on your workstation.
- Stopping at the first layer. Obfuscation is layered; decoding one base64 blob often reveals another. Keep peeling until you reach the real command.
- Missing the auto-execution trigger.
AutoOpen/Document_Open (macros) or the entry logic is how it fires; understand what triggers it.
- Ignoring the next stage. The dropper's value is the URL/command it reveals; extract those and pivot — the downloaded payload is the real malware.
References
- oletools (olevba, oleid) documentation
- CyberChef (gchq.github.io/CyberChef) for layered deobfuscation
- Practical Malware Analysis and SANS FOR610 (script analysis)
- The extracting-iocs, dynamic-analysis-sandboxing, and phishing-email-analysis skills
- MITRE ATT&CK — T1059 (Command and Scripting Interpreter), T1566 (Phishing)
Inputs
- Relevant source code, logs, network traces, or system specifications.
Outputs
- Analysis findings, security audit report, or generated code artifacts.
1---2name: analysing-scripts-and-macros3description: Use when analysing script-based malware — malicious Office macros, PowerShell, JavaScript, and the deobfuscation that reveals what a dropper actually does.4---5678## Prerequisites9- Target system, dependencies and environment configured.1011## Usage12### Purpose1314A large share of real-world attacks start not with a compiled binary but with a script — a malicious Office macro, an obfuscated PowerShell command, a JavaScript dropper in an email. These are the initial-access and dropper stages, and they're heavily obfuscated to evade detection and human eyes. This skill covers analysing and deobfuscating script-based malware to reveal what it actually does — usually download and run the next stage.1516### When to use it1718Analysing phishing attachments and droppers (the most common thing a SOC/IR analyst faces), or any script-based sample. It's often more immediately relevant than binary reversing, because scripts are where most intrusions begin. Do it in the isolated lab, and read scripts statically rather than running them where you can.1920### Procedure21221. **Extract the script from its container.** Office documents are containers — macros live inside the OLE/OOXML structure. `oletools` (`olevba`) pulls VBA macros out without opening the document in Office (which would run them):23 ```24 olevba suspicious.docm # extract + flag VBA macros, no Office needed25 oleid suspicious.docm # quick risk indicators26 ```27 For other types: extract the script from the email, HTML, or archive.282. **Read it statically first — don't run it.** The whole point is to understand it without execution. Malicious scripts are obfuscated but ultimately have to deobfuscate themselves to run, so the logic is there to be followed.293. **Deobfuscate in layers.** Script obfuscation is usually layered: base64/hex encoding, string concatenation and reversal, character-code arithmetic, and `eval`/`Invoke-Expression` of a reconstructed string. Peel each layer:30 - decode base64/hex (CyberChef is ideal for chaining decode operations);31 - resolve string concatenation and reversal;32 - substitute variables to see the reconstructed command.33 ```34 # CyberChef: chain From Base64 -> decode -> etc. to unwrap layers35 ```364. **Find the payload action.** After deobfuscation, most droppers reveal the same thing: a URL to download the next stage, a command to run it, and often a persistence step. That downloaded URL and the executed command are your key indicators.375. **For PowerShell specifically**, watch for `-EncodedCommand` (base64), `IEX`/`Invoke-Expression`, download cradles (`New-Object Net.WebClient).DownloadString`, and `-WindowStyle Hidden -NoProfile` — the hallmarks of a download-and-execute cradle. Decode the encoded command to read it.386. **Extract indicators and pivot** — the URLs, dropped filenames, and commands feed IoC extraction and detection; the downloaded next stage (if retrievable safely) becomes the next sample to analyse.3940### Cheatsheet4142```43extract WITHOUT opening/running44 Office macros: olevba doc.docm / oleid doc.docm (oletools)45 other: pull script from email / HTML / archive4647read STATICALLY, deobfuscate in LAYERS (CyberChef chains the steps)48 base64 / hex decode49 string concat + reversal50 char-code arithmetic51 eval / Invoke-Expression of the rebuilt string -> the real command5253PowerShell red flags54 -EncodedCommand (base64) | IEX / Invoke-Expression55 (New-Object Net.WebClient).DownloadString (download cradle)56 -WindowStyle Hidden -NoProfile -ExecutionPolicy Bypass5758the payload is usually: download URL (next stage) + run command + persistence59 -> these are your key IoCs (feeds extracting-iocs)60```6162### Reading the script6364- **A deobfuscated download-and-execute cradle** = the classic dropper; the URL it fetches and the command it runs are your primary indicators and the pivot to the next stage. This is the payoff of deobfuscation.65- **Heavy layered obfuscation** (base64 inside string-reversal inside char-code math) = intentional evasion, not complexity for its own sake; peel it layer by layer — CyberChef makes chaining the decodes manageable.66- **`Invoke-Expression`/`eval` of a reconstructed string** = the moment the script runs its real payload; whatever is passed to it, deobfuscated, is the actual command.67- **A macro with `AutoOpen`/`Document_Open`** = auto-execution on document open — how the macro fires without further user action beyond enabling macros.68- **A URL and a dropped filename** = the indicators IR needs to block and hunt, often obtainable without ever running the script.69- **A fully deobfuscated script** = you understand the initial-access stage and have its IoCs — frequently more actionable, faster, than reversing a binary.7071### Pitfalls7273- **Opening the document in Office to "see the macro".** That runs it. Extract with olevba/oletools instead, statically.74- **Running the script to deobfuscate it.** Tempting (let it decode itself), but that's execution — do it in the lab only, and prefer manual/CyberChef deobfuscation. Never run a dropper on your workstation.75- **Stopping at the first layer.** Obfuscation is layered; decoding one base64 blob often reveals another. Keep peeling until you reach the real command.76- **Missing the auto-execution trigger.** `AutoOpen`/`Document_Open` (macros) or the entry logic is how it fires; understand what triggers it.77- **Ignoring the next stage.** The dropper's value is the URL/command it reveals; extract those and pivot — the downloaded payload is the real malware.7879### References8081- oletools (olevba, oleid) documentation82- CyberChef (gchq.github.io/CyberChef) for layered deobfuscation83- Practical Malware Analysis and SANS FOR610 (script analysis)84- The extracting-iocs, dynamic-analysis-sandboxing, and phishing-email-analysis skills85- MITRE ATT&CK — T1059 (Command and Scripting Interpreter), T1566 (Phishing)8687## Inputs88- Relevant source code, logs, network traces, or system specifications.8990## Outputs91- Analysis findings, security audit report, or generated code artifacts.