Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions .github/workflows/shipped-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# The shipped team-server image, built and started.
#
# This file exists because of a measurement, not a policy. The first time
# anyone built `software/c2/Dockerfile` on a machine that was not the one
# it was written on, it failed six different ways. Four of those failures
# hit every architecture, and they had been there long enough that the
# image's own base had changed Debian release underneath it. Nothing in
# this repository ever built it, so nothing ever said so.
#
# A separate workflow rather than a job inside ci.yml, deliberately: this
# guards one artefact, it is the only thing that needs Docker and a long
# apt step, and a reader looking at a red run should be able to tell from
# the name alone that the image is what broke.
#
# It builds AND starts. Defect 5 built cleanly and then died at import
# with "No module named 'software'", so a job that stopped at a green
# build would have reported success over an image that could not run.
# That is the whole reason for the second step.
name: Shipped image

on:
push:
branches: ["**"]
paths:
- "software/c2/Dockerfile"
- "software/c2/docker-compose.yml"
- "software/c2/docker-entrypoint.sh"
- "software/c2/server.py"
- "software/c2/beacon.py"
- ".github/workflows/shipped-image.yml"
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
image:
name: build and start (docker, linux)
runs-on: ubuntu-latest
# The apt step alone pulls ~140 MB and the NetExec install compiles,
# so this is not a two-minute job. Measured locally at 8-14 minutes
# from a cold cache.
timeout-minutes: 40
steps:
- uses: actions/checkout@v4

- name: What docker is here
run: |
docker --version
echo "runner arch: $(uname -m)"

# The context is the repository root, because the image needs the
# software/ package: server.py imports software.c2.listeners and
# software.c2.stagers. Building with a context of software/c2 is
# exactly what made the image unable to start.
- name: Build software/c2/Dockerfile
run: |
docker build \
-f software/c2/Dockerfile \
-t raccoon-c2:ci \
.

# Not a smoke test of the entrypoint: this runs the module the way
# the entrypoint runs it, so every top-level import in server.py is
# executed. --help returns 0 and exits, which is all that is needed
# to prove the imports resolve inside the image.
- name: The server starts inside the image
run: |
docker run --rm --entrypoint python3 raccoon-c2:ci \
-m software.c2.server --help > /tmp/help.txt
echo "--- first lines of --help:"
head -5 /tmp/help.txt
grep -q -- "--operator-port" /tmp/help.txt

# Reported, not asserted. Which tools resolve depends on the
# runner's architecture -- NetExec has no aarch64 wheel and is
# allowed to be absent -- so this prints the truth rather than
# demanding a particular answer. The entrypoint's banner is built
# the same way for the same reason.
- name: What the image actually carries
run: |
docker run --rm --entrypoint sh raccoon-c2:ci -c '
for t in nmap xfreerdp xfreerdp3 vncviewer responder \
relayking nxc secretsdump.py; do
if command -v "$t" >/dev/null 2>&1; then
printf " %-18s %s\n" "$t" "$(command -v "$t")"
else
printf " %-18s absent\n" "$t"
fi
done
python3 - <<PY
import importlib
for name in ("impacket", "ldap3", "lsassy", "flask",
"cryptography", "requests_ntlm"):
try:
importlib.import_module(name)
except Exception as exc:
print(" %-18s ABSENT (%s)" % (name, type(exc).__name__))
else:
print(" %-18s ok" % name)
PY
'

