Private Repository Red Team Infrastructure

NightShade C2 Framework

Production-grade Command and Control framework built for authorized red team research — AES-128 encrypted, anti-sandbox aware, and modular.

PythonFlaskAES-128 Cryptographypynputmss WMIwinreg

NightShade was built during an authorized internship at Femtosoft Technologies for controlled lab research into attacker TTPs. The repository is private. This page documents the architecture and techniques for educational and portfolio purposes. All research was conducted in isolated environments with no live deployment.

What It Is

A Command and Control (C2) framework simulates the infrastructure real threat actors use after gaining initial access to a target — the communication channel between an attacker's server and a compromised host. Understanding C2 at the implementation level is foundational to both red teaming and detection engineering.

NightShade was designed to implement the techniques documented in real-world threat intelligence reports — not as a point-and-click tool, but as a research platform for understanding how each component works and how defenders can detect it.

Architecture

The framework is split into three independent components that communicate over encrypted channels. Separating them means each can be developed, tested, and replaced independently.

C2 Server

Flask-based listener that receives beacons from deployed agents. Manages active sessions, queues commands, and stores returned output. Provides operator interface for tasking agents.

Agent / Implant

Lightweight Python payload deployed on the target. Beacons to the C2 server on a configurable interval, retrieves queued commands, executes them, and returns encrypted output. Runs silently with no visible window.

Encryption Layer

AES-128 in CBC mode with PKCS7 padding. All traffic between agent and server is encrypted — both commands sent and output returned. Key exchange happens at first beacon using a pre-shared key embedded in the agent at build time.

Anti-Sandbox Evasion

Malware analysis sandboxes are automated environments that execute suspicious files and monitor their behavior. They have characteristic fingerprints that differ from real user machines. NightShade detects these fingerprints before executing its main payload.

RAM Check

Sandboxes typically run with limited RAM (2–4GB) to minimize cost. NightShade checks total system RAM — below a threshold, it exits cleanly without executing payload logic.

CPU Core Count

Analysis VMs often have 1–2 cores. Real workstations typically have 4+. A low core count is a strong sandbox indicator — combined with RAM check for higher confidence.

Process Count

Sandboxes run minimal processes. Real Windows machines have 50–100+ background processes from normal operation. Below a threshold process count, execution is aborted.

Sleep Acceleration Detection

Some sandboxes fast-forward time.sleep() calls to speed up analysis. NightShade measures actual wall-clock time against expected sleep duration — discrepancy indicates sandbox acceleration.

def is_sandbox():
    if psutil.virtual_memory().total < 4 * (1024**3):  # < 4GB RAM
        return True
    if psutil.cpu_count(logical=False) < 2:            # < 2 physical cores
        return True
    if len(psutil.pids()) < 50:                        # < 50 processes
        return True
    return False

if is_sandbox():
    sys.exit(0)  # Exit cleanly — no crash, no alert

Persistence Mechanisms

Persistence ensures the agent survives reboots. NightShade implements Windows Registry Run key persistence — one of the most documented and commonly used persistence techniques in real-world malware, making it a high-value technique for both understanding and detecting.

import winreg

def establish_persistence(payload_path):
    key = winreg.OpenKey(
        winreg.HKEY_CURRENT_USER,
        r"Software\Microsoft\Windows\CurrentVersion\Run",
        0, winreg.KEY_SET_VALUE
    )
    winreg.SetValueEx(key, "WindowsUpdateHelper", 0,
                      winreg.REG_SZ, payload_path)
    winreg.CloseKey(key)

The registry key name is chosen to blend with legitimate Windows Update entries — a technique documented in MITRE ATT&CK as T1547.001 (Boot or Logon Autostart Execution: Registry Run Keys).

Agent Capabilities

Keylogging via pynput — captures all keystrokes with window context
📸Screenshot capture via mss — periodic or on-demand screen capture
💻Remote shell — execute arbitrary commands, return output encrypted
📁File operations — upload, download, list directory contents
🔍System enumeration — OS info, users, installed software, network config
🧹Self-sanitization — remove traces, clear logs, uninstall persistence on command

Detection and Defense

Every technique in NightShade was documented alongside its detection counterpart — this is what separates security research from just building malware.

TechniqueMITRE ATT&CKDetection Method
Registry Run Key persistenceT1547.001Monitor HKCU\...\Run for new entries; Sysmon Event ID 13
Encrypted C2 commsT1573.001Anomalous beacon patterns — regular interval outbound connections to new domains
KeyloggingT1056.001Hook detection; process monitoring for SetWindowsHookEx calls
Anti-sandbox evasionT1497.001Detonation in environments that spoof RAM/CPU counts
Self-sanitizationT1070File deletion monitoring; registry key removal alerts