Skip to content
블로그로 돌아가기

YARA 룰로 악성코드 탐지하기: 실전 가이드

u
unJaena Team
2026년 4월 10일10 분 소요
YARA 룰로 악성코드 탐지하기: 실전 가이드

YARA 룰로 악성코드 탐지하기#

YARA는 악성코드 연구자가 악성 샘플을 식별하고 분류하기 위해 사용하는 패턴 매칭 도구입니다. "악성코드 연구자의 스위스 아미 나이프"라고 불리며, 문자열 패턴과 바이너리 패턴을 조합하여 복잡한 탐지 규칙을 작성할 수 있습니다.

YARA 기초#

룰의 기본 구조#

YARA 룰은 세 가지 주요 섹션으로 구성됩니다:

yara
rule ExampleRule {
    meta:
        author = "unJaena Team"
        description = "Example YARA rule"
        date = "2026-04-10"
        severity = "high"

    strings:
        $str1 = "suspicious_string"
        $str2 = { 4D 5A 90 00 }  // MZ header
        $str3 = /https?:\/\/[a-z0-9\-\.]+\.xyz/

    condition:
        uint16(0) == 0x5A4D and
        filesize < 5MB and
        ($str1 or $str2) and
        #str3 > 2
}

핵심 요소 설명#

meta 섹션: 룰에 대한 메타데이터를 정의합니다. 탐지에는 영향을 주지 않지만, 관리와 문서화에 필수적입니다.

strings 섹션: 탐지할 패턴을 정의합니다:

  • 텍스트 문자열: "suspicious_string"
  • 16진수 바이트 패턴: { 4D 5A 90 00 }
  • 정규식: /pattern/

condition 섹션: 탐지 조건을 논리 연산자로 결합합니다.

실전 YARA 룰 작성#

1. RAT (Remote Access Trojan) 탐지#

yara
rule Detect_RAT_Indicators {
    meta:
        description = "Detects common RAT behavior patterns"
        severity = "critical"

    strings:
        $cmd1 = "cmd.exe /c" nocase
        $cmd2 = "powershell -enc" nocase
        $cmd3 = "whoami" nocase
        $net1 = "CONNECT" ascii
        $net2 = "POST /gate" ascii
        $reg1 = "CurrentVersion\\Run" nocase
        $mutex = "Global\\" ascii

    condition:
        uint16(0) == 0x5A4D and
        filesize < 10MB and
        (2 of ($cmd*)) and
        (1 of ($net*)) and
        ($reg1 or $mutex)
}

2. 정보 탈취형 악성코드 탐지#

yara
rule Detect_Stealer_Patterns {
    meta:
        description = "Detects info stealer behavior"
        severity = "high"

    strings:
        $browser1 = "\\Google\\Chrome\\User Data" nocase
        $browser2 = "\\Mozilla\\Firefox\\Profiles" nocase
        $browser3 = "\\Microsoft\\Edge\\User Data" nocase
        $wallet1 = "wallet.dat" nocase
        $wallet2 = "\\Ethereum\\keystore" nocase
        $grab1 = "passwords" nocase
        $grab2 = "cookies" nocase
        $grab3 = "autofill" nocase
        $exfil1 = "multipart/form-data" ascii
        $exfil2 = "Content-Disposition" ascii

    condition:
        uint16(0) == 0x5A4D and
        (2 of ($browser*)) and
        (1 of ($grab*)) and
        (1 of ($exfil*))
}

3. 랜섬웨어 행동 패턴 탐지#

yara
rule Detect_Ransomware_Behavior {
    meta:
        description = "Detects ransomware encryption patterns"
        severity = "critical"

    strings:
        $ext1 = ".locked" ascii
        $ext2 = ".crypt" ascii
        $ext3 = "DECRYPT" ascii nocase
        $ext4 = "RANSOM" ascii nocase
        $note1 = "Your files have been" ascii nocase
        $note2 = "bitcoin" ascii nocase
        $note3 = "payment" ascii nocase
        $shadow = "vssadmin delete shadows" nocase
        $bcdedit = "bcdedit /set" nocase

    condition:
        uint16(0) == 0x5A4D and
        filesize < 20MB and
        (2 of ($ext*)) and
        (1 of ($note*)) and
        ($shadow or $bcdedit)
}

