Skill: Repository Scan — Cross-Stack Source Code Audit
Supplementary Files:
payloads.md — Repository scanning commands, classification scripts, and analysis payloads organized by scan phase
test-cases.md — Structured test cases for surface classification, dependency detection, hotspot mapping, and complete audit workflows
Summary
Repo Scan skill domain covering assessment operations.
Domain: assessment
Description
Cross-stack source code asset audit that classifies every file, detects embedded third-party libraries, and delivers actionable verdicts per module. This skill is used during white-box penetration testing and security code reviews to understand what code is present, what's third-party, and where security risks may hide.
Difference from security-review: security-review provides a checklist for auditing security patterns. This skill focuses on mapping and classifying the codebase itself — understanding what code exists, what's custom vs third-party, and where to focus security analysis.
Use Cases
- White-box penetration test preparation: understand the target codebase structure before deep analysis
- Open-source security audit: map the attack surface of a project before hunting vulnerabilities
- Third-party library inventory: identify embedded dependencies with known vulnerabilities
- M&A security due diligence: assess code quality and security of an acquired codebase
- Supply chain audit: verify what third-party code is actually running in the target
Core Tools
| Tool |
Purpose |
Command Example |
| semgrep |
Pattern-based static analysis |
semgrep --config=auto --json . |
| trivy |
Dependency and container scanning |
trivy fs . |
| grype |
Vulnerability matching for packages |
grype dir:. |
| trufflehog |
Secret scanning in git history |
trufflehog git file://. --since-commit HEAD~100 |
| gitleaks |
Git secret detection |
gitleaks detect --source . |
| cloc |
Line counting by language |
cloc --by-file . |
| gh |
GitHub code search and analysis |
gh search code "<pattern>" --language python |
Methodology
Repo Scan Four-Phase Process
Phase 1: Surface Classification
Enumerate and tag every file:
# Count lines of code by language
cloc --by-file . --json
# Identify file types and structure
find . -type f | sed 's/.*\.//' | sort | uniq -c | sort -rn
# Detect third-party directories
find . -type d \( -name "vendor" -o -name "node_modules" -o -name "third_party" -o -name "external" -o -name "libs" -o -name "deps" \)
Classify each file as:
- Project code — written by the project authors
- Third-party code — embedded libraries, vendored dependencies
- Build artifacts — compiled output, generated files
- Configuration — settings, deployment files
- Test code — test fixtures, mock data
Phase 2: Library Detection
Identify embedded third-party libraries:
# Scan for known libraries and CVEs
trivy fs --scanners vuln .
grype dir:. --output json
# Check specific library versions
grep -r "version" vendor/*/package.json
grep -r "VERSION" libs/*/*.h
Phase 3: Security Hotspot Analysis
Focus review on high-value targets:
# Find authentication-related code
grep -rn "password\|auth\|token\|session\|login" --include="*.py" --include="*.js" --include="*.java" .
# Find database interaction
grep -rn "query\|execute\|cursor\|select\|insert\|update" --include="*.py" .
# Find file operations
grep -rn "open(\|readfile\|upload\|download\|include\(" --include="*.php" .
# Secret scanning
trufflehog filesystem . --json
gitleaks detect --source . --report-format json
Phase 4: Verdict and Report
Assign verdicts per module:
| Verdict |
Meaning |
Action |
| Core Asset |
Custom business logic, high security value |
Deep security review required |
| Extract & Update |
Vendored library, should be managed dependency |
Replace with package manager; check CVEs |
| Rebuild |
Duplicated or outdated wrapper code |
Refactor; apply current security patterns |
| Deprecate |
Dead code, unused modules |
Remove to reduce attack surface |
Cross-Stack Coverage
| Stack |
Key Files |
Security Focus |
| C/C++ |
Makefile, CMakeLists.txt, *.c, *.h |
Buffer overflows, memory management |
| Java/Android |
build.gradle, pom.xml, *.java |
Deserialization, SQL injection |
| iOS |
Podfile, *.swift, *.m |
Keychain usage, certificate pinning |
| Web (JS/TS) |
package.json, *.js, *.ts |
XSS, prototype pollution, supply chain |
| Python |
requirements.txt, *.py |
Pickle deserialization, command injection |
| Go |
go.mod, *.go |
Race conditions, unsafe operations |
| PHP |
composer.json, *.php |
SQL injection, file inclusion |
| Rust |
Cargo.toml, *.rs |
Unsafe blocks, dependency auditing |
Defense Perspective
- Inventory everything: You can't secure what you don't know exists
- Pin dependencies: Lock exact versions to prevent supply chain attacks
- Remove dead code: Every line of code is a potential attack surface
- Separate concerns: Third-party code should be isolated from business logic
- Automate scanning: Integrate repo scanning into CI/CD pipelines
Report Template
# Repository Scan Report
*Target: [repo/project] | Date: [date] | Depth: [fast/standard/deep]*
## Executive Summary
[Total files, languages, third-party ratio, key findings]
## Classification Summary
| Category | Files | Lines of Code | Percentage |
|----------|-------|---------------|------------|
| Project Code | N | N | N% |
| Third-Party | N | N | N% |
| Build Artifacts | N | N | N% |
## Detected Libraries
| Library | Version | Known CVEs | Status |
|---------|---------|------------|--------|
| [Name] | [X.Y.Z] | [N CVEs] | [Outdated/Current] |
## Module Verdicts
| Module | Verdict | Rationale | Security Priority |
|--------|---------|-----------|-------------------|
| [Name] | Core Asset / Extract / Rebuild / Deprecate | [Why] | [High/Med/Low] |
## Security Hotspots
[High-priority files/directories for deep security review]
## Recommendations
[Prioritized action items based on verdicts and findings]
Detection Methods
Repository Activity Audit
- Mass cloning: Single token cloning many repos; suspicious pattern.
- Code search anomalies:
api.github.com/search/code API abuse; rate limit violations.
- Commit frequency: New contributor with many commits to security-sensitive files.
SIEM Detection Rules
- Splunk SPL:
index=github audit | stats count by actor, action | where action="git.clone" | sort -count
- GitHub Advanced Security: Secret scanning, CodeQL alerts in PRs.
- GitGuardian / GitPrey: Secret detection in repositories.
Defense Evasion Techniques
Stealth Cloning
- Slow & distributed: Pace cloning; below per-token rate limit.
- Multiple tokens: Use multiple credentials; spread across many sources.
- Mirror via CI: Use legitimate CI pipeline to mirror repos; appears as routine sync.
Code Search Stealth
- Use authenticated API:
api.github.com/search/code over browser search (rate-limited but less suspicious).
- Local mirror: Clone repos locally; search offline.
- Fork + scan: Fork target repo privately; scan without revealing interest.
Orchestration
ECC Loop Pattern
- Pattern: Batch Processing (classify → detect → map → scan → verdict across multiple files/modules)
- Rationale: Repository scanning processes many files in batch — classification, dependency detection, and hotspot analysis all operate across the entire codebase simultaneously
- Integration: security-review (consumes repo-scan output for targeted review), terminal-ops (evidence capture), continuous-learning (pattern extraction from scan results)
Cross-Skill Pipeline
repo-scan → security-review → verification-loop → chronicle
↓ ↑
search-first (find tools) continuous-learning (persist patterns)
Quality Gate
- Pre-condition: Repository accessible, scanning tools installed
- Post-condition: All files classified, dependencies inventoried, hotspots mapped, verdicts assigned
- Verification: Third-party ratio calculated, secret scan completed, report generated
1---2name: repo-scan3description: Cross-stack source code asset audit that classifies every file, detects embedded third-party libraries, and delivers actionable verdicts per module.4---56789# Skill: Repository Scan — Cross-Stack Source Code Audit1011> **Supplementary Files**:12> - `payloads.md` — Repository scanning commands, classification scripts, and analysis payloads organized by scan phase13> - `test-cases.md` — Structured test cases for surface classification, dependency detection, hotspot mapping, and complete audit workflows1415## Summary1617Repo Scan skill domain covering assessment operations.1819**Domain**: assessment2021## Description2223Cross-stack source code asset audit that classifies every file, detects embedded third-party libraries, and delivers actionable verdicts per module. This skill is used during white-box penetration testing and security code reviews to understand what code is present, what's third-party, and where security risks may hide.2425Difference from `security-review`: security-review provides a checklist for auditing security patterns. This skill focuses on mapping and classifying the codebase itself — understanding what code exists, what's custom vs third-party, and where to focus security analysis.2627## Use Cases2829- White-box penetration test preparation: understand the target codebase structure before deep analysis30- Open-source security audit: map the attack surface of a project before hunting vulnerabilities31- Third-party library inventory: identify embedded dependencies with known vulnerabilities32- M&A security due diligence: assess code quality and security of an acquired codebase33- Supply chain audit: verify what third-party code is actually running in the target3435## Core Tools3637| Tool | Purpose | Command Example |38|------|---------|-----------------|39| semgrep | Pattern-based static analysis | `semgrep --config=auto --json .` |40| trivy | Dependency and container scanning | `trivy fs .` |41| grype | Vulnerability matching for packages | `grype dir:.` |42| trufflehog | Secret scanning in git history | `trufflehog git file://. --since-commit HEAD~100` |43| gitleaks | Git secret detection | `gitleaks detect --source .` |44| cloc | Line counting by language | `cloc --by-file .` |45| gh | GitHub code search and analysis | `gh search code "<pattern>" --language python` |4647## Methodology4849### Repo Scan Four-Phase Process5051**Phase 1: Surface Classification**5253Enumerate and tag every file:5455```bash56# Count lines of code by language57cloc --by-file . --json5859# Identify file types and structure60find . -type f | sed 's/.*\.//' | sort | uniq -c | sort -rn6162# Detect third-party directories63find . -type d \( -name "vendor" -o -name "node_modules" -o -name "third_party" -o -name "external" -o -name "libs" -o -name "deps" \)64```6566Classify each file as:67- **Project code** — written by the project authors68- **Third-party code** — embedded libraries, vendored dependencies69- **Build artifacts** — compiled output, generated files70- **Configuration** — settings, deployment files71- **Test code** — test fixtures, mock data7273**Phase 2: Library Detection**7475Identify embedded third-party libraries:7677```bash78# Scan for known libraries and CVEs79trivy fs --scanners vuln .80grype dir:. --output json8182# Check specific library versions83grep -r "version" vendor/*/package.json84grep -r "VERSION" libs/*/*.h85```8687**Phase 3: Security Hotspot Analysis**8889Focus review on high-value targets:9091```bash92# Find authentication-related code93grep -rn "password\|auth\|token\|session\|login" --include="*.py" --include="*.js" --include="*.java" .9495# Find database interaction96grep -rn "query\|execute\|cursor\|select\|insert\|update" --include="*.py" .9798# Find file operations99grep -rn "open(\|readfile\|upload\|download\|include\(" --include="*.php" .100101# Secret scanning102trufflehog filesystem . --json103gitleaks detect --source . --report-format json104```105106**Phase 4: Verdict and Report**107108Assign verdicts per module:109110| Verdict | Meaning | Action |111|---------|---------|--------|112| **Core Asset** | Custom business logic, high security value | Deep security review required |113| **Extract & Update** | Vendored library, should be managed dependency | Replace with package manager; check CVEs |114| **Rebuild** | Duplicated or outdated wrapper code | Refactor; apply current security patterns |115| **Deprecate** | Dead code, unused modules | Remove to reduce attack surface |116117### Cross-Stack Coverage118119| Stack | Key Files | Security Focus |120|-------|-----------|----------------|121| C/C++ | Makefile, CMakeLists.txt, *.c, *.h | Buffer overflows, memory management |122| Java/Android | build.gradle, pom.xml, *.java | Deserialization, SQL injection |123| iOS | Podfile, *.swift, *.m | Keychain usage, certificate pinning |124| Web (JS/TS) | package.json, *.js, *.ts | XSS, prototype pollution, supply chain |125| Python | requirements.txt, *.py | Pickle deserialization, command injection |126| Go | go.mod, *.go | Race conditions, unsafe operations |127| PHP | composer.json, *.php | SQL injection, file inclusion |128| Rust | Cargo.toml, *.rs | Unsafe blocks, dependency auditing |129130### Defense Perspective131132- **Inventory everything**: You can't secure what you don't know exists133- **Pin dependencies**: Lock exact versions to prevent supply chain attacks134- **Remove dead code**: Every line of code is a potential attack surface135- **Separate concerns**: Third-party code should be isolated from business logic136- **Automate scanning**: Integrate repo scanning into CI/CD pipelines137138## Report Template139140```markdown141# Repository Scan Report142*Target: [repo/project] | Date: [date] | Depth: [fast/standard/deep]*143144## Executive Summary145[Total files, languages, third-party ratio, key findings]146147## Classification Summary148| Category | Files | Lines of Code | Percentage |149|----------|-------|---------------|------------|150| Project Code | N | N | N% |151| Third-Party | N | N | N% |152| Build Artifacts | N | N | N% |153154## Detected Libraries155| Library | Version | Known CVEs | Status |156|---------|---------|------------|--------|157| [Name] | [X.Y.Z] | [N CVEs] | [Outdated/Current] |158159## Module Verdicts160| Module | Verdict | Rationale | Security Priority |161|--------|---------|-----------|-------------------|162| [Name] | Core Asset / Extract / Rebuild / Deprecate | [Why] | [High/Med/Low] |163164## Security Hotspots165[High-priority files/directories for deep security review]166167## Recommendations168[Prioritized action items based on verdicts and findings]169```170171## Detection Methods172173### Repository Activity Audit174- **Mass cloning**: Single token cloning many repos; suspicious pattern.175- **Code search anomalies**: `api.github.com/search/code` API abuse; rate limit violations.176- **Commit frequency**: New contributor with many commits to security-sensitive files.177178### SIEM Detection Rules179- **Splunk SPL**: `index=github audit | stats count by actor, action | where action="git.clone" | sort -count`180- **GitHub Advanced Security**: Secret scanning, CodeQL alerts in PRs.181- **GitGuardian / GitPrey**: Secret detection in repositories.182183## Defense Evasion Techniques184185### Stealth Cloning186- **Slow & distributed**: Pace cloning; below per-token rate limit.187- **Multiple tokens**: Use multiple credentials; spread across many sources.188- **Mirror via CI**: Use legitimate CI pipeline to mirror repos; appears as routine sync.189190### Code Search Stealth191- **Use authenticated API**: `api.github.com/search/code` over browser search (rate-limited but less suspicious).192- **Local mirror**: Clone repos locally; search offline.193- **Fork + scan**: Fork target repo privately; scan without revealing interest.194195## Orchestration196197### ECC Loop Pattern198- **Pattern**: Batch Processing (classify → detect → map → scan → verdict across multiple files/modules)199- **Rationale**: Repository scanning processes many files in batch — classification, dependency detection, and hotspot analysis all operate across the entire codebase simultaneously200- **Integration**: security-review (consumes repo-scan output for targeted review), terminal-ops (evidence capture), continuous-learning (pattern extraction from scan results)201202### Cross-Skill Pipeline203```204repo-scan → security-review → verification-loop → chronicle205 ↓ ↑206search-first (find tools) continuous-learning (persist patterns)207```208209### Quality Gate210- Pre-condition: Repository accessible, scanning tools installed211- Post-condition: All files classified, dependencies inventoried, hotspots mapped, verdicts assigned212- Verification: Third-party ratio calculated, secret scan completed, report generated