Mục tiêu chương / Learning objectives
- Phân biệt vulnerability assessment, penetration testing, red team, và bug bounty — khi nào dùng loại nào.
- Mô tả methodology pentest theo PTES/OWASP/NIST 800-115: từ Recon đến Reporting.
- Giải thích OWASP Top 10 (2021) từ góc nhìn developer và security manager.
- So sánh SAST, DAST, IAST, RASP và tích hợp vào CI/CD pipeline.
- Thiết kế chương trình continuous security testing phù hợp với DevSecOps.
- Xác định yêu cầu Rules of Engagement, scope, và legal authorization trước khi test.
1. Lý thuyết cốt lõi / Core theory
1.1. Các loại đánh giá bảo mật (Security assessment types)
| Loại | Mục tiêu | Người thực hiện | Output |
|---|---|---|---|
| Vulnerability Assessment | Tìm và liệt kê lỗ hổng — không exploit | Internal team, scanner tools | Vulnerability list + CVSS scores |
| Penetration Test | Exploit lỗ hổng để đo business impact | Certified tester (CEH/OSCP) | Report: findings + PoC + remediation |
| Red Team Exercise | Simulate APT — test detection & response | External red team, adversary simulation | Attacker TTPs + Blue team gaps |
| Bug Bounty | Crowdsource vulnerability discovery | External researchers (HackerOne/Bugcrowd) | Individual vulnerability reports |
| Security Audit | Verify compliance với policy/standard | Internal audit, external auditor (Big4) | Audit report + compliance status |
CISSP Key Distinction: Vulnerability assessment = tìm holes. Penetration test = chứng minh holes có thể exploit được và impact là gì. Red team = test toàn bộ security posture (people + process + technology). CISSP câu hỏi hay hỏi: "Board muốn biết khả năng attacker xâm nhập và tác động kinh doanh" → Penetration test, không phải VA.
1.2. Penetration Testing Methodology (PTES · OWASP · NIST 800-115)
Pentest theo PTES (Penetration Testing Execution Standard) gồm 7 giai đoạn:
- Pre-engagement: Định nghĩa scope, Rules of Engagement (RoE), legal authorization (written permission!), emergency contacts, NDA. Không có giai đoạn này → pentest là tội phạm.
- Intelligence Gathering (Recon): Passive (OSINT: WHOIS, LinkedIn, Shodan, Google dorks) và Active (DNS enum, network scanning trong scope). Mục tiêu: hiểu attack surface trước khi chạm vào target.
- Threat Modeling: Identify attack vectors, threat actors, và prioritize targets dựa trên business value.
- Vulnerability Analysis: Scan (Nessus/OpenVAS) + manual analysis. Map findings to CVEs và CVSS scores.
- Exploitation: Verify vulnerabilities bằng cách exploit (trong scope). Mục tiêu: đạt access, không phải phá hoại. Document mọi step.
- Post-Exploitation: Privilege escalation, lateral movement, persistence (để demo impact). Nếu mục tiêu là data exfil → extract sample (không phải toàn bộ data).
- Reporting: Executive summary (business impact, risk rating) + Technical details (vuln, PoC, remediation steps). Cleanup artifacts sau test.
Rules of Engagement bắt buộc bao gồm: Authorized systems/IPs (explicit whitelist), time window (testing hours), authorized techniques (no DoS trên production), emergency stop procedure, data handling (captured data phải được encrypt và delete sau test), notification requirements (nếu phát hiện critical vulnerability trong khi test).
1.3. OWASP Top 10 (2021) (Web application vulnerabilities)
1.4. Code Review & Testing Types (SAST · DAST · IAST · RASP)
- SAST (Static Application Security Testing): Phân tích source code mà không chạy app. Tools: Semgrep, SonarQube, Checkmarx, Fortify. Tích hợp vào IDE (shift left) và CI pipeline. False positive rate cao — cần tuning.
- DAST (Dynamic Application Security Testing): Test app đang chạy — gửi malformed input, observe response. Tools: OWASP ZAP, Burp Suite, Nikto. Không cần source code — phù hợp black-box test. Miss business logic flaws.
- IAST (Interactive AST): Agent trong app runtime — monitor từ bên trong trong khi test chạy. Kết hợp coverage của SAST + accuracy của DAST. Tools: Contrast Security, Seeker. Overhead nhẹ.
- RASP (Runtime Application Self-Protection): Agent trong production — monitor và block attacks real-time. Không phải testing tool — là security control. Giống "WAF từ bên trong app".
1.5. Continuous Security Testing & DevSecOps (Fuzzing, pipeline integration)
DevSecOps tích hợp security vào mọi stage của CI/CD pipeline:
- Pre-commit: Git hooks chạy secret scanning (git-secrets, truffleHog), SAST lightweight (Semgrep).
- Build: SCA (Software Composition Analysis) — scan dependencies (Snyk, OWASP Dependency-Check). Container image scanning (Trivy, Clair).
- Test: DAST automated (ZAP in CI mode), IAST during integration testing. Fuzzing (AFL, libFuzzer) cho protocol parsers và file parsers.
- Deploy: Infrastructure-as-Code scanning (tfsec cho Terraform, checkov), Kubernetes security policies (OPA Gatekeeper).
- Production: RASP, WAF, runtime threat detection. Periodic penetration testing (annual minimum, per PCI-DSS).
2. Bài thực hành / Hands-on labs
⚠️ LEGAL WARNING: Chỉ thực hiện các lệnh scan/exploit trên hệ thống bạn được phép rõ ràng bằng văn bản. Unauthorized scanning là vi phạm pháp luật (Computer Fraud and Abuse Act tại Mỹ, Điều 224-225 Bộ luật Hình sự Việt Nam). Dùng lab environment riêng (Metasploitable, HackTheBox, TryHackMe, DVWA).
Lab 1 — Windows Privilege Escalation Check (PowerShell — Lab VM Only)
OS: Windows 11 Lab VM (authorized) · Tool: PowerShell 7
# === WINDOWS SECURITY ASSESSMENT (LAB ONLY) ===
# Run on authorized lab VMs only
Write-Host "=== 1. Missing Security Patches ===" -ForegroundColor Cyan
Get-HotFix | Sort-Object InstalledOn -Descending |
Select-Object -First 10 HotFixID, Description, InstalledOn |
Format-Table -AutoSize
Write-Host "`n=== 2. Enabled Optional Features (attack surface) ===" -ForegroundColor Cyan
Get-WindowsOptionalFeature -Online |
Where-Object { $_.State -eq "Enabled" } |
Where-Object { $_.FeatureName -match "Telnet|TFTP|SMB1|RDS|RemoteDesktop" } |
Select-Object FeatureName, State | Format-Table -AutoSize
Write-Host "`n=== 3. Services running as SYSTEM (high-risk) ===" -ForegroundColor Cyan
Get-WmiObject Win32_Service |
Where-Object { $_.StartName -in @("LocalSystem","NT AUTHORITY\SYSTEM") -and $_.State -eq "Running" } |
Select-Object Name, DisplayName, PathName |
Where-Object { $_.PathName -notlike "*system32*" -and $_.PathName -notlike "*SysWOW64*" } |
Format-Table -AutoSize
Write-Host "`n=== 4. Unquoted Service Paths (privilege escalation vector) ===" -ForegroundColor Cyan
Get-WmiObject Win32_Service |
Where-Object { $_.PathName -notlike '"*' -and $_.PathName -like '* *' } |
Select-Object Name, PathName | Format-Table -AutoSize
Write-Host "`n=== 5. PrivescCheck (if available — lab use only) ===" -ForegroundColor Cyan
if (Test-Path ".\PrivescCheck.ps1") {
Write-Host "Loading PrivescCheck..." -ForegroundColor Yellow
. .\PrivescCheck.ps1
Invoke-PrivescCheck -Extended | Select-Object -First 20
} else {
Write-Host "Download: https://github.com/itm4n/PrivescCheck (for authorized lab use)" -ForegroundColor Gray
}
Write-Host "`n=== 6. AlwaysInstallElevated (MSI privilege escalation) ===" -ForegroundColor Cyan
$hklm = Get-ItemProperty "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Installer" -EA SilentlyContinue
$hkcu = Get-ItemProperty "HKCU:\SOFTWARE\Policies\Microsoft\Windows\Installer" -EA SilentlyContinue
if ($hklm.AlwaysInstallElevated -eq 1 -and $hkcu.AlwaysInstallElevated -eq 1) {
Write-Host "[VULN] AlwaysInstallElevated is ENABLED - privilege escalation possible!" -ForegroundColor Red
} else {
Write-Host "[OK] AlwaysInstallElevated not enabled" -ForegroundColor Green
}
✅ Kết quả mong đợi (lab VM): Missing patches: list của KB numbers chưa được cài (so sánh với WSUS/patch baseline). Unquoted service paths: nếu có "C:\Program Files\My App\service.exe" (không có quotes) → attacker có thể tạo "C:\Program.exe" để hijack. AlwaysInstallElevated enabled → high privilege escalation risk. Trên hardened system: không có unquoted paths, không có AlwaysInstallElevated, patches up-to-date.
Lab 2 — Recon & Web Scanning (Lab Network Only — Kali Linux)
OS: Kali Linux · Tool: nmap · Nikto · theHarvester (lab network/authorized target only)
#!/bin/bash
# === PENTEST RECON & SCANNING (AUTHORIZED LAB ONLY) ===
# Replace 192.168.56.0/24 with your lab network range
LAB_NETWORK="192.168.56.0/24"
TARGET_IP="192.168.56.10" # Metasploitable or authorized target
TARGET_DOMAIN="targetdomain.com" # Replace with authorized domain
echo "=== PHASE 1: PASSIVE RECON ==="
echo "--- WHOIS ---"
whois $TARGET_DOMAIN 2>/dev/null | grep -E "Registrant|Admin|Tech|Emails|Name Server" | head -15
echo -e "\n--- DNS Enumeration ---"
dig +short $TARGET_DOMAIN MX
dig +short $TARGET_DOMAIN NS
dig +short $TARGET_DOMAIN TXT
echo -e "\n--- OSINT: theHarvester (passive) ---"
theHarvester -d $TARGET_DOMAIN -b google -l 50 2>/dev/null | \
grep -E "@|Host:|IP:" | head -20
echo -e "\n=== PHASE 2: NETWORK SCANNING (lab only) ==="
echo "--- Host Discovery ---"
nmap -sn $LAB_NETWORK -oG - 2>/dev/null | grep "Up" | awk '{print $2}'
echo -e "\n--- Service Version Scan ---"
nmap -sV -sC --open -T4 $TARGET_IP -oN /tmp/nmap-scan.txt 2>/dev/null
cat /tmp/nmap-scan.txt | grep -E "open|OS:|Service"
echo -e "\n=== PHASE 3: WEB APPLICATION SCANNING ==="
echo "--- Nikto Web Scanner ---"
nikto -h http://$TARGET_IP -maxtime 120 -output /tmp/nikto-report.txt 2>/dev/null
grep -E "OSVDB|CVE|\+ " /tmp/nikto-report.txt | head -20
echo -e "\n=== PHASE 4: VULNERABILITY IDENTIFICATION ==="
echo "--- Nmap Vuln Scripts ---"
nmap --script=vuln --script-args=unsafe=1 -p 80,443,22,21,3389 $TARGET_IP 2>/dev/null | \
grep -E "VULNERABLE|CVE|State" | head -20
✅ Kết quả mong đợi (Metasploitable lab): nmap phát hiện nhiều port mở (21/FTP, 22/SSH, 80/HTTP, 3306/MySQL, 5432/PostgreSQL — dấu hiệu intentionally vulnerable VM). Nikto báo cáo: outdated Apache, directory listing enabled, default scripts. theHarvester tìm thấy email addresses và subdomains (từ OSINT). Đây là starting point cho exploitation phase trong controlled lab — không bao giờ thực hiện trên production systems.
3. Tình huống doanh nghiệp / Enterprise scenario
Bối cảnh:
Công ty e-commerce VNShop chuẩn bị launch website mới xử lý thanh toán (PCI-DSS yêu cầu). CISO phải trình Board về security assurance program. Dev team muốn "chạy nhanh", không muốn security làm chậm release. Pentest năm ngoái phát hiện SQL injection nhưng chưa được fix vì "không có thời gian".
Security assurance strategy:
- Non-negotiables (PCI-DSS 11.x): Penetration test ít nhất 1 lần/năm và sau mỗi major change. Vulnerability scan mỗi quý (internal) và mỗi quý (external ASV-approved scanner). SQL injection unfixed = PCI fail → delay launch.
- DevSecOps integration (không làm chậm): SAST trong IDE (Semgrep VS Code plugin) — developer thấy issue trước khi commit. SCA trong pipeline (Snyk) — tự động fail build nếu Critical CVE. Target: shift security left, tìm bugs lúc code rẻ hơn lúc prod đắt 100x.
- Risk-based testing: DAST tập trung vào payment flows (highest risk). OWASP ZAP automated trong staging. Manual pentest focus trên business logic (automation miss).
- Bug Bounty program: Sau launch, mở HackerOne với scope = app.vnshop.vn (không bao gồm internal systems). Tận dụng crowd để tìm what internal team missed.
- Remediation SLA: Critical → 24h. High → 7 days. Medium → 30 days. SQL injection unpatched = Critical → escalate to Board nếu không fix trong 24h.
Bài học CISSP: Testing không phải mục đích — verify controls hoạt động mới là mục đích. CISSP manager quan tâm đến risk acceptance, không phải số lượng vulnerabilities. Unfixed critical = business risk được accept explicitly bởi management.
4. Tự kiểm tra / CISSP-style knowledge check
- Tester thực hiện penetration test và phát hiện vulnerability nghiêm trọng ngoài scope đã được approve. Theo phương pháp luận và đạo đức nghề nghiệp, bước tiếp theo là gì?
- CISO yêu cầu "penetration test toàn bộ hệ thống" nhưng không cung cấp Rules of Engagement và không có written authorization. Là security manager, bạn xử lý như thế nào?
- OWASP Top 10 A01 "Broken Access Control" — mô tả 2 ví dụ tấn công cụ thể và control tương ứng từ góc nhìn developer và security manager.
- Công ty bạn có 5 developers và cần security testing. Không có budget cho full pentest. Mô tả minimal viable security testing program với SAST + DAST + SCA, ước tính ROI.
- DAST tìm thấy SQL injection trong staging. SAST không tìm thấy cùng bug này. Giải thích tại sao và điều này nói gì về cần thiết phải dùng nhiều testing types?
- Fuzzing phù hợp nhất cho loại vulnerabilities nào? Cho ví dụ loại phần mềm mà fuzzing đặc biệt hiệu quả và lý do.