INTRO Basic architecture of modern computers Basic and most used assembly instructions on x86 Installing an assembly compiler and RE tools Practice co

Similar documents
hlogin2

No Slide Title

Page 2 of 5 아니다 means to not be, and is therefore the opposite of 이다. While English simply turns words like to be or to exist negative by adding not,

Deok9_Exploit Technique

Page 2 of 6 Here are the rules for conjugating Whether (or not) and If when using a Descriptive Verb. The only difference here from Action Verbs is wh

강의10

IDA 5.x Manual hwp

Microsoft PowerPoint - a8a.ppt [호환 모드]

Microsoft Word - ExecutionStack

Hi-MO 애프터케어 시스템 편 5. 오비맥주 카스 카스 후레쉬 테이블 맥주는 천연식품이다 편 처음 스타일 그대로, 부탁 케어~ Hi-MO 애프터케어 시스템 지속적인 모발 관리로 끝까지 스타일이 유지되도록 독보적이다! 근데 그거 아세요? 맥주도 인공첨가물이

Stage 2 First Phonics

step 1-1

Microsoft Word - FunctionCall

하나님의 선한 손의 도우심 이세상에서 가장 큰 축복은 하나님이 나와 함께 하시는 것입니다. 그 이 유는 하나님이 모든 축복의 근원이시기 때문입니다. 에스라서에 보면 하나님의 선한 손의 도우심이 함께 했던 사람의 이야기 가 나와 있는데 에스라 7장은 거듭해서 그 비결을

1_2•• pdf(••••).pdf

본문01

hlogin7

2 min 응용 말하기 01 I set my alarm for It goes off. 03 It doesn t go off. 04 I sleep in. 05 I make my bed. 06 I brush my teeth. 07 I take a shower.

Microsoft PowerPoint - a6.ppt [호환 모드]

(Microsoft PowerPoint - 1-2\300\345)

CD-RW_Advanced.PDF

Microsoft PowerPoint - ch03ysk2012.ppt [호환 모드]

PowerPoint 프레젠테이션

K7VT2_QIG_v3

농심-내지

Microsoft PowerPoint - a10.ppt [호환 모드]

=

<31325FB1E8B0E6BCBA2E687770>

퇴좈저널36호-4차-T.ps, page Preflight (2)

The_IDA_Pro_Book

11¹Ú´ö±Ô

2 2010년 1월 15일 경상북도 직업 스쿨 운영 자격 취득 위한 맞춤형 교육 시 10곳 100명에 교육 기회 제공 본인에게 적합한 직종 스스로 선택 1인당 최고 100만원까지 교육비 지원 경상북도는 결혼이주여성 100명에게 맞춤형 취업교 육을 제공하는 결혼이민자 직

Microsoft Word - Reverse Engineering Code with IDA Pro-2-1.doc

영어-중2-천재김-07과-어순-B.hwp

untitled

DE1-SoC Board

- 이 문서는 삼성전자의 기술 자산으로 승인자만이 사용할 수 있습니다 Part Picture Description 5. R emove the memory by pushing the fixed-tap out and Remove the WLAN Antenna. 6. INS

untitled

MPLAB C18 C

9

#중등독해1-1단원(8~35)학

Microsoft PowerPoint - 7-Work and Energy.ppt

PowerChute Personal Edition v3.1.0 에이전트 사용 설명서

<BFACBCBCC0C7BBE7C7D E687770>

2. GCC Assembler와 AVR Assembler의차이 A. GCC Assembler 를사용하는경우 i. Assembly Language Program은.S Extension 을갖는다. ii. C Language Program은.c Extension 을갖는다.

- 2 -

02( ) CSTV11-22.hwp

SRC PLUS 제어기 MANUAL

Microsoft Word - Heap_Spray.doc

0125_ 워크샵 발표자료_완성.key

3항사가 되기 위해 매일매일이 시험일인 듯 싶다. 방선객으로 와서 배에서 하루 남짓 지내며 지내며 답답함에 몸서리쳤던 내가 이제는 8개월간의 승선기간도 8시간같이 느낄 수 있을 만큼 항해사로써 체질마저 변해가는 듯해 신기하기도 하고 한편으론 내가 생각했던 목표를 향해

2007 학년도 하반기 졸업작품 아무도 모른다 (Nobody Knows) 얄리, 보마빼 (AIi, Bomaye) 외계인간 ( 外 界 人 間 ) 한국예술종합학교 연극원 극작과 예술전문사 안 재 승

I&IRC5 TG_08권

H3050(aap)

PRO1_09E [읽기 전용]

Microsoft Word - 1. ARM Assembly 실습_xp2.doc

