Software Security Information Security Prof Hans Georg Schaathun - - PowerPoint PPT Presentation

software security
SMART_READER_LITE
LIVE PREVIEW

Software Security Information Security Prof Hans Georg Schaathun - - PowerPoint PPT Presentation

Software Security Information Security Prof Hans Georg Schaathun University of Surrey/lesund University College Autumn 2011 Week 12 Prof Hans Georg Schaathun Software Security Autumn 2011 Week 12 1 / 1 The session Outline Prof


slide-1
SLIDE 1

Software Security

Information Security Prof Hans Georg Schaathun

University of Surrey/Ålesund University College

Autumn 2011 – Week 12

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 1 / 1

slide-2
SLIDE 2

The session

Outline

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 2 / 1

slide-3
SLIDE 3

The session

Session objectives

Be familiar with the most common implementation errors leading to security vulnerabilities Start developing a good methodology for secure design and implementation 2010 CWE/SANS Top 25 Most Dangerous Software Errors Robert Seacord: Secure Coding in C and C++

https://www.securecoding.cert.org/confluence/ display/seccode/Top+10+Secure+Coding+Practices

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 3 / 1

slide-4
SLIDE 4

The session

Security or Useability

This chapter is largely about software bugs

Is this security? . . . or is it useability?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 4 / 1

slide-5
SLIDE 5

The session

Security or Useability

This chapter is largely about software bugs

Is this security? . . . or is it useability?

Answer is yes

Bugs are user (programmer) mistakes – useability. Many bugs cause security vulnerabilities.

Useability is a prerequisite of security.

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 4 / 1

slide-6
SLIDE 6

The session

Security or Useability

This chapter is largely about software bugs

Is this security? . . . or is it useability?

Answer is yes

Bugs are user (programmer) mistakes – useability. Many bugs cause security vulnerabilities.

Useability is a prerequisite of security.

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 4 / 1

slide-7
SLIDE 7

Top Vulnerabilities

Outline

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 5 / 1

slide-8
SLIDE 8

Top Vulnerabilities

Common Weakness Enumeration

2010 CWE/SANS Top 25 Most Dangerous Software Errors

http://cwe.mitre.org/top25/index.html

A very few key vulnerabilities behind most incidents Massive benefit from controlling the top few

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 6 / 1

slide-9
SLIDE 9

Top Vulnerabilities

Top 9

1

Improper neutralisation of input during web page generation (Cross-Site Scripting)

2

Improper neutralisation of Special Elements in SQL Commands (SQL Injection)

3

Buffer overflow without Checking of Input Size

4

Cross-Site Request Forgery

5

Improper Access Control (Authorisation)

6

Reliance on Untrusted Inputs in a Security Decision

7

Improper Limitation of a Pathname to a Restricted Directory (Path Traversal)

8

Unrestricted Upload of File with Dangerous Type

9

Improper neutralisation of Special Elements used in an OS Command

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 7 / 1

slide-10
SLIDE 10

Top Vulnerabilities

Top 9

1

Improper neutralisation of input during web page generation (Cross-Site Scripting)

2

Improper neutralisation of Special Elements in SQL Commands (SQL Injection)

3

Buffer overflow without Checking of Input Size

4

Cross-Site Request Forgery

5

Improper Access Control (Authorisation)

6

Reliance on Untrusted Inputs in a Security Decision

7

Improper Limitation of a Pathname to a Restricted Directory (Path Traversal)

8

Unrestricted Upload of File with Dangerous Type

9

Improper neutralisation of Special Elements used in an OS Command

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 7 / 1

slide-11
SLIDE 11

Top Vulnerabilities

Trusting Input

Most of the top vulnerabilities relate to user input ... Cross-Site Scripting SQL Injection Reliance on Untrusted Input File upload Path traversal Special elements in OS commands Integrity of Code and Data ...

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 8 / 1

slide-12
SLIDE 12

Top Vulnerabilities

Trusting Input

Most of the top vulnerabilities relate to user input ... Cross-Site Scripting SQL Injection Reliance on Untrusted Input File upload Path traversal Special elements in OS commands Integrity of Code and Data ...

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 8 / 1

slide-13
SLIDE 13

Input Checking

Outline

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 9 / 1

slide-14
SLIDE 14

Input Checking

Top 9

1

