Lecture 10
Lecture 10
Lecture 10
Design
Compile
"Forward Engineering" is an overloaded term, but
in this context, it is the process of building a Fix Tons of Bugs
program.
Compile
Compile
Let's look at some tools:
Fix Tons of Bugs
- Visual Studio/ an IDE
- Compile
gcc
- Strings Extensive Cursing
Assemble
The Reverse Engineering Process Understand
rdx
shr rax, 10 rax = rax >> 10 shift rax's bits right by 10, filling with 10 zeroes on the left
shift rax's bits right by 10, with sign-extension to fill the now
sar rax, 10 rax = rax >> 10
"missing" bits!
ror rax, 10 rax = (rax >> 10) | (rax << 54) rotate the bits of rax right by 10
rol rax, 10 rax = (rax << 10) | (rax >> 54) rotate the bits of rax left by 10
Curious how these work? Play around with the rappel tool ( https://github.com/yrp604/rappel)!
#
Memory (stack)
The stack has several uses. For now, we'll talk about temporary data
storage.
Registers and immediates can be pushed onto the stack to save
values:
mov rax, 0xc001ca75
push rax
push 0xb0bacafe # WARNING: even on 64-bit x86, you can only push 32-bit immediates...
c001ca75
c001ca75
b0bacafe
push rax
stack
(Like mov, push leaves the value in the src register intact.)
Values can be popped back off of the stack (to any register!).
pop rbx # sets rbx to 0xc001ca75
c001ca75
stack
pop rcx # sets rcx to 0xb0bacafe
#
Addressing the Stack
The CPU knows where the stack is because its address is stored in
rsp = 0x7f01f3453050
rsp.
0x7f01f345305
0
c001ca75
stack
rsp = 0x7f01f3453048
push 0xb0bacafe
0x7f01f345304
8
c001ca75
b0bacafe
stack
rsp = 0x7f01f3453050
pop rcx
0x7f01f345305
0
c001ca75
stack
This will store the 64-bit value in rbx into memory at address
0x133337:
mov rax, 0x133337
mov [rax], rbx
https://en.wikipedia.org/wiki/Endianness
Assembly Crash Course
#
Computers Make Decisions
if (authenticated) {
leetness = 1337;
}
else {
leetness = 0;
}
So far, we've just shunted data around.
But how do we make decisions?
#
What to Execute?
First, let's look at how computers execute instructions.
Recall: Assembly instructions are direct translations of binary code.
This binary code lives in memory.
0x10000 0x7fffffffffff
Example:
0x400800
Program
58 5b 48 01 d8 50
Binary Code
#
Control Flow: Jumps
CPUs execute instructions in sequence until told not to.
One way to interrupt the sequence is with a jmp instruction:
mov cx, 1337
jmp STAY_LEET
mov cx, 0
STAY_LEET:
push rcx
0x400800 STAY_LEET
Program mov rcx, 0x1337 jmp STAY_LEET mov rcx, 0 push rcx
Binary Code
STAY_LEET
0x400800 0x400804 0x400806 0x40080a
eb 04
Program
66 b9 37 13 (skip 4 66 b9 00 00 51
Binary Code bytes)