Computer Security and Software Vulnerabilities

 
Software Security Overview
Software Security Overview
 
Mao Bing
Mao Bing
 
Department of Computer Science
Department of Computer Science
NanJing University
NanJing University
 
2
 
Outline
Outline
 
Background
Software Security: Control-flow Hijack Attack
Memory Layout , Stack frame, & Procedure
Buffer Overflow: Vulnerability, & Defenses
RILC, Return-Oriented Programming
ASLR & CFI
Software Security: Non-control Data Attack
Data Oriented Programming
Summary
 
3
 
Outline
Outline
 
Background
Software Security: Control-flow Hijack Attack
Memory Layout , Stack frame, & Procedure
Buffer Overflow: Vulnerability, & Defenses
RILC, Return-Oriented Programming
ASLR & CFI
Software Security: Non-control Data Attack
Data Oriented Programming
Summary
 
4
 
Computer Security
Computer Security
Computer security, also
known as cybersecurity or IT
security, is the “...
protection
of information systems from
theft
 (
secrecy/confidentiality
)
or 
damage
 (
integrity
) to the
hardware, the software, and
to the information on them, ...”
—Gasser, Morrie (1988)
 
5
 
How Many Vulnerabilities?
How Many Vulnerabilities?
 
6
 
Before Morris Worm, Computer Security is:
Before Morris Worm, Computer Security is:
Encryption & Decryption
Access Control
DAC
MAC
Logic Bomb
Back Door
 
7
 
Until 198
Until 198
8…
8…
Access Control
Encryption & Decryption
Logic Bomb
Back Door
 
 
Computer
Security
 
8
Morris Worm
Morris Worm
Generating IP
address(Randomly)
Address detection
Is the host
real?
Is 
the
Vulnerability
exist?
Attack,
&
Infection
Y
Y
N
N
A
u
t
h
o
r
:
 
R
o
b
e
r
t
 
T
a
p
p
a
n
 
M
o
r
r
i
s
 
9
 
Morris Worm
Morris Worm
Vulnerability: Buffer Overflow
Attack & Infection
Hijack control flow & execute SHELLCODE
Add the virus to the head or tail of the program
 
10
Effect of Morris Worm
Effect of Morris Worm
 
The U.S. 
Government Accountability
Office
 put the cost of the damage at
$100,000–10,000,000
.
Around 
6,000
 major UNIX machines
were infected by the Morris
worm(about 
60,000
 computers
attached to the Internet).
Prompted DARPA to fund the
establishment of the 
CERT/CC
 at
Carnegie Mellon University.
11
What changes do Morris Worm bring to
What changes do Morris Worm bring to
Computer Security?
Computer Security?
 
A real Buffer Overflow
 
Attack
 
Return Address
 
Control flow
 
Software
Security
 
12
 
Outline
Outline
 
Background
Software Security: Control-flow Hijack Attack
Memory Layout , Stack frame, & Procedure
Buffer Overflow: Vulnerability, & Defenses
RILC, Return-Oriented Programming
ASLR & CFI
Software Security: Non-control Data Attack
Data Oriented Programming
Summary
 
13
 
Outline
Outline
 
Background
Software Security: Control-flow Hijack Attack
Memory Layout , Stack frame, & Procedure
Buffer Overflow: Vulnerability, & Defenses
RILC, Return-Oriented Programming
ASLR & CFI
Software Security: Non-control Data Attack
Data Oriented Programming
Summary
14
Anatomy of a Program in Memory
Anatomy of a Program in Memory
support process execution
support process execution
(LIFO)
(LIFO)
15
Stack
Stack
The stack is used for: 
The stack is used for: 
passing arguments,
storing return information
storing return information
, saving
registers, and for local storage.
16
Procedure Call
Procedure Call
The compiled code for a function has three parts: the “
setup
setup
” where the
stack frame is initialized; the “
body
body
” where the actual computation of
the procedure is performed; and the “
finish
finish
” where the stack state is
restored and the procedure returns.
Set up(real):
Set up(real):
   push ebp
 
  
saved old ebp
   movl esp, ebp      
 
  
