Environmental keying is a technique that restricts agent execution to specific systems. If the keying check fails, the agent will exit immediately and silently without executing any code or attempting to connect to the C2 server.
The agent will only execute if the machine's hostname matches the specified value.
**Use Case:** When you know the exact hostname of your target system.
**Example:** If you set the keying value to `WORKSTATION-01`, the agent will only run on a machine with that exact hostname.
**Security:** Secure (hash-based)
#### 2. Domain Keying
The agent will only execute if the machine's domain name matches the specified value. Domain matching is forgiving and checks both the full domain and individual parts.
**Use Case:** When targeting systems within a specific Active Directory domain.
**Example:** If you set the keying value to `CONTOSO`, the agent will match:
- **Hash-Based Storage (Hostname/Domain/Registry-Matches):** The keying value is never stored in plaintext in the agent binary. Instead, a SHA256 hash of the uppercase value is embedded
- **Plaintext Storage (Registry-Contains):** ⚠️ When using Registry keying with "Contains" mode, the value is stored in **plaintext** in the binary - easily extractable
- **Uppercase Normalization:** All values (except Registry-Contains mode) are converted to uppercase before hashing to ensure consistent matching regardless of case
- **Runtime Hashing:** During execution, the agent hashes the current hostname/domain/registry-value and compares it to the stored hash
- **Forgiving Domain Matching:** For domain keying, the agent checks:
1. The full domain name (e.g., `CORP.CONTOSO.LOCAL`)
2. Each part split by dots (e.g., `CORP`, `CONTOSO`, `LOCAL`)
### Example Scenarios
**Scenario 1: Targeted Workstation**
```
Enable Keying: Yes
Keying Method: Hostname
Keying Value: FINANCE-WS-42
```
This agent will only execute on the machine named `FINANCE-WS-42`.
**Scenario 2: Domain-Wide Campaign**
```
Enable Keying: Yes
Keying Method: Domain
Keying Value: CONTOSO
```
This agent will execute on machines where the domain contains `CONTOSO`: