<!-- Copyright (c) 2026 defconxt. All rights reserved. -->
<!-- Licensed under AGPL-3.0 — see LICENSE file for details. -->
<!-- NERF is a trademark of defconxt. -->
---
name: analyzing-shellcode
description: >-
  Analyze shellcode payloads to determine functionality, extract configuration, identify encoding schemes, and map system call sequences.
domain: cybersecurity
subdomain: reverse-engineering
tags:
  - shellcode
  - emulation
  - syscalls
  - encoding
  - payload-analysis
version: "1.0"
author: defconxt
license: AGPL-3.0
metadata:
  mitre-attack: ["T1059", "T1620"]
  cwe: ["CWE-94"]
  tools: ["scdbg", "speakeasy", "unicorn", "capstone", "pwntools"]
---

# Analyzing Shellcode

## Overview

Analyze shellcode payloads to determine functionality, extract configuration, identify encoding schemes, and map system call sequences.

## Prerequisites

| Tool / Requirement | Details |
|---|---|
| `scdbg` | Security tooling |
| `speakeasy` | Security tooling |
| `unicorn` | Security tooling |
| `capstone` | Security tooling |
| `pwntools` | Security tooling |
| Isolated lab environment for testing | Environment requirement |
| Authorization and signed Rules of Engagement (RoE) | Environment requirement |
| Relevant target samples or systems acquired through authorized channels | Environment requirement |

## Quick Reference

```bash
# Emulate shellcode with scdbg
scdbg -f shellcode.bin -s -1

# Disassemble with capstone
python3 -c "
from capstone import *
code = open('shellcode.bin','rb').read()
md = Cs(CS_ARCH_X86, CS_MODE_64)
for i in md.disasm(code, 0x0):
    print(f'0x{i.address:x}: {i.mnemonic} {i.op_str}')
"

# Emulate with unicorn
python3 shellcode_emulator.py --file shellcode.bin --arch x64
```

## Workflow

### Step 1: Preparation and Reconnaissance

```bash
# Identify target and gather initial intelligence
file ./target_sample
scdbg --version 2>/dev/null || echo "Install scdbg"

# Set up working directory
mkdir -p /tmp/analyzing-shellcode/{output,logs,artifacts}
```

### Step 2: Primary Analysis

```bash
# Execute primary analysis with scdbg
# Refer to Quick Reference above for detailed commands
echo "[*] Running Analyzing Shellcode with scdbg..."

# Log all operations
script -q /tmp/analyzing-shellcode/logs/session.log
```

### Step 3: Deep Investigation

```bash
# Apply speakeasy for secondary analysis
echo "[*] Deep investigation with speakeasy..."

# Cross-reference findings
diff /tmp/analyzing-shellcode/output/primary.json /tmp/analyzing-shellcode/output/secondary.json
```

### Step 4: Documentation and Reporting

```bash
# Generate structured findings report
cat <<'EOF' > /tmp/analyzing-shellcode/output/report.json
{
  "technique": "analyzing-shellcode",
  "domain": "reverse-engineering",
  "tools_used": ["scdbg", "speakeasy"],
  "findings": [],
  "recommendations": []
}
EOF
```

## Detection

```yaml
title: Shellcode Detection
id: b9d23f9f-c9b2-4404-a7a1-bbc06ce08add
status: experimental
description: Detects suspicious activity related to analyzing shellcode techniques in reverse engineering context
logsource:
  category: process_creation
  product: windows
detection:
  selection:
    CommandLine: "*analyzing*shellcode*"
  condition: selection
level: medium
tags:
  - attack.t1059
  - attack.t1620
  - attack.defense_evasion
falsepositives:
  - Malware analysis sandbox performing automated binary inspection
```


**Detection Opportunities**

| Indicator | Source | Detection Logic |
|---|---|---|
| Shellcode Detection | windows/process_creation | Sigma rule (medium) |
| ATT&CK Coverage | MITRE ATT&CK | T1059, T1620 |

## Verification

- [ ] Environment and tools verified and operational
- [ ] Target samples acquired through authorized channels
- [ ] Primary analysis completed with findings documented
- [ ] Secondary validation performed with independent tooling
- [ ] All artifacts preserved in structured output directory
- [ ] Detection opportunities documented for blue team

## References

- [MITRE ATT&CK T1059](https://attack.mitre.org/techniques/T1059) — Related technique
- [scdbg Documentation](https://scdbg.org/) — Primary tooling
- [speakeasy Reference](https://speakeasy.org/) — Secondary tooling
