Claude Code Tổng Hợp

Dùng Claude Code làm pentest automation trên VPS isolated

Hướng dẫn dùng Claude Code làm pentest automation trên VPS isolated: nmap scan, OWASP test, exploit POC. Setup sandbox an toàn, không leak credential.

Thanh Nguyễn Cập nhật Đăng 7 phút đọc 9 khối lệnh

Dùng Claude Code làm pentest automation trên VPS isolated
Mục lục bài viết
  1. 1. Setup VPS isolated cho pentest
  2. 2. Cài Claude Code và pentest tools
  3. 3. Sandbox Claude Code với Docker
  4. 4. Network isolation với Docker bridge
  5. 5. Workflow basic: recon target
  6. 6. Prompt pentest mẫu
  7. 7. OWASP Top 10 automated test
  8. 8. Tránh leak credential và sensitive data
  9. 9. Generate report markdown từ findings
  10. 10. Use case cho CTF và bug bounty
  11. 11. Giới hạn và cảnh báo
  12. 12. Audit log mọi action Claude làm
  13. FAQ

Cảnh báo: bài này chỉ dùng để pentest app của chính bạn hoặc target có quyền (bug bounty program, CTF, lab cá nhân). Pentest hệ thống không có quyền là vi phạm luật. Đọc kỹ pháp lý trước khi áp dụng.

Claude Code với khả năng chạy bash, gọi tool, đọc output rất phù hợp làm pentest assistant. Có thể parallel chạy nmap + nikto + sqlmap, phân tích output, đề xuất exploit chain, viết POC. Setup trên VPS isolated giúp tránh leak credential và side-effect ra production.

Bài này hướng dẫn dựng VPS pentest lab với Claude Code: cấu hình sandbox an toàn, cài tool, viết workflow auto-pentest cho app web mình quản lý. Test trên Cloud VPS TND 4GB Debian 12.

1. Setup VPS isolated cho pentest

Pentest VPS phải tách biệt với prod, dev, personal. Tạo VPS riêng với:

  • Cloud VPS 4GB Debian 12, IP public riêng.
  • Không cài app prod, không có data thật.
  • Firewall outbound: chỉ allow IP target và Claude API endpoint.
  • SSH key riêng, không share với account khác.

2. Cài Claude Code và pentest tools

Terminal2. Cài Claude Code và pentest toolsbash
# Cài Node.js + Claude Codecurl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash -sudo apt install -y nodejsnpm install -g @anthropic-ai/claude-code # Cài pentest tool basicsudo apt install -y nmap nikto sqlmap dirb gobuster wfuzz ffuf hydrasudo apt install -y python3-pippip3 install impacket bloodhound netexec # Nuclei (fast template scanner)go install -v github.com/projectdiscovery/nuclei/v3/cmd/nuclei@latestnuclei -update-templates

3. Sandbox Claude Code với Docker

Không để Claude truy cập host VPS trực tiếp. Chạy trong container isolated:

Code3. Sandbox Claude Code với Dockerdockerfile
# Dockerfile cho pentest sandboxFROM debian:12 RUN apt-get update && apt-get install -y     curl nodejs npm nmap nikto sqlmap dirb     python3 python3-pip git tmux jq     && rm -rf /var/lib/apt/lists/* RUN npm install -g @anthropic-ai/claude-code # Non-root userRUN useradd -m -s /bin/bash pentestUSER pentestWORKDIR /home/pentest CMD ["bash"]
Terminal3. Sandbox Claude Code với Dockerbash
# Build và chạydocker build -t pentest-sandbox . docker run -it --rm   --network pentest-net   --cap-drop ALL   --security-opt no-new-privileges   -v $PWD/results:/home/pentest/results   -e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY   pentest-sandbox

Cap-drop ALL nghĩa là container không có capability đặc biệt nào, không thể mount, không thể raw socket. Tăng độ an toàn.

4. Network isolation với Docker bridge

Terminal4. Network isolation với Docker bridgebash
# Tạo network với DNS giảdocker network create --internal pentest-net # Hoặc cho phép outbound chỉ tới target IPdocker network create   --opt com.docker.network.bridge.name=br-pentest   pentest-net # Iptables rule: chỉ cho phép outbound tới target.example.comsudo iptables -I FORWARD -i br-pentest ! -d 1.2.3.4 -j DROPsudo iptables -I FORWARD -i br-pentest -d 1.2.3.4 -j ACCEPT

Cách này đảm bảo Claude không gọi tool quét target khác ngoài list đã whitelist. Tránh accidental DDoS hoặc scan illegal.

5. Workflow basic: recon target

Terminal5. Workflow basic: recon targetbash
# Tạo CLAUDE.md cho projectcat > /home/pentest/CLAUDE.md <<'MD'# Pentest Workflow You are a pentest assistant. Your task:1. Run recon tools on target listed in target.txt2. Save output to results/ folder3. Analyze findings, propose exploit chain4. NEVER run destructive commands (DROP, DELETE, rm -rf on target)5. Document findings in markdown report Tools available: nmap, nikto, sqlmap, dirb, ffuf, nucleiTarget: only IPs/domains in target.txtMD # Tạo target.txtecho "test.myapp.com" > /home/pentest/target.txt # Khởi động Claudecd /home/pentestclaude

6. Prompt pentest mẫu