2 소식나누기 대구시 경북도 영남대의료원 다문화가족 건강 위해 손 맞잡다 다문화가정 행복지킴이 치료비 지원 업무협약 개인당 200만원 한도 지원 대구서구센터-서부소방서 여성의용소방대, 업무협약 대구서구다문화가족지원센터는 지난 4월 2일 다문화가족의 지역사회 적응 지원을

public key private key Encryption Algorithm Decryption Algorithm 1

휠세미나3 ver0.4

¹Ìµå¹Ì3Â÷Àμâ

(Asynchronous Mode) ( 1, 5~8, 1~2) & (Parity) 1 ; * S erial Port (BIOS INT 14H) - 1 -

49-9분동안 표지 3.3

<B3EDB9AEC1FD5F3235C1FD2E687770>

저작자표시 - 비영리 - 변경금지 2.0 대한민국 이용자는아래의조건을따르는경우에한하여자유롭게 이저작물을복제, 배포, 전송, 전시, 공연및방송할수있습니다. 다음과같은조건을따라야합니다 : 저작자표시. 귀하는원저작자를표시하여야합니다. 비영리. 귀하는이저작물을영리목적으로이용할


Microsoft PowerPoint - hy2-12.pptx

구문 분석

MicrocontrollerAcademy_Lab_ST_040709

Microsoft PowerPoint - o8.pptx

<30322D28C6AF29C0CCB1E2B4EB35362D312E687770>

DIY 챗봇 - LangCon

Microsoft PowerPoint - a9.ppt [호환 모드]

solution map_....

_KF_Bulletin webcopy

Reusing Dynamic Linker For Exploitation Author : Date : 2012 / 05 / 13 Contact : Facebook : fb.me/kwonpwn

야쿠르트2010 3월 - 최종

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

2

<B3EDB9AEC1FD5F3235C1FD2E687770>

PowerPoint 프레젠테이션

<32B1B3BDC32E687770>

Journal of Educational Innovation Research 2019, Vol. 29, No. 1, pp DOI: (LiD) - - * Way to

<B1E2C8B9BEC828BFCFBCBAC1F7C0FC29322E687770>

untitled

IKC43_06.hwp

歯15-ROMPLD.PDF

02.Create a shellcode that executes "/bin/sh" Excuse the ads! We need some help to keep our site up. List Create a shellcode that executes "/bin/sh" C

대한한의학원전학회지26권4호-교정본(1125).hwp

01.ROP(Return Oriented Programming)-x86 Excuse the ads! We need some help to keep our site up. List Return Oriented Programming(ROP) -x86 Gadgets - PO

Something that can be seen, touched or otherwise sensed

13주-14주proc.PDF

카테고리 시리즈 명 SME 컨텐트 에센스 심화 컨텐트 탬플릿 평가 대 분 류 중 분 류 개수 평균 시간 개수 총 시간 개수 총 시간 유 형 개수 유무 경영일반 경영기법 Performance Management를 위한 전략적 성과면담 김정일 20 0:43:09 8 6:3

아니라 일본 지리지, 수로지 5, 지도 6 등을 함께 검토해야 하지만 여기서는 근대기 일본이 편찬한 조선 지리지와 부속지도만으로 연구대상을 한정하 기로 한다. Ⅱ. 1876~1905년 울릉도 독도 서술의 추이 1. 울릉도 독도 호칭의 혼란과 지도상의 불일치 일본이 조선

프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어

슬라이드 1

6주차.key

04-다시_고속철도61~80p

5/12¼Ò½ÄÁö

182 동북아역사논총 42호 금융정책이 조선에 어떤 영향을 미쳤는지를 살펴보고자 한다. 일제 대외금융 정책의 기본원칙은 각 식민지와 점령지마다 별도의 발권은행을 수립하여 일본 은행권이 아닌 각 지역 통화를 발행케 한 점에 있다. 이들 통화는 일본은행권 과 等 價 로 연

Transcription:

Basic reverse engineering on x86 This is for those who want to learn about basic reverse engineering on x86 (Feel free to use this, email me if you need a keynote version.) v0.1 SeungJin Beist Lee beist@grayhash.com http://grayhash.com

INTRO Basic architecture of modern computers Basic and most used assembly instructions on x86 Installing an assembly compiler and RE tools Practice code in assembly

Remind kernel (OS) process1 process2 process3 CPU, registers and memory process4 process5 processn process 1 memory register

For beginners You need to think that only CPU, registers, memory and external drives like HDD or SSD are used in your computer Ignore software/hardware interrupts at the moment The 3 items are enough to get the concept in this lecture CPU, registers, memory

Assembly instructions CPU vendors make new assembly instructions for every brand new CPU But you don t have to learn about all the instructions At the first, around 20~30 instructions are enough

Popular instructions Most of instructions are arithmetic operations, branches, data move and so on in most programs And system calls They usually cover over 80% in many programs

