Upload
others
View
6
Download
0
Embed Size (px)
Citation preview
리버스 엔지니어링 저자특강 Part II Information Security Team, Nexon America April 16, 2013 강병탁 (window31)
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Agenda
• 1부 (2 hours)
• 공인인증서 탈취 악성코드 리버싱
• Handy-Ray 리버싱
• 암호화된 코드 리버싱
• 알려진 암호화 찾기
• 디스어셈블리 엔진을 이용한 아이디어
• 암호화 로직 검출 휴리스틱 알고리즘
• 코드 뜯어내기
• 암호화 한방에 풀어내기
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Agenda
• 2부 (2 hours)
• Themida 기능분석
• 각종 기능과 옵션 활용 방법
• API Re-direction 의 강점과 한계
• 문자열 암호화
• VM 코드 반영시 주의사항
• 악성코드 탐지 로직 개발
• 시그니처가 필요없는 탐지 아이디어
• 휴리스틱 키로거 탐지
• 유저 레벨에서 커널 레벨 루트킷 안전하게 탐지
• Your report is my report
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Agenda
• 2부 (cont.)
• 보안기능 우회
• 시그니처 우회 원리
• 디버깅 시점 선정하기
• VM 분석과 우회
• 무결성 검사 우회
• 3부 - Tip (so far as time permits)
• 서비스 오픈전 온라인 게임 리버스 엔지니어링 검수 방법론
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
저자소개
• 강병탁 (window31)
• “리버스 엔지니어링 바이블, 코드 재창조의 미학” 저자
• 前 넥슨 코리아 게임보안팀 팀장
• 現 넥슨 아메리카 정보보안팀 팀장
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
당부의 말
이 세션은 “튜토리얼” 시간입니다.
50% 의 내용이 리버스 엔지니어링 시연임을
참고해 주세요
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
1부
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
공인인증서 탈취 악성코드
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
1. 공인인증서 탈취 악성코드
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
1. 공인인증서 탈취 악성코드 (cont.)
• 어떤 원리로 가져가는가?
• 어떤 행위를 하는가?
• 주요 로직은 무엇인가?
• 키보드 보안이 보호하고 있는 상황에서 비밀번호를 어떻게 탈취하
는가?
• 인증서 탈취 악성코드를 탐지하는 방법은?
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
파일 구성
• svchcst.exe : launcher
• msvcrt99.dll : core dll
• update.bin : fake certification
• ms_patch.log : log file
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
인증서 탈취
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
낚시의 끝은 어디까지…
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
옛날의 경우, 공인인증서 모듈 취약점
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Memory Hacking
• 2007년 9월 4일, 인터넷뱅킹에 대한 메모리해킹 위험 확산
• KBS 취재파일 “댁의 예금은 안녕하십니까?”
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Memory Hacking Scenario
Step 1) 유저 PC 에 악성코드 감염
Step 2) 유저가 계좌이체를 시도
Step 3) 악성코드는 계좌번호와 금액을 해커의 계좌로 바꿔치기
Step 4) 유저는 ID,PW,OTP 값을 입력하고 계좌이체를 진행하지만 실제로는 해커의 계좌로 금액 전송
• 계좌 정보와 금액은 메모리에 보관된다는 것이 포인트
• OTP 도 우회됨
• 메모리에는 모든 정보가 다 있다!
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
인터넷 뱅킹 기반의 메모리 해킹
• Keylogging : 메모리 정보 검색을 통한 키로깅
• 계좌이체 문제
• HTS 문제
• IE 6.0 문제
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Decryption or Encryption 함수를 노려라
• Encryption Function Hook
• BlockEnc(param1, param2, szPlainText, …);
Hooking Plain Text !!!
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
IE upgrade event
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
누구나 많이 사랑하는
많은 이들을 행복하게 해주는 “결과 내 검색”
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
데이터 검색 기능
데이터 검색 기능
1) 100 을 찾는다
2) 결과 내 99를 찾는다
3) 결과 내 98을 찾는다
4) ….
5) 고급스런 표현으로 소거법
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Simple Exploit
• 내 계좌에서 다른 계좌로 메모리에서 찾기 쉬운 금액을 송금
을 한다. (ex, 12,345원)
• 사용자에게 송금 내용이 맞는지 확인하는 창이 떴을때
TSearch를 이용해 ezPlus에서 사용하고 있는 메모리 영역 중
송금액과 일치하는 data가 있는지 검사한다.
• 찾아보니 실제 두군데 메모리 영역이 나왔다. 둘다 1원 모자라
는 값으로 수정하고 다시 ezPlus로 가서 비밀번호를 입력하고
송금하기를 누른다.
• 실제 송금 내용을 확인하는 창을 보니 1원 모자라는 금액이 송
금이 되었다.
• 계좌조회를 하니 실제 송금된 내용도 1원 모자랐다!!
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
데이터 셔플링
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
온라인 게임업계에서 메모리 해킹 피해
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
클라이언트 보안의 한계
• 비주얼 키보드나, 키보드보안 등 모두 클라이언트 기반
• 클라이언트는 리버스 엔지니어링으로 코드 공격 가능
• 코드를 변조함으로써 모든 보안장치 해제 가능
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
IE 10.0 에서 메모리 해킹 방지기능
• 고 무작위성(High Entropy) 주소공간배치난수화(ASLR)
메모리상의 주소를 임의적으로 만드는 메모리 보호기법
• 강제ASLR
메모리에 불러오는 '모든 모듈' 위치를 무작위 로드
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
암호화된 코드 리버싱
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
2. 암호화된 코드 리버싱
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
2. 암호화된 코드 리버싱
• 암호화 로직 분석 방법
• 암호화 한방에 풀어내기
• 알려진 암호화 탐지 로직 제작 방법
• 휴리스틱 암호화 탐지 로직 제작 방법
• Splunk 를 이용한 가상화 코드 분석 방법
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
FindCrypt
• 알려진 암호화 알고리즘을 탐지해 준다.
• 주의 ! 코드 사이즈를 계산해야 함
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
깨고 싶은가? 그렇다면 코딩부터 해 볼 것!
Attack Here !!
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
깨고 싶은가? 그렇다면 코딩부터 해 볼 것!
Attack Here !!
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
암호화 알고리즘의 시그니처는 중요하다
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
암호화 알고리즘의 시그니처는 중요하다
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
디스어셈블러 엔진 사용은 필수!
• 원하는 코드만 걸러내자 !
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
암호화 로직 뜯어내기
Target application My application
Binary Extracting Code Simulation
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
종합 예제 – 암호화 한방에 풀어내기
• 슈도 코드 제작!
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
종합 예제 – 암호화 한방에 풀어내기 (cont.)
• 원하는 코드만 걸러내자 !
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
휴리스틱 암호화 탐지 로직 제작 방법
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Splunk 를 이용한 리버스 엔지니어링
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
2부
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Themida 기능분석
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
VMWare/Virtual PC
• VirtualPC compatible (not default
option)
• 가상머신에서 실행 여부
• 리버서가 내 바이너리를 VPC 에
서 분석하는 것을 원치 않는다면
이 옵션을 추가
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Monitor Blockers & Resource Encryption
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Advanced API-Wrapping
• Themida 의 Core feature, 그러나 현실은 시궁창일 수도.
• Level 1 과 Level 2 는 극심한 차이를 보임
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Protection Macros
• 함수 단위의 protection (map 파일이 필요함)
• 그다지 추천하지는 않음.
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Code Replace
• 소스코드 레벨에서의 Themida 옵션
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Code Replace
• 소스코드 레벨에서의 Themida 옵션
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Encode
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Clear code
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
VM !
• VM_START_WITHLEVEL(x)
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
CHECK_CODE_INTEGRITY
• 허접하게 Hash 검사를 구현할 바에야는 차라리 이게 낫다 !
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
악성코드 탐지 로직 만들기
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
시그니처 없는 탐지 로직
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
RAT 부류 악성코드 탐지
• 원격제어를 구현하려면 무엇이 필요한가? - 원격제어에 쓰이는 API 탐지 • IAT Check - mouse_event - keybd_event - BitBlt - GetDC - CreateDC - SendInput - PostMessage - SendMessage
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
터미널 서버 접속시도 하는 악성코드 탐지
• 터미널 세션 정보 탐지 - 터미널 세션 정보를 얻는 악성코드 - 주로 시스템 프로세스에 dll injection 형태로 주입 • IAT Check - 7 WTSEnumerateSessionsW : 세션 정보 검색 - 8 WTSFreeMemory - 3 WTSEnumerateProcessesW : active process 정보
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
휴리스틱 키로거 탐지
• 알고리즘
Step 1) Native process 에 포함된 전체 HANDLE 을 enum 함
Step 2) 해당 HANDLE 중, file 속성을 가진 것을 얻고 내용 읽음 Step 3) txt 파일이라면 (0x20 ~ 0x7A 사이) detection 그냥 파일이라면 전송하여 분석하거나 doubt++
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
드라이버를 쓰지 않고 안전하게 커널 루트킷 탐지
• 루트킷의 트렌드를 파악해보자!
- 루트킷은 아래 두가지 중 반드시 한가지를 거침
1) DLL 기반 - 요즘은 EXE 를 사용하지 않고 DLL 위주 동작 - Native process 에 dll injection
2) 몸체가 없는 형태 - DLL 없이 코드만 풀어넣는 형태 - System process 에 code injection
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
DLL Injection 기반 Rootkit 탐지
• Ring3 에서도 안전하게 탐지 가능함
- Heap 전체를 스캔함
- VirtualQuery() 로 메모리 속성 파악
- MEM_IMAGE 인 경우 Process32Next 로 name 획득
- 얻어진다면, 정상 DLL, 그렇지 않다면 루트킷!
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Code Injection 기반 Rootkit 탐지
• 역시 Ring3 에서도 안전하게 탐지 가능함
- Thread 리스트를 구함
- 스택의 맨 위에는 스레드의 시작 번지가 보임
- 해당 스레드가 MEM_PRIVATE 인지 체크
- MEM_PRIVATE 속성을 가진 스레드가 있다면 그것은 code injection 방식!
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
MBR 파괴 악성코드 탐지
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
보안 기능 우회
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
5. 보안기능 우회
• Themida 우회
• 백신 시그니처 우회
• 동적분석 방해 로직 리버싱
• 알려지지 않은 안티 리버싱
• 해시 검사 우회
• Direct Call 우회
악용 소지가 있으므로 DEMO, 시연으로만 대체합니다.
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
패킹 전
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
UPX
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
Themida
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
여기까지 왔을 때!
아직 시간이 많이 남아 있다면
리버싱 Tip 으로 다음 내용을진행합니다.
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
리버싱 자동화
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
게임보안 이야기
Copyright by Nexon America Inc. www.nexon.net
Reference Comments
서비스 오픈전, 온라인 게임
리버스 엔지니어링 검수 방법론