diff --git a/plugins/redteam/.claude-plugin/plugin.json b/plugins/redteam/.claude-plugin/plugin.json index 6a66edf..e3844b0 100644 --- a/plugins/redteam/.claude-plugin/plugin.json +++ b/plugins/redteam/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "redteam", "displayName": "Red Team", - "version": "0.1.1", + "version": "0.1.2", "description": "두 템플릿을 공격하는 red team 장치: 역할별 서브에이전트(정찰·인증/인가·입력·의존성·설정·프론트), 발동 스킬, 핀 고정 오픈소스 도구 실행 래퍼와 발견 수집 도구. 훅은 두지 않는다(요청할 때만 돈다).", "author": { "name": "donghyeon.kang" diff --git a/plugins/redteam/README.md b/plugins/redteam/README.md index 1b9b4c3..af9fe39 100644 --- a/plugins/redteam/README.md +++ b/plugins/redteam/README.md @@ -19,13 +19,13 @@ ## 도구와 라이선스 | 도구 | 라이선스 | 비고 | |---|---|---| -| gitleaks | MIT | 비밀 값 | +| gitleaks | MIT | 비밀 값(`--redact`로 결과 파일에 값 원문을 남기지 않음) | | semgrep CE | 엔진 LGPL-2.1 | SAST(공식 이미지, 룰은 런타임·`--metrics=off`로 코드 안 보냄) | | trivy | Apache-2.0 | 의존성/이미지 — 기존 게이트와 공유 | | osv-scanner | Apache-2.0 | lockfile 교차검증 | | checkov | Apache-2.0 | IaC·compose·Dockerfile | | hadolint | GPL-3.0 | Dockerfile(실행만) | -| OWASP ZAP | Apache-2.0 | DAST baseline·api | +| OWASP ZAP | Apache-2.0 | DAST baseline·api(`-z "-silent"`로 텔레메트리·업데이트 확인을 끔) | | nuclei | MIT | 노출 템플릿(로컬 대상만) | | schemathesis | MIT | OpenAPI 퍼징 | | trufflehog | AGPL-3.0 | 심층 비밀 값(실행만, 배포 안 함) | diff --git a/plugins/redteam/scripts/redteam-scan.sh b/plugins/redteam/scripts/redteam-scan.sh index 5a940e9..fdf893a 100755 --- a/plugins/redteam/scripts/redteam-scan.sh +++ b/plugins/redteam/scripts/redteam-scan.sh @@ -4,11 +4,12 @@ # bash redteam-scan.sh --target <소스경로|URL> --out <결과폴더> [옵션] # # 모드: -# secrets gitleaks: 소스·git 히스토리의 비밀 값 +# secrets gitleaks: 소스·git 히스토리의 비밀 값(--redact로 결과에 값 원문을 남기지 않음) # sast semgrep CE: 정적 분석(룰은 런타임에 레지스트리에서, --metrics=off로 코드 안 보냄) # deps trivy fs: 의존성 취약점(HIGH/CRIT 요약) # config checkov + hadolint: compose·Dockerfile·IaC 오구성 -# dast-baseline OWASP ZAP baseline: 띄운 앱에 수동(passive) 스캔(헤더·쿠키·CSP) +# dast-baseline OWASP ZAP baseline: 띄운 앱에 수동(passive) 스캔(헤더·쿠키·CSP). ZAP은 -silent로 +# call home(텔레메트리·업데이트 확인·뉴스)을 끈다(dast-api도 같다) # dast-api ZAP api-scan + schemathesis: OpenAPI 기반 능동·퍼징 (--api 필요) # nuclei nuclei: 알려진 노출·오구성 템플릿 (대상은 내 로컬 URL만) # pin tools.lock의 모든 도구를 받아 실제 digest를 출력(고정에 붙여 쓴다) @@ -89,9 +90,11 @@ case "${MODE}" in do_pin ;; secrets) + # --redact: 찾은 값 원문 대신 REDACTED를 쓴다. 이 결과를 읽는 에이전트 컨텍스트에 비밀 값이 들어가지 않게. + # 위치(파일·줄·커밋·규칙)는 그대로 남으니 고칠 곳을 찾는 데는 모자라지 않다. ref="$(image_ref gitleaks)"; ensure_image "${ref}" docker run --rm -v "${TARGET}:/repo:ro" "${ref}" \ - detect --source=/repo --no-banner --report-format json --report-path /dev/stdout \ + detect --source=/repo --no-banner --redact --report-format json --report-path /dev/stdout \ > "${OUT}/secrets.json" 2> "${OUT}/secrets.log" || true echo "→ ${OUT}/secrets.json" ;; @@ -126,7 +129,7 @@ case "${MODE}" in [ -n "${TARGET}" ] || { echo "--target 필요" >&2; exit 2; } ref="$(image_ref zap)"; ensure_image "${ref}" docker run --rm "${netarg[@]}" -v "${OUT}:/zap/wrk:rw" "${ref}" \ - zap-baseline.py -t "${TARGET}" -J dast-baseline.json -r dast-baseline.html \ + zap-baseline.py -t "${TARGET}" -J dast-baseline.json -r dast-baseline.html -z "-silent" \ > "${OUT}/dast-baseline.log" 2>&1 || true echo "→ ${OUT}/dast-baseline.json" ;; @@ -134,7 +137,7 @@ case "${MODE}" in [ -n "${API}" ] || { echo "--api 필요" >&2; exit 2; } ref="$(image_ref zap)"; ensure_image "${ref}" docker run --rm "${netarg[@]}" -v "${OUT}:/zap/wrk:rw" "${ref}" \ - zap-api-scan.py -t "${API}" -f openapi -J dast-api.json -r dast-api.html \ + zap-api-scan.py -t "${API}" -f openapi -J dast-api.json -r dast-api.html -z "-silent" \ > "${OUT}/dast-api.log" 2>&1 || true st="$(image_ref schemathesis)"; ensure_image "${st}" docker run --rm "${netarg[@]}" "${st}" \ diff --git a/plugins/redteam/tests/test_redteam.py b/plugins/redteam/tests/test_redteam.py index fd35c5d..af91b11 100644 --- a/plugins/redteam/tests/test_redteam.py +++ b/plugins/redteam/tests/test_redteam.py @@ -6,6 +6,7 @@ finding.py의 정규화·검사·정렬·보고 로직과, tools.lock·redteam-s """ import json import os +import shutil import subprocess import sys import tempfile @@ -150,5 +151,62 @@ class ScanScriptTest(unittest.TestCase): self.assertIn(mode, r.stdout + r.stderr, "help에 모드 없음: %s" % mode) +FAKE_DOCKER = """#!/usr/bin/env bash +# 시험용 docker: 받은 인자를 한 줄(\\x1f로 구분)로 남기고, 이미지가 이미 있다고 답한다. +printf '%s\\x1f' "$@" >> "$FAKE_DOCKER_LOG"; printf '\\n' >> "$FAKE_DOCKER_LOG" +exit 0 +""" + + +class ScanEgressTest(unittest.TestCase): + """도구가 찾은 비밀 값 원문을 결과 파일에 남기지 않고, 밖으로 사용 정보를 보내지 않게 부르는지 본다. + + 가짜 docker로 redteam-scan.sh가 실제로 넘기는 인자를 받아 확인한다(docker를 띄우지 않는다). + """ + + def setUp(self): + self.dir = tempfile.mkdtemp() + os.makedirs(os.path.join(self.dir, "bin")) + docker = os.path.join(self.dir, "bin", "docker") + with open(docker, "w", encoding="utf-8") as fh: + fh.write(FAKE_DOCKER) + os.chmod(docker, 0o755) + self.log = os.path.join(self.dir, "docker.log") + + def tearDown(self): + shutil.rmtree(self.dir, ignore_errors=True) + + def run_calls(self, *args): + """모드를 돌리고 `docker run` 호출마다 인자 목록을 돌려준다.""" + # 필요한 값만 넘긴다: 가짜 docker가 먼저 잡히는 PATH와 기록 파일. + env = {"PATH": os.path.join(self.dir, "bin") + os.pathsep + os.defpath, "FAKE_DOCKER_LOG": self.log} + r = subprocess.run(["bash", os.path.join(SCRIPTS, "redteam-scan.sh"), *args, + "--out", os.path.join(self.dir, "out")], + capture_output=True, text=True, timeout=30, env=env) + self.assertEqual(r.returncode, 0, r.stderr) + with open(self.log, encoding="utf-8") as fh: + calls = [line.rstrip("\n").rstrip("\x1f").split("\x1f") for line in fh if line.strip()] + return [c for c in calls if c[:1] == ["run"]] + + def test_secrets_redacts_values_in_report(self): + calls = self.run_calls("secrets", "--target", self.dir) + self.assertEqual(len(calls), 1) + self.assertIn("--redact", calls[0], "gitleaks 결과 파일에 비밀 값 원문이 남는다") + + def test_sast_keeps_metrics_off(self): + calls = self.run_calls("sast", "--target", self.dir) + self.assertIn("--metrics=off", calls[0]) + + def test_zap_runs_silent(self): + for args, script in ((("dast-baseline", "--target", "http://127.0.0.1:9"), "zap-baseline.py"), + (("dast-api", "--api", "http://127.0.0.1:9/openapi.json"), "zap-api-scan.py")): + open(self.log, "w").close() + zap = [c for c in self.run_calls(*args) if script in c] + self.assertEqual(len(zap), 1, script) + c = zap[0] + self.assertIn("-z", c, "%s에 ZAP 옵션(-z)이 없다" % script) + self.assertIn("-silent", c[c.index("-z") + 1].split(), "%s가 ZAP call home(텔레메트리·업데이트 확인)을 끄지 않는다" % script) + + if __name__ == "__main__": unittest.main()