Professional Documents
Culture Documents
What is Security?
1 Security is
a state of being free from fear or danger.
(danger in the form of attacks)
2 Security is
OAkin
ensuring that “all desired assurances” are met
Dan Boneh
What is Security?
Cryptography and Network Security
Cryptography
Dan Boneh
What is Security?
Cryptography and Network Security
Cryptography
Dan Boneh
What is Security?
Cryptography and Network Security
Cryptography
Passive Approaches
Dan Boneh
What is Security?
Cryptography and Network Security
Cryptography
Active vs Passive
Dan Boneh
What is Security?
Cryptography and Network Security
Cryptography
OAkin
Dan Boneh
What is Security?
Cryptography and Network Security
Cryptography
1 Any feeling of security that results from such steps stems from
Dan Boneh
What is Security?
Cryptography and Network Security
Cryptography
Shaky Basis :(
Dan Boneh
What is Security?
Cryptography and Network Security
Cryptography
Dan Boneh
What is Security?
Cryptography and Network Security
Cryptography
Network Security
Dan Boneh
What is Security?
Cryptography and Network Security
Cryptography
Secure Interactions
Dan Boneh
What is Security?
Cryptography and Network Security
Cryptography
Dan Boneh
What is Security?
Cryptography and Network Security
Cryptography
A Useful Perspective
Dan Boneh
What is Security?
Cryptography and Network Security
Cryptography
Cryptography
and
3 digital signature algorithms (like DSA, RSA).
4 The tools serve as building blocks for constructing
cryptographic protocols
1
This is our main focus
Dan Boneh
What is Security?
Cryptography and Network Security
Cryptography
Cryptographic Algorithms
Dan Boneh
What is Security?
Cryptography and Network Security
Cryptography
Symmetric Algorithms
1 Symmetric Encryption/Decryption:
1 a pair of functions C = E(P, K ) and P = D(C, K )
2 strength depends only on the length of the key
2 Hash Functions:
1 d = H(M);
2 d is a fixed size digest (or hash or image) and
OAkin 3 M is a message (or pre-image) of any size.
4 strength depends only on the size of the digest
Dan Boneh
What is Security?
Cryptography and Network Security
Cryptography
Asymmetric Algorithms
Dan Boneh
What is Security?
Cryptography and Network Security
Cryptography
1 Symmetric Cryptography
1 Symmetric encryption/decryption
2 Hashing
2 Asymmetric Cryptography
1 Encryption/Decryption
2 Signatures
3 Key Distribution/Establishment
4 Identify types of Internet interactions to be secured
OAkin
5 Interactions in different layers - MAC, Network, Transport,
Application
6 Network security protocols
7 Some active security mechanisms not based on cryptography
Dan Boneh
Control Hijacking
Control Hijacking:
Defenses
Dan Boneh
Recap: control hijacking attacks
Stack smashing: overwrite return address or function pointer
Heap spraying: reliably exploit a heap overflow
Use after free: attacker writes to freed control structure,
which then gets used by victim program
Integer overflows
Format string vulnerabilities
⋮ Dan Boneh
The mistake: mixing data and control
• An ancient design flaw:
– enables anyone to inject control signals
local ret
SFP arguments
variables addr
stack frame
data overwrites
return address
Later we will see that mixing data and code is also the
reason for XSS, a common web vulnerability
Dan Boneh
Preventing hijacking attacks
1. Fix bugs:
– Audit software
• Automated tools: Coverity, Infer, … (more on this next week)
– Rewrite software in a type safe languange (Java, Go, Rust)
• Difficult for existing (legacy) code …
Platform Defenses
Dan Boneh
Marking memory as non-execute (DEP)
Prevent attack code execution by marking stack and heap as non-executable
Dan Boneh
Attack: Return Oriented Programming (ROP)
Control hijacking without injecting code:
stack libc.so
args
ret-addr exec()
sfp printf()
Dan Boneh
ROP: in more detail
To run /bin/sh we must direct stdin and stdout to the socket:
dup2(s, 0) // map stdin to socket
dup2(s, 1) // map stdout to socket
execve("/bin/sh", 0, 0);
kBouncer
pop rdi pop rsi pop rax syscall kernel
ret ret ret ret
Idea: before a syscall, check that every prior ret is not abnormal
• How: use Intel’s Last Branch Recording (LBR)
Dan Boneh
A very different idea: kBouncer
kBouncer
pop rdi pop rsi pop rax syscall kernel
ret ret ret ret
Hardening the
executable
Dan Boneh
Run time checking: StackGuard
• Many run-time checking techniques …
– we only discuss methods relevant to overflow protection
• Solution 1: StackGuard
– Run time tests for stack integrity.
– Embed “canaries” in stack frames and verify their integrity
prior to function return.
Frame 2 Frame 1
top
local canary sfp ret str local canary sfp ret str of
stack
Dan Boneh
Canary Types
• Random canary:
– Random string chosen at program startup.
– Insert canary string into every stack frame.
– Verify canary before returning from function.
• Exit program if canary changed. Turns potential exploit into DoS.
– To corrupt, attacker must learn current random string.
Dan Boneh
StackGuard enhancement: ProPolice
• ProPolice - since gcc 3.4.1. (-fstack-protector)
– Rearrange stack layout to prevent ptr overflow.
String args
Growth ret addr Protects pointer args and local
SFP pointers from a buffer overflow
CANARY
Stack local string buffers
Growth local non-buffer variables pointers, but no arrays
copy of pointer args Dan Boneh
MS Visual Studio /GS [since 2003]
Compiler /GS option:
– Combination of ProPolice and Random canary.
– If cookie mismatch, default behavior is to call _exit(3)
Function prolog: Function epilog:
sub esp, 8 // allocate 8 bytes for cookie mov ecx, DWORD PTR [esp+8]
mov eax, DWORD PTR ___security_cookie xor ecx, esp
xor eax, esp // xor cookie with current esp call @__security_check_cookie@4
mov DWORD PTR [esp+8], eax // save in stack add esp, 8
ptr to high
next handler buf next
next handler next handler mem
attack code
Dan Boneh
Defenses: SAFESEH and SEHOP
• /SAFESEH: linker flag
– Linker produces a binary with a table of safe exception handlers
– System will not jump to exception handler not on list
Dan Boneh
Summary: Canaries are not full proof
• Canaries are an important defense tool, but do not prevent all
control hijacking attacks:
– Some stack smashing attacks leave canaries unchanged: how?
– Heap-based attacks still possible
– Integer overflow attacks still possible
– /GS by itself does not prevent Exception Handling attacks
(also need SAFESEH and SEHOP)
Dan Boneh
Even worse: canary extraction
A common design for crash recovery:
• When process crashes, restart automatically (for availability)
• Often canary is unchanged (reason: relaunch using fork)
local
Danger:
⋯ buffer
AC A N A R Y
ret
addr
crash
local ret
⋯ buffer C A N A R Y
addr
No crash
local ret
⋯ buffer C A N A R Y
addr
No crash
Dan Boneh
Similarly: extract ASLR randomness
A common design for crash recovery:
• When process crashes, restart automatically (for availability)
• Often canary is unchanged (reason: relaunch using fork)
local ret
Danger: ⋯ buffer
AC A N A R Y
addr
crash
Extract ret-addr to
local ret
de-randomize
code location
⋯ buffer BC A N A R Y
addr
crash
local ret
Extract stack ⋯ buffer C A N A R Y
addr
No crash
function pointers to local ret
de-randomize heap ⋯ buffer C A N A R Y
addr
No crash
Dan Boneh
More methods: Shadow Stack
Shadow Stack: keep a copy of the stack in memory
• On call: push ret-address to shadow stack on call
• On ret: check that top of shadow stack is equal to
ret-address on stack. Crash if not.
• Security: memory corruption should not corrupt shadow stack
Dan Boneh
Tags prevent buffer overflows and use after free
tags (4 bits): 8 BE BE BE 7 7 5 5
Example:
p p+48
16 bytes
(1) char *p = new char(40); // p = 0x B000 6FFF FFF5 1240 (*p tagged as B)
(2) p[50] = ’a’; // B≠7 ⟹ tag mismatch exception (buffer overflow)
(3) delete [] p; // memory is re-tagged from B to E
(4) p[7] = ‘a’; // B≠E ⟹ tag mismatch exception (use after free)
Control Flow
Integrity (CFI)
Dan Boneh
Control flow integrity (CFI) [ABEL’05, …]
Coarse CFI: ensure that every indirect call and indirect branch
leads to a valid function entry point or branch target
Dan Boneh
Coarse CFI: Control Flow Guard (CFG) (Windows 10)
Coarse CFI:
• Protects indirect calls by checking against a bitmask of all valid
function entry points in executable
ensures target is
the entry point of a
function
Dan Boneh
Coarse CFI using EndBranch (Intel) and BTI (ARM)
New instruction EndBranch (Intel) and BTI (ARM):
⦚
• After an indirect JMP or CALL: call eax
the next instruction in the
instruction stream must be EndBranch
⦚
• If not, then trigger a #CP fault EndBranch
and halt execution
⦚
• Ensures an indirect JMP or CALL can only go add ebp, 4
to a valid target address ⇒ no func. ptr. hijack
⦚
(compiler inserts EndBranch at valid locations)
Dan Boneh
CFG, EndBranch, BTI: limitations
Poor man’s version of CFI:
• Protects
• Doindirect calls byattacker
not prevent checking from
againstcausing
a bitmask of all valid
function entryto
a jump points in executable
a valid wrong function
• Hard to build accurate control
ensures target is
flow graph statically the entry point of a
function
Dan Boneh
An example
void HandshakeHandler(Session *s, char *pkt) {
s->hdlr = &LoginHandler;
... Buffer overflow over Session struct ... Attacker controls
} handler
Dan Boneh