# The compose file is the documented way to run this, and its build
# context is part of the defect that stopped the server from
# starting. A config parse catches a broken context or a renamed
# dockerfile path without a second full build.
- name: docker-compose.yml still resolves
working-directory: software/c2
run: docker compose config --quiet
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,20 @@ RACCOON_PORT=443 RACCOON_SSL=1 docker compose up -d
docker compose logs -f raccoon-c2
```

The Docker image (`python:3.12-slim`) includes all tools pre-installed:
Impacket, NetExec, Lsassy, RelayKing, and Responder. It runs with
`network_mode: host` and `NET_RAW`/`NET_ADMIN` capabilities (required for
Responder).
The Docker image (`python:3.12-slim-bookworm`) includes all tools
pre-installed: Impacket, Lsassy, RelayKing, and Responder, plus NetExec on
the architectures PyPI serves it for. The start-up banner lists what is
actually present rather than what is intended, so read it rather than this
paragraph. It runs with `network_mode: host` and `NET_RAW`/`NET_ADMIN`
capabilities (required for Responder).

The Debian release in that tag is deliberate. The image used to say
`python:3.12-slim`, which moved from Debian 12 to Debian 13 underneath it;
`freerdp2-x11` does not exist in 13, and the build stopped working for
everyone without a commit in this repository. NetExec is the one tool that
may be missing: its RDP library `aardwolf` publishes no Linux `aarch64`
wheel and wants a Rust toolchain, so on arm64 the install is skipped and
the image builds without it.

| Environment Variable | Default | Description |
|---------------------|---------|-------------|
Expand Down
6 changes: 5 additions & 1 deletion docs/AGENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,11 @@ more.
bounds or none at all, and no file pins an exact version. The
server image installs six packages with no version constraint at all and
builds NetExec, Responder and RelayKing from moving git branches with no
tag. A rebuild a month later is a different image.
tag. A rebuild a month later is a different image. The base image's
Debian release is now pinned, and that is not a fix for this: it was
pinned because `python:3.12-slim` had already moved from Debian 12 to
13, taking `freerdp2-x11` with it and breaking the build on every
architecture. The dependencies above are still unpinned.
- **Two dependencies are old, and neither is imported here.** `netifaces`
0.11.0 (May 2021) is its last release, and being a C extension it breaks on
new CPython rather than merely ageing. Nothing in the repository imports it:
Expand Down
56 changes: 47 additions & 9 deletions software/c2/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
FROM python:3.12-slim
# The Debian release is pinned, and that is not housekeeping. This file
# said `python:3.12-slim`, which moved from Debian 12 to Debian 13
# underneath it; `freerdp2-x11` does not exist in 13, and the build died
# at step 3 of 20 for everyone who cloned this repository. An unpinned
# base means the image's contents change without a commit here.
#
# Moving to trixie later means `freerdp3-x11`, whose binary is
# `xfreerdp3` and not `xfreerdp` -- server.py now looks up both names, so
# that move is a one-line change rather than a silently broken RDP button.
FROM python:3.12-slim-bookworm

LABEL maintainer="TrashPandaPaws" \
description="Raccoon C2 Team Server with Impacket, NetExec, RelayKing & Responder"

# python3-dev is here for the architectures PyPI has no wheel for. `arc4`,
# a NetExec dependency, publishes manylinux x86_64 wheels and no Linux
# aarch64 one, so pip compiles it from source on arm64 and needs Python.h.
# Without this the build succeeded on amd64 and failed on arm64, which is
# why it went unnoticed.
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc libffi-dev libssl-dev \
gcc libffi-dev libssl-dev python3-dev \
nmap iputils-ping net-tools \
git pipx \
freerdp2-x11 \
Expand All @@ -20,25 +34,49 @@ RUN pip install --no-cache-dir \
requests-ntlm

ENV PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/local/bin
RUN pipx install git+https://github.com/Pennyw0rth/NetExec
# NetExec is allowed to fail, and the `||` is the whole point. Its RDP
# library `aardwolf` has no Linux aarch64 wheel and wants a Rust
# toolchain; carrying cargo and compiling crates in a slim image for one
# optional tool is the wrong trade. So on an architecture PyPI serves, the
# tool is there; on one it does not, the image still builds and the
# entrypoint reports NetExec as missing instead of claiming it.
RUN pipx install git+https://github.com/Pennyw0rth/NetExec \
|| echo "NetExec not installed: no wheel for this architecture and no Rust toolchain in this image"

# Install Responder
#
# `ln -sf`, not `ln -s`. A plain link fails with "File exists" the moment
# pip installs its own console script at the same path, which means the
# step could only succeed when pip had FAILED.
RUN git clone --depth 1 https://github.com/lgandx/Responder.git /opt/Responder \
&& chmod +x /opt/Responder/Responder.py \
&& ln -s /opt/Responder/Responder.py /usr/local/bin/responder
&& ln -sf /opt/Responder/Responder.py /usr/local/bin/responder

# Install RelayKing
#
# This is where that bit us: `pip install -e .` started succeeding and
# installing a `relayking` entry point, so the following `ln -s` died on
# "File exists" and broke the build on every architecture. The
# `2>/dev/null` on the pip call hid which of the two branches had run.
RUN git clone --depth 1 https://github.com/depthsecurity/RelayKing-Depth.git /opt/RelayKing \
&& cd /opt/RelayKing && pip install --no-cache-dir -e . 2>/dev/null \
|| pip install --no-cache-dir -r /opt/RelayKing/requirements.txt \
&& ln -s /opt/RelayKing/relayking.py /usr/local/bin/relayking \
&& ln -sf /opt/RelayKing/relayking.py /usr/local/bin/relayking \
&& chmod +x /opt/RelayKing/relayking.py

WORKDIR /opt/raccoon-c2

COPY server.py .
COPY beacon.py .
COPY __init__.py .
# The whole package, not three flat files.
#
# This used to be `COPY server.py .` and two siblings, while server.py
# imports `software.c2.listeners` and `software.c2.stagers`. The image
# built and then died at start-up with "No module named 'software'" -- so
# the shipped team server could not run at all, on any architecture. The
# build context is the repository root (see docker-compose.yml), which is
# what the listener image already used.
COPY software/__init__.py ./software/
COPY software/c2/ ./software/c2/
ENV PYTHONPATH=/opt/raccoon-c2

RUN mkdir -p /data/raccoon-c2

Expand All @@ -52,7 +90,7 @@ EXPOSE 8443

VOLUME ["/data/raccoon-c2"]

COPY docker-entrypoint.sh /entrypoint.sh
COPY software/c2/docker-entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
10 changes: 9 additions & 1 deletion software/c2/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
services:
raccoon-c2:
build: .
build:
# The repository root, because the image needs the `software/`
# package: server.py imports `software.c2.listeners` and
# `software.c2.stagers`, and a context of this directory cannot
# COPY them. With the old context the image built and then died at
# start-up with "No module named 'software'". The listener service
# below has always used this context for the same reason.
context: ../..
dockerfile: software/c2/Dockerfile
container_name: raccoon-c2
restart: unless-stopped
network_mode: host
Expand Down
68 changes: 60 additions & 8 deletions software/c2/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,57 @@ echo -e "${D} ─────────────────────
echo ""

# Tool versions
#
# `_tool` reports what is actually there. The three lines below used to
# read `$(nxc --version 2>/dev/null || echo 'installed')`, which printed
# the word "installed" under a green tick for a tool that was absent --
# it claimed NetExec in an image deliberately built without it. A banner
# that cannot be wrong is worth more than one that is always green.
_tool() {
# $1 label, $2 command that must be on PATH, $3.. how to ask for a version
if ! command -v "$2" >/dev/null 2>&1; then
printf "%b [ ]%b %b%-13s%b %bnot installed%b\n" "$D" "$N" "$W" "$1" \
"$N" "$D" "$N"
return
fi
# The version is dug out, not trusted. Measured: `relayking --version`
# exits 1 and prints six lines of ASCII art before the version, and
# `responder --version` prints nothing at all -- so a plain `cmd | head
# -1 || echo unknown` showed an empty string for both, because head
# exits 0 whatever it read. Pull the first version-shaped token out of
# the output, strip the colour codes, and say "installed" when there is
# none rather than printing a blank.
local out ver
out="$("${@:3}" 2>/dev/null | sed 's/\x1b\[[0-9;]*m//g')"
ver="$(printf '%s' "$out" | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -1)"
printf "%b [✓]%b %b%-13s%b %b%s%b\n" "$G" "$N" "$W" "$1" "$N" "$D" \
"${ver:-installed}" "$N"
}

