Download as pdf or txt
Download as pdf or txt
You are on page 1of 62

제목 쓰는 공간입니다

다형성 바이러스 분석 방법
㈜ AhnLab / ASEC
한창규 선임 연구원
목차

Ⅰ. 바이러스 개요

Ⅱ. 바이러스 분석

Ⅲ. 다형성 바이러스

Ⅳ. Case Study

Ⅴ. 결 론

2
Ⅰ. 바이러스 개요
1. 바이러스 정의

2. 바이러스 분류

3. 바이러스 발전 단계

4. 감염 기법

3
1.바이러스 정의
‰악성코드 정의
9 The Malware (for "malicious software") is any program
or file that is harmful to a computer user.
Thus, malware includes computer Viruses, Worms,
Trojan horses, and also SpyWare, programming that
gathers information about a computer user without
permission. (영문 Terms)

‰바이러스 정의
9 We define a computer ‘virus’ as a program can
‘infect’ other programs by modifying them to include
a possibly evolved copy of itself. ( Fred Cohen 1984 ]

4
2.바이러스 분류
바이러스 분류

기준 세부내용
■ 부트바이러스 (부트 섹터 감염, Brain, Monkey, Anti-CMOS )
■ 파일 바이러스 (COM, EXE 실행파일 감염, 예루살렘, Sunday, Scorpion, Crow )
감염 대상
■ 부트/파일 바이러스 (부트섹터, 파일 모두 감염, Invader(1990), 안락사(Euthanasia))
■ 매크로 바이러스 (XM/Laroux)

■ DOS 바이러스 ( Brain, 예루살렘, 미켈란 젤로 등등)


■ Window 바이러스 (NE 계열 바이러스, PE 계열 바이러스)
운영 체제
■ Unix 바이러스
■ 기타

■ 기생형 바이러스 (Parasitic Virus)


■ 겹쳐쓰기형 바이러스 (Overwriting Virus)
감염 위치
■ 산란형 바이러스 (Spawning)
■ 연결형 바이러스 (linking Virus)

■ 상주형 바이러스 (Resident Virus)


동작 원리
■ 비상주형 바이러스 (Non-Resident Virus)

5
3.바이러스 발전 단계


제 11세대
세대
• 단순한 구조, 분석 용이
(Primitive)
(Primitive)
• Stoned Virus, Jerusalem Virus

제제 22세대
세대
(Encryption)
(Encryption) • 암호화 기법 사용
• Cascade Virus, Slow Virus


제 33세대
세대
(Stealth) • 은폐 기법 사용
(Stealth)
• Joshi Virus, Wanderer Virus


제 44세대
세대
(Armour) • 분석 방해 (Polymorphic, EPO 기법)
(Armour)
• Whale Virus

6
4.감염 기법 (1/4)
Entry Point를 수정하는 방법

감염전 프로그램 크기

감염전 프로그램

Entry Point

감염후 프로그램 크기

감염후 프로그램 바이러스

Entry Point

7
4.감염 기법 (2/4)
Entry Point 부분의 코드를 수정하는 방법

감염전 프로그램 크기

감염전 프로그램

Entry Point

11

감염후 프로그램 바이러스


22
Entry Point

8
4.감염 기법 (3/4)
EPO (Entry Point Obscuring) 기법

감염전 프로그램 크기

감염전 프로그램

Entry Point

11

감염후 프 로 그 램 바이러스
22
Entry Point

9
4.감염 기법 (4/4)
EPO (Entry Point Obscuring) 기법

[감염전 코드]
코드]

[감염후 코드]
코드]

10
Ⅱ. 바이러스 분석
1. 사전 지식

2. 분석 과정

3. 진단법

11
1.사전 지식(1/14)

분석
분석 도구
도구 운영체제
운영체제 // 통신
통신 분석
분석 기본
기본 지식
지식

• 기본 툴 • 운영체제 • StartUp Code


- Frhed HexaEditor, UltraEdit - Process / Thread, DLL
- Process Explorer - 가상메모리 / Memory Mapping
• 실행 파일 구조 (EXE, NE, PE)
- PEID, LordPE - 드라이버, 서비스 프로세스
- Dependency Walker - Kernel/Synchronization Object
- Structured Exception Handling • 실행 압축
• 모니터링 툴
- FileMon
- RegMon • 통신 • DLL Injection 기법
- TcpViewer, NetStat - TCP / UDP 프로토콜
- Analyzer, Etherreal - 통신 프로그램 구조 • Stealth 기법
• 디버깅 / 디어셈플 툴 - Socket API
- Dos Debuger
• Windows File Protection
- OllyDbg
- IDA Pro
- WinDbg
- SoftICE