set %ebp as frame pointer
Finish(real):
Finish(real):
   pop ebp
 
  
restore %ebp
   ret
 
      
 
  
ret
Call(virtual):
Call(virtual):
   push 
return addr.
 
  
   jump to func      
 
Ret(virtual):
Ret(virtual):
   pop 
return addr.
 
  
   jump to   
the addr.   
 
17
Stack Frame Structure
Stack Frame Structure
The key of the Buffer Overflow Attack!!!
 
18
 
Outline
Outline
 
Background
Software Security: Control-flow Hijack Attack
Memory Layout , Stack frame, & Procedure
Buffer Overflow: Vulnerability, & Defenses
RILC, Return-Oriented Programming
ASLR & CFI
Software Security: Non-control Data Attack
Data Oriented Programming
Summary
 
19
 
Vulnerability Metrics: Buffer Overflow
Vulnerability Metrics: Buffer Overflow
20
Buffer Overflow 
Buffer Overflow 
& 
& 
Morris Worm
Morris Worm
Aside from being the first computer worm to be distributed via the Internet,
the worms attack  was a classic stack smash against the fingerd daemon.
 Morris 
recounts his thoughts on the
overflow attack: “I had heard of the
potential for exploits via 
overflow of
overflow of
the data segment buffers
the data segment buffers
 overwriting
the next variable. That is, people were
worried about code like this:
char  buf[512];
int is_authorized;
func(){
        …;
        
gets(buf);
gets(buf);
}
21
Buffer Overflow
Buffer Overflow
large_string
large_string
: AAAAAAAAAAA……….. AAAAAA7c80dfdd0804874
 
 
x
 
offset = x
shellcode
shellcode
    \xdd\xdf\x80\x7c\xff\xff\xff\xff
    \xdd\xdf\x80\x7c\xff\xff\xff\xff
    \xdb\x53\x87\x7c\x63\xce\x86\x7c
    \xdb\x53\x87\x7c\x63\xce\x86\x7c
    \xc6\x3a\x87\x7c\xfa\x20\x87\x7c
    \xc6\x3a\x87\x7c\xfa\x20\x87\x7c
    \xc6\x3a\x87\x7c\x63\x3e\x86\x7c
    \xc6\x3a\x87\x7c\x63\x3e\x86\x7c
    \x44\x21\x86\x7c\xea\xd4\x83\x7c
    \x44\x21\x86\x7c\xea\xd4\x83\x7c
22
Buffer Overflow Attack Step
Buffer Overflow Attack Step
Vulnerability
Vulnerability
program
program
Success
Success
Determining the buffer size to
Determining the buffer size to
write exactly int EIP
write exactly int EIP
Find memory space to
Find memory space to
host the shellcode
host the shellcode
Jump to the shellcode in a
Jump to the shellcode in a
reliable way
reliable way
Get shellcode and
Get shellcode and
finalize the exploit
finalize the exploit
 
23
 
Defense
Defense
 
  Vulnerability
  Vulnerability
 
 
Return
Return
Address
Address
 
  
  
Malicious
Malicious
code
code
 
24
 
Defense(Vulnerability): Writing Correct Code
Defense(Vulnerability): Writing Correct Code
Writing correct code is a laudable but
remarkably 
expensive proposition 
, especially
when writing in a language such as 
C that has
error-prone idioms
 such 
as null-terminated
strings
 and a culture that favors performance
over correctness.
 
25
 
Defense(Return Address): StackGuard
Defense(Return Address): StackGuard
StackGuard
 is a compiler technique for
providing 
code pointer integrity checking
to the return address in function activation
records. StackGuard is implemented as
 a
small patch to gcc
 that enhances the code
generator for emitting code to set up and
tear down functions. The enhanced setup
code places a “
canary
” 4 word next to the
return address on the stack.
26
Defense(Malicious 
Defense(Malicious 
Code
Code
): Non-Executable Data
): Non-Executable Data
large_string
large_string
: AAAAAAAAAAA……….. AAAAAA7c80dfdd0804874
 
 
x
 
