latest run 54 pass 0 fail 0 skipevidence →
HKB Operations: pages
HKB OperationsKnowledge space

Starred pages

Pages

Page directory · Labels · [ hides this

Detection test

A CodeBuild job in Sandbox that once a month makes a short-lived EC2 instance act like a compromised host, so GuardDuty raises a real finding. It shows detection works end to end, not only that it is configured.

Flow

Detection test flowOn the first Wednesday of the month at 10:00 Denver time, EventBridge Scheduler in the Sandbox account starts the hkb-detection-test CodeBuild project. The job starts one t4g.nano instance in private subnet A. Over Session Manager the instance looks up GuardDuty's test domain, then the job reads the instance's role credentials and uses them from CodeBuild, outside the instance, for two read-only API calls, and terminates the instance. GuardDuty in Sandbox sees the DNS query and the credential use. Its findings go to Security Hub and the alert event bus in the Security account, where control test TL-02 reads them.AWS CloudSandbox · hkb-sandboxSecurity · hkb-securityPrivate subnet Avia the NAT instanceSchedulerfirst Wednesdayhkb-detection-testCodeBuild, 20 minSTS and EC2 APIstwo read-only callsTest instancet4g.nano, minutesGuardDutySandbox detectorEvent busalert emailSecurity HubTL-02 reads the findingThe instance shuts itself down after 30 minutes if the job dies. Credentials are never logged.Job logs: /aws/codebuild/hkb-detection-test, kept 90 days. 2 retries if a run fails.Legend1Request or run orderRequest / dataEvent / logAttached / governsBlueOpens its pagestarts1starts, terminates2test-domain lookup3its credentials4uses them, outside5sees the callsfindings6High findings
Detection test flowOpen full sizeClose

The instance lives for minutes. The finding is the evidence, read from Security Hub by control test TL-02.

Configuration

SettingValue
ScheduleEventBridge Scheduler, the first Wednesday of the month at 10:00 Denver time, inside the NAT instance's weekday hours so the instance can reach Systems Manager; 2 retries. The scheduler's role, hkb-detection-test-schedule, may only start this project
JobCodeBuild project hkb-detection-test, no source, 20-minute timeout. It runs outside the VPC: GuardDuty's credential finding looks for use from an address other than the instance's, and Sandbox's own NAT address would not count
InstanceOne t4g.nano on the latest Amazon Linux 2023 image, IMDSv2 required, no public IP, in private subnet A behind the NAT instance. A trap terminates it when the job ends, pass or fail, and it shuts itself down (and terminates) after 30 minutes if the job dies
ActivityOver Session Manager, the instance resolves guarddutyc2activityb.com, the test domain GuardDuty's documentation gives for this purpose. The job then reads the instance's role credentials from its metadata service and calls sts:GetCallerIdentity and ec2:DescribeInstances with them from CodeBuild. The log records the role's ARN and counts, never the credentials
Expected findingsBackdoor:EC2/C&CActivity.B!DNS is required. InstanceCredentialExfiltration is reported when it fires, not required: AWS does not say whether CodeBuild's addresses count as outside the account, and GuardDuty may learn a repeating source
EvidenceControl test TL-02 needs the DNS finding from Sandbox in Security Hub within the last 36 days, and the schedule enabled. One or two GuardDuty alert emails a month are expected
Latest resultControl test TL-02, PASS in the 2026-11-15 evidence snapshot: 1 test-domain and 1 credential finding(s) from Sandbox in the last 36 days
Job rolehkb-detection-test: start, command and terminate its own instance, pass only the instance role, read the image parameter, write its own logs. The policy pins the subnet, the hkb-net-nat-clients security group, Amazon-owned images, the instance type and IMDSv2
Boundaryhkb-detection-boundary (9 statements), the organization's first write-capable permissions boundary. Writes stay in this account and Region; it denies any instance type but t4g.nano, and terminating or commanding any instance not tagged Component=detection-test
Instance rolehkb-detection-target, under hkb-workload-boundary: Session Manager's agent and ec2:DescribeInstances, nothing else, since its credentials outlive the instance by up to six hours
Pentest policyNo command-and-control server is hosted, and the activity is EC2 in HKB's own account. AWS's penetration testing policy permits testing EC2; it doesn't address this kind of test directly, so this is HKB's reading
Logs/aws/codebuild/hkb-detection-test, kept 90 days
CostUnder a cent or two a month: minutes of a t4g.nano and of CodeBuild
Deployed byThe hkb-baseline-detection-test StackSet, to Sandbox only, us-east-1

Sources

  • Templates and scripts: baseline/hkb-baseline-detection-test.yaml, verify/hkb-verify.sh
  • Decisions: DQ-139, DQ-141, DQ-142

Page information

Owner
Platform Engineering
Status
current Current: generated from the templates and records in the repository at this build.
Generated from
baseline/hkb-baseline-detection-test.yaml
Linked from
Findings review, Sandbox, Prowler, hkb-forward-guardduty-findings