고급 기법#

와일드카드와 점프#

바이너리 패턴에서 특정 바이트가 가변적일 때 와일드카드를 사용합니다:

yara
strings:
    // 와일드카드 (?)
    $hex1 = { 4D 5A ?? ?? 00 }

    // 점프 (가변 길이)
    $hex2 = { E8 [4-8] 85 C0 }

    // 대안 (OR)
    $hex3 = { (6A 40 | 6A 00) 68 }

모듈 활용#

YARA는 내장 모듈을 통해 PE 파일, ELF 파일 등의 구조적 분석이 가능합니다:

yara
import "pe"
import "math"

rule Suspicious_PE_Characteristics {
    meta:
        description = "PE file with suspicious characteristics"

    condition:
        pe.is_pe and
        pe.number_of_sections > 6 and
        pe.timestamp < 1000000000 and
        math.entropy(0, filesize) > 7.5 and
        pe.imports("kernel32.dll", "VirtualAlloc") and
        pe.imports("kernel32.dll", "WriteProcessMemory")
}

성능 최적화#

YARA 룰의 성능을 최적화하기 위한 핵심 원칙:

  1. condition을 빠른 검사부터 시작: uint16(0) == 0x5A4D와 같은 매직 바이트 검사를 먼저 수행
  2. filesize 제한: 불필요한 대용량 파일 스캔 방지
  3. 문자열 수 최소화: 필요한 패턴만 정의
  4. 정규식 남용 금지: 가능하면 고정 문자열 사용
  5. 와일드카드 범위 제한: [0-100]보다 [4-8]처럼 좁은 범위 사용

AI와 YARA의 결합#

전통적인 YARA 룰 기반 탐지와 AI 분석을 결합하면 더 강력한 위협 탐지가 가능합니다.

탐지 파이프라인#

수집된 파일 ↓ YARA 스캔 (160+ 룰) ├─ 매칭된 룰 정보 ├─ 심각도 분류 └─ 매칭 패턴 상세 ↓ CAPA 분석 (행위 기반) ├─ 악성 기능 식별 └─ MITRE ATT&CK 매핑 ↓ AI 종합 분석 ├─ 컨텍스트 기반 위험 평가 ├─ 오탐 필터링 └─ 자연어 분석 보고서

장점#

  • YARA의 강점: 빠른 패턴 매칭, 낮은 오탐률, 명확한 탐지 근거
  • AI의 강점: 컨텍스트 이해, 새로운 위협 패턴 식별, 종합적 분석
  • 시너지: YARA가 의심 파일을 필터링하고, AI가 심층 분석을 수행

커뮤니티 룰셋 활용#

혼자서 모든 YARA 룰을 작성할 필요는 없습니다. 검증된 커뮤니티 룰셋을 활용하세요:

  • YARA-Rules: 커뮤니티가 관리하는 포괄적인 룰 컬렉션
  • Signature-Base: Florian Roth(Neo23x0)가 관리하는 고품질 룰셋
  • Malpedia: 악성코드 패밀리별 분류된 YARA 룰
  • ThreatFox: abuse.ch의 위협 인텔리전스 기반 IOC

결론#

YARA는 악성코드 탐지의 기초이자 핵심 도구입니다. 정적 패턴 매칭이라는 단순한 원리 위에 구축되어 있지만, 잘 작성된 YARA 룰은 복잡한 위협도 효과적으로 탐지할 수 있습니다.

AI 기반 분석과 결합하면, YARA의 빠른 필터링 능력과 AI의 깊은 분석 능력이 시너지를 발휘하여, 더욱 정확하고 효율적인 위협 탐지 시스템을 구축할 수 있습니다.

unJaena 플랫폼에서는 160개 이상의 YARA 룰과 CAPA 행위 분석을 AI 파이프라인에 통합하여, 업로드된 파일에 대한 자동화된 악성코드 분석을 제공합니다.

공유하기

최신 포렌식 인사이트를 받아보세요

매월 디지털 포렌식과 AI 분석에 관한 뉴스레터를 보내드립니다.

뉴스레터 구독하기