資安產學個案研討 許 富 皓 資 訊 工 程 學 系 國 立 中 央 大 學

69
資資資資資資資資 資 資 資 資 資 資

Upload: hali

Post on 04-Feb-2016

69 views

Category:

Documents


0 download

DESCRIPTION

資安產學個案研討 許 富 皓 資 訊 工 程 學 系 國 立 中 央 大 學. SQL Injection [ SK ]. SQL Injection Version of Hello World. Let’s surf the Internet for fun. Wow! Be a member for free. What is SQL Injection?. Many web pages take parameters from web users , and make SQL query to the database . - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

資安產學個案研討

許 富 皓資 訊 工 程 學 系

國 立 中 央 大 學

Page 3: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

SQL Injection Version of Hello World

Let’s surf the Internet for fun.

Wow! Be a member for free.

Page 4: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

What is SQL Injection?Many web pages take parameters from web users, and make SQL query to the database.

Take for instance when a user login a web page, the web page accepts that user name and password and makes SQL query to the database to check if the user has valid name and password.

With SQL Injection, it is possible for us to send crafted user name and/or password field that will change the SQL query and thus grant us something else.

Page 5: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

SQL Injection Attack Channels

SQL injection is one type of web hacking that require nothing but port 80 and it might just work even if the admin is patch-happy.

It attacks on the web application (like ASP, JSP, PHP, CGI, etc) itself rather than on the web server or services running in the OS.

Page 6: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

What You Should Look for?Try to look for pages that allow you to submit data, i.e:

login page, search page, feedback, etc.

Sometimes, HTML pages use POST command to send parameters to another ASP page. Therefore, you may not see the parameters in the URL. However, you can check the source code of the HTML, and look for "FORM" tag in the HTML code. You may find something like this in some HTML codes:

<FORM action=Search/search.asp method=post><input type=hidden name=A value=C></FORM>

Everything between the <FORM> and </FORM> have potential parameters that might be useful (exploit wise).

Page 7: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

What If You Can't Find Any Page That Takes Input?

You should look for pages like ASP, JSP, CGI, or PHP web pages. Try to look especially for URL that takes parameters, like:

http://duck/index.asp?id=10

Page 8: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

How Do You Test If It Is Vulnerable?

Start with a single quote trick. Input something like:

hi' or 1=1--

into login, or password, or even in the URL.

Example:  - Login: hi' or 1=1-- - Pass: hi' or 1=1-- - http://duck/index.asp?id=hi' or 1=1—

If luck is on your side, you will get login without any login name or password.

Page 9: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Hidden Field

If you must do this with a hidden field, just download the source HTML from the site, save it in your hard disk, modify the URL and hidden field accordingly. Example:

<FORM action=http://duck/Search/search.asp method=post><input type=hidden name=A value="hi' or 1=1--"></FORM>

Page 10: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Database Table Example (1) [CQU]

Page 11: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Database Table productPName PCategory price number bar code

bread food 30 100 100-234-7

cake food 300 20 100-987-6

cookie food 50 70 100-812-9

model car

toy 200 20 300-567-7

figure toy 300 80 300-987-9

paper stationery 0.5 5000 981-897-7

pen stationery 20 300 981-967-0

Page 12: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Web Application Input and Its Corresponding SQL Query

Take an asp page that will link you to another page with the following URL:

http://duck/index.asp?category=food

In the URL, 'category' is the variable name, and 'food' is the value assigned to the variable. In order to do that, an ASP might contain the following code:

v_cat = request("category")sqlstr="SELECT * FROM product

WHERE PCategory='" & v_cat & "'"set rs=conn.execute(sqlstr)

As we can see, our variable will be wrapped into v_cat and thus the SQL statement should become:

SELECT * FROM product WHERE PCategory='food'

The query should return a result set containing one or more rows that match the WHERE condition, in this case, 'food'.

Page 13: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Why ' or 1=1-- ?Now, assume that we change the URL into something like this:

http://duck/index.asp?category=food' or 1=1--

Now, our variable v_cat equals to "food' or 1=1-- ", if we substitute this in the SQL query, we will have:

SELECT * FROM product WHERE PCategory='food' or 1=1--'

The query now should now select everything from the product table regardless if PCategory is equal to 'food' or not.