offset = x
shellcode
shellcode
    \xdd\xdf\x80\x7c\xff\xff\xff\xff
    \xdd\xdf\x80\x7c\xff\xff\xff\xff
    \xdb\x53\x87\x7c\x63\xce\x86\x7c
    \xdb\x53\x87\x7c\x63\xce\x86\x7c
    \xc6\x3a\x87\x7c\xfa\x20\x87\x7c
    \xc6\x3a\x87\x7c\xfa\x20\x87\x7c
    \xc6\x3a\x87\x7c\x63\x3e\x86\x7c
    \xc6\x3a\x87\x7c\x63\x3e\x86\x7c
    \x44\x21\x86\x7c\xea\xd4\x83\x7c
    \x44\x21\x86\x7c\xea\xd4\x83\x7c
DEP
 
No Executable
 
27
 
Outline
Outline
 
Background
Software Security: Control-flow Hijack Attack
Memory Layout , Stack frame, & Procedure
Buffer Overflow: Vulnerability, & Defenses
RILC, Return-Oriented Programming
ASLR & CFI
Software Security: Non-control Data Attack
Data Oriented Programming
Summary
 
28
 
Return-to-libc(RILC)
Return-to-libc(RILC)
29
Return-to-libc(RILC)
Return-to-libc(RILC)
large_string
large_string
: AAAAAAAAAAA……….. AAAAAA  7c80dfdd  0804874
 
 
x
 
offset = x
abs_0
.text:7c80dfdd                mov     edx, edi
.text:7c80dff0                 mov     eax, edi
.text:7c80dff2                 sar     edx, 1Fh
.text:7c80dff5                 xor     eax, edx
.text:7c80dff7                 sub     eax, edx
.text:7c80dff9                 retn
30
Limitations
Limitations
1.
Expressive power
2.
Easy to be defensive
An Exploit
An Exploit
Malicious
Malicious
Behavior
Behavior
function 1()
function 1()
function2()
function2()
function3()          …….
function3()          …….
functionN()
functionN()
 
31
 
Return Oriented Programming
Return Oriented Programming
32
Return Oriented Programming
Return Oriented Programming
Gadget2:
Gadget2:
0x7C86CE63
pop edi
 
    ret
Gadget3:
Gadget3:
0x7C8753DB:  inc ebx
 
   dec ecx
 
   ret
Gadget1:
Gadget1:
0x7C8720FA: pop esi
 
  ret
Gadget4
Gadget4
0x7C80DFDD: pop ebx
 
   ret
 
ESP
 
0x7C8720FA
 
data:esi
 
0x7C83D4EA
 
0x7C8753DB
 
0x7C80DFDD
 
ESP
 
ESP
 
ESP
 
ESP
 
ESP
 
data:edi
 
payload:
33
Enough gadgets for attack?
Enough gadgets for attack?
f
7 c7 07 00 00 00
0f 95 45 c3
  
c
7 07 00 00 00 0f
95
45
c3
test 
$0x00000007, %edi
setnzb -61(%ebp)
movl
 $0x0f000000, (%edi)
xchg
 %ebp, %eax
inc %ebp
ret
The set of gadgets  described is
Turing complete 
by inspection, so
return-oriented programs can do
anything possible with x86 code.
(
The Geometry of Innocent Flesh
The Geometry of Innocent Flesh
on the Bone:Return-into-libc
on the Bone:Return-into-libc
without Function Calls (on the
without Function Calls (on the
x86) Hovav Shacham, ACM CCS
x86) Hovav Shacham, ACM CCS
2007
2007
)
 
34
 
ROP: Contribution
ROP: Contribution
1.
Describe an efficient algorithm for analyzing libc to
recover the instruction sequences that can be used in
attack
2.
Bypass StackGuard & DEP
3.
But…
 
35
 
Outline
Outline
 
Background
Software Security: Control-flow Hijack Attack
Memory Layout , Stack frame, & Procedure
Buffer Overflow: Vulnerability, & Defenses
RILC, Return-Oriented Programming
ASLR & CFI
Software Security: Non-control Data Attack
Data Oriented Programming
Summary
 
36
 
Address Space Layout Randomization
Address Space Layout Randomization
Code Segment
0x7C83D4EA: 
0x7C83D4EA: 
pushad
 
  push edi
 
  ret