Improper neutralisation of input during web page generation (Cross-Site Scripting)

2

Improper neutralisation of Special Elements in SQL Commands (SQL Injection)

3

Buffer overflow without Checking of Input Size

4

Cross-Site Request Forgery

5

Improper Access Control (Authorisation)

6

Reliance on Untrusted Inputs in a Security Decision

7

Improper Limitation of a Pathname to a Restricted Directory (Path Traversal)

8

Unrestricted Upload of File with Dangerous Type

9

Improper neutralisation of Special Elements used in an OS Command

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 10 / 1

slide-15
SLIDE 15

Input Checking

Input Checking

4 out of 9 vulnerabilities

very similar instances of input checking

E.G. SQL injection

SELECT * FROM users WHERE name=’John’ ;

Now, say the user enters a name, instead of using ’John’

SELECT * FROM users WHERE name=’$n’ ;

What if the user enters

Mary’ ; DROP TABLE users ; ... ’

What happens?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 11 / 1

slide-16
SLIDE 16

Input Checking

Input Checking

4 out of 9 vulnerabilities

very similar instances of input checking

E.G. SQL injection

SELECT * FROM users WHERE name=’John’ ;

Now, say the user enters a name, instead of using ’John’

SELECT * FROM users WHERE name=’$n’ ;

What if the user enters

Mary’ ; DROP TABLE users ; ... ’

What happens?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 11 / 1

slide-17
SLIDE 17

Input Checking

Input Checking

4 out of 9 vulnerabilities

very similar instances of input checking

E.G. SQL injection

SELECT * FROM users WHERE name=’John’ ;

Now, say the user enters a name, instead of using ’John’

SELECT * FROM users WHERE name=’$n’ ;

What if the user enters

Mary’ ; DROP TABLE users ; ... ’

What happens?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 11 / 1

slide-18
SLIDE 18

Input Checking

Input Checking

4 out of 9 vulnerabilities

very similar instances of input checking

E.G. SQL injection

SELECT * FROM users WHERE name=’John’ ;

Now, say the user enters a name, instead of using ’John’

SELECT * FROM users WHERE name=’$n’ ;

What if the user enters

Mary’ ; DROP TABLE users ; ... ’

What happens?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 11 / 1

slide-19
SLIDE 19

Input Checking

Input Checking

4 out of 9 vulnerabilities

very similar instances of input checking

E.G. SQL injection

SELECT * FROM users WHERE name=’John’ ;

Now, say the user enters a name, instead of using ’John’

SELECT * FROM users WHERE name=’$n’ ;

What if the user enters

Mary’ ; DROP TABLE users ; ... ’

What happens?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 11 / 1

slide-20
SLIDE 20

Input Checking

Input Checking

4 out of 9 vulnerabilities

very similar instances of input checking

E.G. SQL injection

SELECT * FROM users WHERE name=’John’ ;

Now, say the user enters a name, instead of using ’John’

SELECT * FROM users WHERE name=’$n’ ;

What if the user enters

Mary’ ; DROP TABLE users ; ... ’

What happens?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 11 / 1

slide-21
SLIDE 21

Input Checking

What may happen

SELECT * FROM users WHERE name=’Mary’ ; DROP TABLE users ; ... ’’ We select user Mary, and then drop the table

Successful availability attack — the table is destroyed

The string delimiter (’) in the input

allows the user to terminate the string (which was expected) and add another command (which was not expected)

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 12 / 1

slide-22
SLIDE 22

Input Checking

What may happen

SELECT * FROM users WHERE name=’Mary’ ; DROP TABLE users ; ... ’’ We select user Mary, and then drop the table

Successful availability attack — the table is destroyed

The string delimiter (’) in the input

allows the user to terminate the string (which was expected) and add another command (which was not expected)

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 12 / 1

slide-23
SLIDE 23

Input Checking

What should happen

SELECT * FROM users WHERE name=’Mary’’ ; DROP TABLE users ; ... ’’ The special character is escaped

and treated as part of the string

The offending Command is now part of the name

and not harmful

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 13 / 1

slide-24
SLIDE 24

Input Checking

What should happen

SELECT * FROM users WHERE name=’Mary’’ ; DROP TABLE users ; ... ’’ The special character is escaped

and treated as part of the string

The offending Command is now part of the name

and not harmful

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 13 / 1

slide-25
SLIDE 25

