Memory Exploits & Defenses: Presenter: Kevin Snow
Memory Exploits & Defenses: Presenter: Kevin Snow
Stack Smashing
Return-to-libc
Heap Overflow
Generic Stack Frame
Caller
Callee
Stack Smashing
Goal:
Point return address to our buffer,
which contains executable code
Stack Smashing
Goal:
Point return address to an existing
library function
return-to-libc
f(){
g(&foo);
}
g(char *x){
char y [SZ];
scanf(y);
}
Good: Good:
printf(“%d”, num); printf(“%s”, myString);
Bad: Bad:
printf(“%d”); printf(myString);
Format String Errors
Goal:
Craft a special string that can write
arbitrary values to arbitrary
addresses
Format String Errors
f(){
int x; int y;
char s[128];
scanf(s);
printf(s);
}
Heap Overflow
Goal:
Overwrite function pointers on heap
to point to injected code
Heap Overflow
Canary
Library Wrapper
Shadow Stack
W⊕X Pages
Canary
Many problems:
• User written input loops not protected
• We can still corrupt local variables
• We can still do a heap overflow
Shadow Stacks
• Local variables
• Heap overflow overwrites function pointers
W⊕X Pages
Encoded
Instruction ⊕ Processor
Stream XOR
Practical Considerations
Shared libraries
Kc et al. implemented in hardware
(ideally)
Barrantes et al. implemented in emulator
Performance may suffer
ISR Thwarts an Attack
0-day exploit
shellcode[] =
"\x31\xdb" // xorl Encoded:
"\x8d\x43\x17"// leal "\x31\xdb" // xorl
"\xcd\x80" // int "\x8d\x43\x17"// leal
... //... "\xcd\x80" // int
... //...
Decoded:
“\x23\x54” //invalid
“\xa3\x2f\x9e” //invalid
“\x65\xc1 //invalid
Crash!
ISR Conclusions
Goal:
Distinguish between correct and
incorrect guesses
Attack Methodology
Encoded Decoded:
Guess:
“\x23\x54” //invalid
\x01 //ret?
\x02 //ret? \xc5 //invalid (crash)
\x03 //ret? \xef //invalid (crash)
\x04 //ret? \x7a //invalid (crash)
\x05 //ret? \xc3 //valid
(observable behavior)
Return attack
Jump attack
Extended attack
Return Attack
… …
Return address Address of buffer
… Original return address
Bottom of stack Bottom of stack
… …
Near return (0xc3) Harmless instr. (0x90)
(Previously guessed) Near return (0xc3)
… …
Address of buffer Address of buffer
… …
(1) Apparently correct (2) Double check
Reducing False Positives (3)
… …
Guessed ret instr. Guessed ret instr.
0x00 0xFF
0x00 0xFF
Address of buffer Address of buffer
… …
Strength:
• Use not restricted to special circumstances
Weaknesses:
• 2-byte instruction must be guessed
• Infinite loops created
Extended Attack
Extended Attack
{
offset
offset
Jump Attack
offset
offset
Address of buffer
Strengths:
• Not restricted to special circumstances
• Only creates a few infinite loops
Weaknesses:
• Initially 2-byte instructions must be guessed
MicroVM
delta_mmap
Means:
return-to-libc, lack of entropy in
PaX ASLR randomization
The Exploit
Note:
Offset? Result:
0x00000001 Crash!
0x00000002 Crash!
0x00000003 Crash!
Sleep 16 seconds
0x00000004
64-bit architecture
• Can increase randomness from 2^16 to 2^40
Randomization Frequency
Granularity
• Permute stack variables
• Permute code & library functions
• Permute static data
Combine with other approaches
Questions?
References
Wheres the FEEB?
On the Effectiveness of
Instruction Set Randomization
N. Sovarel, D. Evans, and N. Paul
USENIX Security, 2005
References