Nuget 스캐너
⚠️ 작업 진행 중 — 프로젝트는 활발히 개발 중입니다. 핵심 스캐닝 엔진을 재구축하고 있습니다
NuReaper는 NuGet 패키지의 보안을 자동으로 분석하는 .NET 8 백엔드 API입니다. NuGet 패키지 링크를 제공하면 시스템이 전체 의존성 트리를 재귀적으로 다운로드하고, 컴파일된 코드를 디컴파일한 뒤, 모든 메서드에서 악성 패턴을 스캔하여 상세한 위협 보고서를 반환합니다.
🔍 비기술 독자를 위한 설명: 스마트폰에 앱을 설치하는 상황을 생각해 보세요. 앱과 함께 수십 개의 작은 라이브러리들이 자동으로 설치됩니다. NuReaper는 실제 컴파일된 바이너리 코드를 살펴보면서 이들 각각을 검사하고, 의심스러운 서버에 연결하려 하거나, 숨겨진 코드를 실행하거나, 실제 동작을 난독화하려는 것이 있는지 탐지합니다.
NuGet 패키지 URL과 함께 단일 HTTP 요청을 보내면 NuReaper가 다음을 수행합니다:
.nupkg 파일을 가져와 SHA-256 해시를 계산합니다엔진은 IL(Intermediate Language) 명령어 수준에서 코드를 분석하고, 악성 소프트웨어의 특징인 7가지 패턴을 인식합니다:
| # | 패턴 | 설명 |
|---|---|---|
| 1 | 직접 API 호출 | 의심스러운 문자열이 즉시 네트워크 호출에 사용됨 |
| 2 | 문자열 할당 | URL이 변수에 할당된 후 네트워크 호출로 전달됨 |
| 3 | 문자열 구성 | 연결로 URL을 생성("http://" + var + "/path") — 난독화 기법 |
| 4 | 문자열 보간 | 보간으로 URL을 조립($"{part1}{part2}") |
| 5 | 문자 전용 보간 | 문자 배열에서 문자 단위로 URL을 생성 — 고급 난독화 |
| 6 | DefaultInterpolatedStringHandler | 정적 분석에서 문자열을 숨기기 위해 사용되는 저수준 보간 메커니즘 |
| 7 | 베어 API 호출 | 명시적 문자열 없이 직접 네트워크 호출(TcpClient.Connect, Socket.Connect, Process.Start) |
Network: HttpClient, WebClient, DNS, TcpClient, WebSocket
Execution: Process.Start, Assembly.Load, Activator.CreateInstance
Low-level: DllImport, VirtualAlloc, CreateThread, NtCreateThreadEx
System: ManagementObjectSearcher (WMI)
String-based: Concatenation, CharArray, Interpolation, StringBuilder
Suspicious: URL, IP address, .onion address, Base64
점수 산정 알고리즘은 다음을 고려합니다:
POST /api/PackageScan주어진 NuGet 패키지와 전체 의존성 트리를 스캔합니다.
요청:
{
"url": "https://www.nuget.org/packages/System.Net.Http/4.3.4"
}
응답:
{
"rootPackageName": "System.Net.Http",
"rootPackageVersion": "4.3.4",
"totalPackages": 12,
"totalFindingsFromAllPackages": 5,
"threatLevelAllPackages": 47.5,
"scannedTimeAllPackages": "2026-03-25T12:00:00Z",
"packages": [
{
"packageName": "System.Net.Http",
"version": "4.3.4",
"sha256Hash": "abc123...",
"threatLevel": 35.0,
"totalFindings": 3,
"findings": [
{
"type": "HttpClientCall",
"confidenceScore": 95.0,
"dangerLevel": 60.0,
"evidence": "http://example.com/payload",
"location": "MyClass::SendData",
"hopDepth": 0,
"flowTrace": "[Pattern1] Direct API call using string..."
}
]
}
],
"dependencyGraph": {
"rootPackage": "[email protected]",
"nodes": [...],
"edges": [...],
"cycles": [...]
}
}
클린 아키텍처를 기반으로 하며 관심사의 엄격한 분리를 따릅니다:
NuReaperBackend/
├── NuReaper.Api/ # API layer — controllers, middleware, startup
├── NuReaper.Application/ # Application layer — commands, interfaces, DTOs, validation
├── NuReaper.Domain/ # Domain core — entities, enums, abstractions
├── NuReaper.Infrastructure/ # Implementations — scanners, parsers, repositories
│ └── Repositories/
│ ├── Scanners/ # IL analysis engine
│ │ ├── Analysis/ # ScanModule, ScanMethod, NetworkApiCallScan
│ │ ├── Detectors/ # 7 pattern detectors (Pattern1–Pattern7)
│ │ ├── Patterns/ # PatternRegistry (regex: URL, IP, .onion, Base64)
│ │ ├── RiskCalculation/# Threat scoring algorithm
│ │ ├── Finders/ # Locating API calls within IL instructions
│ │ ├── VariableAnalysis/# Tracking variable values across IL
│ │ └── StringAnalysis/ # Reconstructing strings from fragments
│ ├── Parsers/ # .nuspec file parsing
│ ├── GraphBuilders/ # Dependency graph construction (BFS + recursion)
│ └── FileHelpers/ # Download, extract, SHA-256
└── Docker/
├── Dockerfile
└── docker-compose.yml
| 영역 | 기술 / 패턴 |
|---|---|
| 아키텍처 | 클린 아키텍처 |
| 계층 간 통신 | CQRS + MediatR |
| IL 코드 분석 | dnlib |
| 입력 검증 | FluentValidation + MediatR Pipeline Behavior |
| 객체 매핑 | AutoMapper |
| 로깅 | Serilog (콘솔 + 일별 롤링 파일) |
| API 문서화 | Swagger / OpenAPI |
| 데이터베이스 | Entity Framework Core + MySQL (Pomelo) |
| HTTP | 연결 풀링을 사용하는 IHttpClientFactory |
| 컨테이너화 | Docker + Docker Compose |
| 테스트 | xUnit + Moq |
Package URL
│
▼
DependencyGraphBuilder ← builds dependency graph from .nuspec files
│ (recursion + BFS, cycle detection)
▼
List of unique packages
│
▼ (parallel, SemaphoreSlim — CPU-1 threads)
NetworkApiCallScan per package
├── DownloadPackageAsync ← fetches .nupkg
├── CalculateSha256 ← integrity verification
├── ExtractNupkgAsync ← unpacks the archive
└── GetAssemblyFiles ← lists .dll files
│
▼ (Parallel.ForEachAsync)
ScanModule (per .dll)
│
▼ (Parallel.ForEach — all types and methods)
ScanMethod (per method)
│
▼ (7 pattern detectors)
Pattern1..7 → FindingSummaryDto
│
▼
CalculateThreatLevel ← score 0–100
│
▼
ScanPackageResultResponse
| 패키지 | 용도 |
|---|---|
dnlib | .NET IL 디컴파일 및 분석 |
MediatR | CQRS — 명령/쿼리 파이프라인 |
FluentValidation | 요청 검증 |
AutoMapper | 계층 간 객체 매핑 |
Serilog | 구조화된 로깅 |
Pomelo.EntityFrameworkCore.MySql | MySQL ORM |
Swashbuckle.AspNetCore | Swagger UI |
xUnit + Moq | 단위 테스트 |
이 프로젝트는 PolyForm Noncommercial License 1.0.0에 따라 제공되며, 상업적 사용은 금지됩니다. 상업적 라이선스 또는 문의는 다음으로 연락하세요: [email protected]