12
1.사전 지식(2/14)
StartUp Code

[메인 덧셈 프로그램]
프로그램] [StartUp Code]

13
1.사전 지식(3/14)
실행파일 구조

14
1.사전 지식(4/14)
실행파일 구조 (Import Directory Table)

[Import Directory Table]

[Import Name Table]

[Import Hints / Names]

15
1.사전 지식(5/14)
실행파일 구조 (Export Directory Table)

[Export Directory Table]

[Export Address Table]

[Export Name Table]

16
1.사전 지식(6/14)
실행 압축 (분석지연, AV 진단우회, 다양한 변형 제작)

[실행압축 종류]
종류]

17
1.사전 지식(7/14)
실행 압축 (OEP)

[실행압축 이전 OEP]

[실행압축 이후 OEP]

18
1.사전 지식(8/14)
DLL Injection 기법 1

‰ 레지스트리 등록 기법
- user32.dll 를 사용하는 프로그램에 Injection (NT 계열)
- user32.dll 이 다른 프로세스에 attach 될때 레지스트리에 등록된 dll를 로드하여 attach
시켜줌

[HKLM\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Windows]
"AppInit_DLLs"="d:\Work\Test\Debug\Test.dll “

‰ Windows Message Hook 기법


- 정상적인 DLL Injection 기법(정상 프로그램에서 주로 사용되며, Win9x/NT 계열)
- SetWindowsHookEx, UnhookWindowsHookEx API 사용

19
1.사전 지식(9/14)
DLL Injection 기법 2

‰ DLL Forwarding 기법 (Proxy DLL)


- 원본 DLL의 이름을 변경한후, Hooking DLL를 원본 DLL 과 동일한 이름으로 변경
- Hooking Dll 에서는 원본 Dll의 함수를 Export 해야 하며, 원하는 동작후에
원본 함수를 호출해야 함

원본 : ws2_32.dll Î ws2_32_org.dll
Hook : hook.dll Î ws2_32.dll

‰ Remote Thread 기법
- 타 프로세스에 Thread를 생성하는 API 이용 (NT 계열)
- DLL Injection를 사용하는 최근 악성코드의 대부분이 이 기법 사용
- CreateRemoteThread, WriteProcessMemory API 사용

20
1.사전 지식(10/14)
[Win32/Korgo.worm DLL Injection]

21
1.사전 지식(11/14)
‰ Stealth 기법
9 사용자가 악성코드의 설치/ 감염 여부를 확인 못하도록 함
9 악성 코드 진단 회피

고전적 기법

• 유사한 파일명, 파일크기 변경, 파일명 숨김 등등


• 도스/BIOS 인터럽트 후킹
- 인터럽트 백터를 수정하여 메모리에 상주한 바이러스 코드 호출

최신 기법

• IAT(Import Address Table) Hooking


• SSDT(System Service Dispatch Table) Hooking
• IRP(I/O Request Packet) Hooking
• DKOM(Direct Kernel Object Manipulation)

22
1.사전 지식(12/14)
Stealth 기법 (SSDT 후킹)

23
1.사전 지식(13/14)
‰ WFP (Windows File Protection)
9 A mechanism that protects system files from being modified or deleted
9 시스템 안정성 (Stability) 확보
9 시스템 무결성 (Integrity] 확보
9 DLL HELL 문제 해결

SFC.DLL SFCFILES.DLL

WFP executable content. Contains list of protected files

In XP only a proxy to SFC_OS.DLL Exports SfcGetFiles API

System
System File
File
SFC_OS.DLL Checker SFC.EXE
Checker

System File Checker utility


WFP executable content
Utility to scan WFP protected files for changes
and replace altered versions.

24
1.사전 지식(14/14)
WFP (Windows File Protection) 무력화 기법

‰ Closing Directory Change Notification Handle

‰ Terminating SFC Watcher Thread via undocumented SFC API

‰ Disable WFP for 1 minute

‰ Disable WFP Permanently via patches and undocumented


registry value

‰ Disable WFP Permanently for specific files via patching the


protected file list

25
2.분석 과정(1/2)

기초
기초 분석 (외형 분석
분석(외형 분석,, 증상
증상 분석
분석,, 자료 분석)) Î
자료 분석 Î 상세분석
상세분석

외형 분석 증상 분석 자료 분석 상세 분석 엔진 반영

‰ 파일유형 ‰ 전 이미지 ‰ 증상 정보 ‰ 디어셈블 분석 ‰ 엔진 반영


