The programs are the ones that the lessons build. They read a snapshot folder (account by default) and send nothing to any cloud.
Map an account (lesson 1)
| Task | Command |
|---|
| Make the snapshot of the lab account | python3 gen_account.py (seed 2 in another folder: python3 gen_account.py 2 account2) |
| Count resources by service and region, list what is outside the approved regions | python3 account_map.py [folder] |
| Read an ARN | arn:partition:service:region:account:resource, for example arn:aws:iam::111122223333:user/alice.morgan |
| Split an ARN in Python | arn.split(":", 5) |
Decide a request (lesson 2)
| Task | Command |
|---|
| Decide every request of the snapshot | python3 policy_eval.py [folder] |
| Decide one request in Python | decide(policies, {"action": ..., "resource": ..., "context": {...}}) |
| The order | A matching Deny wins (explicit deny). Else a matching Allow. Else no (implicit deny). |
| Same account | An Allow on the identity or on the resource is enough |
| Different accounts | Both sides must allow |
| Deny when MFA is missing | "BoolIfExists": {"aws:MultiFactorAuthPresent": "false"} |
Find policies that give too much (lesson 3)
| Task | Command |
|---|
| Audit users, roles and policies | python3 iam_audit.py [folder] (exit code 1 on critical or high) |
| Audit one policy file | python3 iam_audit.py --policy FILE |
| Test a policy against must-allow and must-not-allow lists | python3 policy_test.py POLICY.json [TESTS.json] |
| Patterns to look for | "Action": "*", "service:*" on "*", iam:PassRole on *, a trust policy for "AWS": "*" with no condition |
Keys (lesson 4)
| Task | Command |
|---|
| Age and last use of every access key | python3 key_report.py [folder] [today] |
| Find key IDs by hand | grep -rnoE "(AKIA|ASIA)[A-Z0-9]{16}" FOLDER |
| Scan a folder and name the owner of each key | python3 scan_keys.py [folder] [iam-folder] (exit code 1 on a finding) |
| Tell the key types apart | AKIA... long-lived, ASIA... temporary |
Storage (lesson 5)
| Task | Command |
|---|
| Decide which buckets are public, and why | python3 buckets.py [FILE] (exit code 1 when one is public by mistake) |
| Stop public ACLs that exist | IgnorePublicAcls |
| Stop a public policy that exists | RestrictPublicBuckets |
| Refuse new public ACLs and policies | BlockPublicAcls, BlockPublicPolicy |
| Refuse plain HTTP | A Deny with "Bool": {"aws:SecureTransport": "false"} |
Network (lesson 6)
| Task | Command |
|---|
| List the ports that the internet can reach | python3 reach.py [FILE] (exit code 1 on a port that is not expected) |
| Ask who can reach one port of one instance | python3 reach.py FILE INSTANCE PORT |
| Security group | Around a machine, allow rules only, stateful |
| Network ACL | Around a subnet, allow and deny, lowest number first, stateless |
Audit log (lesson 7)
| Task | Command |
|---|
| Print the risky calls and the gaps | python3 trail.py [folder] |
| Timeline of one address | python3 trail.py FOLDER --ip ADDRESS |
| Timeline of one access key | python3 trail.py FOLDER --key ACCESS_KEY_ID |
| Fields to read first | eventTime, userIdentity, eventSource, eventName, sourceIPAddress, errorCode, requestParameters |
| Sign-in without MFA | eventName ConsoleLogin, additionalEventData.MFAUsed No |
| Task | Command |
|---|
| Start the mock on your own machine | python3 imds_mock.py optional 8700 > imds.log 2>&1 & then echo $! > imds.pid |
| Stop it | kill $(cat imds.pid) |
| Get a session token | curl -s -X PUT -H "X-aws-ec2-metadata-token-ttl-seconds: 60" http://127.0.0.1:8700/latest/api/token |
| Use the token | curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://127.0.0.1:8700/latest/meta-data/instance-id |
| Judge a list of URLs without any traffic | python3 safe_fetch.py --list FILE |
| Print only the status code | curl -s -o /dev/null -w "%{http_code}\n" URL |
Keys for encryption (lesson 9)
| Task | Command |
|---|
| Make a lab key | python3 kms_mock.py create NAME |
| Rotate, disable or enable it | python3 kms_mock.py rotate NAME, disable NAME, enable NAME |
| Encrypt a file with a data key | python3 envelope.py encrypt FILE ROLE |
| Decrypt it | python3 envelope.py decrypt FILE.sealed ROLE |
Infrastructure as code (lesson 10)
| Task | Command |
|---|
| Make a plan file in the Terraform JSON shape | python3 gen_plan.py [seed] [file] |
| Scan a plan with rules | python3 iac_scan.py [PLAN] [RULES] (exit code 1 on high) |
| Use the scan as a gate | python3 iac_scan.py > scan.txt && echo APPLY || echo STOP |
Containers (lesson 11)
| Task | Command |
|---|
| Check manifests for settings that break isolation | python3 k8s_check.py [folder] (exit code 1 on high) |
| Settings to look for | privileged, hostNetwork, hostPID, hostPath, no runAsNonRoot, the tag latest, no limits |
Incident response (lesson 12)
| Task | Command |
|---|
| Plan the response to a leaked key | python3 respond.py FOLDER ACCESS_KEY_ID [NOW] |
| Check sealed evidence | (cd FOLDER-response/evidence && sha256sum -c SHA256SUMS) |
| The order | Key inactive, scope in the log, end role sessions, close new doors, logging on, snapshot then stop, undo changes, new credential last |
| The calls | aws iam update-access-key --user-name USER --access-key-id KEY_ID --status Inactive, aws iam put-role-policy --role-name ROLE --policy-name revoke-sessions --policy-document file://revoke.json, aws ec2 create-snapshot --volume-id VOLUME_ID, aws ec2 stop-instances --instance-ids ID (not run in this course) |
Posture (lesson 13)
| Task | Command |
|---|
| Rank the findings of an account and write a report | python3 posture.py [folder] [report.md] (exit code 1 on critical) |
| The score | critical 9, high 6, medium 3, low 1, and 3 more when the internet can use it today |
Where each file comes from in a real account
The course reads snapshot files. In an account you make them with the AWS CLI. This course does not run these calls: they need an account. The real answers have AWS's own shape: a short script joins them into the shape of this course (lessons 2, 5, 6 and 7 say where). requests.json, cross.json, ci-usage.json and ci-tests.json are invented for the exercises.
| Snapshot file | Calls in a real account |
|---|
inventory.json | AWS Config or AWS Resource Explorer (lesson 1, Field notes) |
iam.json | aws iam get-account-authorization-details |
| key age and last use | aws iam generate-credential-report, then aws iam get-credential-report |
buckets.json | aws s3api get-bucket-policy, get-bucket-acl, get-bucket-encryption and get-public-access-block (each with --bucket NAME), and aws s3control get-public-access-block --account-id ID |
network.json | aws ec2 describe-security-groups, describe-network-acls, describe-route-tables, describe-instances |
trails.json | aws cloudtrail describe-trails, aws cloudtrail get-trail-status --name TRAIL |
events.json | aws cloudtrail lookup-events (management events, last 90 days, one region), or the log files in the bucket of the trail |
Safety habits
- Work on snapshots and on your own machine. Never send a test request to an account or a system that is not yours.
- No long-lived key where a role can do the job. No key in code, logs, images or reports.
- Print a key ID in full and never more than the start of a secret.
- In an incident, choose the action that can be undone: inactive before delete, stop before terminate, snapshot first.
- Read both sides: the policy of the identity and the policy of the resource.
- A missing security setting counts as wrong until someone writes the safe value.
- Say what the log cannot show. "Unknown" is a finding.
- Take defaults and limits from the provider's current documentation, not from memory.