Skip to content

About

Evidence-driven C/C++ vulnerability remediation: sanitizer/SARIF intake, isolated patch verification

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

code-shield

ํ•œ๊ตญ์–ด ยท English

C/C++ protocolยทplatform ์ฝ”๋“œ์˜ ์ทจ์•ฝ์  finding์„ ์žฌํ˜„ ๊ฐ€๋Šฅํ•œ ์ฆ๊ฑฐ๋กœ ์ •๊ทœํ™”ํ•˜๊ณ , ํ›„๋ณด ํŒจ์น˜๋ฅผ ๊ฒฉ๋ฆฌ๋œ ๋ณต์‚ฌ๋ณธ์—์„œ ๊ฒ€์ฆํ•˜๋Š” MVP๋‹ค. ์ €์žฅ์†Œ ์ด๋ฆ„์€ code-shield์ด๊ณ , ๊ณต๊ฐœ Python package์™€ CLI๋Š” ์ด๋ฆ„ ์ถฉ๋Œ์„ ํ”ผํ•˜๊ธฐ ์œ„ํ•ด ์ค‘๋ฆฝ์ ์ธ ๋‚ด๋ถ€ ์ด๋ฆ„ protocol-remediator๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

Quick start

# Python core (๋Ÿฐํƒ€์ž„ dependency ์—†์Œ)
python3 -m venv .venv
.venv/bin/pip install -e .
.venv/bin/python -m unittest discover -s tests -v

# React console
cd frontend
npm install
npm run dev   # http://127.0.0.1:5173

ํ™”๋ฉด

์ฝ˜์†” ๊ฐœ์š”: fixture matrix, generated corpus, CWE coverage, verification gate ์ง€ํ‘œ C/C++ fixture matrix: CWE๋ณ„ target๊ณผ ์—ฌ์„ฏ gate์˜ ํ†ต๊ณผ ์—ฌ๋ถ€
๊ฐœ์š” ๋Œ€์‹œ๋ณด๋“œ โ€” fixture matrix 5/5, generated corpus 50/50, CWE coverage, ๊ฒ€์ฆ gate ์š”์•ฝ Fixture matrix โ€” CWE-121/190/416/787/476 target๋ณ„ reproducerยทbuildยทtestsยทrescanยทrefuzzยทprotocol gate ๊ฒฐ๊ณผ
nodejs/http-parser case study: reproducer, ํŒจ์น˜ ์ „ํ›„ probe ๊ฒฐ๊ณผ, finding ๋ชฉ๋ก ์ œ์•ˆ ํŒจ์น˜ diff์™€ evidence/safety invariant ๋ชฉ๋ก
Case study (nodejs/http-parser) โ€” reproducer ์ •๋ณด, ํŒจ์น˜ ์ „ํ›„ probe ๊ฒฐ๊ณผ, CWE/CVE finding ๋ชฉ๋ก Evidence โ€” ์ œ์•ˆ ํŒจ์น˜ diff์™€ evidence/context JSON ๊ฒฝ๋กœ, safety invariant ๋ชฉ๋ก

์ฝ˜์†”์€ ์ €์žฅ์†Œ์— ํฌํ•จ๋œ fixture matrixยทgenerated corpusยทcase study ๊ฒฐ๊ณผ๋ฅผ ์ •์  ๋ฐ์ดํ„ฐ๋กœ ๋ณด์—ฌ์ค€๋‹ค.

ํ˜„์žฌ ๊ตฌํ˜„์˜ ์ค‘์‹ฌ์€ ํŒจ์น˜ ์ƒ์„ฑ ๋ชจ๋ธ์ด ์•„๋‹ˆ๋ผ ๋‹ค์Œ ๊ฒ€์ฆ ํ๋ฃจํ”„๋‹ค.

sanitizer ๋˜๋Š” SARIF
  -> Finding + EvidenceBundle
  -> source context
  -> manual/external-agent patch
  -> ์›๋ณธ ์žฌํ˜„
  -> build
  -> patched reproducer
  -> tests
  -> static rescan
  -> bounded refuzz
  -> protocol oracle
  -> verified report