Input Checking

What should happen

SELECT * FROM users WHERE name=’Mary’’ ; DROP TABLE users ; ... ’’ The special character is escaped

and treated as part of the string

The offending Command is now part of the name

and not harmful

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 13 / 1

slide-26
SLIDE 26

Input Checking

Cross-Site Scripting

http://www.phpnuke.org/user.php?op=userinfo&uname= <script>alert(document.cookie);</script> Malicious code passed as an HTTP GET argument Principle as before No input checking in the web page

causes execution of code from the user

No limit to what this can achieve Other web pages (other sites)

can hide code actually loading the URL no user interaction at all

Source: http://www.cgisecurity.com/xss-faq.html

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 14 / 1

slide-27
SLIDE 27

Input Checking

Cross-Site Scripting

http://www.phpnuke.org/user.php?op=userinfo&uname= <script>alert(document.cookie);</script> Malicious code passed as an HTTP GET argument Principle as before No input checking in the web page

causes execution of code from the user

No limit to what this can achieve Other web pages (other sites)

can hide code actually loading the URL no user interaction at all

Source: http://www.cgisecurity.com/xss-faq.html

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 14 / 1

slide-28
SLIDE 28

Input Checking

Cross-Site Scripting

http://www.phpnuke.org/user.php?op=userinfo&uname= <script>alert(document.cookie);</script> Malicious code passed as an HTTP GET argument Principle as before No input checking in the web page

causes execution of code from the user

No limit to what this can achieve Other web pages (other sites)

can hide code actually loading the URL no user interaction at all

Source: http://www.cgisecurity.com/xss-faq.html

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 14 / 1

slide-29
SLIDE 29

Input Checking

Cross-Site Scripting

http://www.phpnuke.org/user.php?op=userinfo&uname= <script>alert(document.cookie);</script> Malicious code passed as an HTTP GET argument Principle as before No input checking in the web page

causes execution of code from the user

No limit to what this can achieve Other web pages (other sites)

can hide code actually loading the URL no user interaction at all

Source: http://www.cgisecurity.com/xss-faq.html

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 14 / 1

slide-30
SLIDE 30

Input Checking

Cross-Site Scripting

http://www.phpnuke.org/user.php?op=userinfo&uname= <script>alert(document.cookie);</script> Malicious code passed as an HTTP GET argument Principle as before No input checking in the web page

causes execution of code from the user

No limit to what this can achieve Other web pages (other sites)

can hide code actually loading the URL no user interaction at all

Source: http://www.cgisecurity.com/xss-faq.html

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 14 / 1

slide-31
SLIDE 31

Input Checking

Cross-Site Scripting

http://www.phpnuke.org/user.php?op=userinfo&uname= <script>alert(document.cookie);</script> Malicious code passed as an HTTP GET argument Principle as before No input checking in the web page

causes execution of code from the user

No limit to what this can achieve Other web pages (other sites)

can hide code actually loading the URL no user interaction at all

Source: http://www.cgisecurity.com/xss-faq.html

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 14 / 1

slide-32
SLIDE 32

Input Checking

Cross-Site Scripting

http://www.phpnuke.org/user.php?op=userinfo&uname= <script>alert(document.cookie);</script> Malicious code passed as an HTTP GET argument Principle as before No input checking in the web page

causes execution of code from the user

No limit to what this can achieve Other web pages (other sites)

can hide code actually loading the URL no user interaction at all

Source: http://www.cgisecurity.com/xss-faq.html

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 14 / 1

slide-33
SLIDE 33

Input Checking

Path traversal

Say you allow uploading and downloading of files.

the user specifies the filename a directory is hardcoded and prepended

so the user enters foobar.jpeg

it becomes /opt/archive/foobar.jpeg safe enough

What if the user enters ../../etc/passwd?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 15 / 1

slide-34
SLIDE 34

Input Checking

Path traversal

Say you allow uploading and downloading of files.

the user specifies the filename a directory is hardcoded and prepended

so the user enters foobar.jpeg

it becomes /opt/archive/foobar.jpeg safe enough

What if the user enters ../../etc/passwd?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 15 / 1

slide-35
SLIDE 35

Input Checking

Path traversal

Say you allow uploading and downloading of files.

the user specifies the filename a directory is hardcoded and prepended

so the user enters foobar.jpeg