Terminal6. Prompt pentest mẫubash
# Prompt 1: recon"Đọc target.txt, chạy nmap -sV -sC -p- top 1000 port, lưu output ra results/nmap.txt" # Prompt 2: web fuzz"Trên target test.myapp.com port 80/443, chạy ffuf với SecLists wordlist common.txt,filter status 200/301/302/403, lưu kết quả results/ffuf.txt" # Prompt 3: vuln scan"Chạy nuclei với severity medium,high,critical trên target.Phân tích finding, group theo CWE category, lưu results/nuclei-report.md" # Prompt 4: deep dive"Đọc results/nuclei-report.md, chọn 3 finding nguy hiểm nhất.Đề xuất POC exploit step-by-step (lý thuyết, không chạy thật).Viết defense recommendation cho developer fix."

7. OWASP Top 10 automated test

Terminal7. OWASP Top 10 automated testbash
# Prompt cho Claude"Lập kế hoạch test OWASP Top 10 2021 cho target.example.com:A01 Broken Access Control - dùng Burp Repeater logicA02 Cryptographic Failures - test SSL Labs, mixed contentA03 Injection - sqlmap với form loginA04 Insecure Design - manual reviewA05 Security Misconfiguration - nuclei misconfig templateA06 Vulnerable Components - retire.js, npm auditA07 Auth Failures - hydra brute force /login (rate limit test)A08 Software Data Integrity - check CSP, SRIA09 Logging Failures - test /admin endpoint silentlyA10 SSRF - test image upload URL fetch Chạy tool nào không destructive được, document plan cho phần manual."

8. Tránh leak credential và sensitive data

  • Không bao giờ paste production API key, DB password vào CLAUDE.md.
  • Output tool có thể chứa token, hash, PII -> sanitize trước khi share.
  • Dùng env var temporary trong session, xóa khi exit.
  • Snapshot VPS trước khi pentest, restore sau khi xong để xóa dấu vết.
  • Không commit results/ lên git public.

9. Generate report markdown từ findings

Terminal9. Generate report markdown từ findingsbash
# Prompt"Đọc tất cả file trong results/, tổng hợp findings vào report.md với format:- Executive Summary (1 đoạn cho non-tech)- Methodology- Findings (mỗi finding: title, severity, CWE, evidence, remediation)- Recommendations- Appendix (raw tool output reference) Sort by severity: Critical -> High -> Medium -> Low -> Info"

Claude tổng hợp report đầy đủ trong 1-2 phút. Quality tương đương junior pentester viết tay 2-3 tiếng.

10. Use case cho CTF và bug bounty

  • CTF: Claude phân tích challenge, gợi ý approach, viết exploit script Python.
  • Bug bounty: recon target, classify endpoint, find low-hanging fruit (open redirect, IDOR, XSS).
  • Personal app: regression security test sau mỗi release, đảm bảo không lộ regression.

11. Giới hạn và cảnh báo

  • Claude không phải pentester chuyên nghiệp. Vẫn cần expert review finding.
  • False positive cao với nuclei, sqlmap -> cần verify thủ công.
  • Không thể chain exploit phức tạp (CSRF + IDOR + privilege escalation) tự động.
  • Pentest chỉ trên target có quyền. Vi phạm luật là tù.
  • API cost tăng cao khi prompt nhiều, monitor usage.

12. Audit log mọi action Claude làm

Terminal12. Audit log mọi action Claude làmbash
# Log tất cả bash command Claude chạyscript -f /tmp/pentest-session-$(date +%F).log # Hoặc dùng auditdsudo apt install -y auditdsudo auditctl -w /home/pentest -p wa -k pentest # Xem logsudo ausearch -k pentest --start today

Audit log quan trọng cho compliance và post-mortem nếu pentest đi sai hướng.

FAQ

Pentest target không có quyền có phạm luật không?

Có. Theo Luật An ninh mạng VN 2018 và nhiều nước khác, scan/exploit hệ thống không có quyền là vi phạm. Chỉ pentest app của chính mình, lab CTF, hoặc bug bounty program công khai.

Claude có từ chối generate exploit code không?

Có. Claude từ chối nếu context có dấu hiệu malicious (target không rõ, exploit massive harm). Cần context rõ: target là app của mình, đã có authorization, mục đích defensive.

VPS pentest có cần cấu hình mạnh không?

4GB RAM 2 vCPU là đủ cho pentest cá nhân. Tool như nmap, nuclei chạy thoải mái. Cần thêm khi chạy fuzzing nặng hoặc password cracking GPU.

Có nên dùng Kali Linux thay Debian cho VPS pentest không?

Kali có tool pentest pre-installed nhưng nặng. Cloud VPS hiếm có Kali template. Debian 12 + apt install tool cần là đủ, ít overhead.

Claude Code có thể chạy exploit thật không?

Có nếu user approve mỗi bash command. Best practice: cho Claude propose, user review, manual run trên target. Tránh full auto vì risk side-effect.

Report tự động có đủ chất lượng cho client không?

Cho draft thì có. Senior pentester vẫn cần review, thêm context business impact, verify finding. Quality của Claude = junior pentester writing.

Chia sẻ:Facebook

Thanh Nguyễn

TND

Tư vấn bản quyền, VPS và máy chủ kèm hóa đơn VAT, hợp đồng đầy đủ cho doanh nghiệp.