docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를 Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류. - 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로 자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거, 동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거. - 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming, Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business, Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로, 나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는 title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백). 원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지. - 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서. - 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는 지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지. - Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경. - 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
---
|
||||
id: wiki-2026-0508-adversarial-code-stylometry
|
||||
title: Adversarial Code Stylometry
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-36585B, Code Authorship Obfuscation]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [security, ml, privacy, deanonymization]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: scikit-learn
|
||||
---
|
||||
|
||||
# Adversarial Code Stylometry
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 source code 의 author 를 statistical fingerprint 로 식별 — 그리고 attacker 는 이를 회피한다."**. Code stylometry 는 AST features + n-grams + lexical patterns 로 author 를 95% accuracy 로 deanonymize 가능; adversarial stylometry 는 transformation/obfuscation 으로 이를 무력화한다.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 Feature Family
|
||||
- **Lexical**: identifier length, naming convention, comment density.
|
||||
- **Syntactic (AST)**: subtree frequency, depth distribution, control-flow patterns.
|
||||
- **Layout**: indentation, brace style, line length.
|
||||
- **Semantic**: API choice, idiom preference (list comp vs loop).
|
||||
|
||||
### 매 Attack Surface
|
||||
- **Open-source contributors** — GitHub commits 의 deanonymization.
|
||||
- **Malware authorship** — APT attribution.
|
||||
- **Plagiarism detection** — academic/hiring context.
|
||||
- **Bug bounty / leak** — anonymous reporter identification.
|
||||
|
||||
### 매 Defense
|
||||
1. Code transformation (Caliskan 2018 — paraphrase preserving semantics).
|
||||
2. LLM-mediated rewrite (rewrite via Claude/GPT to neutralize style).
|
||||
3. Style transfer to another author (mimicry).
|
||||
4. Mechanical normalization (autoformatter + identifier randomization).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### AST Feature Extractor
|
||||
```python
|
||||
import ast
|
||||
from collections import Counter
|
||||
|
||||
def ast_node_freq(source: str) -> Counter:
|
||||
tree = ast.parse(source)
|
||||
return Counter(type(n).__name__ for n in ast.walk(tree))
|
||||
```
|
||||
|
||||
### Author Classifier (sklearn)
|
||||
```python
|
||||
from sklearn.ensemble import RandomForestClassifier
|
||||
from sklearn.feature_extraction.text import TfidfVectorizer
|
||||
from sklearn.pipeline import Pipeline
|
||||
|
||||
pipe = Pipeline([
|
||||
("tfidf", TfidfVectorizer(analyzer="char_wb", ngram_range=(2, 5))),
|
||||
("rf", RandomForestClassifier(n_estimators=300, n_jobs=-1)),
|
||||
])
|
||||
pipe.fit(train_sources, train_authors)
|
||||
```
|
||||
|
||||
### Style Obfuscation via Rewrite
|
||||
```python
|
||||
import anthropic
|
||||
|
||||
client = anthropic.Anthropic()
|
||||
|
||||
def neutralize_style(code: str) -> str:
|
||||
msg = client.messages.create(
|
||||
model="claude-opus-4-7",
|
||||
max_tokens=4096,
|
||||
messages=[{"role": "user", "content": f"""Rewrite this code to neutralize authorial style.
|
||||
Preserve semantics exactly. Use generic identifiers, standard idioms, mechanical formatting.
|
||||
|
||||
```python
|
||||
{code}
|
||||
```"""}],
|
||||
)
|
||||
return msg.content[0].text
|
||||
```
|
||||
|
||||
### Mimicry Attack (target style)
|
||||
```python
|
||||
def mimic(code: str, target_samples: list[str]) -> str:
|
||||
"""Rewrite `code` to look like `target_samples` author."""
|
||||
target_blob = "\n---\n".join(target_samples[:3])
|
||||
prompt = f"Target author samples:\n{target_blob}\n\nRewrite preserving semantics:\n{code}"
|
||||
return llm_call(prompt)
|
||||
```
|
||||
|
||||
### Detection of Obfuscated Code
|
||||
```python
|
||||
def obfuscation_signal(code: str) -> float:
|
||||
"""High score → likely autoformatted/normalized."""
|
||||
feats = ast_node_freq(code)
|
||||
entropy = -sum((c/sum(feats.values())) * np.log2(c/sum(feats.values())) for c in feats.values())
|
||||
return 1.0 - entropy / np.log2(len(feats)) # uniform → 0, peaked → 1
|
||||
```
|
||||
|
||||
### Defensive Pre-commit Hook
|
||||
```bash
|
||||
#!/usr/bin/env bash
|
||||
# .git/hooks/pre-commit
|
||||
ruff format --quiet .
|
||||
python -m style_neutralizer **/*.py
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Anonymous OSS contribution | LLM rewrite + autoformat |
|
||||
| Whistleblower | Full mimicry to public author |
|
||||
| Defensive (detection) | Char n-gram + AST RF |
|
||||
| Research baseline | Caliskan 2015 features |
|
||||
|
||||
**기본값**: autoformat + LLM neutralization for adversarial; char n-gram TF-IDF + RF for detection.
|
||||
|
||||
## 🔗 Graph
|
||||
- 변형: [[Code Obfuscation]]
|
||||
- Adjacent: [[Differential Privacy]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: style neutralization, mimicry attack, defensive paraphrase.
|
||||
**언제 X**: ground-truth authorship verification 에 LLM judgment 단독 사용.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Autoformatter 만 의존**: AST/lexical features 는 그대로 leak.
|
||||
- **Identifier rename only**: control-flow signature 가 식별 가능.
|
||||
- **Single-pass LLM rewrite**: subtle idioms 잔존 — multi-pass 필요.
|
||||
- **Train/test 동일 repo**: leakage — author-disjoint split 필수.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Caliskan 2015 USENIX Sec, Abuhamad 2018 CCS).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — AST features, attack/defense patterns |
|
||||
Reference in New Issue
Block a user