About the grammar Assembly grammar itself is easy (both x86 and arm) But the side effect is complicated in x86 And x86 is CISC (Complex Instruction Set Computing)

About the grammar Instruction can be Opcode Opcode + operand Opcode + operands Opcode Operation code Operand Argument for opcode

Size Instruction size The x86 architecture is a variable instruction length From 1 byte to 17 bytes for 80386 (including operands) The default operand size 8, 16 and 32 bits

Opcode Opcode is like when you want to say I want to add a value to a value. (ADD) I want to subtract a value from a value. (SUB)

Operand Operands can be Memory Registers Immediate values (Only for source operands) In a way that I want to add a value to a value. (add register, 2) I want to subtract a value from a value. (sub register, 2)

Instruction samples add eax, 2 add ebx, 4 add eax, ebx sub eax, 2 sub ebx, 4 sub eax, ebx Easy!

Registers There are 4 types General registers - EAX, EBX, ECX, EDX Segment registers - CS, DS, ES, FS, GS, SS Index and pointers - ESI, EDI, EBP, EIP, ESP Indicator - EFLAGS

Registers But, when you do reversing on most of user level programs in x86, you could ignore Segment registers since most of times you don t have to deal with them EFLAGS is important to understand the side effect You can t control EIP directly EAX, EBX, ECX, EDX, ESI, EDI, ESP, EBP are ok

Registers For examples (O) - MOV EAX, 0x2 (O) - MOV ESP, 0x2 (X) - MOV EIP, 0x2

Registers Even though you can control the all registers directly except EIP, there are something ESP - pointing to current address of stack EBP - frame pointer of function ESI - source when you use copy opcode EDI - destination when you use copy opcode EAX - a value for return or multiply opcode or something ECX - a number how many times when you use copy op Not that complicated, you will see

Split off registers A register can be broken into And each has a different size AL - 8 bit (or AH) AL AX - 16 bit EAX - 32 bit 8 bit 8 bit 8 bit 8 bit AX [EAX] EAX

Operands Remember that operands can be 8, 16 and 32 bits Memory and immediate value are as well Example mov ax, word ptr[0x401000] mov ax, 0x4141 Memory BYTE (8bit), WORD (16bit), DWORD (32bit)

Opcode with any operand There are some opcode that don t need any operand Example: nop (no operation)

2 ways to write in ASM There is a bit different between INTEL and AT&T Example: INTEL: mov eax, 0x4 AT&T: mov $0x4, eax There are more differences but very slight It s mostly about opposite of direction source, destination or destination, source We ll take INTEL style

mov instruction mov instruction is for assigning Example: mov eax, 0x4 mov dword ptr[0x401000], eax mov dword ptr[0x401000], 0x4141 mov eax, ebx mov eax, dword ptr[0x401000]

sub instruction sub instruction is to subtract a value from a value Example: sub eax, 0x4 sub dword ptr[0x401000], eax sub dword ptr[0x401000], 0x4141 sub eax, ebx sub eax, dword ptr[0x401000]

add instruction add instruction is to add a value to a value Example: add eax, 0x4 add dword ptr[0x401000], eax add dword ptr[0x401000], 0x4141 add eax, ebx add eax, dword ptr[0x401000]

cmp instruction cmp instruction is to compare a value to a value Example: cmp eax, 0x4 cmp dword ptr[0x401000], eax cmp dword ptr[0x401000], 0x4141 cmp eax, ebx cmp eax, dword ptr[0x401000]

Destination must be writable It is very obvious that destinations must be writable Memory and registers Immediates are just immediates, they can t be writable So, immediates are never for destination operands

test instruction test instruction is usually to know if a value is 0 Example: test eax, eax It does actually and operation for eax and itself So, if eax is not 0, it ll be always not 0 If it s 0, it s always 0 You see this case many times - if (a == 0) { } in C code

EFLAGS time EFLAGS is updated after instructions got executed So that you know the result of these instructions cmp, test And others make EFLAGS updated almost all instruction, even add opcode But, again, for beginners, you don t worry about EFLAGS now

je instruction je instruction is to jump to at an address if the result is equal Example: 0x401096: MOV EAX,1 0x40109B: CMP EAX,1 0x40109E: JE SHORT 004010A2 0x4010A0: MOV ECX,EAX 0x4010A2: MOV EAX,EBX As EAX is 1, the instruction at 0x4010A0 will be not executed

jne instruction jne instruction is to jump to at an address if the result is not equal Example: 0x401096: MOV EAX,1 0x40109B: CMP EAX,2 0x40109E: JNE SHORT 004010A2 0x4010A0: MOV ECX,EAX 0x4010A2: MOV EAX,EBX As it s not equal, the instruction of 0x4010A0 will be not executed