0x7C80DFDD
0x7C80DFDD
: pop ebx
 
   ret
0x7C8753DB:  
0x7C8753DB:  
inc ebx
 
   dec ecx
 
   ret
0x7C86CE63: 
0x7C86CE63: 
pop edi
 
    ret
0x7C8720FA: 
0x7C8720FA: 
pop esi
 
  ret
0x7C863E63: 
0x7C863E63: 
pop ebp
           
 
 ret
 
37
 
Address Space Layout Randomization
Address Space Layout Randomization
Randomization
0x
0x
8F8A
8F8A
D4EA: 
D4EA: 
pushad
 
  push edi
 
  ret
0x
0x
8F7E
8F7E
DFDD
DFDD
: pop ebx
 
   ret
0x
0x
8FD3
8FD3
53DB:  
53DB:  
inc ebx
 
   dec ecx
 
   ret
0x
0x
8FA6
8FA6
CE63: 
CE63: 
pop edi
 
    ret
0x
0x
8FD3
8FD3
20FA: 
20FA: 
pop esi
 
  ret
0x
0x
8F9D
8F9D
3E63: 
3E63: 
pop ebp
           
 
 ret
38
Just-in-time Code Reuse
Just-in-time Code Reuse
 
 
Re-
Randomization
Randomization
Isomeron, NDSS’15
Isomeron, NDSS’15
 
39
 
Control Flow Integrity
Control Flow Integrity
 
CFI idea: During program execution, whenever a machine-code instruction
transfers control, it targets a valid destination, as determined by a Control Flow
Graph (CFG) created ahead of time.
(1)
   sum = 0
(2)
   i = 1
(3)
   while (i<N) do
(4)
    
 
i = i+1
(5)
           if(i%2 == 0)
(6)
                   continue;
(7)
   
 
sum = sum + i
          endwhile
(8)     print (sum)
1: sum = 0
2: i = 1
3: while (i<N) do
4
: I
 = i+1
5: if(i%2==0)
7: sum=sum+i
8: print(sum)
 
40
 
Control Flow Integrity
Control Flow Integrity
 
 
 
 
Jump to the destination only if the tag
is equal to “12345678”
41
Control Flow Integrity
Control Flow Integrity
 
Control Flow Integrity provides:
Provably correct mechanisms that prevent powerful
       attackers from succeeding by protecting against all
       control flow integrity attacks.
Issues:
Performance overhead(average/max: 15%/46%)
Compatibility issues limit its adoption
 
 
 
 
Build CFG statically
Rewrite binary
Verify CFI instrumentation
Perform ID checks at run time
 
42
 
Practical 
Practical 
Control Flow Integrity
Control Flow Integrity
 
 
CCFIR(2013’ S&P)
CCFIR(2013’ S&P)
BinCFI(2013’s USENIX)
BinCFI(2013’s USENIX)
CCFIR(2013’ S&P)
CCFIR(2013’ S&P)
CCFI(2015’CCS)
CCFI(2015’CCS)
 
43
 
Outline
Outline
 
Background
Software Security: Control-flow Hijack Attack
Memory Layout , Stack frame, & Procedure
Buffer Overflow: Vulnerability, & Defenses
RILC, Return-Oriented Programming
ASLR & CFI
Software Security: Non-control Data Attack
Data Oriented Programming
Summary
 
44
 
Outline
Outline
 
Background
Software Security: Control-flow Hijack Attack
Memory Layout , Stack frame, & Procedure
Buffer Overflow: Vulnerability, & Defenses
RILC, Return-Oriented Programming
ASLR & CFI
Software Security: Non-control Data Attack
Data Oriented Programming
Summary
 
45
 
Source Code of do_authentication()
Source Code of do_authentication()
 
46
 
Data-Oriented 
Data-Oriented 
Programming
Programming
 
DOP Example
DOP Example
 
47
  1
 
struct 
server{ 
int 
total, *cur_max, typ;} *srv;
  2
 
int 
connect_limit = MAXCONN; 
int 
*size, *type;
  3
 
char 
buf[MAXLEN];
  4
 
size = &buf[10]; type = &buf[14]
  5
 
...
  6
 
while
(connect_limit--) {
  7
  
readData(sockfd, buf); 
// stack bof
  8
  
if
(*type == NONE ) 
break
;
  9
  
if
(*type == STREAM) 
// condition
10
                              *size = *(srv->cur_max); 
// dereference
11
                        else{
12
                               
srv->typ = *type; 
// assignment
12
                               srv->total += *size; 
// addition
13
                        }
13
  
... (handling) ...
14
 
}
 
Code 1: Vulnerable code with data-oriented gadgets
Code 1: Vulnerable code with data-oriented gadgets
 
Code2: A function increments the integer field of a linked-list by a given value. It
can be simulated by chaining data-oriented gadgets in Code 1.
 
48
 
node
 
node+4
*node  
  var
 
*(node+4)  
  next
 
Target
Target
struct
struct
 node {
 
int
int
 var;
 
node *next;
} 
*
list;
 
49
 
DOP Example
DOP Example
type
&list
size
&addend
srv
&srv - 8
type
&STREAM
size
&list
srv
&list
1.
while(connect_limit--) {
2.
     readData(sockfd, buf);
3.
     if(*type == NONE )              
if(list == NULL) break;
4.
              break;
5.
     if(*type == STREAM)
6.
 
 
*size = *(srv->cur_max);
7.
     else {
8.
 
 srv->typ = *type;       
srv = list;
9.
 
 
srv->total += *size;     
list->var += addend;
10.
     }
11.
}
1.
while(connect_limit--) {
2.
     readData(sockfd, buf);
3.
     if(*type == NONE )
4.
              break;
5.
     if(*type == STREAM)
6.
 
 
*size = *(srv->cur_max); 
 
list = list->next;
7.
     else {
8.
 
 srv->typ = *type;
9.
 
 
srv->total += *size;
10.
     }
11.
}
 
DOP Example
DOP Example
 
50
  1
 
struct node
 {
int
 var; 
node
 *next;}
  2
 
void 
updateList(
struct
 node *list, 
int
 addend) {
  3
  
for
(; list != NULL; list = list->next)
  4
   
list->var +=  addend
  5
 
}
 
DOP: Essential Factor
DOP: Essential Factor
 
51
Loop
Buffer Overflow
Dereference
 
52
 
Summary
Summary
 
Background
Encryption & Decryption, Access Control, Root Causes of the Security
Problems.
Software Security: Control-flow Hijack Attack
Memory Layout , Stack frame, & Procedure
Buffer Overflow: Vulnerability, & Defenses
RILC, Return-Oriented Programming
ASLR & CFI
Software Security: Non-control Data Attack
Data Oriented Programming
 
53
 
Q & A
Q & A
 
Thanks!
Slide Note
Embed
Share

Computer security, also known as cybersecurity or IT security, encompasses the protection of information systems from theft and damage. This overview delves into software security, control-flow attacks, memory vulnerabilities, and the historical impact of events like the Morris Worm. Various aspects such as encryption, access control, buffer overflow vulnerabilities, and the consequences of cyber threats are explored, shedding light on the critical importance of safeguarding digital assets.

  • Computer Security
  • Software Vulnerabilities
  • Cybersecurity
  • Memory Layout
  • Morris Worm

Uploaded on Sep 07, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Software Security Overview Mao Bing Department of Computer Science NanJing University

  2. Outline Background Software Security: Control-flow Hijack Attack Memory Layout , Stack frame, & Procedure Buffer Overflow: Vulnerability, & Defenses RILC, Return-Oriented Programming ASLR & CFI Software Security: Non-control Data Attack Data Oriented Programming Summary 2

  3. Outline Background Software Security: Control-flow Hijack Attack Memory Layout , Stack frame, & Procedure Buffer Overflow: Vulnerability, & Defenses RILC, Return-Oriented Programming ASLR & CFI Software Security: Non-control Data Attack Data Oriented Programming Summary 3

  4. Computer Security Computer security, also known as cybersecurity or IT security, is the ...protection of information systems from theft (secrecy/confidentiality) or damage (integrity) to the hardware, the software, and to the information on them, ... Gasser, Morrie (1988) 4

  5. How Many Vulnerabilities? 5

  6. Before Morris Worm, Computer Security is: Encryption & Decryption Access Control DAC MAC Logic Bomb Back Door 6

  7. Until 1988 Access Control Encryption & Decryption Computer Security Logic Bomb Back Door 7

  8. Morris Worm Author: Robert Tappan Morris Generating IP address(Randomly) Address detection Attack, & Infection Y Y Is the Is the host real? Vulnerability exist? N N 8

  9. Morris Worm Vulnerability: Buffer Overflow Attack & Infection Hijack control flow & execute SHELLCODE Add the virus to the head or tail of the program 9

  10. Effect of Morris Worm The U.S. Government Accountability Office put the cost of the damage at $100,000 10,000,000. Around 6,000 major UNIX machines were infected by the Morris worm(about 60,000 computers attached to the Internet). Prompted DARPA to fund the establishment of the CERT/CC at Carnegie Mellon University. 10

  11. What changes do Morris Worm bring to Computer Security? A real Buffer Overflow Attack Software Security 11

  12. Outline Background Software Security: Control-flow Hijack Attack Memory Layout , Stack frame, & Procedure Buffer Overflow: Vulnerability, & Defenses RILC, Return-Oriented Programming ASLR & CFI Software Security: Non-control Data Attack Data Oriented Programming Summary 12

  13. Outline Background Software Security: Control-flow Hijack Attack Memory Layout , Stack frame, & Procedure Buffer Overflow: Vulnerability, & Defenses RILC, Return-Oriented Programming ASLR & CFI Software Security: Non-control Data Attack Data Oriented Programming Summary 13

  14. Anatomy of a Program in Memory support process execution (LIFO) 14

  15. Stack The stack is used for: passing arguments, storing return information, saving registers, and for local storage. 15

  16. Procedure Call The compiled code for a function has three parts: the setup where the stack frame is initialized; the body where the actual computation of the procedure is performed; and the finish where the stack state is restored and the procedure returns. Set up(real): push ebp movl esp, ebp set %ebp as frame pointer Call(virtual): push return addr. jump to func saved old ebp Finish(real): pop ebp ret Ret(virtual): pop return addr. jump to the addr. restore %ebp ret 16

  17. Stack Frame Structure The key of the Buffer Overflow Attack!!! 17

  18. Outline Background Software Security: Control-flow Hijack Attack Memory Layout , Stack frame, & Procedure Buffer Overflow: Vulnerability, & Defenses RILC, Return-Oriented Programming ASLR & CFI Software Security: Non-control Data Attack Data Oriented Programming Summary 18

  19. Vulnerability Metrics: Buffer Overflow 19

  20. Buffer Overflow & Morris Worm Aside from being the first computer worm to be distributed via the Internet, the worms attack was a classic stack smash against the fingerd daemon. char buf[512]; int is_authorized; func(){ ; gets(buf); } Morris recounts his thoughts on the overflow attack: I had heard of the potential for exploits via overflow of the data segment buffers overwriting the next variable. That is, people were worried about code like this: 20

  21. Buffer Overflow large_string: AAAAAAAAAAA .. AAAAAA7c80dfdd0804874 . . . x argument Return addr shellcode \xdd\xdf\x80\x7c\xff\xff\xff\xff \xdb\x53\x87\x7c\x63\xce\x86\x7c \xc6\x3a\x87\x7c\xfa\x20\x87\x7c \xc6\x3a\x87\x7c\x63\x3e\x86\x7c \x44\x21\x86\x7c\xea\xd4\x83\x7c old %ebp Saved registers offset = x buffer Other data 21

  22. Buffer Overflow Attack Step Find memory space to host the shellcode Determining the buffer size to write exactly int EIP Vulnerability program Success Get shellcode and finalize the exploit Jump to the shellcode in a reliable way 22

  23. Defense Vulnerability Return Address Malicious code 23

  24. Defense(Vulnerability): Writing Correct Code Writing correct code is a laudable but remarkably expensive proposition , especially when writing in a language such as C that has error-prone idioms such as null-terminated strings and a culture that favors performance over correctness. No Function 1 gets(char[]) 2 char *fgets(char *string, int n, FILE *stream) 3 char *strcpy( char *dest, const char *src ) 24

  25. Defense(Return Address): StackGuard StackGuard is a compiler technique for providing code pointer integrity checking to the return address in function activation records. StackGuard is implemented as a small patch to gcc that enhances the code generator for emitting code to set up and tear down functions. The enhanced setup code places a canary 4 word next to the return address on the stack. 25

  26. Defense(Malicious Code): Non-Executable Data DEP large_string: AAAAAAAAAAA .. AAAAAA7c80dfdd0804874 . . . No Executable x argument Return addr shellcode \xdd\xdf\x80\x7c\xff\xff\xff\xff \xdb\x53\x87\x7c\x63\xce\x86\x7c \xc6\x3a\x87\x7c\xfa\x20\x87\x7c \xc6\x3a\x87\x7c\x63\x3e\x86\x7c \x44\x21\x86\x7c\xea\xd4\x83\x7c old %ebp Saved registers offset = x buffer Other data 26

  27. Outline Background Software Security: Control-flow Hijack Attack Memory Layout , Stack frame, & Procedure Buffer Overflow: Vulnerability, & Defenses RILC, Return-Oriented Programming ASLR & CFI Software Security: Non-control Data Attack Data Oriented Programming Summary 27

  28. Return-to-libc(RILC) 28

  29. Return-to-libc(RILC) large_string: AAAAAAAAAAA .. AAAAAA 7c80dfdd 0804874 . . . x argument Return addr abs_0 .text:7c80dfdd mov edx, edi .text:7c80dff0 mov eax, edi .text:7c80dff2 sar edx, 1Fh .text:7c80dff5 xor eax, edx .text:7c80dff7 sub eax, edx .text:7c80dff9 retn old %ebp Saved registers offset = x buffer Other data 29

  30. Limitations 1. Expressive power 2. Easy to be defensive function2() function 1() Malicious Behavior An Exploit function3() . functionN() 30

  31. Return Oriented Programming 31

  32. Return Oriented Programming payload: Gadget4 0x7C80DFDD: pop ebx ret Gadget3: 0x7C8753DB: inc ebx dec ecx ret 0x7C80DFDD Gadget2: 0x7C86CE63 pop edi ESP 0x7C8753DB ret ESP data:edi ESP 0x7C83D4EA Gadget1: 0x7C8720FA: pop esi ESP data:esi ret ESP 0x7C8720FA ESP 32

  33. Enough gadgets for attack? movl $0x0f000000, (%edi) xchg %ebp, %eax inc %ebp ret The set of gadgets described is Turing complete by inspection, so return-oriented programs can do anything possible with x86 code. (The Geometry of Innocent Flesh on the Bone:Return-into-libc without Function Calls (on the x86) Hovav Shacham, ACM CCS 2007) f7 c7 07 00 00 00 0f 95 45 c3 c7 07 00 00 00 0f 95 45 c3 test $0x00000007, %edi setnzb -61(%ebp) 33

  34. ROP: Contribution 1. Describe an efficient algorithm for analyzing libc to recover the instruction sequences that can be used in attack 2. Bypass StackGuard & DEP 3. But 34

  35. Outline Background Software Security: Control-flow Hijack Attack Memory Layout , Stack frame, & Procedure Buffer Overflow: Vulnerability, & Defenses RILC, Return-Oriented Programming ASLR & CFI Software Security: Non-control Data Attack Data Oriented Programming Summary 35

  36. Address Space Layout Randomization High address Code Segment 0x7C80DFDD: pop ebx ret shellcode 0x7C83D4EA: pushad 0x7C83D4EA push edi ret 0x7C862144 0x7C863E63 0x7C863E63: pop ebp ret 0x7C86CE64 0x7C8720FA 0x7C86CE63: pop edi ret 0x7C86CE64 0x7C86CE63 0x7C8720FA: pop esi ret 0x7C8753DB 0x7C8753DB: inc ebx 0xFFFFFFFF dec ecx ret 0x7C80DFDD 36

  37. Address Space Layout Randomization High address Randomization 0x8F7EDFDD: pop ebx ret shellcode 0x8F8AD4EA: pushad 0x7C83D4EA push edi ret 0x7C862144 0x7C863E63 0x8F9D3E63: pop ebp ret 0x7C86CE64 0x7C8720FA 0x8FA6CE63: pop edi ret 0x7C86CE64 0x7C86CE63 0x8FD320FA: pop esi ret 0x7C8753DB 0x8FD353DB: inc ebx 0xFFFFFFFF dec ecx ret 0x7C80DFDD 37

  38. Just-in-time Code Reuse Re-Randomization Isomeron, NDSS 15 38

  39. Control Flow Integrity CFI idea: During program execution, whenever a machine-code instruction transfers control, it targets a valid destination, as determined by a Control Flow Graph (CFG) created ahead of time. 1: sum = 0 2: i = 1 (1) (2) (3) (4) (5) (6) (7) sum = 0 i = 1 while (i<N) do i = i+1 if(i%2 == 0) 3: while (i<N) do 4: I = i+1 5: if(i%2==0) continue; sum = sum + i endwhile (8) print (sum) 7: sum=sum+i 8: print(sum) 39

  40. Control Flow Integrity Jump to the destination only if the tag is equal to 12345678 40

  41. Control Flow Integrity Control Flow Integrity provides: Provably correct mechanisms that prevent powerful attackers from succeeding by protecting against all control flow integrity attacks. Issues: Performance overhead(average/max: 15%/46%) Compatibility issues limit its adoption Build CFG statically Rewrite binary Verify CFI instrumentation Perform ID checks at run time 41

  42. Practical Control Flow Integrity BinCFI(2013 s USENIX) CCFIR(2013 S&P) CCFIR(2013 S&P) CCFI(2015 CCS) 42

  43. Outline Background Software Security: Control-flow Hijack Attack Memory Layout , Stack frame, & Procedure Buffer Overflow: Vulnerability, & Defenses RILC, Return-Oriented Programming ASLR & CFI Software Security: Non-control Data Attack Data Oriented Programming Summary 43

  44. Outline Background Software Security: Control-flow Hijack Attack Memory Layout , Stack frame, & Procedure Buffer Overflow: Vulnerability, & Defenses RILC, Return-Oriented Programming ASLR & CFI Software Security: Non-control Data Attack Data Oriented Programming Summary 44

  45. Source Code of do_authentication() 45

  46. Data-Oriented Programming 46

  47. DOP Example 1 2 3 4 5 6 7 8 9 struct server{ int total, *cur_max, typ;} *srv; int connect_limit = MAXCONN; int *size, *type; char buf[MAXLEN]; size = &buf[10]; type = &buf[14] ... while(connect_limit--) { readData(sockfd, buf); // stack bof if(*type == NONE ) break; if(*type == STREAM) // condition *size = *(srv->cur_max); // dereference else{ srv->typ = *type; // assignment srv->total += *size; // addition } ... (handling) ... } 10 11 12 12 13 13 14 Code 1: Vulnerable code with data-oriented gadgets 47

  48. Target Code2: A function increments the integer field of a linked-list by a given value. It can be simulated by chaining data-oriented gadgets in Code 1. struct node { node int var; node *next; var node+4 } *list; next *node var *(node+4) next 48

  49. DOP Example type &STREAM size &list srv &list type &list size &addend srv &srv - 8 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. } while(connect_limit--) { readData(sockfd, buf); if(*type == NONE ) break; if(*type == STREAM) *size = *(srv->cur_max); list = list->next; else { srv->typ = *type; srv->total += *size; } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. } while(connect_limit--) { readData(sockfd, buf); if(*type == NONE ) if(list == NULL) break; break; if(*type == STREAM) *size = *(srv->cur_max); else { srv->typ = *type; srv = list; srv->total += *size; list->var += addend; } 49

  50. DOP Example 1 2 3 4 5 struct node {int var; node *next;} void updateList(struct node *list, int addend) { for(; list != NULL; list = list->next) list->var += addend } 50

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#