๊ตฌํ˜„๋œ ๊ธฐ๋Šฅ

  • versioned Finding, EvidenceBundle, PatchProposal, VerificationReport JSON ๋ชจ๋ธ
  • detected โ†’ reproducible โ†’ contextualized โ†’ proposed โ†’ plausible โ†’ verified ์ƒํƒœ ์ „์ด
  • AddressSanitizer, MemorySanitizer, UndefinedBehaviorSanitizer ๋ณด๊ณ ์„œ ์ˆ˜์ง‘
  • SARIF 2.1 finding ์ˆ˜์ง‘
  • normalized finding์˜ SARIF 2.1 ๋‚ด๋ณด๋‚ด๊ธฐ
  • source location ์ฃผ๋ณ€์˜ ๊ฐ์‚ฌ ๊ฐ€๋Šฅํ•œ context JSON ์ƒ์„ฑ
  • TOML ๊ธฐ๋ฐ˜ target/build/gate ์„ค์ •
  • network-off, capability-drop, resource-limit๊ฐ€ ์ ์šฉ๋œ Docker ์‹คํ–‰๊ธฐ
  • ๋ช…์‹œ์  opt-in์ด ํ•„์š”ํ•œ local ์‹คํ–‰๊ธฐ
  • ์›๋ณธ target ๋ณต์‚ฌ๋ณธ์—์„œ finding ์žฌํ˜„ ํ›„ ๋ณ„๋„ ๋ณต์‚ฌ๋ณธ์—์„œ patch ๊ฒ€์ฆ
  • patch checksum, reproducer checksum, ๊ฒฝ๋กœ ํƒˆ์ถœ, symlink, ํŒŒ์ผยท๋ผ์ธ ์ œํ•œ ๊ฒ€์‚ฌ
  • test/fuzz harness/reproducer ๊ฐ™์€ ๋ณดํ˜ธ ๊ฒฝ๋กœ์˜ patch ๊ฑฐ๋ถ€
  • ์™ธ๋ถ€ patch agent command ์–ด๋Œ‘ํ„ฐ
  • ๊ฐ command์˜ exit code, stdout/stderr, ์‹œ๊ฐ„๊ณผ gate ๊ฒฐ๊ณผ ๋ณด์กด

์š”๊ตฌ ์‚ฌํ•ญ

  • Python 3.11 ์ด์ƒ
  • patch ๊ฒ€์ฆ์„ ์œ„ํ•œ Git
  • ๊ธฐ๋ณธ ๊ฒฉ๋ฆฌ ์‹คํ–‰์—๋Š” Docker
  • ์˜ˆ์ œ ์‹คํ–‰์—๋Š” Clang

๋Ÿฐํƒ€์ž„ Python dependency๋Š” ์—†๋‹ค.

์„ค์น˜์™€ ํ…Œ์ŠคํŠธ

python3 -m venv .venv
.venv/bin/pip install -e .
.venv/bin/python -m unittest discover -s tests -v

์„ค์น˜ํ•˜์ง€ ์•Š๊ณ  ์‹คํ–‰ํ•˜๋ ค๋ฉด:

PYTHONPATH=src python3 -m protocol_remediator --help
PYTHONPATH=src python3 -m unittest discover -s tests -v

๋™์  end-to-end suite๋Š” examples์˜ C/C++ fixture matrix๋‹ค. Clang ASan/UBSan์œผ๋กœ CWE-121, CWE-190, CWE-416, CWE-787, CWE-476์„ ์‹ค์ œ ์žฌํ˜„ํ•œ ๋‹ค์Œ, ๊ฐ invariant๋ฅผ ๋ณต๊ตฌํ•˜๋Š” patch์— ๋Œ€ํ•ด ์—ฌ์„ฏ gate๋ฅผ ๋ชจ๋‘ ์‹คํ–‰ํ•œ๋‹ค. fixture๋ณ„ ์ž…๋ ฅ๊ณผ ๊ฒ€์ฆ ๋ฒ”์œ„๋Š” examples/README.md์— ์ •๋ฆฌ๋˜์–ด ์žˆ๋‹ค.

unit-test framework ์—†์ด ์‹ค์ œ matrix๋งŒ ์‹คํ–‰ํ•˜๋ ค๋ฉด:

PYTHONPATH=src python3 examples/run_fixture_matrix.py

๋” ๋งŽ์€ C/C++ ๋ณ€ํ˜• ์˜ˆ์ œ๋ฅผ ์ž๋™ ์ƒ์„ฑํ•ด ์‹คํ–‰ํ•˜๋ ค๋ฉด:

PYTHONPATH=src python3 examples/run_generated_corpus.py --count 50

