# Malware Config Extraction String Decoding

> Use when a sample's readable strings are hidden behind encoding (XOR, base64, hex, custom alphabets, stack-built strings) and you need the plaintext for IOCs and YARA rules. Covers recognizing encoding types from byte patterns, single and multi-byte XOR brute force, base64 and hex decoding pipelines, stack-string reconstruction, and validating decoded output. Use when FLOSS decoded output exists but needs interpretation, when strings look like gibberish, or when building the plaintext string set for detection.

- Skill: `mizazhaider-ceh/malware-config-extraction-string-decoding` (Agent Skill)
- Install (CLI): `npx get-skill add mizazhaider-ceh/malware-config-extraction-string-decoding`
- Raw SKILL.md: https://api.skillmd.com/api/skills/mizazhaider-ceh/malware-config-extraction-string-decoding/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: mizazhaider-ceh (https://skillmd.com/u/mizazhaider-ceh)
- Updated: 2026-11-22
- Page: https://skillmd.com/skills/mizazhaider-ceh/malware-config-extraction-string-decoding

---


Malware authors encode strings to hide IOCs from static view: C2 URLs
XORed with a byte, API names built on the stack, configs base64ed twice.
FLOSS recovers many automatically, but the analyst still needs to
recognize what was used, finish the decode, and judge the output. This
sub-skill covers the decoding workhorse techniques for the parent
config-extraction skill. Scope: decode strings only from samples you are
authorized to handle, in an isolated lab, during authorized DFIR or
threat intel work.

## Quick Workflow

1. Collect the encoded material: FLOSS decoded/stack output, long
   gibberish strings, high-entropy blobs.
2. Identify the encoding: try XOR scoring, base64 alphabet check, hex
   check, in that order.
3. Decode with the matching method; keep the key and parameters.
4. Validate: plaintext should contain URLs, paths, or structured text.
5. Extract IOCs and YARA strings from the validated plaintext.
6. Record the encoding, key, and decoder script with the sample.

## 1. Recognizing encoding types

```text
Single-byte XOR:   every byte shifted; printable scoring finds the key
Multi-byte XOR:    repeating key; look for repeating patterns in ciphertext
Base64:            alphabet A-Za-z0-9+/=, length multiple of 4
Hex:               only 0-9a-fA-F, even length
Stack strings:     FLOSS stack output; short fragments that join into words
Custom alphabet:   base64-like but with a shuffled alphabet table nearby
```

Quick triage in Python:

```python
import base64, re

def guess(s: str) -> str:
    s = s.strip()
    if re.fullmatch(r"[0-9a-fA-F]+", s) and len(s) % 2 == 0 and len(s) > 16:
        return "maybe-hex"
    if re.fullmatch(r"[A-Za-z0-9+/=]+", s) and len(s) % 4 == 0 and len(s) > 20:
        return "maybe-base64"
    return "maybe-xor-or-custom"

for line in open("gibberish.txt"):
    print(guess(line), line[:40].strip())
```

## 2. XOR brute force

```python
def xor_single(blob: bytes):
    results = []
    for key in range(256):
        pt = bytes(b ^ key for b in blob)
        score = sum(32 <= c < 127 for c in pt) / len(pt)
        if score > 0.85:
            results.append((score, key, pt))
    return sorted(results, reverse=True)[:3]

def xor_multi(blob: bytes, maxkeylen=16):
    # Try key lengths by looking for the one that maximizes
    # printable ratio after repeating-key XOR
    best = None
    for kl in range(2, maxkeylen + 1):
        # simple approach: recover key bytes by most-common-byte heuristic
        key = bytearray()
        ok = True
        for i in range(kl):
            chunk = blob[i::kl]
            # assume most common plaintext byte is 0x00 or space; try both
            for guess_pt in (0x00, 0x20):
                k = max(set(chunk), key=chunk.count) ^ guess_pt
                key.append(k)
                break
        pt = bytes(b ^ key[i % kl] for i, b in enumerate(blob))
        score = sum(32 <= c < 127 for c in pt) / len(pt)
        if best is None or score > best[0]:
            best = (score, bytes(key), pt)
    return best
```

