Software Security Ge Zhang Security: When is it software problem - - PDF document

software security
SMART_READER_LITE
LIVE PREVIEW

Software Security Ge Zhang Security: When is it software problem - - PDF document

Software Security Ge Zhang Security: When is it software problem Network Problem: caused by the flaws in networking mechanisms such as network protocols. OS Problem: caused by the flaws in OS mechanisms such OS resource management


slide-1
SLIDE 1

Software Security

Ge Zhang

slide-2
SLIDE 2

Security: When is it software problem

Network Problem: caused by the flaws in networking

mechanisms such as network protocols.

OS Problem: caused by the flaws in OS

mechanisms such OS resource management policies.

Software Problem: caused by the flaws in software

implementation or design

Employee Problem: people do not pay attention on

security

slide-3
SLIDE 3

Why is software security a challenge

Complexity of systems and software. Security is not a static feature. Different goals between software projects

and security:

Goals of software projects: functionality, usability,

efficiency, time-to-market.

Goals of security: confidentiality, integrity,

availability…

Software experts are not security experts.

slide-4
SLIDE 4

Causes for Security problems (in programming)

Flaws and oversights in the design and

implementation

What is written is not what is meant

slide-5
SLIDE 5

Principles for security design 1

Secure the weakest link

a software system is only

as secure as its weakest component

slide-6
SLIDE 6

Principles for security design 2

Practice Defense in Depth

slide-7
SLIDE 7

Principles for security design 3

Fail securely

slide-8
SLIDE 8

Principles for security design 4

Follow the Principle of

least privilege

slide-9
SLIDE 9

Principles for security design 5

Compartmentalize

slide-10
SLIDE 10

Principles for security design 6

Keep it simple

slide-11
SLIDE 11

Principles for security design 7

Promote privacy

slide-12
SLIDE 12

Principles for security design 8

  • Remember that hiding secrets is hard
  • Many people assume that code

compiled into binary is sufficiently well protected against attackers.

  • Reverse Engineering
  • Sometimes, attackers do not need to

have the source code.

  • Enigma machine
slide-13
SLIDE 13

Principles for security design 9

Be reluctant to trust

slide-14
SLIDE 14

Principles for security design 10

Use your community

resources

“Many-eyeballs

phenomenon”;

Not a panacea

slide-15
SLIDE 15

Verification Architectural Analysis

Information gathering

Understand the requirements of a system Attempts to understand the proposed architecture at a high

level

Have a number of questions about the system and the

  • environment. Answer the questions.

Analysis

Attack trees

Reporting

Ranking, order Easy to understand

slide-16
SLIDE 16

Implementation Security Analysis

Auditing source code

Implementation should meet the design Look for implementation specific vulnerabilities.

(e.g., buffer overflow, race conditions, SQL injections)

Source-level security auditing tools

RATS, Flawfinder, Findbugs, etc

slide-17
SLIDE 17

What’s wrong?

  • #include "string"
  • int main()
  • {
  • int is_successful = 0;

//flag

  • char passwd[4];
  • while(is_successful == 0)
  • {
  • printf("Please input your password:\n");
  • scanf("%s", passwd);
  • if (strcmp(passwd,"007") == 0)
  • is_successful = 1;
  • }
  • printf("You are James Bond, now!\n");
  • }
slide-18
SLIDE 18

Buffer overflow

slide-19
SLIDE 19

Buffer overflow

slide-20
SLIDE 20

Buffer

What is buffer

  • Chunks of the same data type are allocated, the

memory region is called buffer

  • In the stack
  • Non-static local variables: int array[4];
  • In the heap
  • Malloc, new: int *pArray = new int[4];

What is buffer overflow

  • When a program writes past the boundary of a

buffer.

slide-21
SLIDE 21

Process memory organization

A process in memory:

  • code (Program code; marked read-only, so any attempts to

write to it will result in segmentation fault)

  • data segment (Global and static variables)
  • stack, heap (Dynamic variables)
slide-22
SLIDE 22

Process memory organization

slide-23
SLIDE 23

More about the stack

Stack frames Example:

foo(){ } bar(){ foo(); } main(){ bar(); }

slide-24
SLIDE 24

More about the stack

What a stack frame should hold for a

subroutine?

Parameters to the function The return address The old frame pointer Local variables

slide-25
SLIDE 25

How stack is used

slide-26
SLIDE 26

Buffer Overflows

void function(char *str) { char buffer[8]; strcpy(buffer,str); } void main() { char large_string[256]; int i; for( i = 0; i < 255; i++) large_string[i] = 'A'; function(large_string); }

slide-27
SLIDE 27

Buffer Overflows

slide-28
SLIDE 28

Buffer Overflows

slide-29
SLIDE 29

Buffer Overflows

slide-30
SLIDE 30

Buffer Overflows

slide-31
SLIDE 31

Buffer Overflows

slide-32
SLIDE 32

Buffer Overflows

slide-33
SLIDE 33

Buffer Overflows

slide-34
SLIDE 34

Buffer Overflows

slide-35
SLIDE 35

A short discussion

Which consequences can be result in?

slide-36
SLIDE 36

Prevention

Avoid the usage of suspect functions

strcpy(), sprintf(), fscan(), gets()

Do bound checking yourself (input verification) Choose a language which is more immune

(e.g., Java)

slide-37
SLIDE 37

A short discussion

Is strncpy() more secure? Is the following code secure?

char dest[4]; char source[]=”Hello!”; strncpy(dest, source, sizeof(dest));

slide-38
SLIDE 38

Review

What is software security? Why software security is so challenge? 10 principles of secure design Buffer overflow