판단 정보 수집 추가 분석 여부 결정
‰ 상세 디버깅
‰ 문자열 추출 ‰ 샘플 실행 ‰ 각종 정보 ‰ 진단시그니쳐
및 분석 수집 및 함수 작성
‰ 후 이미지
‰ 파일 등록 정보 수집 ‰ 로그 정보 ‰ 분석정보
정보 활용 수집/분석 작성
‰ 증상 정보
‰ 샘플 접수 분석
정보 활용

분 석 과 정

26
2.분석 과정(2/2)
바이러스 분석 과정

1. 기본 외형 분석
2. 샘플 셋 생성 및 기본 증상 확인
3. 바이러스의 감염 유형 파악(전위형, 후위형)
4. 디버깅을 통한 바이러스의 전반적인 기능 확인
(감염 대상, 감염 조건, 감염 기법 등등)
5. 호스트 프로그램 실행 부분 분석
6. 바이러스 특징 분석 (일반, 암호화, 다형성 등등)
7. 진단명 명명
8. 진단 문자열 추출
9. 치료 데이터 작성 및 검증 작업

27
3.진단법 (1/3)
바이러스 진단법

1. Signature 기반 진단법
- 진단 위치 (Entry Point / 프로그램의 전체 크기)
- Signature (특정 영역 / 특정 코드)
- 특정 위치 진단법 (by Ahnlab)

2. Non-Signature 기반 진단법
- 전용진단 함수 제작
선행조건 검사
악성코드 각각의 특징을 검사

3. 행위 기반 진단법
- 악성코드 행위에 대한 진단
파일 이름, 인젝션, 파일 Drop, 통신 포트 오픈 등등

28
3.진단법 (2/3)
Signature 기반 진단법
[특정 영역 Signature]

[특정 OP 코드]
코드]

29
3.진단법 (3/3)
Non-Signature 기반 진단법

[전용 진단 함수]
함수]

30
Ⅲ. 다형성 바이러스
1. 다형성 바이러스 개요

2. 변형 기법

3. 다형성 바이러스 진단

31
1.다형성 바이러스 개요 (1/6)
암호화 바이러스

1. 암호화 Key
- 동일한 Decryption 루틴 Encryption
Encryption
- 가변 Key 값 Key
Key

2. Decoding Buffer
- Overwritting hello $#!!%
- Stack Memory
- Allocated Memory
Key
Key
3. 암호화 기법 Substitution
Substitution Table
Table
- Linear / Non-Linear
- Multiple Layer
- RDA

32
1.다형성 바이러스 개요 (2/6)
암호화 바이러스

[감염 상태]
상태]

EP

Host
11
Program

Decoding Routine

22
Encoded Virus
Body

33
1.다형성 바이러스 개요 (3/6)
Polymorphic Virus

[Polymorphic Virus]
[Encrypted Virus]

EP
EP

Encrypted Virus Host


Host
Program
11 Program +
Mutation Engine
Decoding Routine

Encoded Virus
Decoding Routine MtE , TPE , … Body
22
Encoded Virus Mutation
Body Engine

34
1.다형성 바이러스 개요 (4/6)
Polymorphic Virus

[MtE]

35
1.다형성 바이러스 개요 (5/6)
Metamorphic Virus

Polymorphic Virus Metamorphic Virus

G1
G1 *#!^ G1
%


Encoding G2 •

G2
G2
&*^

%#
Virus Virus Metamorphic G3 •
원본
• 원본

• •
• •
Decoding
• G4

Gn
Gn ~!#$
^ Gn

36
1.다형성 바이러스 개요 (6/6)
Metamorphic Virus

[ZMIST]

37
2.변형 기법 (1/4)
사용 명령어 변경

EE :: ModR/M
ModR/M follows
follows the
the opcode
opcode and
and specifies
specifies the
the operand.
operand.
G
G :: The
The reg
reg field
field of
of ModR/M
ModR/M select
select aa general
general register.
register.

01C1 → ADD ECX, EAX 1100 0001


11C1 → ADC ECX, EAX 1100 0001
21C1 → AND ECX, EAX 1100 0001
31C1 → XOR ECX, EAX 1100 0001
31C2 → XOR EDX, EAX 1100 0010

38
2.변형 기법 (2/4)
Garbage 명령 삽입

39
2.변형 기법 (3/4)
사용 Register 변경

1. Same code pattern

40
2.변형 기법 (4/4)
Permutation

V1 V2
22

11
V2 V5
Permutation
V3 V1 44

V4 V4
33

V5 V3

41
3.다형성 바이러스 진단 (1/3)
다형성 바이러스 진단

1. Signature 기반 진단
- 다형성 엔진에 대한 시그니쳐 진단
- 오진 / 비정상 치료

2. 전용진단 함수
- 선행 조건
- 사용된 명령어 패턴 기반 진단

3. Emulation
- Emulation 시작 위치 ( EPO )
- Emulation 종료
- 진단 속도 / 예외 처리
- Anti-Emulation 기법에 대한 대비

42
3.다형성 바이러스 진단 (2/3)
전용 진단 함수 (명령어 패턴)
[Win32/Zmist]

43
3.다형성 바이러스 진단 (3/3)
Anti-Emulation Technique

1. Co-Processor / MMX instruction usage

2. Structured Exception Handling Usage

3. Random Virus Code Execution

4. Use Of Brute Force Decryption of Virus Code (RDA)

5. Use of API

44
Ⅳ. Case Study
1. Win32/Polip 분석

2. 진단

3. 치료

45
3.Win32/Polip 분석 (1/9)
Win32/Polip Virus

EP
1. EPO 기법 사용 EP
PE Header

2. 다형성 엔진 + XTEA 변형 Section Table

3. 섹션 빈 공간에 코드 추가 .text

4. NULL 섹션 추가 Virus
Virus
.data
5. 파일 크기 증가 (60 ~ 70 KB)
.null
6. Win32.Polipos 1.2 by Joseph

.rsrc

46
3.Win32/Polip 분석 (2/9)
Polymorphic Engine - EPO (Entry Point Obscruing)

[Pinball.exe 감염]
감염] [Msn6.exe 감염]
감염]

47
3.Win32/Polip 분석 (3/9)
Polymorphic Engine – Random Memory Access

48
3.Win32/Polip 분석 (4/9)
Polymorphic Engine – Garbage 명령 삽입

[Pinball.exe 감염]
감염] [Msn6.exe 감염]
감염]

49
3.Win32/Polip 분석 (5/9)
Polymorphic Engine – Random Code Execution

50
3.Win32/Polip 분석 (6/9)
XTEA (eXtended Tiny Encryption Algorithm) 원형

51
3.Win32/Polip 분석 (7/9)
XTEA (eXtended Tiny Encryption Algorithm) 변형

52
3.Win32/Polip 분석 (8/9)
XTEA (eXtended Tiny Encryption Algorithm) 변형

53
3.Win32/Polip 분석 (9/9)
Win32/Polip XTEA – Decoding 루틴 구조

54
2.Win32/Polip 진단 (1/2)
Emulation ( Pre-Condition 체크 )

55
2.Win32/Polip 진단 (2/2)
진단문자열 ( Virus Body )

56
3.Win32/Polip 치료 (1/2)
치료 정보

[복호화 후 Stack] [Pinball.exe 감염]


감염]

V1

V2

0x7554
0x7554 치료
치료 데이터
데이터
V3
06 FF 25 84 11 00 01

V4

0x759E
0x759E 치료
치료 위치
위치
02 AB 63 00 00
V5
BC C1 01 00

V6

57
3.Win32/Polip 치료 (2/2)
치료 ( Entry Point 치료 Vs 원본 파일에 가깝게 )

EP
EP
PE Header
EP
EP
Section Table PE Header

Section Table
.text

Virus 치료 .text
Virus
.data

.data
.null

.rsrc
.rsrc

58
Ⅴ. 결 론

59
결론

1. Evolution of Polymorphic Virus

2. Analysis Technique of Polymorphic Virus

3. Scanning Speed

60
참고 문헌

http://www.ahnlab.com
http://www.ncsc.go.kr
http://www.kisa.or.kr
http://www.sysinternals.com
http://www.rootkit.com
http://www.microsoft.com/korea/technet/security
http://msdn.microsoft.com/default.aspx
http://vx.netlux.org/lib/vmd03.html
http://www.bitdefender.com/VIRUS-1000066-en--Win32.Polip.A.html
http://secunia.com/virus_information
http://www.virusbtn.com/index
The Windows 2000 Device Driver Book
Inside Microsoft Windows2000 Third Edition (Mark E. Russinovich)
Programming Applications for Microsoft Windows Fourth Edition (Jeffrey Ritcher)
Subverting The Windows Kernel Rootkits (Greg Hoglund)
Programming the Microsoft Windows Driver Model (Walter Oney)
The Art of Computer Virus Research and Defender (Peter Szor)
Hacker Dissembling Uncovered (Kris Kaspersky)

61
Q/A

경청해 주셔서 감사합니다

62

You might also like