[2009 codeengn conference 03] sionics, kaientt - (파일바이러스 치료로직 개발자...
Post on 22-Apr-2015
805 Views
Preview:
DESCRIPTION
TRANSCRIPT
File Infector Virus Analysis(from the point of view of an anti-virus developer)
sionics , kaientt@issuemakerslab.com
3rd CodeEngn ReverseEngineering Seminar
2
Agenda
0x00 Malware Trends
0x01 File Infector and NOT infector
0x02 Prior Knowledge- PE Format
0x03 File Infection Techniques
0x04 File Infector Virus Analysis – Demonstration
0x05 Development of disinfection code
3rd CodeEngn ReverseEngineering Seminar
3
0x00 Malware Trends
0x00 Malware Trends
3rd CodeEngn ReverseEngineering Seminar
4
The growth of malware
Source: Andreas Marx, http://www.av-test.org
3rd CodeEngn ReverseEngineering Seminar
5
The growth of malware
Source: McAfee Avert Labs (20 Million Malware Samples)
3rd CodeEngn ReverseEngineering Seminar
6
The growth of malware
Source: Symantec CorporationInternet Security Threat Report Volume XIV: April, 2009 (New malicious code signatures)
3rd CodeEngn ReverseEngineering Seminar
7
The growth of malware
Source: Symantec CorporationInternet Security Threat Report Volume XIV: April, 2009 (Malicious code types)
Today's main threats are simple Trojan horses and worms, not file-infectors.
BUT,
3rd CodeEngn ReverseEngineering Seminar
8
file infectors will increase again
>In this age of botnets, rootkits, spyware, and other bleeding-edge security threats, file infectors are frequently thought of as a dead threat.
>Historically, file viruses were among the very first types of virus, dating back to the 1980's.
>recent increase in network file-infecting viruses
>file infectors will increase again
3rd CodeEngn ReverseEngineering Seminar
9
Advantage of File Infector
>생존 시간 증가
— 트로이목마 등의 단일파일 악성코드는 탐지가 쉬우며 치료가 파일 삭제
— 하나 이상의 파일을 감염
— 기존 실행파일들에 감염되면 사용자가 쉽게 감염여부 판단이 어려움> 은폐기능 추가 시 더 어려움
>진단과 치료
— Not Infector> Trojan, Worm, Backdoor 등, 진단시 파일 삭제만으로 치료가능
— File Infector> 감염된 모든 실행 가능한 파일
> 잘못된 진단과 잘못된 치료는 곧 업체의 신뢰성 하락과 고객의 외면
> 어느 정도의 분석 시간과 테스트 기간 필요
– 탐지 회피/지연 목적의 기법
– EPO(Entry-Point Obscuring), Polymorphism3rd CodeEngn ReverseEngineering Seminar
10
Malware Statistics
Monthly Malware Statistics: may 2009 (from Kaspersky Lab)
IFrame.aga is one more version of the iframe that the now widespread Virus.Win32.Virut.ce uses to infect web pages. And Sality.ae is the latest version of the well-known Sality virus.
3rd CodeEngn ReverseEngineering Seminar
11
0x01 File Infector and NOT infector
0x01 File Infector and NOT infector
3rd CodeEngn ReverseEngineering Seminar
12
File infector virus
Glossary
3rd CodeEngn ReverseEngineering Seminar
13
File Infector and NOT infector
NOT infector- Trojan, Backdoor, Worm, Rootkit, Spyware, Adware
File Infector- Virus (Parite, Virut, Sality, Alman)
3rd CodeEngn ReverseEngineering Seminar
14
File Infector and NOT infector
NOT infector- 파일 자체가 악성- 치료 : 파일 자체를 삭제
3rd CodeEngn ReverseEngineering Seminar
15
File Infector and NOT infector
File Infector- 기존 정상 파일에 바이러스 코드를 추가- 치료 : 바이러스 코드 부분만 삭제 (정상 파일로 복구)
3rd CodeEngn ReverseEngineering Seminar
16
Common Malicious Code Analysis
>Dynamic Analysis
>Static Analysis
>Most modern malware use some sort of runtime packer (70-90%)
— If static analysis of malware is needed, protective layer(s) must be opened
3rd CodeEngn ReverseEngineering Seminar
17
실행압축 해제 루틴 (복호화)
실행압축 (암호화)
일반 실행 파일 실행압축된 실행 파일
Executable compression
3rd CodeEngn ReverseEngineering Seminar
18
(Bonus) Common Malware Behavior - Analysis
>최초 감염
— 취약점(80% 이상)을 통한 최초 파일 생성
>파일 생성
— 자신복사, 다운로드, 드롭
>실행되도록 등록 (부팅 시)
— 레지스트리, 서비스, BHO
>동작— 프로세스, 쓰레드, DLL Injection
>네트워크 활동
— 포트 오픈, 특정 도메인/포트 접속, IRC 접속
>악성행위
— 보안기능 비활성화, 온라인 게임 계정 절취, DDoS, 스팸메일 발송
3rd CodeEngn ReverseEngineering Seminar
19
최초 감염
>브라우저/윈도우 취약점을 Exploit한 후 파일 생성
— Buffer Overflow (Heap, Stack)
— Format String
— Privilege Escalation
— Memory Corruption
>탐지
— 일반적인 다운로드와 다름> 사용자 모르게 파일이 생성되고 실행됨
— Shellcode
3rd CodeEngn ReverseEngineering Seminar
20
일반적인 파일 다운로드 (사용자가 인지)
Memory Corruption에 의한 파일 다운로드 (사용자 인지 불가능)3rd CodeEngn ReverseEngineering Seminar
21
파일 생성
>자신복사, 다운로드, 드롭
>파일/디렉토리 관련 API
— CreateFile
— ReadFile
— WriteFile
— CopyFile
— GetSystemDirectory
— GetWindowsDirectory
3rd CodeEngn ReverseEngineering Seminar
22
최초 파일 최초 파일
최초 파일
인터넷
파일 #1
최초 파일
파일 복사
다운로드
드롭
임시 디렉토리(Temp)
www.x.com/a.exe
윈도우 시스템 디렉토리(windows\system32)
파일 생성
3rd CodeEngn ReverseEngineering Seminar
233rd CodeEngn ReverseEngineering Seminar
24
다운로드
>관련 API
— URLDownloadToFileA
3rd CodeEngn ReverseEngineering Seminar
25
다운로드
3rd CodeEngn ReverseEngineering Seminar
26
드롭
>리소스 섹션 등으로부터 내부의 파일을 드롭함
>관련 API
— FindResourceA
— LoadResource
3rd CodeEngn ReverseEngineering Seminar
27
드롭
3rd CodeEngn ReverseEngineering Seminar
28
드롭
3rd CodeEngn ReverseEngineering Seminar
29
실행되도록 등록 (부팅 시)
>레지스트리, 서비스, BHO
>관련 API
— RegCreateKey
— RegOpenKeyEx
— RegSetValueEx
— RegQueryValueEx
— CreateServiceA
— OpenServiceA
— StartServiceA
3rd CodeEngn ReverseEngineering Seminar
30
실행되도록 등록 (부팅 시)
>시스템 재 시작시에 자동으로 실행되도록 설정
>해당 레지스트리 경로— HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
— HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
— HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options
— HKML\SYSTEM\CurrentControlSet\Services
3rd CodeEngn ReverseEngineering Seminar
31
실행되도록 등록 (부팅 시)
3rd CodeEngn ReverseEngineering Seminar
32
프로세스 동작
>프로세스, 쓰레드, DLL Injection, 서비스
>관련 API
— CreateProcess
— FindProcess
— TerminateProcess
— CreateThread
— CreateRemoteThread
— ShellExecute
— StartServiceA
3rd CodeEngn ReverseEngineering Seminar
33
DLL을 인젝션 하기 위한 프로세스 검색
프로세스 동작
3rd CodeEngn ReverseEngineering Seminar
34
CreateRemoteThread를이용한 DLL Injection
프로세스 동작
3rd CodeEngn ReverseEngineering Seminar
35
네트워크 활동
>포트 오픈, 특정 도메인/포트 접속, IRC 접속
>관련 API— WSAStartup
— WSASend
— socket
— send
— recv
— listen
— accept
— gethostbyname
— InternetGetConnectedState
3rd CodeEngn ReverseEngineering Seminar
36
네트워크 활동
3rd CodeEngn ReverseEngineering Seminar
37
악성행위
>보안기능 비활성화, 온라인 게임 계정 절취, DDoS, 스팸메일 발송
3rd CodeEngn ReverseEngineering Seminar
38
온라인 게임/포털 사이트 계정 절취를 위한 네트워크 관련 API 후킹
악성행위
3rd CodeEngn ReverseEngineering Seminar
39
국산 백신 제품들의 업데이트를 방해하는 코드 루틴
악성행위
3rd CodeEngn ReverseEngineering Seminar
40
악성행위
3rd CodeEngn ReverseEngineering Seminar
41
Malicious Behavior Analysis
Demonstration
VirutMalicious Behavior (related API, IRCBot)
3rd CodeEngn ReverseEngineering Seminar
42
0x02 Prior Knowledge
0x02 Prior Knowledge- PE Format
3rd CodeEngn ReverseEngineering Seminar
43
PE Format Poster - Ero Carrera
3rd CodeEngn ReverseEngineering Seminar
44
MZ header
PE header
Section 1
Section 2
Section n
Section table
File Headers : MZ Header
3rd CodeEngn ReverseEngineering Seminar
45
MZ header
PE header
Section 1
Section 2
Section n
Section table
File Headers : PE Header
3rd CodeEngn ReverseEngineering Seminar
46
MZ header
PE header
Section 1
Section 2
Section n
Section table
File header
Optional header
File Headers : File Header
3rd CodeEngn ReverseEngineering Seminar
47
MZ header
PE header
Section 1
Section 2
Section n
Section table
File header
Optional header
File Headers : Optional Header
3rd CodeEngn ReverseEngineering Seminar
48
MZ header
PE header
Section 1
Section 2
Section n
Section table
File Headers : Section Header
Section header
Section header
Section header
Section header
3rd CodeEngn ReverseEngineering Seminar
49
0x03 File Infection Techniques
0x03 File Infection Techniques
3rd CodeEngn ReverseEngineering Seminar
50
File Infection Techniques
Header
Section #1
Section #2
Section #n
EPOEP
OEP
Section #n+1
File Infector Virus
- change the entry-point
- add section
animation
3rd CodeEngn ReverseEngineering Seminar
51
File Infection Techniques
Header
Section #1
Section #2
Section #n
EPOEP
Section #n
File Infector Virus
OEP
- change the entry-point
- increase last section size
animation
3rd CodeEngn ReverseEngineering Seminar
52
Section #1
File Infection Techniques
Header
Section #2
Section #n
EP
Section #n+1
File Infector Virus
- patched code at EPanimation
3rd CodeEngn ReverseEngineering Seminar
53
Section #1
File Infection Techniques – EPO(Entry-Point Obscuring)
Header
Section #2
Section #n
EP
Section #n+1
File Infector Virus
- patched with a jump/call routine at somewhere
animation
3rd CodeEngn ReverseEngineering Seminar
54
File Infection Techniques
> injects code in running processes and hooks the following functions in ntdll.dll which transfers control to the virus every time any of these function calls are made
>NtCreateFile
>NtCreateProcess
>NtCreateProcessEx
>NtOpenFile
>NtQueryInformationProcess
3rd CodeEngn ReverseEngineering Seminar
55
File Infector virus features
>Code Execution Starts in the Last Section
>Suspicious Section Characteristics
>Suspicious Code Redirection (EPO)
>Suspicious Code Section Name
> identifier marks of the virus
3rd CodeEngn ReverseEngineering Seminar
56
identifier marks of the virus
Virut
3rd CodeEngn ReverseEngineering Seminar
57
Encode/Decode Operation
>XOR
>NEG
>ADD, SUB
>ROR, ROL
3rd CodeEngn ReverseEngineering Seminar
58
Polymorphism
>mov eax, [edx]
>add eax, 17E0D0DCh
>mov [edx], eax
>push dword ptr [edx]
>pop eax
>add eax, 17E0D0DCh
>push eax
>pop dword ptr [edx]
3rd CodeEngn ReverseEngineering Seminar
59
Dummy Code
>mov eax, eax
>push eax
>pop eax
>nop
3rd CodeEngn ReverseEngineering Seminar
60
0x04 File Infector Virus Analysis – Demonstration
0x04 File Infector Virus Analysis – Demonstration
3rd CodeEngn ReverseEngineering Seminar
61
File Infector Virus Analysis
how to get malware samples
3rd CodeEngn ReverseEngineering Seminar
62
Malware Sample
http://www.offensivecomputing.net/ (Offensive Computing)
3rd CodeEngn ReverseEngineering Seminar
63
Malware Sample
http://vx.netlux.org/vl.php (VX Heavens)
3rd CodeEngn ReverseEngineering Seminar
64
Malware Sample
http://cafe.naver.com/malzero (바이러스 제로 시즌 2)
3rd CodeEngn ReverseEngineering Seminar
65
Approach for File Infector Virus Analysis
>File Compare, Original and Infected File
>Top-Down— 1. VEP (Infected_EP or Patched_Code)
— 2. Decode_Loop
— 3. Decode_Key
— 4. Find restore OEP routine
— 5. OEP offset> (OEP or Original_Code_before_Patched address)
>Bottom-Up— 1. VEP (Infected_EP or Patched_Code)
— 2. Find restore OEP routine> (set BP at OEP or Original_Code_before_Patched address)
— 3. Check if data is encoded
— 4. Decode_Loop
— 5. Decode_Key 3rd CodeEngn ReverseEngineering Seminar
66
Parite.A
>It's terrible
3rd CodeEngn ReverseEngineering Seminar
67
Parite.A
Header
Section #1
Section #2
Section #n
EPOEP
OEP
Section #n+1
Parite.A
Decode routine
Encoded
- encoded XOR operations
animation
3rd CodeEngn ReverseEngineering Seminar
68
Polymorphism in Parite.A
> xor 연산의 피연산자 중 xor_key 구하는 것
> (1)— push xor_key
— pop [register]
> (2)— mov [register], xor_key
> xor 연산의 피연산자중 디코드된 데이터 구하는 것
> (1)— push [데이터 주소]
— xor [esp], xor_key
— pop [데이터 주소]
> (2)— xor [데이터 주소], xor_key
>카운터 증가
> (1)— sub edi, 3
— dec edi
> (2)— sub edi, 4
3rd CodeEngn ReverseEngineering Seminar
69
File Infector Virus Analysis
Parite.ADemonstration (Top-Down)
IDA
3rd CodeEngn ReverseEngineering Seminar
70
Sality.AE
Header
Section #1
Section #2
Section #nSection #n
Sality.AE
-EPO (Entry-Point Obscuring)
- ADD or SUB
EP CALL
Decode routine
Original Code
Encoded
animation
3rd CodeEngn ReverseEngineering Seminar
71
Polymorphism in Sality.AE
3rd CodeEngn ReverseEngineering Seminar
72
Polymorphism in Sality.AE
3rd CodeEngn ReverseEngineering Seminar
73
File Infector Virus Analysis
Sality.AEDemonstration (Bottom-Up)
Ollydbg, IDA
3rd CodeEngn ReverseEngineering Seminar
74
0x05 Development of disinfection code
0x05 Development of disinfection code
Parite.A
Sality.AE
3rd CodeEngn ReverseEngineering Seminar
75
Development of disinfection code
NeededPrecise PE parserStrong disassembler
Development using Pythonpefile - Ero Carrerapydasm – Ero Carrera
3rd CodeEngn ReverseEngineering Seminar
76
> instruction opcode VS. instruction operands
>E8 ???????? => CALL XXXXXXXX
>68 332211E8 => PUSH E8112233
>68332211E8E840100000
Why Need Disassembler
3rd CodeEngn ReverseEngineering Seminar
77
Development of disinfection code
3rd CodeEngn ReverseEngineering Seminar
78
Consideration
>Virus를 치료시 Overlay에 대한 고려
>Virus가 추가한 section의 Data를 지우거나 section 자체를 지울 경우
— Optional header의 SizeOfImage를 계산 후 수정
>JMP나 CALL 호출을 할 경우 해당 주소의 범위 체크
>pydasm을 사용할 경우 지원하지 않는 OP Code에 대한 예외처리
— Sality.AE (SAL: shift arithmetic left)
3rd CodeEngn ReverseEngineering Seminar
79
Scan Filter
>PE 파일인지 체크
>EP가 마지막 section에서 시작하는지 체크 (Parite.A)
>OPTIONAL_HEADER의 Magic Signature 체크
>OPTIONAL_HEADER의 Subsystem 체크
3rd CodeEngn ReverseEngineering Seminar
80
Scan Filter
>FILE_HEADER의 Characteristics 체크
>마지막 section의 SizeOfRawData 가 0x1000 이하인지 체크(Parite.A)
>마지막 section의 Characteristics 체크
3rd CodeEngn ReverseEngineering Seminar
81
Parite.A detection
> Step 1:
— Find Decode Key
— 가장 처음의 [push] or [mov]의 오퍼랜드 데이터
> Step 2:
— Encoded Data의 시작위치 찾기
— Decode Key를 찾은 이후 나오는 [push] or [mov] 의 오퍼랜드 데이터
> Step 3:
— Encode Data의 시작 위치로 부터 4Byte 가져오기
— Test_Data를찾는 과정
> Step 4:
— (복호화된 데이터는 항상 일정)
— Decode_Key와 Test_Data를 XOR연산 후 0x00017D8 인지 확인하여 Parite.A 식별
3rd CodeEngn ReverseEngineering Seminar
82
Parite.A disinfection
> Step 1:
— Encoded_Data의 시작 위치로 부터 약 72Byte를 Decode_Key로 Decode
> Step 2:
— Decode 된 Data의 특정 위치에서 OEP, IAT Offset 등의 값을 추출
> Step 3:
— Parite.A가 추가한 마지막 section header 삭제
— Calc New SizeOfImage
— NumberOfSections 카운트 1 감소
— OEP 및 Import Address Table, Import Name Table의 값 복구
> Step 4:
— Parite.A가 추가한 마지막 section Data 삭제
3rd CodeEngn ReverseEngineering Seminar
83
Development of disinfection code
Parite.ADemonstration
3rd CodeEngn ReverseEngineering Seminar
84
Virus.Sality.AE detection
>1단계
— 마지막 섹션으로 점프하는 CALL (E8) 찾기
>2단계
— 처음 나오는 CALL (E8) 찾기
>3단계
— 디코드 루프 찾기
— JMP (E9) 식별하기>디코드된 데이터의 시작 위치 찾기
>4단계
— X-Ray 기법> decode_key 찾기, decode_key와 특정 데이터 연산 후 Sality.AE 식별
3rd CodeEngn ReverseEngineering Seminar
85
>Decode Key를 모르는 상태에서 Encode Data와 Decode Data를 알경우 Key를 알아내는 방법
>ADD
>SUB
Using X-Ray Method
+ =
-=
- =
-=
Decode Key0x????????
Decode Data0x000000E8
Encode Data0xFC75F238
Decode Data0x000000E8
Encode Data0xFC75F238
Decode Key0x????????
Decode Key0x038A0EB0
Decode Key0x????????
Decode Key0x????????
Decode Key0x21E5ABD8
+ =Decode Key0x038A0EB0
Decode Data0x000000E8
Decode Data0x000000E8
Encode Data0x21E5ACC0
Encode Data0x21E5ACC0
Encode Data0xE9F74E50
Decode Data0xED815D00
- =Decode Key0x21E5ABD8
Decode Data0xED815D00
Encode Data0x0F6708D8
3rd CodeEngn ReverseEngineering Seminar
86
86
Virus.Sality.AE disinfection
>disinfection
— Encode Data 영역 Decode 후 Original Code before Patched (EPO) 복구
— Overlay 식별
— 바이러스 코드 시작위치부터 삭제
— Section header의 Section size 관련 필드 조정> SizeOfRawData
> VirtualSize
— Optional header의 SizeOfImage 조정
— Overlay가 있을 경우 Overlay 복구
3rd CodeEngn ReverseEngineering Seminar
87
Development of disinfection code
Sality.AEDemonstration
3rd CodeEngn ReverseEngineering Seminar
88
Questions
Questions?
contact us via e-mailsionics 0x40 issuemakerslab.comkaientt 0x40 issuemakerslab.com
3rd CodeEngn ReverseEngineering Seminar
top related