Siddhant Mandal← All operations

Case study · 01

MorphShell

Sandboxed Shellcode Behavioral Analysis Framework

A Python framework for sandboxed shellcode behavioral analysis, safely emulating raw shellcode with Unicorn Engine and disassembling instructions via Capstone instead of executing samples natively.

GitHub

01

Overview

MorphShell is a sandboxed framework for analyzing raw shellcode behaviorally rather than signature-by-signature. It emulates instructions instead of executing them natively, extracts a behavioral feature vector, and classifies the sample’s likely intent with a trained model.

02

The problem

Signature-based detection struggles against novel or lightly obfuscated shellcode, and native execution of unknown samples is unsafe on analysis hosts. Analysts need a way to observe what shellcode does — not just what it looks like — without ever letting it run for real.

03

Architecture

  1. 01Emulation layer
    Unicorn Engine emulates raw shellcode in an isolated CPU/memory context.
  2. 02Disassembly layer
    Capstone decodes executed instructions for inspection and tracing.
  3. 03Feature extraction
    A pipeline captures instruction flow, memory writes, Linux int 0x80 syscalls, loop structures, NOP sleds, and write-then-execute patterns.
  4. 04Classification
    A Random Forest model (scikit-learn) scores the extracted features against known behavioral families.
  5. 05Reporting
    Results are serialized to JSON with classification confidence for downstream review.

04

The solution

By emulating rather than executing, MorphShell observes real instruction-level behavior — memory writes, syscalls, control flow — while keeping the host completely safe. That behavioral trace becomes a feature vector a classifier can reason about, turning raw execution traces into a confidence-scored verdict.

05

Implementation

  1. Unicorn Engine initializes an isolated emulated memory space and CPU context per sample.
  2. Capstone disassembles each executed instruction alongside emulation for human-readable tracing.
  3. A feature extractor watches the instruction stream for syscall invocations, memory write regions, loop back-edges, NOP sled runs, and write-then-execute sequences — common shellcode staging behavior.
  4. The resulting feature vector is passed to a trained Random Forest classifier, which outputs a predicted behavioral family and confidence score.
  5. A JSON report is generated summarizing the trace, extracted features, and classification result.

06

Challenges

  • Distinguishing genuine malicious staging behavior (write-then-execute, NOP sleds) from benign-looking but structurally similar instruction sequences.
  • Keeping emulation faithful enough to trigger the shellcode’s real behavior without native execution risk.
  • Building a feature set expressive enough for a classical ML model to separate behavioral families reliably.

07

Lessons learned

  • Behavioral, feature-based detection generalizes better than static signatures against unseen samples.
  • Emulation fidelity (accurate syscall and memory modeling) matters as much as the classifier itself.
  • Clear, structured reporting (JSON) makes a research tool usable in an actual analyst workflow.

08

Future work

  • Expand syscall coverage beyond Linux int 0x80 to cover additional execution environments.
  • Add support for multi-stage shellcode that downloads or decrypts secondary payloads mid-execution.
  • Explore a lightweight neural classifier as a complement to the Random Forest baseline.
Next operationPrivDrift