Deploying Canarytokens for Early Intrusion Detection: Trapping Documents, API Keys, and Database Credentials

Security tutorial - IT technology blog
Security tutorial - IT technology blog

The 2 AM Reality Check: Why Perimeter Alerts Arrive Too Late

It is 2:14 AM, and your pager goes off. You flip open your laptop, squint at the terminal, and start grepping through /var/log/auth.log and Nginx access logs. Someone bypassed your perimeter. Maybe they phished a developer’s VPN token, or an unpatched microservice leaked an environment variable. By the time your SIEM correlates enough failed requests to page you, the intruder has been mapping your jump host for 40 minutes.

A midnight SSH brute-force incident taught me to lock down new servers from day one. Tightening SSH configs, restricting firewall rules, and patching packages are basic hygiene. Still, a live 2 AM breach exposes a harsh reality: perimeter tools only catch attackers who kick down the front door. Once someone slips in with valid credentials, they move quietly—listing directories, reading configs, and hunting for database strings.

Deception engineering closes that gap. Instead of waiting for an attacker to trip a noisy signature, you plant realistic decoys—Canarytokens—right where an intruder expects to find high-value targets.

How Canarytokens Work: Tripwires for Intruders

Picture a Canarytoken as a digital dye pack. It looks like an ordinary asset: a Word file, an AWS access key, a MySQL config, or an internal URL. Embedded inside is a unique identifier tied to a callback endpoint. The moment someone opens that file, resolves that hostname, or tests that credential, the token phones home. You immediately get the source IP, timestamp, User-Agent, and the exact memo you attached.

Traditional intrusion detection systems often flood on-call engineers with hundreds of false positives a week. Canarytokens produce almost zero noise. No legitimate CI/CD pipeline, cron job, or developer has any reason to open Q4_Executive_Bonuses.docx inside an obscure backup folder. Nor will a healthy service authenticate with a fake key in /opt/legacy/.env.bak. If that alert fires at 2 AM, someone—or their script—is poking around where they do not belong.

To cover the first places attackers look during post-exploitation, deploy three core traps:

  • Sensitive Documents: Decoy PDFs or DOCX files with hidden DNS or web-bug callbacks that fire when opened.
  • API Keys and Cloud Credentials: Fake AWS IAM keys or bearer tokens that alert when an attacker runs aws sts get-caller-identity.
  • Database Credentials: Decoy connection strings pointing to a Canarytoken DNS hostname, triggering an alert on lookup.

Hands-On: Deploying Canarytokens Across Your Infrastructure

Thinkst hosts a free public instance at canarytokens.org for quick experiments. For production environments, however, self-host the server so internal hostnames and alert metadata never leave your network.

Step 1: Self-Hosting Canarytokens with Docker

Provision a dedicated utility VM with Docker and Docker Compose, and make sure UDP/TCP port 53 plus ports 80 and 443 are reachable. Clone the official repository and copy the sample environment files:

git clone https://github.com/thinkst/canarytokens-docker.git
cd canarytokens-docker
cp frontend.env.dist frontend.env
cp switchboard.env.dist switchboard.env

Open frontend.env and switchboard.env to set your callback domain, such as tokens.internal.company.com. Point an NS record for that subdomain to your Docker host so DNS tokens resolve directly to Switchboard. Then launch the stack:

docker compose up -d
docker compose ps

After the containers report healthy, open the web UI and configure Webhook or Slack alerts. Trigger a quick test notification to confirm messages land in your incident channel.

Step 2: Planting Decoy API Keys and AWS Credentials

Intruders almost always sweep home directories and old deployment folders for cloud keys first. Note that AWS API key tokens require either Thinkst’s hosted service or an AWS CloudTrail/SQS integration on your self-hosted stack. Generate an AWS Keys token with a specific memo like prod-bastion-01 /home/ubuntu/.aws/credentials.

Save the generated key pair in a believable path on your bastion or app server:

mkdir -p /opt/backups/legacy-app
cat <<'EOF' > /opt/backups/legacy-app/.env.old
APP_ENV=staging
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
AWS_DEFAULT_REGION=us-east-1
EOF
chmod 600 /opt/backups/legacy-app/.env.old

Test the tripwire from a separate machine using boto3 (or the AWS CLI) to verify your alert channel fires:

import boto3

client = boto3.client(
    "sts",
    aws_access_key_id="AKIAIOSFODNN7EXAMPLE",
    aws_secret_access_key="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
    region_name="us-east-1",
)

try:
    print(client.get_caller_identity())
except Exception as exc:
    print("Expected auth failure, check Canarytokens alert:", exc)

CloudTrail-backed alerts typically arrive within 15 to 60 seconds, delivering the caller’s source IP and user agent.

Step 3: Trapping Sensitive Documents

Servers are rarely the final stop; attackers also pillage spreadsheets and architecture docs from shared drives and S3 buckets. In the Canarytokens UI, pick Microsoft Word Document or Acrobat Reader PDF. Give it a tempting memo like NAS Share - Network_Passwords_2026.docx, then download the file.

Drop the document onto an internal Samba share, Confluence page, or admin backup folder. Keep it out of directories scanned by antivirus engines or backup indexers, or add an exclusion so scanners do not trigger false alarms. When an intruder exfiltrates the file and opens it in Word or Adobe Acrobat on an internet-connected machine, the embedded DNS callback resolves and exposes their external IP.

Step 4: Setting Up Decoy Database Credentials

Files like ~/.my.cnf or DATABASE_URL configs are prime targets when an attacker wants to dump customer tables. Create a DNS Token with the memo app-node-03 decoy postgres uri. Canarytokens will generate a unique hostname like a1b2c3d4.tokens.internal.company.com.

Embed a realistic decoy connection string inside a dormant config file or legacy script:

cat <<'EOF' > /var/www/html/config.php.bak
<?php
// Legacy analytics DB - do not remove
define('DB_HOST', 'a1b2c3d4.tokens.internal.company.com');
define('DB_NAME', 'analytics_prod');
define('DB_USER', 'svc_analytics_ro');
define('DB_PASS', 'Tr0ub4dor&3!2026');
EOF

Confirm the DNS tripwire works from your terminal before leaving it behind:

dig +short a1b2c3d4.tokens.internal.company.com

The moment an attacker pastes that hostname into psql, mysql, or a recon script, the DNS lookup fires your webhook—before a TCP handshake even starts.

Wrapping Up Your Early-Warning System

Catching an intruder while they are still enumerating hosts beats waking up to a ransomed database. Canarytokens add lightweight, low-noise tripwires across documents, API keys, and database configs without installing agents on every server.

To make this stick in production, route your Canarytokens webhook straight into the Slack or PagerDuty channel your on-call team monitors. Keep an encrypted inventory of every planted token so engineers do not trip them during audits. Most importantly, treat any real trigger as a high-priority incident: isolate the host and rotate credentials immediately.

Share: