Gaurav S. Gaurav S. Kc Kc, , Angelos Angelos D.
- D. Keromytis
Keromytis Columbia University Columbia University
e e-
- NeXSh: OS Fortification
e- -NeXSh: OS Fortification NeXSh: OS Fortification e Protecting - - PowerPoint PPT Presentation
e- -NeXSh: OS Fortification NeXSh: OS Fortification e Protecting Software from Internet Malware Protecting Software from Internet Malware Gaurav S. Kc Kc, , Angelos Angelos D. D. Keromytis Keromytis Gaurav S. Columbia University
07 NOV, 2005. ACSAC 2 Gaurav S. Kc / Columbia University
Internet worms and Internet-
cracking tools
Override program control to execute malcode
Morris '88, Code Red II '01, Nimda '01, Slapper '02, Blaster '03, MS Slapper '02, Blaster '03, MS-
SQL Slammer '03, Sasser '04 Sasser '04
Automatic propagation
“j00 j00 got got h4x0r3d h4x0r3d!!” !!”
Create backdoors, install rootkits rootkits (conceal (conceal malcode existence), join a malcode existence), join a bot bot-
net, generate spam spam
07 NOV, 2005. ACSAC 3 Gaurav S. Kc / Columbia University
07 NOV, 2005. ACSAC 4 Gaurav S. Kc / Columbia University
Inter-
process communication (IPC)
Access: network, persistent storage devices
Process scheduling and context-
switching
Activation records
07 NOV, 2005. ACSAC 5 Gaurav S. Kc / Columbia University void function(char *s, float y, int x) { int a; int b; char buffer[SIZE]; int c; strcpy(buffer, s); return; }
PC FP SP
Activation Frame Header return_address, old_frame_pointer Activation Frame Header return_address, old_frame_pointer
07 NOV, 2005. ACSAC 6 Gaurav S. Kc / Columbia University 0xbfffffff foo: bar:
program stack frames
main: bar() { ... int $0x80 ; trap instr. ... } foo() { bar(); } main() { foo(); }
program.c
socki_lookup
kernel
0xffffffff
KERNEL MEMORY USERSPACE MEMORY
sock_create: sock_alloc: system_call() { call *0x0(,%eax,4); } sys_socket() { sock_create(); } sock_create() { sock_alloc(); } sock_alloc() { socki_lookup(); } socki_lookup() { ... }
system-call stack frames
system_call: sys_socket:
Machine instruction in .text section
07 NOV, 2005. ACSAC 7 Gaurav S. Kc / Columbia University 0xbfffffff foo: bar:
program stack frames
main: bar() { socket(...); } foo() { bar(); } main() { foo(); }
program.c
socket:
libc stack frames
socket() { ... int $0x80 ; trap instr. ... }
libc.so
socki_lookup
kernel
0xffffffff
KERNEL MEMORY USERSPACE MEMORY
sock_create: sock_alloc: system_call() { call *0x0(,%eax,4); } sys_socket() { sock_create(); } sock_create() { sock_alloc(); } sock_alloc() { socki_lookup(); } socki_lookup() { ... }
system-call stack frames
system_call: sys_socket:
Machine instruction in LIBC .text section
07 NOV, 2005. ACSAC 8 Gaurav S. Kc / Columbia University
C: A low-level, systems language with unsafe features
No bounds-checking. Not strongly typed.
Arbitrary memory overwrites
Common security vulnerabilities
Buffer overflows Format-string vulnerability Integer overflows Double-free vulnerability
07 NOV, 2005. ACSAC 9 Gaurav S. Kc / Columbia University
Phrack magazine, BugTraq, worms in “the wild”
1. 1.
Trigger Trigger vulnerability vulnerability in software in software
2. 2.
Overwrite Overwrite code code pointer pointer
3. 3.
Execute Execute malcode malcode of the attacker’s choosing, and invoke system calls
07 NOV, 2005. ACSAC 10 Gaurav S. Kc / Columbia University
1. 1.
2. 2.
3. 3.
Focus of e-NeXSh!
07 NOV, 2005. ACSAC 11 Gaurav S. Kc / Columbia University
void function(char *s, float y, int x) { int a; int b; char buffer[SIZE]; int c; strcpy(buffer, s); return; }
PC
int x float y char *s
0x0abcdef0
0x4fedcba8 int a int b char buffer[SIZE] int c
Stacksmashing (Code Injection) Overrun buffer Overwrite return address Injected code invokes system call ... ... &buffer &buffer &buffer ... ... int $0x80 nop nop nop ... ... &buffer &buffer &buffer ... call &system push “/bin/sh” nop nop nop Stacksmashing (LIBC-Based) Overrun buffer Overwrite return address Injected code invokes LIBC function
Buffer-overflow vulnerability
07 NOV, 2005. ACSAC 12 Gaurav S. Kc / Columbia University
07 NOV, 2005. ACSAC 13 Gaurav S. Kc / Columbia University
If ( If (call stack call stack doesn’t match doesn’t match call graph call graph) ) exit ( exit (LIBC LIBC-
based attack); );
If ( If (system call system call invoked from invoked from data memory data memory) ) exit ( exit (injected code execution injected code execution); );
07 NOV, 2005. ACSAC 14 Gaurav S. Kc / Columbia University 0xbfffffff foo: bar:
program stack frames
main: bar() { socket(...); } foo() { bar(); } main() { foo(); }
program.c
0xffffffff
KERNEL MEMORY USERSPACE MEMORY
sock_create:
kernel
system_call() { // validate “return address” call *0x0(,%eax,4); } sys_socket() { sock_create(); } sock_create() { sock_alloc(); }
system-call stack frames
system_call: sys_socket:
socket:
e-NeXSh.so
socket() { // validate call stack libc.so :: socket(); }
e-NeXSh.so
socket() { int $0x80 ; trap instr. }
libc.so
socket:
libc stack frames
socki_lookup sock_alloc:
Valid return address Valid call stack
07 NOV, 2005. ACSAC 15 Gaurav S. Kc / Columbia University
07 NOV, 2005. ACSAC 16 Gaurav S. Kc / Columbia University 0xbfffffff foo: ... ... call socket
program stack frames
main: bar() { socket(...); } foo() { bar(); } main() { foo(); }
program.c
0xffffffff
KERNEL MEMORY USERSPACE MEMORY
socket:
e-NeXSh.so
socket() { // validate call stack libc.so :: socket(); }
e-NeXSh.so
INVALID call stack
07 NOV, 2005. ACSAC 17 Gaurav S. Kc / Columbia University
07 NOV, 2005. ACSAC 18 Gaurav S. Kc / Columbia University 0xbfffffff
program stack frames
main: bar() { socket(...); } foo() { bar(); } main() { foo(); }
program.c kernel
0xffffffff
KERNEL MEMORY USERSPACE MEMORY
system_call() { // validate “return address” call *0x0(,%eax,4); } sys_socket() { sock_create(); } sock_create() { sock_alloc(); }
system-call stack frames
system_call:
foo: ... ... int $0x80
INVALID return address
07 NOV, 2005. ACSAC 19 Gaurav S. Kc / Columbia University
07 NOV, 2005. ACSAC 20 Gaurav S. Kc / Columbia University
No, this can only be done via a system call
No, the kernel’s system-
call handler sets this up
No, we can randomise randomise the offsets for the .stack and .text segments, and the offsets for the .stack and .text segments, and also also randomise randomise the old the old-
FP and return addresses on the stack. This prevents an attacker from creating a seemingly valid, but fake s prevents an attacker from creating a seemingly valid, but fake stack. tack.
Very minimal: assembly code (~10LOC) and C code (~50LOC) in the : assembly code (~10LOC) and C code (~50LOC) in the
See results for ApacheBench benchmarks and UNIX utilities ApacheBench benchmarks and UNIX utilities
07 NOV, 2005. ACSAC 21 Gaurav S. Kc / Columbia University
Apache Macro-benchmarks: ApacheBench
14796.128 ±244.96 14663.876 ±142.90 14566.668 ±197.86
1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 11000 12000 13000 14000 15000
Average # Requests per second (with std. deviation)
Apache Apache with e-NeXSh disabled Apache with e-NeXSh enabled
07 NOV, 2005. ACSAC 22 Gaurav S. Kc / Columbia University
ctags -
R ; ; tar tar -
c ; ; gzip gzip ; ; scp scp user@localhost user@localhost: :
07 NOV, 2005. ACSAC 23 Gaurav S. Kc / Columbia University
07 NOV, 2005. ACSAC 24 Gaurav S. Kc / Columbia University
07 NOV, 2005. ACSAC 25 Gaurav S. Kc / Columbia University
07 NOV, 2005. ACSAC 26 Gaurav S. Kc / Columbia University
07 NOV, 2005. ACSAC 27 Gaurav S. Kc / Columbia University
07 NOV, 2005. ACSAC 28 Gaurav S. Kc / Columbia University