_pymod() {
# $1 label, $2 distribution name. The three module lines below used to
# print a hardcoded green tick beside this, so an absent package would
# have read "[✓] Lsassy not installed" -- the same defect as the one
# above, left in place by the first version of this fix.
local ver
ver="$(python3 -c "import importlib.metadata as m; print(m.version('$2'))" \
2>/dev/null)"
if [ -n "$ver" ]; then
printf "%b [✓]%b %b%-13s%b %b%s%b\n" "$G" "$N" "$W" "$1" "$N" "$D" \
"$ver" "$N"
else
printf "%b [ ]%b %b%-13s%b %bnot installed%b\n" "$D" "$N" "$W" "$1" \
"$N" "$D" "$N"
fi
}

echo -e "${G} [✓]${N} ${W}Python${N} ${D}$(python3 --version 2>&1)${N}"
echo -e "${G} [✓]${N} ${W}Flask${N} ${D}$(python3 -c 'import importlib.metadata; print(importlib.metadata.version("flask"))')${N}"
echo -e "${G} [✓]${N} ${W}Impacket${N} ${D}$(python3 -c 'import importlib.metadata; print(importlib.metadata.version("impacket"))')${N}"
echo -e "${G} [✓]${N} ${W}NetExec${N} ${D}$(nxc --version 2>/dev/null || echo 'installed')${N}"
echo -e "${G} [✓]${N} ${W}Lsassy${N} ${D}$(python3 -c 'import importlib.metadata; print(importlib.metadata.version("lsassy"))')${N}"
echo -e "${G} [✓]${N} ${W}RelayKing${N} ${D}$(python3 /opt/RelayKing/relayking.py --version 2>/dev/null || echo 'installed')${N}"
echo -e "${G} [✓]${N} ${W}Responder${N} ${D}$(python3 /opt/Responder/Responder.py --version 2>/dev/null || echo 'installed')${N}"
_pymod "Flask" flask
_pymod "Impacket" impacket
_tool "NetExec" nxc nxc --version
_pymod "Lsassy" lsassy
_tool "RelayKing" relayking python3 /opt/RelayKing/relayking.py --version
_tool "Responder" responder python3 /opt/Responder/Responder.py --version
echo ""