jmp instruction jmp instruction is to jump to at an address Example: 0x40108A: MOV EAX,4 0x40108F: JMP SHORT 00401093 0x401091: MOV EAX,EBX 0x401093: MOV ECX,EBX The instruction at 0x401091 will be not executed

Branches are important Catching up branches is one of most important things when you do reverse engineering if, jump, else is everywhere in modern programs There are many more than jmp/je/jne js/jns/jo/jno/jc/jnc/jb/jbe/jae/ja/jl/jle/jge/jg But it sounds very logic, for examples je - jump equal jne - jump not equal http://en.wikipedia.org/wiki/branch_(computer_science)

xor instruction xor instruction is very simple, it s to xor a value with a value Example: xor eax, eax The result will be 0

push instruction push instruction is to push a value onto stack memory Example: push 0x4 push eax push dword ptr[0x401000] After a push operation, ESP value is decreased Remember, ESP points to a current address of stack

pop instruction pop instruction is to pop a value from stack memory Example: pop eax pop dword ptr[0x401000] After a pop operation, ESP value is increased

call call instruction is to call a function jmp instruction is to just jump to an address But, call instruction pushes the next instruction address onto stack memory So that the callee can know where to go back Example: call eax call dword ptr[0x401000] call 0x401000

ret ret instruction to return to a caller It pops a return address from stack This is how a callee can go back to a caller Example: ret ret opcode can have an argument, but we ll ignore it for now

How to go back to callers main() { my_first_code(); } (1) main() { my_first_code(); } void my_first_code() { my_dumb_code(); } (2) void my_first_code() { my_dumb_code(); } (6) void my_dumb_code() { my_l33t_code(); } (3) void my_dumb_code() { my_l33t_code(); } (5) void my_l33t_code() { printf( meh ); } void my_l33t_code() { printf( meh ); } (4)

How to go back to callers 0x401015: call 0x401064 0x40101A: mov eax, ebx.................. 0x401064: nop 0x401065: ret...... push 0x40101A jmp 0x401064 call instruction pushes the next instruction on stack ret instruction gets the value from stack and mov eip, [esp] These are pseudo-code, it s different in real world

Addressing modes We ve mentioned only register, immediate, direct memory, and register indirect addressing modes But there are more Base-index Base-index with displacement Direct offset addressing (by the compiler) However, we ll not cover those 3 addressing modes

Installing before practice Flat assembler A neat assembly compiler (http://flatassembler.net) http://115.68.24.145/fasmw17003.zip Run FASMW.EXE

Your first assembly Type this code in Flat Assembler include 'win32ax.inc'.code start: mov eax, 2 mov ecx, 3 nop mov eax, 4 mov ebx, dword [0x401000] ; without ptr.end start 1. [File] - [Save as] - [test.asm] 2. [Run] - [Compile] Then, check out if test.exe is generated

To use label in flat assember To jump, you can specify a label include 'win32ax.inc'.code start: mov eax, 2 mov ecx, 3 jmp test_label test_label: nop xor ebx, ebx.end start You use labels for implementing branches if - else, for, while, etc

Installing before practice Olly Debugger A popular debugger for Windows (http://www.ollydbg.de) http://115.68.24.145/odbg110.zip Run ollydbg.exe

Olly Debugger [File] - [Open] - Select the test.exe You ll see your program being debugged Basic commands F7 - Step into F8 - Step out F9 - Run

Practice time 1. 2. Flat Assembler 3. OllyDBG Open 4. Step-by-step 5.

Practice 1 1. - eax 0x100 - eax ebx - ebx 0x10 - ebx ecx - ecx edx - edx ecx - edx

Practice 2 2. - esp 0x4 - esp 0x100 - esp 0x4 - esp 0x90 - esp 0x4 - esp 0x80 - pop eax - pop ebx - pop ecx - eax, ebx, ecx - esp (, -4, -8)

Practice 3 3. if - esp 0x100 - pop eax - eax 0xffff ebx 1 - eax 0xffff ebx 0 - eax ebx

Practice 4 4. for - C ebx = 0; for(ecx=0; ecx<8; ecx++) { ebx = ebx + ecx + 1; } edx = ebx; - edx

Practice 5 5. - func_1, func_2, func_3 label - func_1: eax 0x10 - func_2: ebx 0x30 - func_3: ecx eax ebx - func_1, func_2, func_3-3 ecx

Practice 6 6. trick - start get_string - start get_string - get_string return address eax - call eax start -, call eax db "test_go" - start, ebx "test_go" - ebx [TIP] call func_address db this_is_test db 0x0

Practice 7 7. (simple xor) [ ] - eax "reversing" - for - for key "reversing" xor - [ ] - xor - for - xor key - - key: nothiiing

To be added later REFERENCES