it becomes /opt/archive/foobar.jpeg safe enough

What if the user enters ../../etc/passwd?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 15 / 1

slide-36
SLIDE 36

Input Checking

Path traversal

Say you allow uploading and downloading of files.

the user specifies the filename a directory is hardcoded and prepended

so the user enters foobar.jpeg

it becomes /opt/archive/foobar.jpeg safe enough

What if the user enters ../../etc/passwd?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 15 / 1

slide-37
SLIDE 37

Input Checking

Dangerous Filenames

Some systems deduce file type from filename

e.g. *.jpg for JFIF/EXIF images e.g. *.php for PHP scripts

Dangerous: the filename is under user control Allows user to mark data as code and vice versa E.g. uploaded files on a web server

do you allow the users to upload PHP scripts? might your server execute them?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 16 / 1

slide-38
SLIDE 38

Input Checking

Dangerous Filenames

Some systems deduce file type from filename

e.g. *.jpg for JFIF/EXIF images e.g. *.php for PHP scripts

Dangerous: the filename is under user control Allows user to mark data as code and vice versa E.g. uploaded files on a web server

do you allow the users to upload PHP scripts? might your server execute them?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 16 / 1

slide-39
SLIDE 39

Input Checking

Dangerous Filenames

Some systems deduce file type from filename

e.g. *.jpg for JFIF/EXIF images e.g. *.php for PHP scripts

Dangerous: the filename is under user control Allows user to mark data as code and vice versa E.g. uploaded files on a web server

do you allow the users to upload PHP scripts? might your server execute them?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 16 / 1

slide-40
SLIDE 40

Input Checking

Dangerous Filenames

Some systems deduce file type from filename

e.g. *.jpg for JFIF/EXIF images e.g. *.php for PHP scripts

Dangerous: the filename is under user control Allows user to mark data as code and vice versa E.g. uploaded files on a web server

do you allow the users to upload PHP scripts? might your server execute them?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 16 / 1

slide-41
SLIDE 41

Input Checking

Passing information to external programs

Improper neutralisation of Special Elements used in an OS Command Calling external programs is high risk

library calls is lower risk Why is this?

library calls provide type checking

external programs take arguments as strings ... control codes and data are mixed

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 17 / 1

slide-42
SLIDE 42

Input Checking

Passing information to external programs

Improper neutralisation of Special Elements used in an OS Command Calling external programs is high risk

library calls is lower risk Why is this?

library calls provide type checking

external programs take arguments as strings ... control codes and data are mixed

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 17 / 1

slide-43
SLIDE 43

Input Checking

The rlogin bug

rlogin(1) used to allow remote login access to Unix systems

rlogin [-luser] hostname

The rlogin client contacts a remote host which runs login(1)

Running rlogin -l css1hs kyle, would . . . on kyle, cause the running of login css1hs.

Now, login(1) has many uses,

login -froot is a forced login (as root) ... no password prompt

rlogin -l -froot kyle – what happens?

login -froot – superuser login without password Unused functionality is exploited. ... unless rlogin sanitises the input

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 18 / 1

slide-44
SLIDE 44

Input Checking

The rlogin bug

rlogin(1) used to allow remote login access to Unix systems

rlogin [-luser] hostname

The rlogin client contacts a remote host which runs login(1)

Running rlogin -l css1hs kyle, would . . . on kyle, cause the running of login css1hs.

Now, login(1) has many uses,

login -froot is a forced login (as root) ... no password prompt

rlogin -l -froot kyle – what happens?

login -froot – superuser login without password Unused functionality is exploited. ... unless rlogin sanitises the input

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 18 / 1

slide-45
SLIDE 45

Input Checking

The rlogin bug

rlogin(1) used to allow remote login access to Unix systems

rlogin [-luser] hostname

The rlogin client contacts a remote host which runs login(1)

Running rlogin -l css1hs kyle, would . . . on kyle, cause the running of login css1hs.

Now, login(1) has many uses,

login -froot is a forced login (as root) ... no password prompt

rlogin -l -froot kyle – what happens?

login -froot – superuser login without password Unused functionality is exploited. ... unless rlogin sanitises the input

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 18 / 1

slide-46
SLIDE 46

Input Checking

What to do?

Two methods (principles):

1

Input checking: reject unexpected input

2

Sanitising: accept the input, make sure it is handled correctly (escaping)