# RACCOON_HOST/PORT: the beacon socket. RACCOON_OPERATOR_HOST/PORT: the GUI
Expand All @@ -41,7 +85,7 @@ OPERATOR_PORT="${RACCOON_OPERATOR_PORT:-8444}"
OPERATOR_HOST="${RACCOON_OPERATOR_HOST:-127.0.0.1}"
DATA="${RACCOON_DATA:-/data/raccoon-c2}"

CMD=(python3 /opt/raccoon-c2/server.py
CMD=(python3 -m software.c2.server
--host "$HOST"
--port "$PORT"
--operator-host "$OPERATOR_HOST"
Expand All @@ -65,7 +109,15 @@ echo -e "${D} ┌────────────────────
echo -e "${D} │${N} ${C}Beacons${N} ${W}http://${HOST}:${PORT}${N}"
echo -e "${D} │${N} ${C}GUI${N} ${W}http://${OPERATOR_HOST}:${OPERATOR_PORT}${N}"
echo -e "${D} │${N} ${C}Data${N} ${W}${DATA}${N}"
echo -e "${D} │${N} ${C}Tools${N} ${W}impacket nxc lsassy relayking responder nmap${N}"
# Built from what is on PATH, not from a list written once. The fixed
# list claimed `nxc` in an image that had none.
_present=""
for _t in nmap nxc responder relayking xfreerdp xfreerdp3 vncviewer; do
command -v "$_t" >/dev/null 2>&1 && _present="${_present} ${_t}"
done
python3 -c "import impacket" 2>/dev/null && _present="${_present} impacket"
python3 -c "import lsassy" 2>/dev/null && _present="${_present} lsassy"
echo -e "${D} │${N} ${C}Tools${N} ${W}${_present# }${N}"
echo -e "${D} └──────────────────────────────────────────────┘${N}"
echo ""

Expand Down
14 changes: 13 additions & 1 deletion software/c2/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,19 @@ def api_server_rdp():
return jsonify({"error": "target required"}), 400

if mode == "xfreerdp":
cmd_parts = ["xfreerdp"]
# Looked up, not assumed. freerdp2 ships `xfreerdp` and
# freerdp3 ships `xfreerdp3`; this used to hardcode the former,
# so moving the image's Debian base -- which happened once
# already, unnoticed -- would leave the RDP button failing at
# runtime for an operator to discover. The VNC branch below
# has always probed its viewer names; this now matches it.
client = next(
(name for name in ("xfreerdp", "xfreerdp3")
if shutil.which(name)), None)
if client is None:
return jsonify({"error": "No RDP client found (install "
"freerdp2-x11 or freerdp3-x11)"}), 400
cmd_parts = [client]
cmd_parts.append(f"/v:{target}")
if port:
cmd_parts.append(f"/port:{port}")
Expand Down
12 changes: 11 additions & 1 deletion software/tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,21 @@ def _nothing_is_pinned():
_read("software", "tests", "requirements.txt")]
image = _read("software", "c2", "Dockerfile")
pip_block = image.split("RUN pip install", 1)[1].split("\n\n", 1)[0]
# The third clause used to be `re.search(r"NetExec\s*$", image, re.M)`:
# the NetExec line happening to end the line was read as "its git ref
# carries no tag". Adding a `\` continuation to that line defeated the
# probe without changing a thing about pinning, and the suite reported
# this finding as fixed. So ask the question the finding actually
# asks -- are the three source builds pulling a moving ref? -- which a
# reformat cannot answer differently.
sources = re.findall(r"(?:git\+https://|https://)github\.com/\S+", image)
moving = [url for url in sources
if "@" not in url.split("github.com/", 1)[1]]
return (not any("==" in line for text in reqs
for line in text.splitlines()
if not line.lstrip().startswith("#"))
and not re.search(r"[<>=]", pip_block)
and re.search(r"NetExec\s*$", image, re.M) is not None)
and len(moving) >= 3)


def _the_old_dependencies_are_still_declared():
Expand Down
Loading
Loading