No bound checking In stack or in heap Why it is a serious problem? Overwritten data Consequence of buffer overflow Counteracts

slide-39
SLIDE 39

SQL injection

slide-40
SLIDE 40

Web application processing

1.

Take user input from a web form and pass it to a server-side script via HTTP methods such as POST or GET.

2.

Process request, open connection to database.

3.

Query database and retrieve results.

4.

Send processed results back to user.

slide-41
SLIDE 41

Example

$name = $HTTP_POST_VARS["name"]; $passwd = $HTTP_POST_VARS[“passwd"]; $query = “select name from users where name = ‘”.$name.”’ and passwd = ‘”.$passwd.”’” ; $result = mysql_query($query);

slide-42
SLIDE 42

What is SQL Injection?

slide-43
SLIDE 43

Further?

Delete:

Select users from table where name = ‘whatever’; DROP TABLE users; -

Another way to bypass Authentication

select * from users where

username=‘admin’;--’ and password=‘whocares’;

slide-44
SLIDE 44

Prevention? A short discussion

Firewall? System patch?

slide-45
SLIDE 45

Prevention

Check and filter user input.

Length limit on input (most attacks depend on long query

strings).

Different types of inputs have a specific language and

syntax associated with them, i.e. Name, email, etc

Do not allow suspicious keywords (DROP, INSERT,

SELECT, SHUTDOWN) as name for example.

“Warning: illegal use of this application

has been detected. You IP address has been recorded…”

slide-46
SLIDE 46

Race Condition

slide-47
SLIDE 47

Discussion

Public class Counter extends HttpServlet{

int count =0; public void doGet(HttpServletRequest in, HttpServletResponse out) throws ServeletException, IOException{

  • ut.setContentType(“text/plain”);

Printwriter p = out.getWriter(); count++; p.println(count+”hits so far!”); } }

slide-48
SLIDE 48

Race Conditions

A race condition occurs if

an assumption needs to hold true for a period of time, but actually may not.

Possible problem areas

  • Multi threaded

programming

  • File and database access

“Window of vulnerability”

  • The time interval in which

assumption can be invalidated

slide-49
SLIDE 49

Window of Vulnerability

Action 1 Action 2

Time Interval

Time

slide-50
SLIDE 50

Improved?

Public class Counter extends HttpServlet{

int count =0; public synchronized void doGet(HttpServletRequest in, HttpServletResponse out) throws ServeletException, IOException{

  • ut.setContentType(“text/plain”);

Printwriter p = out.getWriter(); count++; p.println(count+”hits so far!”); } }

slide-51
SLIDE 51

Race Conditions

TOCTTOU (Time of check to time of

use) flaws

Time window of vulnerability Check action Use action Variable

slide-52
SLIDE 52

What is “TOCTTOU Flaw”?

Semantic Characteristic Occurs when two events occur and the

second depends upon the first one

Time Interval where attacker can race in and invalidate the assumption that syscall 2 depends upon

Time Syscall 1 (Time Of Check) Syscall 2 (Time Of Use)

slide-53
SLIDE 53

File System TOCTTOU: Name-Object Binding Flaws

  • Symbolic Link Races (Temporary File Race)

if ((fd = open (pathname, O_WRONLY))<0) if(error == ENOENT) { if ((fd = creat(pathname, mode))<0) err_sys(“creat error”); }

slide-54
SLIDE 54

File System TOCTTOU: Name-Object Binding Flaws

UNIX system provides two different forms of naming, with

different semantics

File path name File descriptor The difference comes from the way the addresses resolve to

the actual objects

File path names are resolved by indirection, requiring the

naming and addressing at least one intermediate object

  • ther than the actual file object being addressed (indirect

pointer to object)

File descriptors are resolved by accessing the file being

addressed (direct pointer to object)

Indirect -> Opens up window of vulnerability

slide-55
SLIDE 55

PRNG

slide-56
SLIDE 56

slide 56

How Random is “Random?”

slide-57
SLIDE 57

Random number used in security

Usage

Almost all network security protocols rely on the

randomness of certain parameters

Nonce - used to avoid replay session key

A random number should be unpredictable Measure random numbers: entropy

slide-58
SLIDE 58

Requirements

Utopia True random generators High cost Reality Pseudo random number generators Sequence appears random

“Any one who consider arithmetical methods of producing random digits is, of course, in a state of sin.” John von Neumann [1951]

slide-59
SLIDE 59

PRNG

Computers are completely deterministic machines.

Therefore computers cannot be good at creating true random number.

Pseudo-random number generator (PRNG) Requires inputs, called seed. Requirements

Statistical tests: Uniform distribution (e.g., number of ‘0’

equals number of ‘1’)

Non predictable Fast computing Low memory consumption

slide-60
SLIDE 60

Numeric Generators

Linear Congruential Generator (LCG)

Xn+1 = (Xn * a + b) mod c Xn – current number [x0 – seed] Xn+1 – next number a, b, c are usually prime numbers

[ Lehmer, 1949 ]

slide-61
SLIDE 61

An example for bad seeds

slide-62
SLIDE 62

How to select a good seed?

Hardware solution

Radioactive decay Digital camera + Lava lamp

Interaction

Key sticking and mouse moving

slide-63
SLIDE 63

Auditing software

slide-64
SLIDE 64

Implementation Security Analysis

Auditing source code

Implementation should meet the design Look for implementation specific vulnerabilities.

(e.g., buffer overflow, race conditions, SQL injections)

Source-level security auditing tools

RATS, Flawfinder, Findbugs, etc