์ด runner๋Š” unittest๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ , ์ƒ์„ฑํ•œ ๊ฐ ํ”„๋กœ์ ํŠธ๋ฅผ ๋™์ผํ•œ VerificationPipeline์— ํ†ต๊ณผ์‹œํ‚จ๋‹ค. ๊ฒฐ๊ณผ summary๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ artifacts/generated-corpus-summary.json์— ๋‚จ๋Š”๋‹ค.

Frontend console

ํ˜„์žฌ ๊ตฌํ˜„ ์ƒํƒœ๋ฅผ ์šด์˜ํ˜• ๋Œ€์‹œ๋ณด๋“œ๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š” Vite + React + TypeScript ํ”„๋ก ํŠธ์—”๋“œ๋Š” frontend์— ์žˆ๋‹ค. ์ด ์ฝ˜์†”์€ fixture matrix, generated corpus, Hermes API server ์—ฐ๊ฒฐ๋ฉด, ๊ฒ€์ฆ gate, evidence safety invariant๋ฅผ ํ•œ ํ™”๋ฉด์— ์ •๋ฆฌํ•œ๋‹ค.

cd frontend
npm install
npm run dev

๊ธฐ๋ณธ ๊ฐœ๋ฐœ ์„œ๋ฒ„๋Š” http://127.0.0.1:5173์ด๋‹ค. production build๋Š” ๋‹ค์Œ์œผ๋กœ ํ™•์ธํ•œ๋‹ค.

cd frontend
npm run build

CLI

sanitizer finding ์ˆ˜์ง‘

protocol-remediator ingest-sanitizer \
  --log asan.log \
  --reproducer crash.input \
  --target-name parser \
  --revision 0123456789abcdef \
  --variant asan-x86_64 \
  --output intake/parser-crash

์ถœ๋ ฅ:

intake/parser-crash/finding.json
intake/parser-crash/evidence.json

SARIF ์ˆ˜์ง‘

protocol-remediator ingest-sarif \
  --sarif results.sarif \
  --output intake/sarif

SARIF ๋‚ด๋ณด๋‚ด๊ธฐ

protocol-remediator export-sarif \
  --finding intake/parser-crash/finding.json \
  --finding intake/another/finding.json \
  --output artifacts/findings.sarif

๋ชจ๋ธ ์ค‘๋ฆฝ context ์ƒ์„ฑ

protocol-remediator context \
  --finding intake/parser-crash/finding.json \
  --evidence intake/parser-crash/evidence.json \
  --target-root /path/to/target \
  --output intake/parser-crash/context.json

๊ธฐ์กด patch ๊ฒ€์ฆ

protocol-remediator verify \
  --config /path/to/target/target.toml \
  --finding intake/parser-crash/finding.json \
  --evidence intake/parser-crash/evidence.json \
  --patch candidate.patch \
  --artifacts artifacts

์ข…๋ฃŒ ์ฝ”๋“œ๋Š” verified์ด๋ฉด 0, ๊ฒ€์ฆ ์‹คํŒจ์ด๋ฉด 1, ์„ค์ •ยท์ž…๋ ฅ ์˜ค๋ฅ˜์ด๋ฉด 2๋‹ค.

Hermes agent API server

Hermes API server๋ฅผ ๋„์šฐ๋ฉด remediate๊ฐ€ ๋กœ์ปฌ command ๋Œ€์‹  HTTP API๋กœ patch๋ฅผ ์š”์ฒญํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ธฐ๋ณธ endpoint๋Š” POST /v1/patches์ด๋ฉฐ, finding/evidence/context์™€ target workspace archive๋ฅผ ๋ฐ›์•„ unified diff๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

์˜ˆ์ œ ์„œ๋ฒ„ ์‹คํ–‰:

PYTHONPATH=src python3 -m protocol_remediator.hermes_server \
  --host 127.0.0.1 \
  --port 8765

์„ค์น˜ ํ›„์—๋Š” console script๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

hermes-agent-server --host 127.0.0.1 --port 8765

์šด์˜ backend command๋ฅผ ๋ถ™์ผ ๋•Œ๋Š” argument ๋‹จ์œ„๋กœ --backend-command๋ฅผ ๋ฐ˜๋ณตํ•œ๋‹ค. {context}, {workspace}, {patch_output} placeholder๋ฅผ ์ง€์›ํ•œ๋‹ค.

hermes-agent-server \
  --backend-command my-patch-agent \
  --backend-command --context \
  --backend-command {context} \
  --backend-command --workspace \
  --backend-command {workspace} \
  --backend-command --output \
  --backend-command {patch_output}