A double dash "--" tell MS SQL server ignore the rest of the query, which will get rid of the last hanging single quote (').

• Sometimes, it may be possible to replace double dash with single hash "#".

Page 14: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Other Crafted Input (1) However, if it is not an SQL server, or you simply cannot ignore the rest of the query, you also may try

' or 'a'='a

The SQL query will now become:

SELECT * FROM product WHERE PCategory='food' or 'a'='a'

It should return the same result.

Page 15: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Other Crafted Input (2)

Depending on the actual SQL query, you may have to try some of these possibilities:

' or 1=1--" or 1=1--or 1=1--' or 'a'='a" or "a"="a') or ('a'='a

Page 16: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Attacking Program Bugs

Page 17: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Attack TypesBuffer Overflow Attacks:

Stack Smashing attacksReturn-into-libc attacksHeap overflow attacksFunction pointer attacks.dtors overflow attacks.setjump/longjump buffer overflow attacks.

Format string attacks:Integer overflow and integer sign attacks

Page 18: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Why Buffer Overflow Attacks Are So Dangerous?

Easy to launch:Attackers can launch a buffer overflow attack by just sending a craft string to their targets to complete such kind of attacks.

Plenty of targets:Plenty of programs have this kind of vulnerabilities.

Cause great damage:Usually the end result of a buffer overflow attack is the attacker’s gaining the root privilege of the attacked host.

Internet worms proliferate through buffer overflow attacks.

Page 19: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Stack Smashing Attacks

Page 20: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Principle of Stack Smashing Attacks

Overwrite control transfer structures, such as return addresses or function pointers, to redirect program execution flow to desired code.

Attack strings carry both code and address(es) of the code entry point.

Page 21: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Explanation of BOAs (1)

b

return address add_g

address of G’s

frame point

C[0]

H’s stack

frame

G(int a)

{

H(3);

add_g:

}

H( int b)

{ char c[100];

int i;

while((c[i++]=getch())!=EOF)

{

}

}

C[99]

Input String: xyz

Z

Y

X

G’s stack frame

0xabc

0xaba0xabb

Page 22: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Explanation of BOAs (2)

b

return address add_g

address of G’s

frame point

C[0]

H’s stack

frame

addrress oxabc

G(int a)

{

H(3);

add_g:

}

H( int b)

{ char c[100];

int i;

while((c[i++]=getch())!=EOF)

{

}

}

C[99]

Injected Code0xabc

Attack String: xxInjected Codexy0xabc

Length=108 bytes

0xaba0xabb x

x

x

y

Page 23: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Injected Code:

The attacked programs usually have root privilege; therefore, the injected code is executed with root privilege.

The injected code is already in machine instruction form; therefore, a CPU can directly execute it.

However the above fact also means that the injected code must match the CPU type of the attacked host.

Usually the injected code will fork a shell; hence, after an attack, an attacker could have a root shell.

Page 24: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Injected Code of Remote BOAs

In order to be able to interact with the newly forked root shell, the injected code usually need to execute the following two steps:

Open a socket.

Redirect standard input and output of the newly forked root shell to the socket.

Page 25: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Example of Injected Code for X86 Architecture : Shell Code

char shellcode[] = "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd\x80\xe8\xdc\xff\xff\xff/bin/sh";

Page 26: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Two Factors for A Successful Buffer Overflow-style Attack(1)

A successful buffer overflow-style attack should be able to overflow the right place (e.g. the place to hold a return address with the correct value (e.g. the address of injected code entry point)).

Page 27: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Two Factors for A Successful Buffer Overflow-style Attack(2)

buffer where the

overflow startinjected code

return address

offset between the beginning of the

overflowed buffer and the overflow

target.

address of injected code

entry point.

The offset and the entry point address are non-predicable. They can

not decided by just looking the source code or local binary code.

Page 28: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Non-predictable OffsetFor performance concerns, most compilers don’t allocate memory for local variables in the order they appear in the source code, sometimes some space may be inserted between them. (Source Code doesn’t help)Different compiler/OS uses different allocation strategy. (Local binaries don’t help)Address obfuscation insert random number of space between local variables and return address. (Super good luck may help)

Page 29: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Non-predicable Entry Point Address

[fhsu@ecsl]#

0xbfffffff system data

environment variablesargument stringsenv pointersargv pointers

argc

webserver –a –b security

command line arguments

and environment variables

function main()’s stack frame

Page 30: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Strategies Used by Attackers to Increase Their Success Chance

Repeat address patterns.

Insert NOP (0x90) operations before the entry point of injected code.

One-byte long instructions that doesn’t change the semantic of an injected code could replace NOP.

Page 32: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

An Exploit Code Generation ProgramThis program uses the following three loop to generate the attack string which contains the shell code.

for(i=0;i<sizeof(buff);i+=4)

*(ptr++)=jump;

for(i=0;i<sizeof(buff)-200-strlen(evil);i++) buff[i]=0x90;

for(j=0;j<strlen(evil);j++) buff[i++]=evil[j];

Page 33: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Return-into-libc Attacks

Page 34: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Return-into-libc Attacks

A mutation of buffer overflow attacks.Utilize code already resided in the attacked programs’ address space, such as libc functions.Attack strings carry entry point address(es) of a desired libc function, new frame point address and parameters to the function.

Page 35: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

How Parameters and Local Variables

Are Represented in an Object File?

abc(int aa)

{int bb;

bb=aa;

:

:

}

abc:

function prologue

*(%ebp-4)=*(%ebp+8)

function epilogue

aa

return address

previous frame

pointbb

ebpa C function equivalent assembly code

P.S.: function prologue and function epilogue are added by a compiler

Page 36: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

A Way to Change the Parameters and

Local Variables of a Function. A parameter or a local variable in an object file is represented through its offset between the position pointed by %ebp and its own position. Therefore, the value of the %ebp register decides where a function to get its parameters and local variables. In other words, if an attacker can change the %ebp of a function, then she/he can also change the function’s parameters and local variables.

Page 37: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Function Prologue and Epilogue

#include <stdio.h>

int add_three_items(int a, int b, int c){ int d;

d=a+b+c; return d;}

add_three_items: pushl %ebp movl %esp, %ebp subl $4, %esp

movl 12(%ebp), %eax addl 8(%ebp), %eax addl 16(%ebp), %eax movl %eax, -4(%ebp) movl -4(%ebp), %eax

leave ret

leave=movl %ebp,%esp

popl %ebp

function prologue

function epilogue

3

4

P.S.: the assembly code in this and next slide are created by a Linux C compiler.

Page 38: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Function Calls

main(){ int a, b,c,f; extern int add_three_items();

a=1; b=2; c=3; f=add_three_items(a,b,c);}

main: pushl %ebp movl %esp, %ebp subl $24, %esp

andl $-16, %esp movl $0, %eax subl %eax, %esp movl $1, -4(%ebp) movl $2, -8(%ebp) movl $3, -12(%ebp)

subl $4, %esp pushl -12(%ebp) pushl -8(%ebp) pushl -4(%ebp) call add_three_items addl $16, %esp

movl %eax, -16(%ebp)

leave ret

leave=movl %ebp,%esp

popl %ebp

1

2

5

Page 39: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Code Created by a Free BSD C Compiler

function: pushl %ebp movl %esp, %ebp subl $40, %esp leave retmain: pushl %ebp movl %esp, %ebp subl $8, %esp andl $-16, %esp movl $0, %eax addl $15, %eax addl $15, %eax shrl $4, %eax sall $4, %eax subl %eax, %esp pushl $3 pushl $2 pushl $1 call function addl $12, %esp leave ret

void function(int a, int b, int c) { char buffer1[5]; char buffer2[10];}

main(int argc, char *argv[]) { int a, b;

function(1,2,3);}

gcc -S test.c;

Page 40: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

heap

bss

%ebp

ret addr (EIP)

$1

$2

$3

%ebp

ret addr (EIP)

low

highsp

bp

function: pushl %ebp movl %esp, %ebp subl $40, %esp leave retmain: pushl %ebp movl %esp, %ebp subl $8, %esp andl $-16, %esp movl $0, %eax addl $15, %eax addl $15, %eax shrl $4, %eax sall $4, %eax subl %eax, %esp pushl $3 pushl $2 pushl $1 call function addl $12, %esp leave ret

leave =movl %ebp, %esppopl %ebp

Page 41: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Explanation of Return-into-libc

b

return address add_g

address of G’s frame point

C[9]

G(int a)

{

H(3);

add_g:

}

H( int b)

{ char c[10];

overflow occurs

here

} C[0]

H’s stack frame

ebpany value

abc(), e.g. system()

any value

abc: pushl %ebp

movl %esp,%ebp

esp

parameter 1, e.g. pointer to /bin/sh

Page 42: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Explanation of Return-into-libc

b

return address add_g

address of G’s frame point

C[9]

G(int a)

{

H(3);

add_g:

}

H( int b)

{ char c[10];

overflow occurs

here

} C[0]

H’s stack frame

ebpany value

abc(), e.g. system()

any value

abc: pushl %ebp

movl %esp,%ebp

esp

parameter 1, e.g. pointer to /bin/sh

movl %ebp,%esp

(an instruction in function epilogue)

Page 43: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Explanation of Return-into-libc

b

return address add_g

address of G’s frame point

C[9]

G(int a)

{

H(3);

add_g:

}

H( int b)

{ char c[10];

overflow occurs

here

} C[0]

H’s stack frame

ebpany value

abc(), e.g. system()

any value

abc: pushl %ebp

movl %esp,%ebp

esp

parameter 1, e.g. pointer to /bin/sh

any value(popl %ebp)

Page 44: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Explanation of Return-into-libc

b

return address add_g

address of G’s frame point

C[9]

G(int a)

{

H(3);

add_g:

}

H( int b)

{ char c[10];

overflow occurs

here

} C[0]

H’s stack frame

ebpany value

abc(), e.g. system()

any value

abc: pushl %ebp

movl %esp,%ebp

esp

parameter 1, e.g. pointer to /bin/sh

any value

(ret)

Page 45: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Explanation of Return-into-libc

b

return address add_g

address of G’s frame point

C[9]

G(int a)

{

H(3);

add_g:

}

H( int b)

{ char c[10];

overflow occurs

here

} C[0]

H’s stack frameebp

any value

any value

any value

abc: pushl %ebp

movl %esp,%ebp

esp

parameter 1, e.g. pointer to /bin/sh

After the following two instruction in function system()’s function prologue is executed

pushl %ebp movl %esp, %ebp, the position of %esp and %ebp is shown in the figure.

Page 46: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Properties of Return-into-libc Attacks

The exploit strings don’t need to contain executable code.

Page 47: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Heap/Data/BSS Overflow Attacks

Page 48: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Principle of Heap/Data/BSS Overflow Attacks

Similarly to stack smashing attacks, attackers overflow a sensitive data structure by providing a buffer which is adjacent to the sensitive data structure more data than the buffer can store; hence, to overflow the sensitive data structure.

The sensitive data structure may contain:• A function pointer• A pointer to a string• … and so on.

Both the buffer and the sensitive data structure may locate at the heap, or data, or bss section.

Page 49: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Heap and Data/BSS Sections

The heap is an area in memory that is dynamically allocated by the application by using a system call, such as malloc() .

On most systems, the heap grows up (towards higher addresses).

The data section is initialized at program loading-time.The bss section contains uninitialized data, and is allocated at run-time.

Until it is written to, it remains zeroed (or at least from the application's point-of-view).

Page 50: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Heap Overflow Example

#define BUFSIZE 16

int main()

{ int i=0;

char *buf1 = (char *)malloc(BUFSIZE);

char *buf2 = (char *)malloc(BUFSIZE);

:

while((*(buf1+i)=getchar())!=EOF)

i++;

:

}

Page 51: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

BSS Overflow Example#define BUFSIZE 16 int main(int argc, char **argv) { FILE *tmpfd; static char buf[BUFSIZE], *tmpfile; : tmpfile = "/tmp/vulprog.tmp"; gets(buf); tmpfd = fopen(tmpfile, "w"); :}

Page 52: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

BSS and Function Pointer Overflow Example

int goodfunc(const char *str);

int main(int argc, char **argv)

{ int i=0;

static char buf[BUFSIZE];

static int (*funcptr)(const char *str);

:

while((*(buf+i)=getchar())!=EOF)

i++;

:

}

Page 53: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Function Pointer Attacks

Page 54: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Principle of Function Pointer Attacks

Utilizing a function pointer variable’s adjacent buffer to overwrite the content of the function pointer variable so that it will point to the code chosen by attackers.

A function pointer variable may locate at the stack section, the data section, or at the bss section.

Page 55: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Countermeasures of

Buffer Overflow Attacks

Page 56: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Countermeasures of Buffer Overflow Attacks (1)

Array bounds checking.

Non-executable stack/heap.

Safe C library.

Compiler solutions, e.g.,StackGuard

RAD

Type safe language, e.g. Java.

Static source code analysis.

Page 57: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Countermeasures of Buffer Overflow Attacks (2)

Anomaly Detection, e.g. through system calls.

Dynamic allocation of memory for data that will overwrite adjacent memory area.

Memory Address Obfuscation/ASLR

Randomization of executable Code.

Network-based buffer overflow detection

Page 58: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Array Bounds Checking

Fundamental solution for all kinds of buffer overflow attacks.

High run-time overhead (1 time in some situations)

Page 59: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Non-executable Stack/Heap

The majority of buffer overflow attacks are stack smashing attacks; therefore, a non-executable stack could block the majority of buffer overflow attacks.

Disable some original system functions, e.g. signal call handling, nested functions.

Page 60: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Safe C Library

Some string-related C library functions, such as strcpy and strcat don’t check the buffer boundaries of destination buffers, hence, modifying these kinds of unsafe library functions could secure programs that use these function.Replace strcpy with strncpy, or replace strcat with strncat, … and so on.Drawback: Plenty of other C statements could still results in buffer overflow vulnerabilities.

E.g. while ((*(ptr+i)=getchar())!=EOF) i++;

Page 61: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Compiler Solutions: StackGuard

Put a canary word before each return address in each stack frame. Usually, when a buffer overflow attack is launched, not only the return address but also the canary word will be overwritten; thus, by checking the integrity of the canary word, this mechanism can defend against stack smashing attacks.Low performance overhead.Change the layout of the stack frame of a function; hence, this mechanism is not compatible with some programs, e.g. debugger.Only protect return addresses.

Page 62: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Compiler Solutions: RAD

Store another copies of return addresses in a well-protected area, RAR.When a function is call, instead of saving its return address in its corresponding stack frame, another copy of its return address is saved in RAR. When the function finishes, before returning to its caller, the callee checks the return address in its stack frame to see whether the RAR has a copy of that address. If there is no such address in the RAR, then a buffer overflow attack is alarmed.Low performance overhead.Only protect return addresses.

Page 63: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Type Safe Language, e.g. Java

These kinds of languages will automatically perform array bound checking.

The majority of programs are not written in these kinds of languages; rewriting all programs with these kinds of languages becomes an impossible mission.

Page 64: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Static Source Code Analysis.

Analyze source code to find potential program statements that could result in buffer overflow vulnerabilities. E.g. program statements like

while((*(buf+i)=getchar())!=EOF) i++;

are not safe.False positive and false negative.Difficulty to obtain the source code.

Page 65: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Anomaly Detection

This mechanism is based on the idea that most malicious code that is run on a target system will make system calls to access certain system resources, such as files and sockets.This technique has two main parts:

Preprocessingmonitoring.

False positive and false negative.

Page 66: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Memory Address Obfuscation/ASLR

This approach randomizes the layout of items in main memory; hence attackers can only guess the address where their injected code reside and the address of their target functions.Change the run-time memory layout specifying by the original file format.Increase the complexity of debugging a program.

Page 67: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Aspects of Address Obfuscation (1)

The first is the randomization of the base addresses of memory regions.

This involves the randomization of the base address of • the stack

• heap

• the starting address of dynamically linked libraries

• the locations of functions and static data structures contained in the executable.

The second aspect includes permuting the order of variables and functions.

Page 68: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Aspects of Address Obfuscation(2)

The last is the introduction of random length gaps, such as

padding in stack frames

padding between malloc allocations

padding between variables and static data structures

random length gaps in the code segment, with jumps to get over them.

Page 69: 資安產學個案研討 許  富  皓 資 訊 工 程 學 系 國  立  中  央  大  學

Randomization of executable Code

This method involves the randomization of the code that is executed in a process. This approach encrypts instructions of a process, and decrypts instructions when they are prepared to be executed. Because attackers don’t know the key to encrypt their code, their injected code can not be decrypted correctly. As a result their code can not be executed.The main assumption of this method is that most attacks that attempt to gain control of a system are code-injection attacks.Need special hardwares to improve performance overhead.