CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

32
CNIT 127: Exploit Development Lecture 7: 64-bit Assembler Not in textbook Rev. 3-9-17

Transcript of CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Page 1: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

CNIT 127: Exploit Development

Lecture 7: 64-bit Assembler

Not in textbook

Rev. 3-9-17

Page 2: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

64-bit Registers

• rip = Instruction pointer • rsp = top of stack

Page 3: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)
Page 4: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Windows Limitations

• Windows doesn't implement full 64-bit addressing

• Windows 2008 Server uses 44 bits – Max. 16 TB RAM

• Windows 8.1, 2015 revision, uses 48 bits – Max. 256 TB RAM

• Links Ch L7d, L7e

Page 5: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

OS Limitations

• OS uses top half

• User programs use lower half

Page 6: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

System Calls

• syscall replaces INT 80

Page 7: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

L7h: Searchable Linux Syscall Table

Page 8: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

L7c: Introduction to x64 Assembly Intel Developer Zone

• More details about registers

Page 9: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Common Opcodes

Page 10: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Syscall 1: Write

Page 11: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Simplest Program: ABC

Page 12: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Works, then Crashes (no exit)

Page 13: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Exit

Page 14: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Works Without Crashing

Page 15: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Letters in Order

Page 16: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Using a .data section

• db = "Define Byte"

Page 17: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Objdump

Page 18: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Using gdb

• .data and .text sections appear the same

Page 19: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

.text and .data Sections

Page 20: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

info registers

Page 21: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Using read

Page 22: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

"echo" with a .data section

Page 23: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Works with Junk at End

Page 24: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Caesar Cipher

Page 25: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Works for 4 Bytes Only

Page 26: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Objdump Shows a 32-bit Value

Page 27: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Intel 64 and IA-32 Architectures Software Developer's Manual

Page 28: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Must use a Register

Page 29: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Now it Works

Page 30: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Challenge 1 "Hello from YOURNAME"

Page 31: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Challenge 2 Caesar (3 steps back)

Page 32: CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)

Challenge 3: XOR Encryption