เป้าหมาย
เปิดชุดบริการตรวจจับให้ครอบคลุมทั้ง organization แบบรวมศูนย์ เข้าใจว่าแต่ละตัวตอบคำถามอะไร ส่ง finding ร้ายแรงไปหาคนอัตโนมัติ และมี playbook รับมือเหตุที่เจอบ่อยที่สุด: access key หลุด
แต่ละบริการตอบคำถามอะไร
| บริการ | คำถาม | ข้อมูลจาก |
|---|---|---|
| CloudTrail | "ใครทำอะไร เมื่อไร จากไหน" | API call ทุกตัว (management events ฟรี 90 วันใน Event history) |
| GuardDuty | "มีพฤติกรรมเหมือนถูกโจมตีไหม" | CloudTrail, VPC Flow Logs, DNS logs, EKS/S3/RDS/Lambda/malware protection plans |
| Config | "ตอนนี้และเมื่อวานตั้งค่าเป็นอย่างไร ผิดกฎไหม" | บันทึก configuration item ทุกครั้งที่ resource เปลี่ยน + rules |
| Security Hub CSPM | "ผ่านมาตรฐาน (เช่น AWS Foundational Security Best Practices, CIS) แค่ไหน" | ตรวจด้วย Config rules + รวม finding รูปแบบ ASFF |
| Security Hub (ตัวใหม่) | "ความเสี่ยงไหนสำคัญสุด เมื่อเอาสัญญาณมารวมกัน" | correlate GuardDuty, Inspector, CSPM, Macie ใช้รูปแบบ OCSF |
| Inspector | "มีช่องโหว่ CVE ใน EC2/ECR image/Lambda ไหม" | สแกนต่อเนื่อง |
| IAM Access Analyzer | "อะไรเปิดให้นอก org เข้าถึง / สิทธิ์ไหนไม่เคยถูกใช้" | วิเคราะห์ policy |
| Macie | "มี PII อยู่ใน S3 bucket ไหน" | สแกนเนื้อหา S3 |
ตั้งแต่กลางปี 2025 (ตอนเปิด Security Hub ใหม่แบบ preview 17 มิ.ย. 2025) Security Hub เดิมเปลี่ยนชื่อเป็น "Security Hub CSPM" และชื่อ "Security Hub" ใช้กับบริการใหม่ที่ GA เมื่อ 2 ธ.ค. 2025 — สองตัวใช้รูปแบบ finding ต่างกัน (ASFF vs OCSF) และ automation rule ไม่ sync กัน ใน CLI ตัว CSPM ยังเป็น
aws securityhubระวังสับสนเวลาอ่านบทความเก่า
สถาปัตยกรรมแบบรวมศูนย์ (ต่อจากบท 01)
ทุกบัญชี ──CloudTrail org trail──▶ S3 ใน Log Archive (Object Lock / ห้ามลบ)
ทุกบัญชี ──GuardDuty, Security Hub, Config, Inspector, Access Analyzer──▶ delegated admin = บัญชี Audit
บัญชี Audit ──EventBridge (finding severity สูง)──▶ SNS / Slack / ระบบ ticket- org trail สร้างจาก management/delegated admin ครั้งเดียว ครอบทุกบัญชีรวมบัญชีใหม่ — บัญชีลูกปิดไม่ได้
- เปิดบริการด้วย auto-enable สำหรับบัญชีใหม่ ไม่งั้นบัญชีที่สร้างทีหลังจะไม่มีใครเฝ้า
- ป้องกันไม่ให้ใครปิดได้ด้วย SCP (บท 01)
- ทุก region ที่ใช้งาน — GuardDuty/Config เป็นบริการ regional ผู้โจมตีชอบรันเครื่องขุดเหรียญใน region ที่คุณไม่เคยดู (หรือปิด region ไม่ใช้ด้วย SCP)
ค่าใช้จ่ายที่ต้องคิดก่อนเปิดทั้ง org
| บริการ | คิดตาม | กับดัก |
|---|---|---|
| GuardDuty | ปริมาณ event/log ที่วิเคราะห์ + protection plan | บัญชีที่มี traffic DNS/flow log มหาศาล |
| Config | จำนวน configuration item ที่บันทึก + rule evaluation | resource ที่เปลี่ยนบ่อย (ENI ของ Lambda/ECS) → ใช้ periodic recording หรือ exclude type |
| CloudTrail | management events สำเนาแรกฟรี, data events (S3/Lambda) คิดต่อ event | เปิด S3 data events กับทุก bucket รวมถึง bucket ที่มี request มหาศาล |
⚠️ ต้องตรวจสอบ: GuardDuty และ Security Hub CSPM มี free trial 30 วัน, Inspector 15 วัน ในบัญชีที่เพิ่งเปิดใช้ — ใช้ช่วงนี้ดูหน้า Usage เพื่อประเมินค่าจริงก่อนตัดสินใจ ราคาต่อหน่วยดูที่หน้า pricing ของแต่ละบริการ
Incident response: access key หลุด (เคสที่เจอบ่อยที่สุด)
ทำตามลำดับ อย่าลบอะไรก่อนเก็บหลักฐาน
| ขั้น | ทำอะไร | คำสั่ง/ที่ |
|---|---|---|
| 1. ยืนยัน | finding จาก GuardDuty (เช่น UnauthorizedAccess:IAMUser/InstanceCredentialExfiltration...) หรือ GitHub แจ้ง secret scanning |
GuardDuty console / อีเมล |
| 2. กักกัน | deactivate คีย์ (ไม่ลบ) + แนบ deny-all ให้ user + ถ้าเป็น role ให้ revoke session เก่า | aws iam update-access-key --status Inactive, AWSDenyAll, "Revoke active sessions" ของ role |
| 3. สืบ | คีย์ถูกใช้ทำอะไรบ้าง สร้าง user/role/EC2/Lambda ใหม่ไหม ใน region ไหน | CloudTrail Lake / Athena / lookup-events ตาม AccessKeyId |
| 4. กำจัด | ลบทุกอย่างที่ผู้โจมตีสร้าง (IAM user ลับ, EC2 ขุดเหรียญใน region อื่น, Lambda backdoor) | ตามผลขั้น 3 ทุก region |
| 5. กู้คืน | ให้เจ้าของงานเปลี่ยนไปใช้ role/OIDC แทน access key | บท 5a-03 |
| 6. บทเรียน | ทำไมคีย์ถึงหลุด เพิ่ม guardrail | SCP ห้ามสร้าง access key, pre-commit secret scan |
เปิด case กับ AWS Support เมื่อพบการใช้งานผิดปกติ — AWS มักพิจารณาค่าใช้จ่ายที่เกิดจากการถูกโจมตีเป็นรายกรณี
ลองเลย 🧪
ทำใน บัญชี sandbox/dev (ไม่ต้องเป็นทั้ง org) · ⚠️ GuardDuty มี free trial 30 วัน หลังจากนั้นคิดเงิน — ถ้าไม่ใช้ต่อให้ปิด (ขั้นเก็บกวาด)
aws sso login --profile dev
export AWS_PROFILE=dev AWS_REGION=ap-southeast-1ทดลอง A — CloudTrail: ใครล็อกอินคอนโซลและใครสร้าง/ลบอะไรล่าสุด
aws cloudtrail describe-trails --query "trailList[].[Name,IsMultiRegionTrail,IsOrganizationTrail]" --output table
aws cloudtrail lookup-events --region us-east-1 \
--lookup-attributes AttributeKey=EventName,AttributeValue=ConsoleLogin \
--max-results 5 --query "Events[].[EventTime,Username]" --output table
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=ReadOnly,AttributeValue=false \
--max-results 10 --query "Events[].[EventTime,EventName,Username]" --output table→ ถ้า describe-trails ว่าง = บัญชีนี้มีแค่ Event history 90 วัน ไม่มี trail เก็บระยะยาว (ในบัญชีที่อยู่ใต้ Control Tower จะเห็น org trail) · ConsoleLogin ของ IAM Identity Center/root มักถูกบันทึกที่ us-east-1
ทดลอง B — GuardDuty + finding ตัวอย่าง
DET=$(aws guardduty list-detectors --query "DetectorIds[0]" --output text)
[ "$DET" = "None" ] && DET=$(aws guardduty create-detector --enable --query DetectorId --output text)
echo $DET
aws guardduty create-sample-findings --detector-id "$DET" \
--finding-types "UnauthorizedAccess:EC2/SSHBruteForce" "CryptoCurrency:EC2/BitcoinTool.B!DNS"
sleep 15
aws guardduty list-findings --detector-id "$DET" \
--finding-criteria '{"Criterion":{"service.additionalInfo.sample":{"Eq":["true"]}}}' \
--query "FindingIds" --output text | head -c 200; echoผลที่ควรเห็น: detector ID และรายการ finding ID ในคอนโซล GuardDuty จะเห็น finding ที่ขึ้นต้นด้วย [SAMPLE] — ลองเปิดดูว่ามีข้อมูลอะไรบ้าง (resource, IP ต้นทาง, severity)
ทดลอง C — ส่ง finding ร้ายแรงเข้าอีเมลอัตโนมัติ
TOPIC=$(aws sns create-topic --name sec-findings --query TopicArn --output text)
aws sns subscribe --topic-arn "$TOPIC" --protocol email --notification-endpoint "[[email protected]]"
ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
aws sns set-topic-attributes --topic-arn "$TOPIC" --attribute-name Policy --attribute-value "{
\"Version\":\"2012-10-17\",
\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"events.amazonaws.com\"},
\"Action\":\"sns:Publish\",\"Resource\":\"$TOPIC\",
\"Condition\":{\"StringEquals\":{\"aws:SourceAccount\":\"$ACCOUNT\"}}}]}"
aws events put-rule --name guardduty-high \
--event-pattern '{"source":["aws.guardduty"],"detail-type":["GuardDuty Finding"],"detail":{"severity":[{"numeric":[">=",7]}]}}'
aws events put-targets --rule guardduty-high --targets "Id"="sns","Arn"="$TOPIC"
# สร้าง sample finding ระดับ high เพื่อทดสอบ (กด Confirm subscription ในอีเมลก่อน)
aws guardduty create-sample-findings --detector-id "$DET" \
--finding-types "UnauthorizedAccess:IAMUser/InstanceCredentialExfiltration.OutsideAWS"ผลที่ควรเห็น: อีเมล JSON ของ finding ภายในไม่กี่นาที (severity ≥ 7 = High ขึ้นไป) — ในงานจริงส่งเข้า Slack/PagerDuty ผ่าน Lambda หรือ Amazon Q Developer in chat applications
ทดลอง D — Config rule ตรวจ bucket ที่ไม่บล็อก public access (⚠️ Config คิดต่อ configuration item ที่บันทึก — ถ้ายังไม่เคยเปิด Config ในบัญชีนี้ ข้ามข้อนี้หรือเปิดผ่านคอนโซล Config → Get started แบบเลือกบันทึกเฉพาะ resource type ที่ต้องการ)
aws configservice describe-configuration-recorders --query "ConfigurationRecorders[].name" --output text
aws configservice put-config-rule --config-rule '{
"ConfigRuleName": "s3-account-public-access-blocked",
"Source": {"Owner": "AWS", "SourceIdentifier": "S3_ACCOUNT_LEVEL_PUBLIC_ACCESS_BLOCKS_PERIODIC"},
"MaximumExecutionFrequency": "TwentyFour_Hours"
}'
aws configservice start-config-rules-evaluation --config-rule-names s3-account-public-access-blocked
sleep 30
aws configservice describe-compliance-by-config-rule --config-rule-names s3-account-public-access-blocked \
--query "ComplianceByConfigRules[0].Compliance.ComplianceType" --output textผลที่ควรเห็น: COMPLIANT (ถ้าเปิด Block Public Access ระดับบัญชีไว้ตั้งแต่ 3a) หรือ NON_COMPLIANT → แก้ด้วย aws s3control put-public-access-block --account-id [ACCOUNT] --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true
ทดลอง E — IAM Access Analyzer หาของที่เปิดให้นอกบัญชี
aws accessanalyzer create-analyzer --analyzer-name account-external --type ACCOUNT 2>/dev/null || true
ANALYZER=$(aws accessanalyzer list-analyzers --type ACCOUNT --query "analyzers[0].arn" --output text)
aws accessanalyzer list-findings-v2 --analyzer-arn "$ANALYZER" \
--query "findings[?status=='ACTIVE'].[resourceType,resource]" --output table→ ทุกแถวคือ resource ที่คนนอกบัญชีเข้าถึงได้ ต้องอธิบายได้ทุกแถว ถ้าอธิบายไม่ได้คือปัญหา (analyzer แบบ external access ไม่คิดเงิน)
เก็บกวาด
# ถ้าเปิดเทอร์มินัลใหม่ ตั้งตัวแปรคืนก่อน
DET=${DET:-$(aws guardduty list-detectors --query "DetectorIds[0]" --output text)}
TOPIC=${TOPIC:-$(aws sns list-topics --query "Topics[?ends_with(TopicArn, ':sec-findings')].TopicArn" --output text)}
aws events remove-targets --rule guardduty-high --ids sns
aws events delete-rule --name guardduty-high
aws sns delete-topic --topic-arn "$TOPIC"
aws guardduty archive-findings --detector-id "$DET" --finding-ids $(aws guardduty list-findings --detector-id "$DET" \
--finding-criteria '{"Criterion":{"service.additionalInfo.sample":{"Eq":["true"]}}}' --query "FindingIds" --output text)
aws configservice delete-config-rule --config-rule-name s3-account-public-access-blocked 2>/dev/null || true
aws accessanalyzer delete-analyzer --analyzer-name account-external # ไม่คิดเงิน จะเก็บไว้ก็ได้
# ถ้าไม่ใช้ GuardDuty ต่อหลัง trial (ไม่แนะนำในบัญชีจริง):
# aws guardduty delete-detector --detector-id "$DET"ถ้าพัง: ไม่ได้อีเมล → ยังไม่ confirm subscription หรือ topic policy ไม่อนุญาต events.amazonaws.com · NoAvailableConfigurationRecorderException → ยังไม่ได้เปิด Config recorder · sample finding ไม่ trigger rule → ตรวจว่าเลือก finding type ที่ severity ≥ 7
กับดักที่เจอบ่อย
| อาการ | สาเหตุ / แก้ |
|---|---|
| ผู้โจมตีรัน EC2 ขุดเหรียญใน region ที่ไม่มีใครดู | เปิด GuardDuty แค่ region หลัก — เปิดทุก region ที่อนุญาต และปิด region อื่นด้วย SCP |
| ผู้โจมตีปิด CloudTrail ก่อนลงมือ | trail อยู่ในบัญชีเดียวกัน — ใช้ org trail ส่งไป Log Archive + SCP ห้าม cloudtrail:StopLogging/DeleteTrail |
| บิล Config สูงผิดปกติ | บันทึก ENI/resource ที่เปลี่ยนบ่อยแบบ continuous — ใช้ periodic recording หรือ exclude |
| finding หลายพันรายการไม่มีใครดู | ไม่มี triage — ส่งเฉพาะ severity สูงเป็น alert, ที่เหลือเข้า backlog ทบทวนรายสัปดาห์ และ suppress ที่ยอมรับแล้ว |
| ลบคีย์ที่หลุดทันทีแล้วสืบต่อไม่ได้ | deactivate ก่อน เก็บ access key ID ไว้ค้น CloudTrail |
| ตั้ง automation ตาม ASFF แต่เปิด Security Hub ตัวใหม่ | คนละรูปแบบ (OCSF) — ตรวจว่า integration รองรับตัวไหน |
สรุปจำง่าย
CloudTrail = ใครทำอะไร, GuardDuty = ถูกโจมตีไหม, Config = ตั้งค่าถูกไหม, Security Hub = รวมและจัดลำดับความเสี่ยง — รวมศูนย์ที่บัญชี Audit + auto-enable บัญชีใหม่ + ทุก region — finding ร้ายแรงต้องไปถึงคนอัตโนมัติ — คีย์หลุด: deactivate → สืบ → กำจัด → เปลี่ยนเป็น role