target.toml์—์„œ๋Š” ๋‹ค์Œ์ฒ˜๋Ÿผ Hermes mode๋ฅผ ์ง€์ •ํ•œ๋‹ค.

[agent]
mode = "hermes"
url = "http://127.0.0.1:8765"
timeout_seconds = 30

๊ทธ๋‹ค์Œ ๊ธฐ์กด remediate ๋ช…๋ น์„ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•œ๋‹ค.

protocol-remediator remediate \
  --config examples/length-prefixed-parser/target.hermes.toml \
  --finding artifacts/hermes-cli-input/finding.json \
  --evidence artifacts/hermes-cli-input/evidence.json \
  --artifacts artifacts/hermes-cli

๊ฐœ๋ฐœ์šฉ end-to-end ํ™•์ธ์€ ๋‹ค์Œ runner๋กœ ์‹คํ–‰ํ•œ๋‹ค. ์ด runner๋Š” ์ž„์‹œ Hermes server๋ฅผ ๋„์šฐ๊ณ , API client๋กœ patch๋ฅผ ๋ฐ›์€ ๋‹ค์Œ ๊ฒ€์ฆ ํ๋ฃจํ”„๋ฅผ ๋๊นŒ์ง€ ์‹คํ–‰ํ•œ๋‹ค.

PYTHONPATH=src python3 examples/run_hermes_demo.py

์™ธ๋ถ€ command agent ์ƒ์„ฑ๊ณผ ๊ฒ€์ฆ

Hermes๋ฅผ ์“ฐ์ง€ ์•Š๊ณ  ๋กœ์ปฌ command๋ฅผ ์ง์ ‘ ํ˜ธ์ถœํ•˜๋ ค๋ฉด target.toml์— agent command๋ฅผ ๋ฌธ์ž์—ด ๋ฐฐ์—ด๋กœ ์ง€์ •ํ•œ๋‹ค.

[agent]
mode = "command"
command = [
  "my-patch-agent",
  "--context",
  "{context}",
  "--workspace",
  "{workspace}",
  "--output",
  "{patch_output}",
]
timeout_seconds = 900

๊ทธ๋‹ค์Œ ๋‹ค์Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•œ๋‹ค.

protocol-remediator remediate \
  --config /path/to/target/target.toml \
  --finding intake/parser-crash/finding.json \
  --evidence intake/parser-crash/evidence.json \
  --artifacts artifacts

core๋Š” ํŠน์ • LLM API๋ฅผ ์ง์ ‘ ํ˜ธ์ถœํ•˜์ง€ ์•Š๋Š”๋‹ค. Hermes backend๋‚˜ ์™ธ๋ถ€ command๊ฐ€ context๋ฅผ ์ฝ๊ณ  unified diff๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ณ„์•ฝ์ด๋‹ค. agent ์ž‘์—…์€ ์›๋ณธ target์ด ์•„๋‹Œ ์ž„์‹œ ๋ณต์‚ฌ๋ณธ์—์„œ ์‹คํ–‰๋œ๋‹ค.

target ์„ค์ •

์ „์ฒด ์˜ˆ์‹œ๋Š” target.toml์— ์žˆ๋‹ค.

[project]
name = "my-protocol"
language = "c++"
root = "."

[executor]
mode = "docker"
image = "my-frozen-toolchain@sha256:..."
timeout_seconds = 300
network = false

[reproduction]
failure_regex = "AddressSanitizer|heap-buffer-overflow"

[verification]
required_gates = [
  "build",
  "reproducer",
  "tests",
  "rescan",
  "refuzz",
  "protocol",
]

[gates]
build = [["cmake", "-S", ".", "-B", "build"], ["cmake", "--build", "build"]]
reproducer = [["./build/fuzz_target", "{reproducer}"]]
tests = [["ctest", "--test-dir", "build", "--output-on-failure"]]
rescan = [["./tools/run-sast", "--fail-on-new"]]
refuzz = [["./tools/refuzz", "--seconds", "60"]]
protocol = [["./tools/protocol-oracle"]]

๊ฐ command๋Š” shell ๋ฌธ์ž์—ด์ด ์•„๋‹ˆ๋ผ argument ๋ฐฐ์—ด์ด๋‹ค. ์ง€์› placeholder:

  • {workspace}: executor์—์„œ ๋ณด์ด๋Š” ์ž„์‹œ target ๊ฒฝ๋กœ
  • {reproducer}: checksum ๊ฒ€์ฆ ํ›„ ์ž„์‹œ target์— ๋ณต์‚ฌํ•œ reproducer ๊ฒฝ๋กœ

