Mục tiêu chương / Learning objectives
- Phân biệt và biết khi nào dùng SAST, DAST, IAST, RASP, SCA và fuzz testing.
- Thực hành DAST cơ bản với OWASP ZAP và Nikto trên môi trường lab.
- Hiểu OWASP Testing Guide v4.2 và cách tổ chức security test plan cho web app.
- Kiểm thử API security theo OWASP API Security Top 10.
- Nắm khung OWASP MASTG cho mobile app security testing.
- Viết security regression tests và tích hợp vào CI/CD pipeline.
1. Lý thuyết cốt lõi / Core theory
1.1. Security Testing Types (SAST / DAST / IAST / RASP / SCA / Fuzzing)
SAST (Static Application Security Testing) — phân tích source code không cần chạy app; phát hiện sớm (CI/CD), ít false negatives cho known patterns, nhiều false positives; tools: Semgrep, SonarQube, Checkmarx, Veracode, Fortify. DAST (Dynamic Application Security Testing) — tấn công app đang chạy từ bên ngoài (black-box); không cần source code, tìm được runtime issues; tools: OWASP ZAP, Burp Suite, Nikto. IAST (Interactive AST) — agent chạy bên trong app khi functional tests chạy, kết hợp ưu điểm SAST + DAST; tools: Contrast Security, Seeker. RASP (Runtime Application Self-Protection) — agent chạy trong production, block attacks real-time; tools: Sqreen, Imperva RASP. SCA (Software Composition Analysis) — phân tích open source dependencies; tools: OWASP Dependency-Check, Snyk, Black Duck. Fuzz testing — gửi random/mutated inputs để crash app; AFL++, Atheris (Python), libFuzzer.
Testing Quadrant cho Security: SAST = shift-left (tìm bugs sớm, rẻ nhất); DAST = pre-production (realistic attack simulation); IAST = QA phase (best accuracy); RASP = production (last line of defense); SCA = continuous (dependency always-on monitoring). Mọi mature AppSec program dùng kết hợp tất cả, không chỉ một loại.
1.2. DAST Tools Deep Dive (ZAP / Burp Suite / Nikto)
OWASP ZAP (Zed Attack Proxy): open-source, proxy-based, tích hợp CI/CD qua CLI (zap-cli) hoặc Docker. Modes: automated scan (quick), spider + active scan (thorough), API scan với OpenAPI spec. Burp Suite: industry-standard cho manual pentest; Proxy intercept, Scanner, Repeater (replay modified requests), Intruder (brute force/fuzzing), Comparer. Community edition đủ dùng cho lab. Nikto: web server scanner, kiểm tra outdated software, dangerous files/CGIs, misconfigurations; nhanh, noisy (không stealth), tốt cho initial recon.
1.3. OWASP Testing Guide v4.2 (Web App Pentest Methodology)
OTG (OWASP Testing Guide) cung cấp methodology có structure cho web app security testing, chia theo 11 categories: Information Gathering, Configuration & Deployment, Identity Management, Authentication, Authorization, Session Management, Input Validation, Error Handling, Cryptography, Business Logic, Client-side Testing. Mỗi category có test cases cụ thể (ví dụ OTG-AUTHN-001: Testing for Credentials Transported over an Encrypted Channel). Kết quả mapping sang OWASP Top 10 và CWE.
1.4. API Security Testing & Mobile Testing (OWASP API Top 10 / MASTG)
OWASP API Security Top 10 (2023): API1 - Broken Object Level Authorization (BOLA/IDOR), API2 - Broken Authentication, API3 - Broken Object Property Level Authorization, API4 - Unrestricted Resource Consumption, API5 - Broken Function Level Authorization, API6 - Unrestricted Access to Sensitive Business Flows, API7 - Server-Side Request Forgery, API8 - Security Misconfiguration, API9 - Improper Inventory Management, API10 - Unsafe Consumption of APIs. Testing: Postman security collections, REST Assured, custom scripts kiểm tra horizontal/vertical privilege escalation.
OWASP MASTG (Mobile Application Security Testing Guide) — thay thế MSTG; test cases cho iOS và Android theo MASVS levels L1/L2/R. Key tests: static analysis của APK/IPA (MobSF), dynamic analysis (Frida hooks, Objection framework), network traffic analysis (Burp proxy qua WiFi), local storage inspection, authentication flow testing.
1.5. Security Regression Testing & Bug Bounty (Regression + Responsible Disclosure)
Security regression tests: sau khi fix một vulnerability, viết automated test để đảm bảo nó không tái xuất hiện (regression). Ví dụ: fix SQL injection trong getUserById() → thêm test case gửi payload ' OR '1'='1 và assert rằng query parameterized, không trả về kết quả bất thường. Test này chạy trong CI/CD mỗi PR. Bug bounty và Responsible Disclosure: coordinated vulnerability disclosure (CVD) — researcher báo cáo cho vendor trước khi public, vendor có thời gian fix (thường 90 ngày theo Google Project Zero); HackerOne/Bugcrowd là platforms phổ biến; security test reporting phải include: severity (CVSS score), proof of concept, impact, remediation recommendation.
2. Bài thực hành / Hands-on labs
Lab 1 — API Security Testing với PowerShell (Windows)
OS: Windows 11 · Tool: PowerShell 7 · Target: local test API hoặc httpbin.org.
# Security testing của REST API endpoints
# Sử dụng httpbin.org như target (safe, legal)
$baseUrl = "https://httpbin.org"
# Test 1: Kiểm tra HTTP headers bảo mật
Write-Host "=== Security Headers Check ===" -ForegroundColor Yellow
$response = Invoke-WebRequest -Uri "$baseUrl/get" -Method GET -ErrorAction SilentlyContinue
$secHeaders = @("Strict-Transport-Security","X-Content-Type-Options","X-Frame-Options",
"Content-Security-Policy","X-XSS-Protection","Referrer-Policy")
foreach ($h in $secHeaders) {
$val = $response.Headers[$h]
if ($val) { Write-Host " [OK] $h`: $val" -ForegroundColor Green }
else { Write-Host " [MISSING] $h" -ForegroundColor Red }
}
# Test 2: Test authentication bypass attempt
Write-Host "`n=== Auth Bypass Attempt (expected: 401/403) ===" -ForegroundColor Yellow
try {
$r = Invoke-WebRequest -Uri "$baseUrl/bearer" -Method GET -ErrorAction Stop
Write-Host " [WARN] No auth required - Status: $($r.StatusCode)" -ForegroundColor Red
} catch {
$code = $_.Exception.Response.StatusCode.value__
Write-Host " [OK] Auth required - HTTP $code returned" -ForegroundColor Green
}
# Test 3: Simulate IDOR check (Object Level Authorization)
Write-Host "`n=== IDOR Simulation (API1 — OWASP API Top 10) ===" -ForegroundColor Yellow
$myUserId = 42
$otherUserId = 43
Write-Host " My user ID: $myUserId — accessing /user/$otherUserId data..."
Write-Host " Expected: 403 Forbidden. If 200 → BOLA/IDOR vulnerability." -ForegroundColor Cyan
# Test 4: Rate limiting check
Write-Host "`n=== Rate Limiting Check (API4 — Unrestricted Resource Consumption) ===" -ForegroundColor Yellow
$times = 1..5 | ForEach-Object {
$sw = [System.Diagnostics.Stopwatch]::StartNew()
Invoke-RestMethod "$baseUrl/get" -ErrorAction SilentlyContinue | Out-Null
$sw.ElapsedMilliseconds
}
Write-Host " Response times (ms): $($times -join ', ')"
Write-Host " If no slowdown after many requests → rate limiting may be absent" -ForegroundColor Cyan
✅ Kết quả mong đợi / Expected output: Security headers check hiển thị những header nào có/thiếu. httpbin.org thiếu nhiều security headers — đây là điểm cải tiến điển hình. Auth check xác nhận /bearer trả về 401 khi không có token. Rate limit check ghi lại response times — nếu đồng đều → không có rate limiting. Ý nghĩa: đây là checklist OWASP API Security Top 10 có thể tự động hóa trong CI/CD.
Lab 2 — DAST với OWASP ZAP và Nikto (Bash)
OS: Ubuntu 22.04 · Tool: Bash + OWASP ZAP (Docker) + Nikto · Target: DVWA hoặc WebGoat local.
# Option A: Chạy ZAP baseline scan qua Docker (không cần install ZAP)
# Target: WebGoat chạy local trên port 8080
LOCAL_IP=$(ip route get 8.8.8.8 2>/dev/null | awk '{print $7; exit}')
TARGET="http://${LOCAL_IP:-127.0.0.1}:8080"
echo "Target: $TARGET"
# ZAP baseline scan (passive only — safe, không tấn công tích cực)
docker run --rm --network=host zaproxy/zap-stable \
zap-baseline.py -t "$TARGET" -r /tmp/zap-report.html \
--hook=/zap/auth_hook.py 2>/dev/null | tail -20
# Hoặc dùng ZAP CLI nếu đã cài
if command -v zap-cli &>/dev/null; then
zap-cli quick-scan --self-contained \
--start-options "-config api.disablekey=true" "$TARGET" 2>/dev/null | tail -20
fi
# Option B: Nikto scan (nhanh hơn, không cần Docker)
echo "=== Nikto Web Server Scan ==="
if command -v nikto &>/dev/null; then
# Scan các điểm phổ biến: outdated software, default files, misconfig
nikto -h "$TARGET" -Tuning 1,2,3,4,6 -maxtime 60 2>/dev/null | \
grep -E "^\+|OSVDB|CVE" | head -25
else
echo "Install: sudo apt install nikto"
echo "Nikto checks: outdated software, default files, HTTP methods, misconfigurations"
fi
echo "=== Tóm tắt kiểu findings Nikto thường phát hiện ==="
echo " + Server leaks version info (X-Powered-By, Server header)"
echo " + OPTIONS method enabled (TRACK/TRACE — XST attack vector)"
echo " + Default pages (/admin, /phpinfo.php, /.git/)"
echo " + Clickjacking: X-Frame-Options header missing"
✅ Kết quả mong đợi / Expected output: ZAP baseline scan report HTML với findings phân loại theo risk (High/Medium/Low/Informational). Nikto báo các issues như: + Server: Apache/2.4.41 (Ubuntu) — version disclosure; + OSVDB-877: HTTP TRACE method is active; + /phpinfo.php: PHP info disclosed. Bài học: DAST cần môi trường staging — không bao giờ chạy active scan trên production mà không có authorization.
3. Tình huống doanh nghiệp / Real-world scenario
Bối cảnh:
Một ngân hàng chuẩn bị ra mắt mobile banking app mới. CISO yêu cầu security testing đầy đủ trước khi launch. Team có 3 tuần và budget cho external pentest hạn chế.
Kế hoạch testing 3 tuần:
- Tuần 1 — Automated (SAST + SCA + DAST): Chạy SAST (Semgrep + SonarQube) trên source code toàn bộ. SCA kiểm tra tất cả dependencies. ZAP automated scan trên staging backend API. Fix tất cả High/Critical findings.
- Tuần 2 — Mobile Testing (OWASP MASTG): MobSF static analysis trên APK và IPA. Burp proxy để intercept mobile traffic. Kiểm tra certificate pinning, secure storage (Keychain/Keystore), authentication flow.
- Tuần 3 — Manual + API Testing: OWASP API Security Top 10 manual testing trên payment APIs. Kiểm tra BOLA: mỗi endpoint có kiểm tra ownership của object không? Test business logic: có thể chuyển âm số tiền không?
- Security regression suite: Sau khi fix, tạo automated tests cho mỗi finding — chạy trong CI/CD mỗi PR.
Bài học: 80% vulnerabilities có thể tìm được bằng automated tools. 20% còn lại (business logic, BOLA, auth flow) cần manual testing. Đầu tư vào automated testing → tiết kiệm chi phí pentest hàng năm.
4. Tự kiểm tra / Knowledge check
- Phân biệt SAST và DAST. Loại nào phát hiện được Business Logic vulnerabilities tốt hơn?
- IAST hoạt động như thế nào và tại sao có độ chính xác cao hơn SAST/DAST riêng lẻ?
- OWASP API Security Top 10: API1 (BOLA) là gì? Cho ví dụ cụ thể về lỗ hổng và cách test.
- Fuzz testing phù hợp nhất để tìm loại lỗ hổng nào? Cho ví dụ tool và target.
- Security regression test là gì và tại sao quan trọng hơn chỉ fix vulnerability?