Secure Programming Lai Zit Seng November 2012. A Simple Program int main() { char name[100]; printf("What is your name?\n"); gets(name); printf("Hello,

Slides:



Advertisements
Similar presentations
h Protection from cyber attacks is achieved by acting on several levels: first, at the physical and material, placing the server in a place as safe as.
Advertisements

November 1, 2004Introduction to Computer Security ©2004 Matt Bishop Slide #12-1 Chapter 12: Design Principles Overview Principles –Least Privilege –Fail-Safe.
Modular Programming With Functions
Practical techniques & Examples
CSc 352 Programming Hygiene Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
1 Design Principles CSSE 490 Computer Security Mark Ardis, Rose-Hulman Institute April 13, 2004.
Lecture 2 Page 1 CS 236, Spring 2008 Security Principles and Policies CS 236 On-Line MS Program Networks and Systems Security Peter Reiher Spring, 2008.
Stack buffer overflow.
It’s always better live. MSDN Events Security Best Practices Part 2 of 2 Reducing Vulnerabilities using Visual Studio 2008.
Stack buffer overflow
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Information Networking Security and Assurance Lab National Chung Cheng University The Ten Most Critical Web Application Security Vulnerabilities Ryan J.W.
(Breather)‏ Principles of Secure Design by Matt Bishop (augmented by Michael Rothstein)‏
FunctionsFunctions Systems Programming. Systems Programming: Functions 2 Functions   Simple Function Example   Function Prototype and Declaration.
 2007 Pearson Education, Inc. All rights reserved C Functions.
CMSC 414 Computer and Network Security Lecture 18 Jonathan Katz.
 2007 Pearson Education, Inc. All rights reserved C Functions.
CMSC 414 Computer and Network Security Lecture 17 Jonathan Katz.
C Lecture Notes Functions (Cont...). C Lecture Notes 5.8Calling Functions: Call by Value and Call by Reference Used when invoking functions Call by value.
FunctionsFunctions Systems Programming Concepts. Functions   Simple Function Example   Function Prototype and Declaration   Math Library Functions.
Simple Buffer Overflow Example Dan Fleck CS469 Security Engineering Reference: Coming up: Buffer Overflows.
Buffer Overflow Attacks. Memory plays a key part in many computer system functions. It’s a critical component to many internal operations. From mother.
Designing Security In Web Applications Andrew Tomkowiak 10/8/2013 UW-Platteville Software Engineering Department
Thomas Levy. Agenda 1.Aims: CIAN 2.Common Business Attacks 3.Information Security & Risk Management 4.Access Control 5.Cryptography 6.Physical Security.
Lecture 18 Page 1 CS 111 Online Design Principles for Secure Systems Economy Complete mediation Open design Separation of privileges Least privilege Least.
An anti-hacking guide.  Hackers are kindred of expert programmers who believe in freedom and spirit of mutual help. They are not malicious. They may.
Methods Review. 2. Class-wide vs. local variables. 3. Why C# bans global variables. 4. Nested blocks. 5. Scope of identifiers.
CMSC 414 Computer (and Network) Security Lecture 14 Jonathan Katz.
Chapter 6 Buffer Overflow. Buffer Overflow occurs when the program overwrites data outside the bounds of allocated memory It was one of the first exploited.
BLENDED ATTACKS EXPLOITS, VULNERABILITIES AND BUFFER-OVERFLOW TECHNIQUES IN COMPUTER VIRUSES By: Eric Chien and Peter Szor Presented by: Jesus Morales.
Buffer Overflows Lesson 14. Example of poor programming/errors Buffer Overflows result of poor programming practice use of functions such as gets and.
The Protection of Information in Computer Systems Part I. Basic Principles of Information Protection Jerome Saltzer & Michael Schroeder Presented by Bert.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
CGI Security COEN 351. CGI Security Security holes are exploited by user input. We need to check user input against Buffer overflows etc. that cause a.
Watching Software Run Brian ChessNov 18, Success is foreseeing failure. – Henry Petroski.
Design and Implementation Principles for Secure Systems.
Some possible final exam questions. DISCLAIMER models only These questions are models only. Some of these questions may or may not appear in the final.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Chapter 1 – Introduction Part 4 1. Message Authentication Codes Allows for Alice and Bob to have data integrity, if they share a secret key. Given a message.
A Tool for Pro-active Defense Against the Buffer Overrun Attack D. Bruschi, E. Rosti, R. Banfi Presented By: Warshavsky Alex.
EPSII 59:006 Spring Call-by-value example #include void increment(int); //prototype for increment function int main(void) { int a=1; printf("Value.
Buffer overflow and stack smashing attacks Principles of application software security.
(Breather)‏ Principles of Secure Design by Matt Bishop (augmented by Michael Rothstein)‏
Fall 2008CS 334: Computer SecuritySlide #1 Design Principles Thanks to Matt Bishop.
UNIT 11 Random Numbers.
June 1, 2004Computer Security: Art and Science © Matt Bishop Slide #13-1 Chapter 13: Design Principles Overview Principles –Least Privilege –Fail-Safe.
Function Call Stack and Activation Frame Stack Just like a pile of dishes Support Two operations push() pop() LIFO (Last-In, First-Out) data structure.
Netprog: Chat1 Chat Issues and Ideas for Service Design Refs: RFC 1459 (IRC)
LINUX Presented By Parvathy Subramanian. April 23, 2008LINUX, By Parvathy Subramanian2 Agenda ► Introduction ► Standard design for security systems ►
June 1, 2004© Matt Bishop [Changed by Hamid R. Shahriari] Slide #13-1 Chapter 13: Design Principles Overview Principles –Least Privilege –Fail-Safe.
Software Security II Karl Lieberherr. What is Security Enforcing a policy that describes rules for accessing resources. Policy may be explicit or implicit.
1 Saltzer [1974] and later Saltzer and Schroeder [1975] list the following principles of the design of secure protection systems, which are still valid:
L131 Assignment Operators Topics Increment and Decrement Operators Assignment Operators Debugging Tips rand( ) math library functions Reading Sections.
Lecture 14 Page 1 CS 236 Online Secure Programming CS 236 On-Line MS Program Networks and Systems Security Peter Reiher.
Content Coverity Static Analysis Use cases of Coverity Examples
Secure Programming Dr. X
Protecting Memory What is there to protect in memory?
Chapter 6 CS 3370 – C++ Functions.
Protecting Memory What is there to protect in memory?
Secure Programming Dr. X
Protecting Memory What is there to protect in memory?
Deitel- C:How to Program (5ed)
Chapter 5 - Functions Outline 5.1 Introduction
Stack buffer overflow.
Effective and Efficient memory Protection Using Dynamic Tainting
System Calls David Ferry CSCI 3500 – Operating Systems
GSM Global System for Mobile Communications, 1992
Security Principles and Policies CS 236 On-Line MS Program Networks and Systems Security Peter Reiher.
Functions that return a value
Presentation transcript:

Secure Programming Lai Zit Seng November 2012

A Simple Program int main() { char name[100]; printf("What is your name?\n"); gets(name); printf("Hello, "); printf(name); printf("!\n"); return 0; }

Buffer Overflow Example #include void foo (char *bar) { char c[12]; strcpy(c, bar); // no bounds checking... } int main (int argc, char **argv) { foo(argv[1]); } Source: Wikipedia

C Functions That Should Be Banned This is badUse this instead gets()fgets() sprintf()snprintf() strcpy()strncpy() strcat()strncat(), strlcat() printf() – needs caution

Race Conditions E.g.: How to create a temporary file in /tmp? – Use a static filename – Dynamically generate a filename – Check, then create the file $ ls –l /tmp total 8 lrwxr-xr-x 1 lzs wheel 11 Nov 12 11:20 tmpXNg2i9 -> /etc/passwd Suppose attacker knows program wants to create this file /tmp/tmpXNg2i9. What can attacker try to do?

Random Number Generation How do you generate random numbers? How do you seed the generator? #include main () { srand(0); printf("Num #1: %d\n", rand()); printf("Num #2: %d\n", rand()); printf("Num #3: %d\n", rand()); } Num #1: Num #2: Num #3: This sequence is fixed. If the seed is known, the random sequence can be entirely pre-determined.

Encryption vs Encoding How do you store secrets? – E.g. if your app needs to store passwords or credentials If you encrypt secrets with a password, then where do you store that password?

Use Standard Libraries and Protocols Make use of whatever is already available: – Glib – D-Bus IPC – SSL/OpenSSL for secure communications Don’t reinvent the wheel

Security by Obscurity Although in some circumstances it can be adopted as part of a defense-in-depth strategy Security through minority Don’t count on the unlikely

Principles Least privilege Economy of mechanism/Simplicity Open design Complete mediation Fail-safe defaults Least common mechanisms Separation of privilege Psychological acceptability/Easy to use Source: The Protection of Information in Computer Systems (

Secure by Design Security needs to be designed from the start

Borrowing from Perl’s Taint Mode You may not use data derived from outside your program to affect something else outside your program – at least, not by accident. $arg = shift; # $arg is tainted $hid = $arg, 'bar'; # $hid is also tainted $line = <>; # Tainted $line = ; # Also tainted open FOO, "/home/me/bar" or die $!; $line = ; # Still tainted $path = $ENV{'PATH'}; # Tainted, but see below $data = 'abc'; # Not tainted system "echo $arg”; # Insecure

2. Avoid buffer overflow 3. Program internals/Design approach 6. Language-specific issues 7. Special topics 2. Avoid buffer overflow 3. Program internals/Design approach 6. Language-specific issues 7. Special topics 1. Validate all input 5. Send info back judiciously 4. Carefully call out to other resources Source: A Program

Multi Facets of Information Security Access control Telecommunications & network security Software development security Cryptography Information security governance & risk management Security architecture & design Business continuity & disaster recovery Operation s security Physical security Legal, regulations, investigations & compliance

Resources lay/seccode/CERT+C+Secure+Coding+Standard HOWTO/index.html

What’s more dangerous than knowing nothing, is knowing something…

Questions? Lai Zit Seng