build์™€ reproducer๋Š” ํ•ญ์ƒ ํ•„์š”ํ•˜๋‹ค. ๊ธฐ๋ณธ ์ •์ฑ…์—์„œ๋Š” ์—ฌ์„ฏ gate๊ฐ€ ๋ชจ๋‘ ํ•„์ˆ˜๋‹ค. ๋Œ€์ƒ ํŠน์„ฑ์ƒ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋Š” gate๊ฐ€ ์žˆ๋‹ค๋ฉด required_gates์—์„œ ๋ช…์‹œ์ ์œผ๋กœ ์กฐ์ •ํ•ด์•ผ ํ•˜๋ฉฐ, ๋ณด๊ณ ์„œ์— ๊ทธ๋Œ€๋กœ ๋‚จ๋Š”๋‹ค.

artifact

๊ฐ ๊ฒ€์ฆ run์€ ๋‹ค์Œ์„ ๋ณด์กดํ•œ๋‹ค.

artifacts/run_<id>/
  candidate.patch
  context.json
  evidence.input.json
  finding.input.json
  finding.final.json
  patch-proposal.json
  patch-stats.json
  verification-report.json

verification-report.json์—๋Š” baseline๊ณผ patched command์˜ ์ถœ๋ ฅ์ด ํฌํ•จ๋œ๋‹ค. PoC๋‚˜ ๋กœ๊ทธ์— ๋น„๋ฐ€์ด ํฌํ•จ๋  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ artifact ์ €์žฅ์†Œ์—๋Š” ๋ณ„๋„ ์ ‘๊ทผยท๋ณด์กด ์ •์ฑ…์„ ์ ์šฉํ•ด์•ผ ํ•œ๋‹ค.

์•ˆ์ „ ๊ฒฝ๊ณ„

  • ๊ธฐ๋ณธ ๊ถŒ์žฅ์€ pinned Docker image์™€ network=false๋‹ค.
  • local executor๋Š” allow_local=true๋ฅผ ์ง์ ‘ ์„ ์–ธํ•ด์•ผ ํ•˜๋ฉฐ ์‹ ๋ขฐํ•  ์ˆ˜ ์—†๋Š” target์—๋Š” ์‚ฌ์šฉํ•˜๋ฉด ์•ˆ ๋œ๋‹ค.
  • ์™ธ๋ถ€๋กœ ๋‚˜๊ฐ€๋Š” LLM command์˜ ๋ฐ์ดํ„ฐ ์ •์ฑ…์€ ์šด์˜์ž๊ฐ€ ๊ฒฐ์ •ํ•œ๋‹ค. core๋Š” ์ž๋™ ์—…๋กœ๋“œํ•˜์ง€ ์•Š๋Š”๋‹ค.
  • plausible์€ build์™€ ์› reproducer๋งŒ ํ†ต๊ณผํ•œ ์ƒํƒœ๋‹ค.
  • verified๋„ program equivalence์˜ ์ฆ๋ช…์€ ์•„๋‹ˆ๋ฉฐ ์‚ฌ๋žŒ ์Šน์ธ์„ ๋Œ€์ฒดํ•˜์ง€ ์•Š๋Š”๋‹ค.
  • ์ž๋™ merge๋Š” ๊ตฌํ˜„ํ•˜์ง€ ์•Š์•˜๋‹ค.

๋‹ค์Œ ๊ตฌํ˜„ ์šฐ์„ ์ˆœ์œ„

  1. ์‹ค์ œ ProFuzzBench/AFLNet target adapter
  2. protocol message sequence์™€ state trace collector
  3. CodeQL ์„ ํƒ adapter ๋ฐ C/C++ source/sink model emitter
  4. ASan/UBSan/MSan๊ณผ architecture matrix ์‹คํ–‰
  5. ์ •์ƒ corpus ๊ธฐ๋ฐ˜ differential protocol oracle
  6. AutoPatchBench runner์™€ ์ •๋Ÿ‰ benchmark report

์กฐ์‚ฌ ๊ทผ๊ฑฐ์™€ ์„ค๊ณ„ ๊ฒฐ์ •์€ docs/research์— ์ •๋ฆฌ๋˜์–ด ์žˆ๋‹ค (Korean).

License

MIT

About

Evidence-driven C/C++ vulnerability remediation: sanitizer/SARIF intake, isolated patch verification

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages