Syllabus and Review: Modern Binary Exploitation CSCI 4968 - Spring 2015 Alex Bulazel
Syllabus and Review: Modern Binary Exploitation CSCI 4968 - Spring 2015 Alex Bulazel
MBE - 01/27/2015
Lecture Overview
1. Syllabus
2. Course Overview
3. Review of Background Material
a. Linux
b. C
c. x86 Assembly
MBE - 01/27/2015
Course Details
Modern Binary Exploitation
MBE - 01/27/2015
Instructor
Instructor: Dr. Blent Yener
Office: Lally 310
Email: [email protected]
MBE - 01/27/2015
Markus
MBE - 01/27/2015
Branden
Sophia
Alex
Jeremy
Patrick
Austin
Office Hours
Office hours:
Wednesday 7-10 PM @ Sage 3101
Come hang out at RPISEC hack nights!
Ask questions, get extra help with MBE
Collaborate on HW/Labs
Work on security projects, challenges, etc
MBE - 01/27/2015
Other Options
MBE - 01/27/2015
MBE - 01/27/2015
Suggested Textbooks
Hacking: The Art of Exploitation, 2nd Edition by Jon Erickson
ISBN 978-1593271442
MBE - 01/27/2015
10
Grade Breakdown
Labs - 60%
10 labs @ 6% each
Lab attendance is MANDATORY as lab
submissions must be checked off in person
Term Projects - 40%
2 Projects @ 20% each
Like a big lab, but over a few weeks
MBE - 01/27/2015
11
Syllabus
READ THE SYLLABUS - Well written, full of details
Its on the course website - rpis.ec/binexp
MBE - 01/27/2015
12
An Atypical Class
Designed and orchestrated by RPISEC (students)
Biggest RPISEC class yet!
CSCI 4971 Secure Software Principles
CSCI 4972 / 6963 Malware Analysis
CSCI 4974 / 6974 Hardware Reverse Engineering
MBE - 01/27/2015
13
14
Lecture Overview
1. Syllabus
2. Course Overview
3. Review of Background Material
a. Linux
b. C
c. x86 Assembly
MBE - 01/27/2015
15
Course Terminology
Machine
A computer, server, sometimes refers to the actual CPU
Binary
An executable such as an .EXE, ELF, MachO or other code
Malware
A malicious binary meant to persist on a machine such as
a Rootkit or Remote Access Tool (RAT)
MBE - 01/27/2015
16
Course Terminology
Vulnerability
A bug in a binary that can be leveraged by an exploit
0day
A previously unknown or unpatched vulnerability that
can be used by an exploit
An 0day can also be an exploit using the unpatched vuln
MBE - 01/27/2015
17
18
MBE - 01/27/2015
19
MBE - 01/27/2015
20
21
Underappreciated Wisdom
22
23
MBE - 01/27/2015
24
25
Course Roadmap
We start off with the fundamentals required
Basic reverse engineering, memory corruption, classical exploitation
MBE - 01/27/2015
26
Lecture Overview
Syllabus
Course Overview
Review of Background Material
Linux
C
x86 Assembly
MBE - 01/27/2015
27
MBE - 01/27/2015
28
MBE - 01/27/2015
29
cd [path]
change directory
.. = previous
pwd
Print working directory
man [command]
Manual for command
apropos [whatever]
Get info on commands/man pages that might do whatever
MBE - 01/27/2015
30
less [file]
Like cat, but paged, good for long documents
mv [file1] [file2]
Move file1 to file2, removing file1 and overwriting file2 if it exists
cp [file1] [file2]
Copy file1 to file2, overwriting file2 if it exists
rm [file]
Deletes file
MBE - 01/27/2015
31
Pipes - |
Take output of one program, send it as input to another
$ echo "hello" | cowsay
_______
< hello >
------\
\
^__^
(oo)\_______
(__)\
)\/\
||----w |
||
||
MBE - 01/27/2015
32
Lecture Overview
Syllabus
Course Overview
Review of Background Material
Linux
C
x86 Assembly
MBE - 01/27/2015
33
Compared to modern
languages, C is considered a
low level language
MBE - 01/27/2015
34
Language Depth
MBE - 01/27/2015
35
MBE - 01/27/2015
36
MBE - 01/27/2015
37
38
Running It
$ gcc basic.c
$ ./basic
hello
hello
hello
hello
hello
...
MBE - 01/27/2015
-o basic -std=gnu99
39
40
MBE - 01/27/2015
41
42
Crash!
$ gcc name2.c -o name2
$ ./name2
Whats your name?
ALEX 1234 ABCD EFGH IJKL
Hello ALEX 1234 ABCD EFGH IJKL
???????????
Segmentation fault (core dumped)
Bottom line: its easy to make grievous errors in C
MBE - 01/27/2015
43
So If C Scared You...
If youre in this class, we expect you to already
know some basic C from CompOrg, CANOS,
OpSys, or NetProg
Otherwise, review C programming ASAP
Hacking: The Art of Exploitation, chapter 0x200
MBE - 01/27/2015
44
Lecture Overview
Syllabus
Course Overview
Review of Background Material
Linux
C
x86 Assembly
MBE - 01/27/2015
45
x86 Assembly
An assembly instruction set
introduced in 1978 by Intel
1978 - 16bit
1985 - 32bit
2001 - 64bit (Itanium)
2003 - 64bit (AMD64)
MBE - 01/27/2015
46
Language Depth
MBE - 01/27/2015
47
there's way too much information to decode the Matrix. You get used to it,
though. Your brain does the translating. I don't even see the code. All I see is
blonde, brunette, redhead. -Cypher, The Matrix
MBE - 01/27/2015
48
49
MBE - 01/27/2015
50
Important Registers
EAX EBX ECX EDX - General purpose registers
ESP - Stack pointer, top of the current stack frame (lower
memory)
EBP - Base pointer, bottom of the current stack frame
(higher memory)
EIP - Instruction pointer, pointer to the next instruction to
be executed by the CPU
EFLAGS - stores flag bits
ZF - zero flag, set when result of an operation equals zero
CF - carry flag, set when the result of an operation is too large/small
SF - sign flag, set when the result of an operation is negative
MBE - 01/27/2015
51
Moving Data
mov ebx, eax
Move the value in eax to ebx
MBE - 01/27/2015
52
Arithmetic Operations
sub edx, 0x11
edx = edx - 0x11;
inc edx
edx++;
// increments edx
dec ebx
ebx--;
// decrements ebx
or edx, 0x1337
edx = edx | 0x1337; // bitwise or edx with 0x1337
MBE - 01/27/2015
53
jnz $LOC
Jump to $LOC if ZF = 0
jg $LOC
Jump to $LOC if the result of a comparison is the destination is
greater than the source
MBE - 01/27/2015
54
Stack Manipulation
push ebx
Subtract 4 from the stack pointer to move it towards lower memory
(zero,) and copy the value in EBX on top of the stack
sub esp, 4
mov DWORD PTR [esp], ebx
pop ebx
Copy the value off the top of the stack and into EBX, the add 4 to the
stack pointer to move it towards higher memory (0xFFFFFFFF)
mov ebx, DWORD PTR [esp]
add esp, 4
MBE - 01/27/2015
55
Calling / Returning
call some_function
Calls the code at some_function. We need to push the return
address onto the stack, then branch to some_function
push eip
mov eip, some_function ; not actually valid
ret
Used to return from a function call. Pops the top of the stack to eip
pop eip
; not actually valid
nop
no operation - does nothing
MBE - 01/27/2015
56
Basic x86
0x08048624: YOLOSWAG\0
mov ebx, 0x08048624
mov eax, 0
LOOPY:
mov cl, BYTE PTR [ebx]
cmp cl, 0
jz
end
inc eax
inc ebx
jmp LOOPY
end:
ret
MBE - 01/27/2015
57
Basic x86
0x08048624: YOLOSWAG\0
mov eax, 0
; set eax to 0
LOOPY:
; is cl 0? (eg \0)
jz
; if cl was 0, go to end
end
inc eax
inc ebx
jmp LOOPY
; go to LOOPY
end:
ret
MBE - 01/27/2015
58
...
mov eax, 0
int len = 0;
LOOPY:
mov cl, BYTE PTR [ebx]
cmp cl, 0
while (*word != 0)
jz
end
inc eax
len++;
inc ebx
word++;
jmp LOOPY
end:
ret
MBE - 01/27/2015
return len;
59
Additional Material
Related Readings:
Hacking: The Art of Exploitation
Chapter 0x200: Programming - C programming and GDB
Practical Reverse Engineering (Dang et al)
Chapter 1 (x86)
Get familiar with the linux command line if you arent already
http://overthewire.org/wargames/bandit/
MBE - 01/27/2015
60