Which is easiest? Which is best? Restrictive Input Checking

err on the side of caution relatively simple — accept a small set of safe inputs availability risk (reject good input) good incidence response allow quick bug fixes

Sanitising requires comprehensive understanding

how to sanitise what is the effect of each possible input? the SQL example cannot be solved by input checking

O’Brian is a valid name ...

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 19 / 1

slide-47
SLIDE 47

Input Checking

What to do?

Two methods (principles):

1

Input checking: reject unexpected input

2

Sanitising: accept the input, make sure it is handled correctly (escaping)

Which is easiest? Which is best? Restrictive Input Checking

err on the side of caution relatively simple — accept a small set of safe inputs availability risk (reject good input) good incidence response allow quick bug fixes

Sanitising requires comprehensive understanding

how to sanitise what is the effect of each possible input? the SQL example cannot be solved by input checking

O’Brian is a valid name ...

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 19 / 1

slide-48
SLIDE 48

Input Checking

What to do?

Two methods (principles):

1

Input checking: reject unexpected input

2

Sanitising: accept the input, make sure it is handled correctly (escaping)

Which is easiest? Which is best? Restrictive Input Checking

err on the side of caution relatively simple — accept a small set of safe inputs availability risk (reject good input) good incidence response allow quick bug fixes

Sanitising requires comprehensive understanding

how to sanitise what is the effect of each possible input? the SQL example cannot be solved by input checking

O’Brian is a valid name ...

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 19 / 1

slide-49
SLIDE 49

Input Checking

Good practice

1

Take a critical view of all input

Don’t trust anyone

2

Have a firm understanding of what the input should look like

don’t accept odd input

3

Be aware of any special characters where the data is used

