Skip to content
Open
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
5 changes: 5 additions & 0 deletions Payload_Type/crypto_provider/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.build
.git
.env
.env.*
!.env.example
10 changes: 10 additions & 0 deletions Payload_Type/crypto_provider/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Mythic supplies these settings to installed service containers.
RABBITMQ_HOST=mythic_rabbitmq
RABBITMQ_PORT=5672
RABBITMQ_USER=mythic_user
RABBITMQ_PASSWORD=
RABBITMQ_VHOST=mythic_vhost
# RABBITMQ_URL may replace the individual connection settings.
# RABBITMQ_URL=amqp://user:password@127.0.0.1:5672/mythic_vhost
EXAMPLE_CRYPTO_PROVIDER_NAME=example_crypto
EXAMPLE_CRYPTO_RPC_TIMEOUT=20s
4 changes: 4 additions & 0 deletions Payload_Type/crypto_provider/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.build/
.env
.env.*
!.env.example
18 changes: 18 additions & 0 deletions Payload_Type/crypto_provider/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:1.27.2-bookworm AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -buildvcs=false -trimpath -o /out/crypto-provider .

FROM debian:bookworm-slim
RUN apt-get update && apt-get install --yes --no-install-recommends ca-certificates \
&& rm -rf /var/lib/apt/lists/* \
&& touch /usr/local/bin/.env \
&& chmod 0444 /usr/local/bin/.env \
&& useradd --system --uid 65532 --no-create-home --shell /usr/sbin/nologin provider
COPY --from=build /out/crypto-provider /usr/local/bin/crypto-provider
COPY NOTICE /usr/share/doc/crypto-provider/NOTICE
WORKDIR /Mythic
USER 65532:65532
ENTRYPOINT ["/usr/local/bin/crypto-provider"]
10 changes: 10 additions & 0 deletions Payload_Type/crypto_provider/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.PHONY: build test run

build:
CGO_ENABLED=0 go build -buildvcs=false -trimpath -o .build/crypto-provider .

test:
go test -race ./...

run: build
.build/crypto-provider
10 changes: 10 additions & 0 deletions Payload_Type/crypto_provider/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
The transport, service, storage, and wire-check scaffolding originated in
mythic-beaconcrypt under the following BSD Zero Clause terms:

BSD Zero Clause License

Copyright (C) 2026 by 0xd6cb6d73 72226198+0xd6cb6d73@users.noreply.github.com

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
85 changes: 85 additions & 0 deletions Payload_Type/crypto_provider/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Crypto provider skeleton

This standalone Go service shows the Mythic crypto-provider API without a particular cryptographic implementation. It registers `example_crypto`, advertises the `example` scheme and explicitly rejects the four protocol methods with `not_implemented`. Replace `internal/provider` with your implementation before building an agent that selects it.

This example requires [Mythic's crypto-provider API v1](https://github.com/0xd6cb6d73/Mythic/blob/crypto-shim/mythic-docker/src/crypto/provider/README.md). The pinned MythicContainer SDK supplies RabbitMQ transport and request authorization, but does not yet have a crypto service registration API. The small adapter here supplies that lifecycle; it does not register a payload type or C2 profile.

## Files to keep and files to replace

| Path | Purpose |
| --- | --- |
| `main.go` | Load provider configuration, connect the backend to the service, and stop on SIGTERM. |
| `internal/provider` | Replace this package with your protocol, agent configuration, key handling, state ownership and limits. |
| `internal/service` | Shared configuration, registration, authorization checks and process lifecycle. |
| `internal/transport` | SDK adapter, exclusive queues, bounded concurrent RPC and reply handling. |
| `internal/storage` | Authenticated client for Mythic's optional opaque state store. |
| `internal/wirecheck` | Checks API messages and storage requests against the rules and limits in Mythic's API document. |

The SDK package `github.com/MythicMeta/MythicContainer/cryptoproviderstructs`, imported as `wire`, supplies the API v1 message types, method names, failure outcomes and routing key. It does not validate messages: `internal/wirecheck` holds this service's checks and limits, which follow Mythic's API document. Mythic still validates every message itself.

The generic files are also used by `mythic-beaconcrypt`; its provider package adapts the Beaconcrypt engine behind the same `service.Backend` interface. Cryptographic algorithms, native libraries and their build dependencies belong in the replaceable provider package and its Docker build.

## Run and install

Run `make test` for the native-free tests, or `make build` to build the service. For a local broker, export `RABBITMQ_URL` or the connection settings shown in `.env.example`, then run `make run`. The SDK also reads an `.env` file beside the executable. The Dockerfile pre-creates that file and runs the binary as an unprivileged user.

To install only this example, stage a small service repository. From the `ExampleContainers` checkout:

```sh
install_root=$(mktemp -d)
mkdir -p "$install_root/Payload_Type"
cp -R Payload_Type/crypto_provider "$install_root/Payload_Type/crypto_provider"
cat > "$install_root/config.json" <<'JSON'
{
"exclude_payload_type": false,
"exclude_c2_profiles": true,
"exclude_documentation_payload": true,
"exclude_documentation_c2": true,
"exclude_documentation_wrapper": true,
"exclude_agent_icons": true
}
JSON
/path/to/Mythic/mythic-cli install folder "$install_root"
rm -rf "$install_root"
```

The installer copies the service before the temporary directory is removed. Installing the entire ExampleContainers repository installs its other examples too. For your own repository, keep this `config.json` and `Payload_Type/<your_service>/` layout, and use `mythic-cli install github <repository-url>`.

Mythic supplies the `RABBITMQ_*` settings to installed containers. `EXAMPLE_CRYPTO_PROVIDER_NAME` defaults to `example_crypto`; `EXAMPLE_CRYPTO_RPC_TIMEOUT` defaults to `20s`. The pinned SDK supports `amqp` URLs. Restart the container after changing connection configuration.

## Required provider lifecycle

`service.Run` starts exclusive provider, resync and startup queues before announcing the service with `consuming_container_sync`. Registration includes `type: crypto`, a version and capabilities; the business route is `<registered-name>_crypto_provider_rpc`. The resync queue re-announces the same definition. Startup notifications do not supply a credential to retain, and constructing a backend does not read or write state.

Every business request carries the transient Mythic authorization context in both its RabbitMQ header and JSON body. The service checks that they agree before calling the backend. Preserve the supplied `context.Context` for every storage RPC, echo `auth_context`, `request_id` and `operation_scope_id` in responses, and never persist or log the authorization context. It changes between attempts and is excluded from request digests.

The SDK owns the connection and outgoing RPC correlation. The adapter processes a bounded number of business requests concurrently so one operation cannot block all other operations. It terminates the worker after connection loss or an uncertain transport timeout; let the container supervisor start a fresh process.

## Implementing the protocol

`internal/provider.Provider.Handle` is the dispatch point:

| Method | Required implementation |
| --- | --- |
| `prepare_profile` | Create or restore a provider profile and return an opaque profile reference and agent configuration. |
| `begin_session` | Authenticate the agent's initial message and routing claims, establish a session, and return its reply and opaque session identity. |
| `open` | Authenticate and decrypt one incoming message within the selected operation and session. |
| `seal` | Encrypt and authenticate one outgoing message within that session. |

Validate every request before processing. Honor the advertised size limit and result-retention interval, and preserve the operation scope when looking up profiles, sessions and request IDs. Keep cryptographic formats opaque to Mythic. A `rejected` failure promises there is no unresolved cryptographic effect; after an ambiguous stateful effect, return `unresolved`. Mythic retries with the same request ID; answer that retry from the saved result instead of repeating the work. Capabilities are sent once, in the registration message; there is no method that asks for them again.

This skeleton advertises `volatile` session persistence because it has no durable implementation. It creates no profiles or sessions and does not claim usable encryption. A real implementation must provide repeatable outcomes for repeated request IDs, reject reuse with changed inputs, and decide whether session state survives a worker restart. Advertise `durable` only when that promise is implemented.

The optional `storage.Store` passed to `provider.New` stores opaque provider state and exact operation results through Mythic RPC. It has three methods. `Load` reads one row. `Commit` changes any number of rows in one namespace atomically: it lists expectations (a row at a revision, or absent), the rows to write, and optionally the request's result. `LookupResult` (`get_result`) returns the result saved for a request ID and digest. For a durable implementation, scope state keys to the Mythic operation, call `LookupResult` before doing any work, and commit the state change and its result together, expecting the revisions you read. A `precondition_failed` commit applied nothing: another writer changed a row, so read again and repeat the step. Keep every row bounded; storage has no method that deletes one. Storage `request_id` values identify transport calls; the immutable operation request ID and input digest identify the cryptographic effect. State access must use the current authenticated request context, so the example performs no storage calls at startup. Mythic's API document describes stateless, single-snapshot and per-session-row layouts.

## Agent-side integration

Installing this service supplies the server half of a protocol. The agent needs its own matching implementation and compile-time configuration. Use the qualified selection `provider:<registered-name>:<scheme>`; for this skeleton that is `provider:example_crypto:example`. Return only the agent configuration your protocol needs from `prepare_profile`.

The payload container must advertise `supported_crypto_schemes: ["example"]` in its payload-type sync definition. These are bare scheme names, independent of the provider worker's registered name. Mythic passes the profile's opaque `agent_config` bytes to the builder as the base64 string `provider_config`; decode it before parsing the provider-specific configuration, and embed it for the selected C2 profile.

For an agent with a provider registry, add the provider's session implementation, register its scheme, and connect its target-specific build preparation and configuration parsing. Profiles should use the shared crypto session interface rather than compare the provider name to a particular library. Do not add Beaconcrypt dependencies or checks to a different provider's agent plumbing.

## License

The original scaffold is available under the BSD Zero Clause terms reproduced in `NOTICE`. Keep this notice when copying the example into a new repository.
35 changes: 35 additions & 0 deletions Payload_Type/crypto_provider/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module github.com/MythicMeta/ExampleContainers/Payload_Type/crypto_provider

go 1.26.0

require (
github.com/MythicMeta/MythicContainer v1.7.0-rc5
github.com/google/uuid v1.6.0
github.com/rabbitmq/amqp091-go v1.14.0
)

require (
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/rs/zerolog v1.34.0 // indirect
github.com/sagikazarmark/locafero v0.12.0 // indirect
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/spf13/viper v1.21.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/net v0.60.0 // indirect
golang.org/x/sys v0.48.0 // indirect
golang.org/x/text v0.42.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect
google.golang.org/grpc v1.83.1 // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
)

replace github.com/MythicMeta/MythicContainer => github.com/0xd6cb6d73/MythicContainer v1.7.0-rc5.0.20261204124904-4cc80093d035
Loading