Example output shape:

```text
single-byte: score=0.97 key=0x4a
  plaintext: b'http://beacon.example-cdn[.]net/api/v2/beacon\x00'
```

Validate by content: a URL, a path, or an API name confirms the key.
When multi-byte heuristics fail, look at the disassembly for the actual
key bytes near the decode loop instead of guessing.

## 3. Base64, hex, and stacked encodings

```python
import base64

def try_b64(s: str):
    s = s.strip()
    try:
        raw = base64.b64decode(s, validate=True)
        # Often the decoded bytes are XORed or hex again: recurse once
        return raw
    except Exception:
        return None

# Pipeline: base64 -> maybe XOR -> maybe decompress
import zlib
raw = try_b64(line)
if raw:
    key, pt = xor_single(raw)[0][1:] if xor_single(raw) else (None, raw)
    try:
        pt = zlib.decompress(pt)
    except Exception:
        pass
    print(pt[:120])
```

Stacked encodings (base64 of XOR of zlib) are common; apply the pipeline
one layer at a time and check readability after each. CyberChef is the
interactive equivalent for exploring unknown stacks before scripting.

## 4. Stack strings

FLOSS already reconstructs most stack strings, but when it misses:

```text
Disassembly shape:
  mov dword ptr [ebp-0x20], 0x70747468   ; "http" (little-endian)
  mov dword ptr [ebp-0x1c], 0x2f2f3a2f   ; "://"
  ...
```

Read the immediates as little-endian ASCII and concatenate. Stack
strings defeat naive `strings` but not FLOSS; if FLOSS found them,
trust its output and move on to IOC extraction.

## 5. Validation

Decoded output must earn trust:

- Contains expected shapes: URLs, IPs, file paths, API names.
- Length is sane: a 12-byte decode of a 200-byte blob means wrong key.
- Cross-check: the decoded C2 appears in the sandbox network trace.
- Negative check: decoding with a wrong key gives garbage; your key
  should be clearly better than neighbors (sharp scoring peak, not a
  plateau).

Record the key derivation: hardcoded constant, nearby ASCII string, or
brute-forced. Brute-forced keys get lower confidence until the sandbox
corroborates.

## Edge cases

- Wide-character encoded strings: decode first, then interpret as
  UTF-16LE; XOR on wide strings needs a wide-aware scorer.
- Rolling keys (key changes per byte): look for the key schedule in
  disassembly; brute force will not find it.
- Encodings that are also compressed: decode, then try zlib/lzma
  before concluding garbage.
- Decoy strings: some samples decode to plausible-but-unused text;
  confirm usage via trace or memory before publishing IOCs.
- Case where FLOSS decoded output is truncated: re-run with
  increased limits or decode manually from the blob.

## Escalation

- If the encoding is custom and unrecognized after disassembly
  review, escalate to a reverse engineer; reimplementing unknown
  transforms risks false IOCs.
- If decoded strings contain victim PII, escalate handling per
  incident rules.

- If decoded output is still structured but unreadable (possible second encoding), escalate to disassembly review of the decode loop rather than guessing.
- If the encoding key is victim-specific, document the derivation so each victim's strings decode correctly.

## Detection and defender view

Decoded strings are the highest-quality YARA inputs: they are the
attacker's real IOCs, not the encoded camouflage. Prefer decoded
plaintext strings over encoded blobs in rules (encoded blobs change
with each key rotation; the plaintext intent is stable). Share decoder
scripts with the team; the next sample from the family decodes in
seconds. When plaintext reveals a new C2, the network IOC goes to the
SOC the same day, not with the final report.

## Key references

- Mandiant FLARE FLOSS:
  https://github.com/mandiant/flare-floss
- CyberChef:
  https://gchq.github.io/CyberChef/
- MITRE ATT&CK: T1027 (Obfuscated Files or Information), T1140
  (Deobfuscate/Decode Files or Information)
- Practical Malware Analysis (Sikorski and Honig), Chapter 13
  (data encoding)

- CyberChef wiki (encoding recipes):
  https://github.com/gchq/CyberChef/wiki