be wary of quotation marks (’/"), backslashes, control characters etc. special scenarios like slashes in filenames

4

Don’t use user input if you do not have to

e.g. filenames can be generated by the system

5

Spend some time on every instance of user input

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 20 / 1

slide-50
SLIDE 50

Other Issues

Outline

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 21 / 1

slide-51
SLIDE 51

Other Issues Management Information

Decision Making

Reliance on Untrusted Inputs in a Security Decision. Decision Making depends on Information Where does this information come from? What CObIT Criteria are essential for this information?

Integrity Reliability of Management Information

Can your adversaries have forged information? Are your decissions steered by your enemy?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 22 / 1

slide-52
SLIDE 52

Other Issues Management Information

Decision Making

Reliance on Untrusted Inputs in a Security Decision. Decision Making depends on Information Where does this information come from? What CObIT Criteria are essential for this information?

Integrity Reliability of Management Information

Can your adversaries have forged information? Are your decissions steered by your enemy?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 22 / 1

slide-53
SLIDE 53

Other Issues Management Information

Decision Making

Reliance on Untrusted Inputs in a Security Decision. Decision Making depends on Information Where does this information come from? What CObIT Criteria are essential for this information?

Integrity Reliability of Management Information

Can your adversaries have forged information? Are your decissions steered by your enemy?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 22 / 1

slide-54
SLIDE 54

Other Issues Management Information

Decision Making

Reliance on Untrusted Inputs in a Security Decision. Decision Making depends on Information Where does this information come from? What CObIT Criteria are essential for this information?

Integrity Reliability of Management Information

Can your adversaries have forged information? Are your decissions steered by your enemy?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 22 / 1

slide-55
SLIDE 55

Other Issues Management Information

Decision Making

Reliance on Untrusted Inputs in a Security Decision. Decision Making depends on Information Where does this information come from? What CObIT Criteria are essential for this information?

Integrity Reliability of Management Information

Can your adversaries have forged information? Are your decissions steered by your enemy?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 22 / 1

slide-56
SLIDE 56

Other Issues Management Information

Decision Making

Reliance on Untrusted Inputs in a Security Decision. Decision Making depends on Information Where does this information come from? What CObIT Criteria are essential for this information?

Integrity Reliability of Management Information

Can your adversaries have forged information? Are your decissions steered by your enemy?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 22 / 1

slide-57
SLIDE 57

Other Issues Management Information

Decision Making

Reliance on Untrusted Inputs in a Security Decision. Decision Making depends on Information Where does this information come from? What CObIT Criteria are essential for this information?

Integrity Reliability of Management Information

Can your adversaries have forged information? Are your decissions steered by your enemy?

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 22 / 1

slide-58
SLIDE 58

Other Issues Management Information

Untrusted Inputs in a Security Decision

What controls can you use against this?

Technical

Unlikely – Intelligent Input needed to choose trusted sources

Operational

Yes – good operational information gathering

Managerial

Yes – choose trust policy

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 23 / 1

slide-59
SLIDE 59

Other Issues Management Information

Untrusted Inputs in a Security Decision

What controls can you use against this?

Technical

Unlikely – Intelligent Input needed to choose trusted sources

Operational

Yes – good operational information gathering

Managerial

Yes – choose trust policy

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 23 / 1

slide-60
SLIDE 60

Other Issues Management Information

Untrusted Inputs in a Security Decision

What controls can you use against this?

Technical

Unlikely – Intelligent Input needed to choose trusted sources

Operational

Yes – good operational information gathering

Managerial

Yes – choose trust policy

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 23 / 1

slide-61
SLIDE 61

Other Issues Management Information

Untrusted Inputs in a Security Decision

What controls can you use against this?

Technical

Unlikely – Intelligent Input needed to choose trusted sources

Operational

Yes – good operational information gathering

Managerial

Yes – choose trust policy

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 23 / 1

slide-62
SLIDE 62

Other Issues Management Information

Quick Summary

Decissions are based on Information ensure reliability and integrity of this information

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 24 / 1

slide-63
SLIDE 63

Other Issues The last three of the nine

Top 9

1

Improper neutralisation of input during web page generation (Cross-Site Scripting)

2

Improper neutralisation of Special Elements in SQL Commands (SQL Injection)

3

Buffer overflow without Checking of Input Size

4

Cross-Site Request Forgery

5

Improper Access Control (Authorisation)

6

Reliance on Untrusted Inputs in a Security Decision

7

Improper Limitation of a Pathname to a Restricted Directory (Path Traversal)

8

Unrestricted Upload of File with Dangerous Type

9

Improper neutralisation of Special Elements used in an OS Command

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 25 / 1

slide-64
SLIDE 64

Other Issues The last three of the nine

Buffer Overflows

Classic problem Limited memory buffer

writing unlimited data objects – often user input system does not check the buffer limits

Clever attackers can

  • verwrite executable code

inserting custom code to be executed

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 26 / 1

slide-65
SLIDE 65

Other Issues The last three of the nine

Buffer Overflows

Classic problem Limited memory buffer

writing unlimited data objects – often user input system does not check the buffer limits

Clever attackers can

  • verwrite executable code

inserting custom code to be executed

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 26 / 1

slide-66
SLIDE 66

Other Issues The last three of the nine

Why is this code insecure?

bool IsPasswordOkay ( void ) { char Password [12] ; gets ( Password ) ; i f ( ! strcmp ( Password , " goodpass " ) ) return true ; else return ( false ) ; } void main ( void ) { bool PwStatus ; puts ( " Enter password : " ) ; PwStatus = IsPasswordOkay ( ) ; i f ( PwStatus == false ) { puts ( " Access denied " ) ; e x i t (−1) ; } else puts ( " Access granted " ) ; }

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 27 / 1

slide-67
SLIDE 67

Other Issues The last three of the nine

Cross-Site Request Forgery (CSRF)

like the stranger in the airport, asking you to take just this parcel along on the flight ... Web vulnerability

trick a user’s client to make your request request made with his credentials

Integrity problem

Attackers can forge requests

The attacker can gain all the priviliges of the user

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 28 / 1

slide-68
SLIDE 68

Other Issues The last three of the nine

Cross-Site Request Forgery (CSRF)

like the stranger in the airport, asking you to take just this parcel along on the flight ... Web vulnerability

trick a user’s client to make your request request made with his credentials

Integrity problem

Attackers can forge requests

The attacker can gain all the priviliges of the user

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 28 / 1

slide-69
SLIDE 69

Other Issues The last three of the nine

Cross-Site Request Forgery (CSRF)

like the stranger in the airport, asking you to take just this parcel along on the flight ... Web vulnerability

trick a user’s client to make your request request made with his credentials

Integrity problem

Attackers can forge requests

The attacker can gain all the priviliges of the user

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 28 / 1

slide-70
SLIDE 70

Other Issues The last three of the nine

Improper Access Control

Fairly obvious – restrict access to authorised users But, get the roles right

should match business roles

The exercise for next week explores management of

access privileges identity

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 29 / 1

slide-71
SLIDE 71

Other Issues The last three of the nine

Improper Access Control

Fairly obvious – restrict access to authorised users But, get the roles right

should match business roles

The exercise for next week explores management of

access privileges identity

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 29 / 1

slide-72
SLIDE 72

Other Issues The last three of the nine

Improper Access Control

Fairly obvious – restrict access to authorised users But, get the roles right

should match business roles

The exercise for next week explores management of

access privileges identity

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 29 / 1

slide-73
SLIDE 73

Coding Practices

Outline

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 30 / 1

slide-74
SLIDE 74

Coding Practices

Seacord’s 10 Principles

Validate input Heed compiler warnings Architect and design for security policies. Keep it simple. Default deny. Adhere to the principle of least privilege. Sanitize data sent to other systems. Practice defense in depth. Use effective quality assurance techniques. Adopt a secure coding standard.

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 31 / 1

slide-75
SLIDE 75

Coding Practices Default Deny

Default Deny

  • r principle of least privilege

Default Deny is a General Principle with many Applications

Access Control Input Validation Feature Selection

Advantage: prevents unnecessary integrity/confidentiality risks

accepting risks only when necessary

Disadvantage: availability risk

Mitigation by incident respons → bug fix

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 32 / 1

slide-76
SLIDE 76

Coding Practices Default Deny

Default Deny

  • r principle of least privilege

Default Deny is a General Principle with many Applications

Access Control Input Validation Feature Selection

Advantage: prevents unnecessary integrity/confidentiality risks

accepting risks only when necessary

Disadvantage: availability risk

Mitigation by incident respons → bug fix

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 32 / 1

slide-77
SLIDE 77

Coding Practices Default Deny

Default Deny

  • r principle of least privilege

Default Deny is a General Principle with many Applications

Access Control Input Validation Feature Selection

Advantage: prevents unnecessary integrity/confidentiality risks

accepting risks only when necessary

Disadvantage: availability risk

Mitigation by incident respons → bug fix

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 32 / 1

slide-78
SLIDE 78

Coding Practices Default Deny

Default Deny

  • r principle of least privilege

Default Deny is a General Principle with many Applications

Access Control Input Validation Feature Selection

Advantage: prevents unnecessary integrity/confidentiality risks

accepting risks only when necessary

Disadvantage: availability risk

Mitigation by incident respons → bug fix

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 32 / 1

slide-79
SLIDE 79

Coding Practices Default Deny

Input Checking

Default deny

Defining harmful inputs is hard Defining correct input is easier Default deny will reject the input when in doubt Note that the SQL example,

the input is both valid and harmful that’s why you need sanitisation as well

You can overdo it

many webpages validate email addresses and reject the plus sign (+)

The plus sign is valid according to the RFC

and has a very important function in non-MS mail servers

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 33 / 1

slide-80
SLIDE 80

Coding Practices Default Deny

Input Checking

Default deny

Defining harmful inputs is hard Defining correct input is easier Default deny will reject the input when in doubt Note that the SQL example,

the input is both valid and harmful that’s why you need sanitisation as well

You can overdo it

many webpages validate email addresses and reject the plus sign (+)

The plus sign is valid according to the RFC

and has a very important function in non-MS mail servers

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 33 / 1

slide-81
SLIDE 81

Coding Practices Default Deny

Input Checking

Default deny

Defining harmful inputs is hard Defining correct input is easier Default deny will reject the input when in doubt Note that the SQL example,

the input is both valid and harmful that’s why you need sanitisation as well

You can overdo it

many webpages validate email addresses and reject the plus sign (+)

The plus sign is valid according to the RFC

and has a very important function in non-MS mail servers

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 33 / 1

slide-82
SLIDE 82

Coding Practices Default Deny

Input Checking

Default deny

Defining harmful inputs is hard Defining correct input is easier Default deny will reject the input when in doubt Note that the SQL example,

the input is both valid and harmful that’s why you need sanitisation as well

You can overdo it

many webpages validate email addresses and reject the plus sign (+)

The plus sign is valid according to the RFC

and has a very important function in non-MS mail servers

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 33 / 1

slide-83
SLIDE 83

Coding Practices Default Deny

Example: path names

Default deny in input validation

Suppose you write an application, where users upload files

The user can specify a filename, e.g. holiday.jpg, ... and you prepend a directory name, e.g. /public/images/

How can this be exploited? Suppose the users use filename /../../etc/passwd. How do we avoid this? Input checking is possible;

../ is an illegal substring.

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 34 / 1

slide-84
SLIDE 84

Coding Practices Default Deny

Example: path names

Default deny in input validation

Suppose you write an application, where users upload files

The user can specify a filename, e.g. holiday.jpg, ... and you prepend a directory name, e.g. /public/images/

How can this be exploited? Suppose the users use filename /../../etc/passwd. How do we avoid this? Input checking is possible;

../ is an illegal substring.

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 34 / 1

slide-85
SLIDE 85

Coding Practices Default Deny

Example: path names

Default deny in input validation

Suppose you write an application, where users upload files

The user can specify a filename, e.g. holiday.jpg, ... and you prepend a directory name, e.g. /public/images/

How can this be exploited? Suppose the users use filename /../../etc/passwd. How do we avoid this? Input checking is possible;

../ is an illegal substring.

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 34 / 1

slide-86
SLIDE 86

Coding Practices Default Deny

Character Encoding

Vulnerabilities in Unicode

Unicode collects characters for (almost) every language UTF-8 is the most common encoding of Unicode Variable length characters

ASCII (American 7-bit character set) uses one byte

Ensuring compatibility.

Western European (non-ASCII) characters use two bytes More exotic characters require 3 or 4 bytes

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 35 / 1

slide-87
SLIDE 87

Coding Practices Default Deny

Unicode encoding

Each byte has a prefix

0 – one-byte character 110 – first byte of two-byte character 1110 – first byte of three-byte character 11110 – first byte of four-byte character 10 – second or later byte of multi-byte character

Remaining bits contain a unicode character number

1 byte : 7 bits 2 bytes : 11 bits (5+6) 3 bytes : 16 bits (4+6+6) 4 bytes : 21 bits (3+6+6+6)

Only shortest possible representation is legal

but illegal representations are often accepted

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 36 / 1

slide-88
SLIDE 88

Coding Practices Default Deny

Exploiting it

Your application bans filenames containing ../ But there are many ways to write /

/ is Unicode 0010 1111

1 byte : 0010 1111 2 byte : 1100 0000 1010 1111 3 byte : 1110 0000 1000 0000 1010 1111 4 byte : 1111 0000 1000 0000 1000 0000 1010 1111

So if your system accepts multi-byte forms, ... your input checking has to ban all representations of /. Default deny makes it easier

Accept only the canonical form

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 37 / 1

slide-89
SLIDE 89

Coding Practices Default Deny

Exploiting it

Your application bans filenames containing ../ But there are many ways to write /

/ is Unicode 0010 1111

1 byte : 0010 1111 2 byte : 1100 0000 1010 1111 3 byte : 1110 0000 1000 0000 1010 1111 4 byte : 1111 0000 1000 0000 1000 0000 1010 1111

So if your system accepts multi-byte forms, ... your input checking has to ban all representations of /. Default deny makes it easier

Accept only the canonical form

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 37 / 1

slide-90
SLIDE 90

Coding Practices Default Deny

Canonical Representation

UTF-8 is an example of the use of canonical representations Several equivalent forms are defined Only the shortest form is canonical Before a safe comparison can be made . . . data should be converted into canonical form

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 38 / 1

slide-91
SLIDE 91

Coding Practices Default Deny

Example: Napster filenames

Napster was ordered by court to block certain songs Solutions

filter downloads based on filename

Napster users by-passed this control

using equivalent (variations of) the song titles

Almost impossible to control

title equivalence is defined by the users...

Blatant breakdown of ‘Default Permit’

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 39 / 1

slide-92
SLIDE 92

Closure

Outline

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 40 / 1

slide-93
SLIDE 93

Closure

Conclusions

Secure coding is an essential part of software development

relatively new field

The Top 25 Vulnerabilities database is a good source

avoid the Top 5 and you will be better than average ... the list is updated regularly — check the latest version

Practices may vary between languages

try to look up a book for whatever language you use

Prof Hans Georg Schaathun Software Security Autumn 2011 – Week 12 41 / 1