Vulnerability Assessment and Secure Coding Practices for Middleware. Part 2 Roadmap

Size: px
Start display at page:

Download "Vulnerability Assessment and Secure Coding Practices for Middleware. Part 2 Roadmap"

Transcription

1 Vulnerability Assessment and Secure Coding Practices for Middleware James A. Kupsch Barton P. Miller Computer Sciences Department University of Wisconsin Elisa Heymann Computer Architecture and Operating Systems Department Universitat Autònoma de Barcelona OGF27, Banff, Alberta, Canada October 12, 2009 This research funded in part by National Science Foundation grant OCI , NATO grant CLG , the National Science Foundation under contract with San Diego Supercomputing Center, and National Science 1Foundation grants CNS and CNS Part 2 Roadmap Part 1: Vulnerability assessment process Part 2: Secure coding practices Introduction Handling errors Numeric parsing ISO/IEC intro Variadic functions Buffer overflows Injections Directory traversal Integer Race conditions File system issues Canonical form Privileges Command line Environment Denial of service Information leaks Memory allocators General engineering Compiler warnings 36

2 Vulnerability Types Description of vulnerability Signs of presence in the code Mitigations Safer alternatives 37 Handling Errors If a call can fail, always check for errors optimistic error handling (i.e. none) is bad When error is detected Handle locally and continue Cleanup and propagate the error Exit the application All APIs you use, or develop, that can fail need to be able to report errors to the caller Using exceptions forces error handling 38

3 Numeric Parsing No Error Indication atoi, atol, atof, scanf family (with %u, %i, %d, %x and %o specifiers) Out of range values results in unspecified behavior Non-numeric input results in 0 Use strtol, strtoul, strtoll, strtoull, strtof, strtod, strtold which allow error detection 39 char *endptr; long longval; Correct Numeric Parsing errno = 0; /* clear to detect all errs */ longval = strtol(s, &endptr, 10); if (errno == ERANGE) {ERROR("overflow");} if (endptr == 0) /* errno is EINVAL */ {ERROR("non-numeric");} if (errno!= 0) {ERROR("other error");} if (*endptr!= '\0') /* parse ok, optional errors */ {ERROR("non-numeric at end");} if (isspace(*s)) {ERROR("space at beginning");} 40

4 Correct Numeric Parsing in C++ iostream inserter's Type safe All errors set stream to failed (test with!is) Use istringstream to parse a string istringstream is(" "); is >> i >> f; if (!is) {ERROR("parse error"); Boost's lexical_cast<t>(s) Throw's bad_lexical_cast exception on failure 41 Missing Error Detection strcat, strcpy, strncat, strncpy, gets, getpass, getwd, scanf (with %s or %[ ], without width specified) Unable to report if buffer would overflow (not enough information present) Only secure in rare case where files or strings are verified for secure values before use Never use these 42

5 ISO/IEC Extensions for the C library: Part 1, Bounds Checking Interface Functions to make the C library safer Meant to easily replace existing library calls with little or no other changes Aborts on error or optionally reports error Very few unspecified behaviors All updated buffers require a size 43 ISO/IEC 24731: Run-time Constraints Property of the arguments that must be true at call time Violations handled by callback default is to abort Common run-time constraints rsize_t parameter type size of the buffer or amount to copy violation if size > RSIZE_MAX catches large size caused by integer overflow Buffer pointers not NULL dst buffer too small for operation usually a violation (snprintf truncates) 44

6 Variadic Functions C functions that can take a variable number of parameters Not type safe Common variadic functions printf, scanf, syslog families never take the format string from the user use compile time constants for format string use compiler warnings in C++, use iostreams instead execl family open with O_CREAT (3rd argument is the mode) 45 Buffer Overflows Description Accessing locations of a buffer outside the boundaries of the buffer Common causes C-style strings Array access and pointer arithmetic in languages without bounds checking Off by one errors Fixed large buffer sizes (make it big and hope) Decoupled buffer pointer and its size If size unknown overflows are impossible to detect Require synchronization between the two Ok if size is implicitly known and every use knows it (hard) 46

7 Why Buffer Overflows are Dangerous An overflow overwrites memory adjacent to a buffer This memory could be Unused Code Program data that can affect operations Internal data used by the runtime system Usual sign is a crash Specially crafted values can be used for an attack 47 Buffer Overflow of User Data Affecting Flow of Control char id[8]; int validid = 0; /* not valid */ id validid \0 \0 \0 \0 gets(id); /* reads "evillogin"*/ id e v i l l 110 n /* validid is now 110 decimal */ if (IsValid(id)) validid = 1; if (validid) {DoPrivilegedOp();} /* gets executed */ o g i validid \0 \0 \0 48

8 C-style String Design Flaws Null terminated array of characters Represented by a pointer to this array Not a proper type, just a convention Only language support is string literals Initialize a char array Create array containing a constant string literal Problems Null may be missing Pointers are difficult to use correctly Size of buffer is kept externally from pointer if at all Many common operations are expensive Can't have a string with a null in it 49 Buffer Overflow Danger Signs: Missing Buffer Size gets, getpass, getwd, and scanf family (with %s or %[ ] specifiers without width) Impossible to use correctly: size comes solely from user input Alternatives Unsafe gets(s) getcwd(s) scanf("%s", s) Safe fgets(s, slen, stdin) getwd(s, slen) scanf("%100s", s) 50

9 Buffer Overflow Danger Signs: scanf family Max field can not be taken from an argument * width suppresses assignment %nc does not null terminate %ns and %n[ ] require a buffer of size n+1 Requires manual coordination of format string, number and types of arguments, and result Example: 3 items must be coordinated char big[100], small[10]; int r, j; r = scanf("%99s %9s %d", big, small, &j); If (r == EOF) ERROR("EOF") If (r!= 3) ERROR("bad line"); 51 strcat, strcpy, sprintf, vsprintf Impossible for function to detect overflow Destination buffer size not passed Difficult to use safely w/o preflight checks Checks require destination buffer size Length of data formatted by printf Difficult & error prone Best incorporated in the function Proper usage: concat s1, s2 into dst If (dstsize < strlen(s1) + strlen(s2) + 1) {ERROR("buffer overflow");} strcpy(dst, s1); strcat(dst, s2); 52

10 Buffer Overflow Danger Signs: Difficult to Use and Truncation strncat(dst, src, n) n is the maximum number of chars of src to append (trailing null also appended) can overflow if n >=(dstsize - strlen(dst)) strncpy(dst, src, n) Writes n chars into dst, if strlen(src) < n, it fills the other n - strlen(src) chars with 0 s If strlen(src) >= n, dst is not null terminated Truncation detection not provided Deceptively insecure n is not a static value, same check required as strcat 53 Safer String Handling: C-library functions snprintf(buf, bufsize, fmt, ) and vsnprintf Truncation detection possible (result >= bufsize implies truncation) Can be used as a safer version of strcpy and strcat Officially doesn t exist until C99 standard Proper usage: concat s1, s2 into dst r = snprintf(dst, dstsize, "%s%s",s1, s2); If (r >= dstsize) {ERROR("truncation");} 54

11 Safer String Handling: BSD s strlcpy and strlcat strlcpy(dst, src, size) and strlcat(dst, src, size) size is always the size of the dst buffer Returns number of chars required result >= size indicates truncation dst always null terminated, except strlcat where dst is not terminated Can read outside src if not null-terminated Not universally implemented (not in linux) 55 Safer String Handling: BSD s strlcpy and strlcat Proper usage: concat s1, s2 into dst /* safe to just check errors at last call */ (void)strlcpy(dst, s1, dstsize); r = strlcat(dst, s2, dstsize) if (r >= dstsize) { if (r == dstsize && dst[r]!= '\0') { /* this should not happen as strlcpy will always terminate */ ERROR("unterminated dst"); } else { ERROR("truncation"); } } 56

12 ISO/IEC 24731: string and memory functions Very easy to convert typical unsafe code Add _s to function name Add destination buffer size parameter Proper usage: concat s1, s2 into dst /* program will abort on error */ strcpy_s(dst, dstsize, s1); strcat_s(dst, dstsize, s2); 57 Preventing Buffer Overflows in C++ Don't use pointers, C-style string, or C-arrays std::string Buffer, length and current size are encapsulated together Dynamically sized Provides many useful and efficient methods std::vector<> Dynamically sized array Safe except operator[] (use at method for safety) std::array<> (new in C++ TR1) Fixed size array Proper usage: concat s1, s2 into dst dst = s1 + s2; 58

13 Potential Problems with C++ Strings System call and libraries expect C-strings c_str method will return a constant C-string pointer Valid only until string is modified Nulls are allowed Truncated at first null when converted to C-string If tests are done on C++-string and used as a C- string these may be different Same problem in other languages such as Perl Denial of service if length not restricted 59 Description Injection Attacks A string constructed with user input, that is then interpreted by another function, where the string is not parsed as expected Command injection (in a shell) Format string attacks (in printf/scanf) SQL injection Cross-site scripting or XSS (in HTML) General causes Allowing metacharacters Not properly quoting user data if metacharacters are allowed 60

14 SQL Injections User supplied values used in SQL command must be validated, quoted, or prepared statements must be used Signs of vulnerability Uses a database mgmt system (DBMS) Uses SQL commands created at run-time Do not use SQL fragments from user create parsable language securely translate to limited SQL 61 SQL Injection Attacks Dynamically generated SQL without validation or quoting is vulnerable $u = " '; drop table t --" $sth = $dbh->do("select * from t where u = '$u'") -- select * from t where u = ' '; drop table t --' Quoting values is safe if done correctly $u = " \\'; drop table t --"; # perl eats one \ $u =~ s/'/''/g; # quote (' -> '') $sth = $dbh->do("select * from t where u = '$u'") -- select * from t where u = ' \''; drop table t - ' What is correctly? Previous example is correct in standard SQL, but incorrect in systems that allow \-escapes 62

15 SQL Injection Mitigations Best to use prepared statements $sth = $dbh->do("select * from t where u =?", $u) Use library functions to perform quoting $sth = $dbh->do("select * from t where u = ". $dbh->quote($u)) Other SQL safe practices Views can be used to limit access to data Stored procedures can help, but not if they dynamically create and execute SQL Restrict rights of database account to minimum required 63 Command Injections User supplied data used to create a string that is the interpreted by command shell such as /bin/sh Signs of vulnerability Use of popen, or system exec of a shell such as sh, or csh Usually done to start another program That has no C API Out of laziness 64

16 Command Injection Mitigations Check user input for metacharacters Quote those that can t be eliminated or rejected replace single quotes with the four characters, '\'', and enclose each argument in single quotes Beware of program argument injections, allowing arguments to begin with "-" can be dangerous Use fork, drop privileges and exec for more control Avoid if at all possible Use C API if exists 65 Perl Command Injection Danger Signs open(f, $filename) Filename is a tiny language besides opening Open files in various modes Can start programs dup file descriptors If $userfile is "rm -rf / ", you probably won t like the result Use separate mode version of open to eliminate vulnerability 66

17 Perl Command Injection Danger Signs Vulnerable to shell interpretation open(c, "$cmd ") open(c, " $cmd") `$cmd` system($cmd) Safe from shell interpretation open(c, "- open(c, " open(c, "- ", $cmd) open(c, " -", $cmd) qx/$cmd/ 67 Eval Injections A string formed from user supplied input that is used as an argument that is interpreted by the language running the code Usually allowed in scripting languages such as Perl, shells, and SQL In Perl eval($s) and s/$pat/$replace/ee $s and $replace are evaluated as perl code 68

18 Format String Injections User supplied allowed to create format strings in scanf or printf printf(userdata) is insecure %n can be used to write memory large field width values can be used to create a denial of service attack Safe to use printf("%s", userdata) or fputs(userdata, stdout) scanf(userdata, ) allows arbitrary writes to memory pointed to by stack values ISO/IEC does not allow %n 69 Description Directory Traversal When user data is used to create a pathname to a file system object that is supposed to be restricted to a particular set of paths or path prefixes, but which the user can circumvent General causes Not checking for path components that are empty, "." or ".." Not creating the canonical form of the pathname (there is an infinite number of distinct strings for the same object) Not accounting for symbolic links 70

19 Directory Traversal Mitigation Use realpath or something similar to create canonical pathnames Use the canonical pathname when comparing filenames or prefixes If using prefix matching to check if a path is within directory tree, also check that the next character in the path is the directory separator or '\0' 71 Integer Vulnerabilities Description Many programming languages allow silent loss of integer data without warning due to Overflow Truncation Signed vs. unsigned representations Code may be secure on one platform, but silently vulnerable on another, due to different underlying integer types. General causes Not checking for overflow Mixing integer types of different ranges Mixing unsigned and signed integers 72

20 Integer Danger Signs Mixing signed and unsigned integers Converting to a smaller integer size_t is unsigned, ptrdiff_t is signed Using a built-in type instead of the API s typedef type Not assigning values to a variable of the correct type before data validation, so the validated value is not the same as the value used 73 Race Conditions Description A race condition occurs when multiple threads of control try to perform a non-atomic operation on a shared object, such as Multithreaded applications accessing shared data Accessing external shared resources such as the file system General causes Using threads without proper synchronization including non-thread (non-reentrant) safe functions Performing non-atomic sequences of operations on shared resources (file system, shared memory) and assuming they are atomic Signal handlers 74

21 File System Race Conditions A file system maps a path, name of a file or other object in the file system, to the internal identifier (device and inode) If an attacker can control any component of the path, multiple uses of a path can result in different file system objects Safe use of path eliminate race condition use only once use file descriptor for other uses verify multiple uses are consistent 75 Race Conditions Checking File Properties Use the path to check properties of a file, and then open the file (also called time of check, time of use TOCTOU) access followed by open Safe to just set the effective ids and then just open the file stat followed by open Safe to open the file and then fstat the file descriptor 76

22 Race Condition File Attributes Using the path to create or open a file and then using the same path to change the ownership or mode of the file Best to create the file with the correct owner, group, and mode at creation Otherwise the file should be created with restricted permissions and then changed to less restrictive using fchown and fchmod If created with lax permissions there is a race condition between the attacker opening the file and permissions being changed 77 Race Condition Creating a File Want to atomically check if file exists and create if not, or fail if it exists Common solution is to check if file exists with stat, then open if it doesn't Open a file or create it if does not exist creat(fname, mode) open(fname, O_CREAT O_WRONLY O_TRUNC, mode) Must use O_CREAT O_EXCL to get desired property Never use O_CREAT without O_EXCL 78

23 Race Condition Creating a File open also fails if the last component of the path is a symbolic link when using O_CREAT O_EXCL fopen never uses O_EXCL Only use for read mode For append or write modes use open and fdopen to create a FILE* from a file descriptor C++ iostreams never use O_EXCL No standard way to get iostream from fd Use use non-standard extension Use library that can create a stream from a fd, such as 79 Safely Create or Open a File If you want to open or create like O_CREAT without O_EXCL use the following: f = open(fname, O_CREAT O_EXCL O_RDWR, mode); if (f == -1 && errno == EEXIST) { f = open(fname, O_RDWR) } Better still use safefile library James A. Kupsch and Barton P. Miller, How to Open a File and Not Get Hacked, 2008 Third International Conference on Availability, Reliability and Security (ARES), Barcelona, Spain Does the above and much more 80

24 Race Condition Temporary Files Temporary directory (/tmp) is the bad part of town for the file system Any process can create a file there Usually has the sticky bit set, so only the owner can delete their files Ok to create true temporary files here Created, immediately deleted, and only accessed through the original file descriptor Storage vanishes when file descriptor is closed Safe use of /tmp directory create a secure directory in /tmp use it to store files 81 Race Condition Temporary Files mktemp, tmpnam, or tempnam, then open Return filename that does not exist a race condition exists if O_EXCL is not used Use mkstemp which returns the filename and a file descriptor to the opened file (use umask to restrict privileges) To create a directory use mkdtemp if available or the following: for (int j = 0; j < 10; ++j) { strcpy(path, template); if (mktemp(path) == NULL) {ERROR("mktemp failed");} if (mkdir(path)!= -1 errno!= EEXIST) { break; } } 82

25 Race Condition Examples Your Actions time Attackers Action s=strdup( /tmp/zxxxxxx) tempnam(s) // s now /tmp/zrandom link = /etc/passwd file = /tmp/zrandom symlink(link, file) f = fopen(s, w+ ) // writes now update // /etc/passwd Safe Version fd = mkstemp(s) f = fdopen(fd, w+ ) 83 Non-canonical Forms If one value can be encoded in multiple different forms they must be converted to a unique canonical form before comparison Paths: use (device, inode) pair, or convert to a canonical form using realpath Usernames and groups: use uid and gid utf: convert to utf-32 or canonical form HTML & URL encoded: decode Case insensitive: convert to all lower (some languages lose info if converted to upper) 84

26 Non-canonical Forms In weakly typed language, such as a shell or Perl, where a value can be a number or string use the correct comparison operator Comparing numbers lexically is bad "100" le "2" "000" ne "0" Comparing strings numerically is bad "111111" > "9sdflkj" "000" == "0abc" "xyz" == "abc" 85 Description Not Dropping Privilege When a program running with a privileged status (running as root for instance), creates a process or tries to access resources as another user General causes Running with elevated privilege Not dropping all inheritable process attributes such as uid, gid, euid, egid, supplementary groups, open file descriptors, root directory, working directory not setting close-on-exec on sensitive file descriptors 86

27 Not Dropping Privilege: chroot chroot changes the root directory for the process, files outside cannot be accessed Only root can use chroot Need to chdir("/") to somewhere underneath the new root directory, otherwise relative pathnames are not restricted Need to recreate all support files used by program in new root: /etc, libraries, 87 Insecure Permissions Set umask when using mkstemp or fopen File permissions need to be secure from creation to destruction Don t write sensitive information into insecure locations (directories need to have restricted permission to prevent replacing files) Executables, libraries, configuration, data and log files need to be write protected 88

28 Insecure Permissions If a file controls what can be run as a privileged users that can update the file are equivalent to the privileged user Owned by privileged user Owned by administrative account No login Never executes anything, just owns files DBMS accounts should be granted minimal privileges for their task 89 Trusted Directory A trusted directory is one where only trusted users can update the contents of anything in the directory or any of its ancestors all the way to the root A trusted path needs to check all components of the path including symbolic links referents for trust A trusted path is immune to TOCTOU attacks from untrusted users safefile library Determines trust based on trusted users & groups 90

29 Command Line Description Convention is that argv[0] is the path to the executable Shells enforce this behavior, but it can be set to anything if you control the parent process General causes Using argv[0] as a path to find other files such as configuration data Process needs to be setuid or setgid to be a useful attack 91 Environment Description A program s environment is a list of strings that a program is allowed to interpret. Libraries are also allowed to use the environment to alter their behavior. Since changes to the environment can alter the execution of a program, library code, and spawned programs, the environment must be carefully controlled. General causes Not sanitizing the environment Allowing user input to alter the environment Not fully specified as to what happens when multiple values with the same name, or value without '=' in it 92

30 Environment Mitigation Record needed values of the environment, sanitize them, clear the environment, add only necessary values, discard others Don't make assumptions about size of values Don t allow code from the user to set environment Use execle or execve to start a process with user supplied environment variables Use setenv instead of putenv 93 Environment Mitigation PATH: list of directories to search for executables given as just a name Only used by execlp and execvp Use execle or execve and full paths Set PATH to something safe /bin:/usr/bin LD_LIBRARY_PATH: list of directories to search for shared libraries, could be used to inject a library into your process Many others 94

31 Denial of Service Description Programs becoming unresponsive due to over consumption of a limited resource or unexpected termination. General causes Not releasing resources Crash causing bugs Infinite loops or data causing algorithmic complexity to consume excessive resources Failure to limit data sizes Failure to limit wait times Leaks of scarce resources (memory, file descriptors) 95 Description Information Leaks Inadvertent divulgence of sensitive information General causes Reusing buffers without completely erasing Providing extraneous information that an adversary may not be able to otherwise obtain Generally occurs in error messages Give as few details as possible Log full details to a database and return id to user, so admin can look up details if needed 96

32 Information Leaks General causes (cont.) Timing attacks where the duration of the operation depends on secret information Lack of encryption when using observable channels Allowing secrets on devices where they can't be erased such as swap space (use mlock) or backups 97 General Software Engineering Don t trust user data You don t know where that data has been Don t trust your own client software either It may have been modified, so always revalidate data at the server. Don t trust your operational configuration either If your program can test for unsafe conditions, do so and quit Don t trust your own code either Program defensively with checks in high and low level functions KISS - Keep it simple, stupid Complexity kills security, its hard enough assessing simple code 98

33 Let the Compiler Help Turn on compiler warnings and fix problems Easy to do on new code Time consuming, but useful on old code Use lint, multiple compilers gcc: -Wall, -W, -O2, -Werror, -Wshadow, -Wpointer-arith, -Wconversion, -Wcast-qual, -Wwrite-strings, -Wunreachable-code and many more Many useful warning including security related warnings such as format strings and integers 99 Let the Perl Compiler Help -w - produce warning about suspect code and runtime events use strict - fail if compile time use Fatal - cause built-in function to raise an exception on error instead of returning an error code use diagnostics - better diagnostic messages 100

34 Perl Taint Mode Taint mode (-T) prevents data from untrusted sources from being used in dangerous ways Untrusted sources Data read from a file descriptor Command line arguments Environment User controlled fields in password file Directory entries Link referents Shared memory Network messages Environment sanitizing required for exec IFS PATH CDPATH ENV BASH_ENV 101 Books Viega, J. & McGraw, G. (2002). Building Secure Software: How to Avoid Security Problems the Right Way. Addison- Wesley. Seacord, R. C. (2005). Secure Coding in C and C++. Addison-Wesley. Seacord, R. C. (2009). The CERT C Secure Coding Standard, Addison-Wesley. McGraw, G. (2006). Software security: Building Security In. Addison-Wesley. Dowd, M., McDonald, J., & Schuh, J. (2006). The Art of Software Assessment: Identifying and Preventing Software Vulnerabilities. Addison-Wesley. 102

35 Questions 103

Part 2 Roadmap. Vulnerability Types. Numeric Parsing No Error Indication. Handling Errors. Correct Numeric Parsing. Correct Numeric Parsing in C++

Part 2 Roadmap. Vulnerability Types. Numeric Parsing No Error Indication. Handling Errors. Correct Numeric Parsing. Correct Numeric Parsing in C++ Part 2 Roadmap Vulnerability Types Part 1: Vulnerability assessment process Part 2: Secure coding practices Introduction Handling errors Numeric parsing ISO/IEC 24731 intro Variadic functions Buffer overflows

More information

10 common programming mistakes that make you vulnerable to attack

10 common programming mistakes that make you vulnerable to attack 10 common programming mistakes that make you vulnerable to attack Elisa Heymann Computer Architecture and Operating Systems Department Universitat Autònoma de Barcelona Elisa.Heymann@uab.es Barton P. Miller

More information

Outline. Classic races: files in /tmp. Race conditions. TOCTTOU example. TOCTTOU gaps. Vulnerabilities in OS interaction

Outline. Classic races: files in /tmp. Race conditions. TOCTTOU example. TOCTTOU gaps. Vulnerabilities in OS interaction Outline CSci 5271 Introduction to Computer Security Day 3: Low-level vulnerabilities Stephen McCamant University of Minnesota, Computer Science & Engineering Race conditions Classic races: files in /tmp

More information

Secure Software Programming and Vulnerability Analysis

Secure Software Programming and Vulnerability Analysis Secure Software Programming and Vulnerability Analysis Christopher Kruegel chris@auto.tuwien.ac.at http://www.auto.tuwien.ac.at/~chris Race Conditions Secure Software Programming 2 Overview Parallel execution

More information

Module: Safe Programming. Professor Trent Jaeger. CSE543 - Introduction to Computer and Network Security

Module: Safe Programming. Professor Trent Jaeger. CSE543 - Introduction to Computer and Network Security CSE543 - Introduction to Computer and Network Security Module: Safe Programming Professor Trent Jaeger 1 1 Avoiding Vulnerabilities How do we write programs to avoid mistakes that lead to vulnerabilities?

More information

CSE 565 Computer Security Fall 2018

CSE 565 Computer Security Fall 2018 CSE 565 Computer Security Fall 2018 Lecture 15: Software Security II Department of Computer Science and Engineering University at Buffalo 1 Software Vulnerabilities Buffer overflow vulnerabilities account

More information

Writing Safe Setuid Programs. Theme

Writing Safe Setuid Programs. Theme Writing Safe Setuid Programs Department of Computer Science Davis, CA 95616-8562 phone (916) 752-8060 email bishop@cs.ucdavis.edu Slide # 1 Theme Using standard robust programming techniques can greatly

More information

CSCE 548 Building Secure Software Buffer Overflow. Professor Lisa Luo Spring 2018

CSCE 548 Building Secure Software Buffer Overflow. Professor Lisa Luo Spring 2018 CSCE 548 Building Secure Software Buffer Overflow Professor Lisa Luo Spring 2018 Previous Class Virus vs. Worm vs. Trojan & Drive-by download Botnet & Rootkit Malware detection Scanner Polymorphic malware

More information

CIT 380: Securing Computer Systems

CIT 380: Securing Computer Systems CIT 380: Securing Computer Systems Secure Programming Slide #1 Topics 1. The nature of trust 2. Input validation 3. Input entry points 4. Integer overflows 5. Format string attacks Slide #2 Trust Relationships

More information

Secure Programming I. Steven M. Bellovin September 28,

Secure Programming I. Steven M. Bellovin September 28, Secure Programming I Steven M. Bellovin September 28, 2014 1 If our software is buggy, what does that say about its security? Robert H. Morris Steven M. Bellovin September 28, 2014 2 The Heart of the Problem

More information

Vulnerability Assessment and Secure Coding Practices for Middleware

Vulnerability Assessment and Secure Coding Practices for Middleware Vulnerability Assessment and Secure Coding Practices for Middleware Barton P. Miller James A. Kupsch Computer Sciences Department University of Wisconsin bart@cs.wisc.edu Elisa Heymann Computer Architecture

More information

C and C++ Secure Coding 4-day course. Syllabus

C and C++ Secure Coding 4-day course. Syllabus C and C++ Secure Coding 4-day course Syllabus C and C++ Secure Coding 4-Day Course Course description Secure Programming is the last line of defense against attacks targeted toward our systems. This course

More information

ONLamp.com: Secure Programming Techniques

ONLamp.com: Secure Programming Techniques Page 1 of 11 Published on ONLamp.com (http://www.onlamp.com/) http://www.onlamp.com/pub/a/onlamp/excerpt/puis3_chap16/index1.html See this if you're having trouble printing code examples O'Reilly Book

More information

Computer Security. Robust and secure programming in C. Marius Minea. 12 October 2017

Computer Security. Robust and secure programming in C. Marius Minea. 12 October 2017 Computer Security Robust and secure programming in C Marius Minea marius@cs.upt.ro 12 October 2017 In this lecture Write correct code minimizing risks with proper error handling avoiding security pitfalls

More information

Execution of Multiple flows (threads, processes, tasks, etc) If not controlled can lead to nondeterministic behavior

Execution of Multiple flows (threads, processes, tasks, etc) If not controlled can lead to nondeterministic behavior Race Conditions March 27, 2006 March 27, 2006 Concurrency Concurrency and Race condition Execution of Multiple flows (threads, processes, tasks, etc) If not controlled can lead to nondeterministic behavior

More information

Software Security II: Memory Errors - Attacks & Defenses

Software Security II: Memory Errors - Attacks & Defenses 1 Software Security II: Memory Errors - Attacks & Defenses Chengyu Song Slides modified from Dawn Song 2 Administrivia Lab1 Writeup 3 Buffer overflow Out-of-bound memory writes (mostly sequential) Allow

More information

SysSec. Aurélien Francillon

SysSec. Aurélien Francillon SysSec Aurélien Francillon francill@eurecom.fr https://www.krackattacks.com/ https://arstechnica.com/information-technology/2017/10/crypto-failure-cripples-millions-ofhigh-security-keys-750k-estonian-ids/

More information

Secure Coding in C and C++ Race conditions

Secure Coding in C and C++ Race conditions Secure Coding in C and C++ Race conditions Lecture 6 Oct 1, 2014 Acknowledgement: These slides are based on author Seacord s original presentation Concurrency and Race condition Concurrency Execution of

More information

Software and Web Security 1. Root Cause Analysis. Abstractions Assumptions Trust. sws1 1

Software and Web Security 1. Root Cause Analysis. Abstractions Assumptions Trust. sws1 1 Software and Web Security 1 Reflections on using C(++) Root Cause Analysis Abstractions Assumptions Trust sws1 1 There are only two kinds of programming languages: the ones people complain about and the

More information

Reflections on using C(++) Root Cause Analysis

Reflections on using C(++) Root Cause Analysis Hacking in C Reflections on using C(++) Root Cause Analysis Abstractions Complexity Assumptions Trust hic 1 There are only two kinds of programming languages: the ones people complain about and the ones

More information

Computer Security. 04r. Pre-exam 1 Concept Review. Paul Krzyzanowski. Rutgers University. Spring 2018

Computer Security. 04r. Pre-exam 1 Concept Review. Paul Krzyzanowski. Rutgers University. Spring 2018 Computer Security 04r. Pre-exam 1 Concept Review Paul Krzyzanowski Rutgers University Spring 2018 February 15, 2018 CS 419 2018 Paul Krzyzanowski 1 Key ideas from the past four lectures February 15, 2018

More information

Chapter 3.2: Numeric Errors

Chapter 3.2: Numeric Errors Introduction to Software Security Chapter 3.2: Numeric Errors Loren Kohnfelder loren.kohnfelder@gmail.com Elisa Heymann elisa@cs.wisc.edu Barton P. Miller bart@cs.wisc.edu DRAFT Revision 1.5, February

More information

Implementation of a simple shell, xssh

Implementation of a simple shell, xssh Implementation of a simple shell, xssh What is a shell? A process that does command line interpretation Reads a command from standard input (stdin) Executes command corresponding to input line In simple

More information

Secure Programming. Buffer Overflows Learning objectives. Type. 3 Buffer Overflows. 4 An Important Vulnerability. 5 Example Overflow

Secure Programming. Buffer Overflows Learning objectives. Type. 3 Buffer Overflows. 4 An Important Vulnerability. 5 Example Overflow Secure Programming Buffer Overflows 2 Learning objectives Understand the definition of a buffer overflow Learn the importance of buffer overflows Know how buffer overflows happen Know how to handle strings

More information

Secure Programming Learning objectives. and Best Practices. Windows shells Launches programs, including other shells Provides

Secure Programming Learning objectives. and Best Practices. Windows shells Launches programs, including other shells Provides 2 Learning objectives 1 Secure Programming Shell and Environment Flaws Ahmet Burak Can Hacettepe University Understand how shells interpret commands, launch and provide environments for processes Understand

More information

Secure Programming. Shell and Environment Flaws. Ahmet Burak Can Hacettepe University

Secure Programming. Shell and Environment Flaws. Ahmet Burak Can Hacettepe University Secure Programming Shell and Environment Flaws 1 Ahmet Burak Can Hacettepe University 2 Learning objectives Understand how shells interpret commands, launch and provide environments for processes Understand

More information

Copyright (2004) Purdue Research Foundation. All rights reserved.

Copyright (2004) Purdue Research Foundation. All rights reserved. CS390S, Week 3: Buffer Overflows, Part 1 Pascal Meunier, Ph.D., M.Sc., CISSP January 23, 2008 Developed thanks to support and contributions from Symantec Corporation, support from the NSF SFS Capacity

More information

Advanced Systems Security: Ordinary Operating Systems

Advanced Systems Security: Ordinary Operating Systems Systems and Internet Infrastructure Security Network and Security Research Center Department of Computer Science and Engineering Pennsylvania State University, University Park PA Advanced Systems Security:

More information

Buffer overflow background

Buffer overflow background and heap buffer background Comp Sci 3600 Security Heap Outline and heap buffer Heap 1 and heap 2 3 buffer 4 5 Heap Outline and heap buffer Heap 1 and heap 2 3 buffer 4 5 Heap Address Space and heap buffer

More information

ECS 153 Discussion Section. April 6, 2015

ECS 153 Discussion Section. April 6, 2015 ECS 153 Discussion Section April 6, 2015 1 What We ll Cover Goal: To discuss buffer overflows in detail Stack- based buffer overflows Smashing the stack : execution from the stack ARC (or return- to- libc)

More information

UMSSIA LECTURE I: SOFTWARE SECURITY

UMSSIA LECTURE I: SOFTWARE SECURITY UMSSIA LECTURE I: SOFTWARE SECURITY THINKING LIKE AN ADVERSARY SECURITY ASSESSMENT Confidentiality? Availability? Dependability? Security by Obscurity: a system that is only secure if the adversary doesn

More information

Program Structure. Steven M. Bellovin April 3,

Program Structure. Steven M. Bellovin April 3, Program Structure We ve seen that program bugs are a major contributor to security problems We can t build bug-free software Can we build bug-resistant software? Let s look at a few examples, good and

More information

SECURE PROGRAMMING TECHNIQUES. Race conditions. General terms. File access races. Network races. Multithreading. Signal handling races MEELIS ROOS 1

SECURE PROGRAMMING TECHNIQUES. Race conditions. General terms. File access races. Network races. Multithreading. Signal handling races MEELIS ROOS 1 Race conditions General terms File access races Network races Multithreading Signal handling races MEELIS ROOS 1 General terms Race condition correctness of the program depends on timing (race with an

More information

I m paranoid, but am I paranoid enough? Steven M. Bellovin February 20,

I m paranoid, but am I paranoid enough? Steven M. Bellovin February 20, I m paranoid, but am I paranoid enough? Steven M. Bellovin February 20, 2007 1 Special Techniques for Secure Programs Buffer overflows are bad in any case Some problems are only a risk for secure programs

More information

(In columns, of course.)

(In columns, of course.) CPS 310 first midterm exam, 10/9/2013 Your name please: Part 1. Fun with forks (a) What is the output generated by this program? In fact the output is not uniquely defined, i.e., it is not always the same.

More information

CptS 360 (System Programming) Unit 6: Files and Directories

CptS 360 (System Programming) Unit 6: Files and Directories CptS 360 (System Programming) Bob Lewis School of Engineering and Applied Sciences Washington State University Spring, 2019 Motivation Need to know your way around a filesystem. A properly organized filesystem

More information

Program Structure I. Steven M. Bellovin November 14,

Program Structure I. Steven M. Bellovin November 14, Program Structure I Steven M. Bellovin November 14, 2010 1 Program Structure We ve seen that program bugs are a major contributor to security problems We can t build bug-free software Can we build bug-resistant

More information

CYSE 411/AIT681 Secure Software Engineering Topic #12. Secure Coding: Formatted Output

CYSE 411/AIT681 Secure Software Engineering Topic #12. Secure Coding: Formatted Output CYSE 411/AIT681 Secure Software Engineering Topic #12. Secure Coding: Formatted Output Instructor: Dr. Kun Sun 1 This lecture: [Seacord]: Chapter 6 Readings 2 Secure Coding String management Pointer Subterfuge

More information

2/9/18. CYSE 411/AIT681 Secure Software Engineering. Readings. Secure Coding. This lecture: String management Pointer Subterfuge

2/9/18. CYSE 411/AIT681 Secure Software Engineering. Readings. Secure Coding. This lecture: String management Pointer Subterfuge CYSE 411/AIT681 Secure Software Engineering Topic #12. Secure Coding: Formatted Output Instructor: Dr. Kun Sun 1 This lecture: [Seacord]: Chapter 6 Readings 2 String management Pointer Subterfuge Secure

More information

11/3/71 SYS BREAK (II)

11/3/71 SYS BREAK (II) 11/3/71 SYS BREAK (II) break -- set program break SYNOPSIS sys break; addr / break = 17. break sets the system s idea of the highest location used by the program to addr. Locations greater than addr and

More information

Verification & Validation of Open Source

Verification & Validation of Open Source Verification & Validation of Open Source 2011 WORKSHOP ON SPACECRAFT FLIGHT SOFTWARE Gordon Uchenick Coverity, Inc Open Source is Ubiquitous Most commercial and proprietary software systems have some open

More information

Outline. Security as an economic good. Risk budgeting with ALE. Failure: Risk compensation. Failure: Displacement activity

Outline. Security as an economic good. Risk budgeting with ALE. Failure: Risk compensation. Failure: Displacement activity CSci 5271 Introduction to Computer Security Day 2: Intro to Software and OS Security Stephen McCamant University of Minnesota, Computer Science & Engineering Security as an economic good Security is a

More information

First Principles Vulnerability Assessment. Motivation

First Principles Vulnerability Assessment. Motivation First Principles Vulnerability Assessment James A. Kupsch Barton P. Miller Computer Sciences Department University of Wisconsin Elisa Heymann Eduardo César Computer Architecture and Operating Systems Department

More information

Programmer s Points to Remember:

Programmer s Points to Remember: Programmer s Points to Remember: Always do bounds checking on arrays. Always do bounds checking on pointer arithmetic. Before you copy to, format, or send input to a buffer make sure it is big enough to

More information

COMP 3704 Computer Security

COMP 3704 Computer Security COMP 3704 Computer Security christian@grothoff.org http://grothoff.org/christian/ 1 Application Security Suppose...... protocol design is secure.... cryptographic primitives are secure.... users / key

More information

Program Structure I. Steven M. Bellovin November 8,

Program Structure I. Steven M. Bellovin November 8, Program Structure I Steven M. Bellovin November 8, 2016 1 Program Structure We ve seen that program bugs are a major contributor to security problems We can t build bug-free software Can we build bug-resistant

More information

David A. Wheeler March 30, 2003

David A. Wheeler  March 30, 2003 David A. Wheeler dwheeler@dwheeler.com http://www.dwheeler.com/secure-programs March 30, 2003 1 Contents: Lessons learned on how to write secure applications, based on past exploits (lots of detail) Not

More information

CS140 Operating Systems Final December 12, 2007 OPEN BOOK, OPEN NOTES

CS140 Operating Systems Final December 12, 2007 OPEN BOOK, OPEN NOTES CS140 Operating Systems Final December 12, 2007 OPEN BOOK, OPEN NOTES Your name: SUNet ID: In accordance with both the letter and the spirit of the Stanford Honor Code, I did not cheat on this exam. Furthermore,

More information

Required reading: StackGuard: Simple Stack Smash Protection for GCC

Required reading: StackGuard: Simple Stack Smash Protection for GCC Continuing with Software Security Writing & testing for Secure Code Required reading: StackGuard: Simple Stack Smash Protection for GCC Optional reading: Basic Integer Overflows Exploiting Format String

More information

Software Security Buffer Overflows more countermeasures. Erik Poll. Digital Security Radboud University Nijmegen

Software Security Buffer Overflows more countermeasures. Erik Poll. Digital Security Radboud University Nijmegen Software Security Buffer Overflows more countermeasures Erik Poll Digital Security Radboud University Nijmegen Recap last week Recurring security problems in C(++) code memory corruption, due to buffer

More information

Processes. CS3026 Operating Systems Lecture 05

Processes. CS3026 Operating Systems Lecture 05 Processes CS3026 Operating Systems Lecture 05 Dispatcher Admit Ready Queue Dispatch Processor Release Timeout or Yield Event Occurs Blocked Queue Event Wait Implementation: Using one Ready and one Blocked

More information

Some recent security news

Some recent security news Some recent security news Swedish ISP didn t update their routers US Postal service hacked; data about 500k employees leaked 73000 security cameras use default passwords Tor network hacked (by law enforcement)

More information

Software Security Buffer Overflows more countermeasures. Erik Poll. Digital Security Radboud University Nijmegen

Software Security Buffer Overflows more countermeasures. Erik Poll. Digital Security Radboud University Nijmegen Software Security Buffer Overflows more countermeasures Erik Poll Digital Security Radboud University Nijmegen Recap last week Recurring security problems in C(++) code buffer overflows bugs with pointers

More information

Topics in Software Security Vulnerability

Topics in Software Security Vulnerability Topics in Software Security Vulnerability Software vulnerability What are software vulnerabilities? Types of vulnerabilities E.g., Buffer Overflows How to find these vulnerabilities and prevent them? Classes

More information

CNIT 127: Exploit Development. Ch 18: Source Code Auditing. Updated

CNIT 127: Exploit Development. Ch 18: Source Code Auditing. Updated CNIT 127: Exploit Development Ch 18: Source Code Auditing Updated 4-10-17 Why Audit Source Code? Best way to discover vulnerabilities Can be done with just source code and grep Specialized tools make it

More information

Advanced System Security: Vulnerabilities

Advanced System Security: Vulnerabilities Advanced System Security: Vulnerabilities Trent Jaeger Systems and Internet Infrastructure Security (SIIS) Lab Computer Science and Engineering Department Pennsylvania State University CSE544 -Advanced

More information

CS 261 Fall Mike Lam, Professor. Structs and I/O

CS 261 Fall Mike Lam, Professor. Structs and I/O CS 261 Fall 2018 Mike Lam, Professor Structs and I/O Typedefs A typedef is a way to create a new type name Basically a synonym for another type Useful for shortening long types or providing more meaningful

More information

I m paranoid, but am I paranoid enough? Steven M. Bellovin October 2,

I m paranoid, but am I paranoid enough? Steven M. Bellovin October 2, I m paranoid, but am I paranoid enough? Steven M. Bellovin October 2, 2008 1 Special Techniques for Secure Programs Buffer overflows are bad in any case Some problems are only a risk for secure programs

More information

Fundamentals of Computer Security

Fundamentals of Computer Security Fundamentals of Computer Security Spring 2015 Radu Sion Software Errors Buffer Overflow TOCTTOU 2005-15 Portions copyright by Bogdan Carbunar and Wikipedia. Used with permission Why Security Vulnerabilities?

More information

Static Vulnerability Analysis

Static Vulnerability Analysis Static Vulnerability Analysis Static Vulnerability Detection helps in finding vulnerabilities in code that can be extracted by malicious input. There are different static analysis tools for different kinds

More information

Developing Secure Software

Developing Secure Software T H E U N I V E R S I T Y O F B R I T I S H C O L U M B I A Developing Secure Software EECE 412 Session 21 Copyright 2004 Konstantin Beznosov T H E U N I V E R S I T Y O F B R I T I S H C O L U M B I A

More information

Agenda. Security and Standard C Libraries. Martyn Lovell Visual C++ Libraries Microsoft Corporation

Agenda. Security and Standard C Libraries. Martyn Lovell Visual C++ Libraries Microsoft Corporation Security and Standard C Libraries Visual C++ Libraries Microsoft Corporation 2003.04.17 1 Agenda Current Situation Security Problems Library impact Proposed Changes Related C++ issues Summary Q&A 2003.04.17

More information

Race Condition Vulnerability Lab

Race Condition Vulnerability Lab Concordia Institute for Information Systems Engineering - INSE 6130 1 Race Condition Vulnerability Lab Copyright c 2006-2012 Wenliang Du, Syracuse University. The development of this document is funded

More information

Possible Defects in TR Randy Meyers N1261

Possible Defects in TR Randy Meyers N1261 1. Possible Defects in TR 24731-1 Since the last meeting, I have received email pointing out possible defects in the Boundschecking TR. This paper summarizes those issues. 2. Typos 2.1 scanf family 6.5.3.*,

More information

Secure Programming II. Steven M. Bellovin September 29,

Secure Programming II. Steven M. Bellovin September 29, Secure Programming II Steven M. Bellovin September 29, 2014 1 I m paranoid, but am I paranoid enough? Steven M. Bellovin September 29, 2014 2 Special Techniques for Secure Programs Buffer overflows are

More information

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

CSci 4061 Introduction to Operating Systems. Programs in C/Unix CSci 4061 Introduction to Operating Systems Programs in C/Unix Today Basic C programming Follow on to recitation Structure of a C program A C program consists of a collection of C functions, structs, arrays,

More information

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files CSC209 Review CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files ... and systems programming C basic syntax functions arrays structs

More information

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs. CSC209 Review CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files... and systems programming C basic syntax functions arrays structs

More information

CSE543 - Introduction to Computer and Network Security

CSE543 - Introduction to Computer and Network Security CSE543 - Introduction to Computer and Network Security Module: Software Vulnerabilities Professor Trent Jaeger 1 Programming Why do we write programs? Function What functions do we enable via our programs?

More information

Layers in a UNIX System. Create a new process. Processes in UNIX. fildescriptors streams pipe(2) labinstructions

Layers in a UNIX System. Create a new process. Processes in UNIX. fildescriptors streams pipe(2) labinstructions Process Management Operating Systems Spring 2005 Layers in a UNIX System interface Library interface System call interface Lab Assistant Magnus Johansson magnusj@it.uu.se room 1442 postbox 54 (4th floor,

More information

CERT C Rules implemented in the LDRA tool suite

CERT C Rules implemented in the LDRA tool suite CERT C Rules implemented in the LDRA tool suite This section lists a snapshot of the CERT C Coding Standard guidelines in 2014 that are automatically checked by version 9.5.1 of the LDRA tool suite. Guidelines

More information

Program Security and Vulnerabilities Class 2

Program Security and Vulnerabilities Class 2 Program Security and Vulnerabilities Class 2 CEN-5079: 28.August.2017 1 Secure Programs Programs Operating System Device Drivers Network Software (TCP stack, web servers ) Database Management Systems Integrity

More information

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo I/O OPERATIONS UNIX Programming 2014 Fall by Euiseong Seo Files Files that contain a stream of bytes are called regular files Regular files can be any of followings ASCII text Data Executable code Shell

More information

CSE 410: Systems Programming

CSE 410: Systems Programming CSE 410: Systems Programming Input and Output Ethan Blanton Department of Computer Science and Engineering University at Buffalo I/O Kernel Services We have seen some text I/O using the C Standard Library.

More information

Buffer overflow is still one of the most common vulnerabilities being discovered and exploited in commodity software.

Buffer overflow is still one of the most common vulnerabilities being discovered and exploited in commodity software. Outline Morris Worm (1998) Infamous attacks Secure Programming Lecture 4: Memory Corruption II (Stack Overflows) David Aspinall, Informatics @ Edinburgh 23rd January 2014 Recap Simple overflow exploit

More information

Introduction to N1031. Components of N1031. Guiding Principles. Walk through, issues, and rationale

Introduction to N1031. Components of N1031. Guiding Principles. Walk through, issues, and rationale Introduction to N1031 Walk through, issues, and rationale Components of N1031 New functions that protect against buffer overflow and always produce null terminated strings New reentrant versions of old

More information

Lecture 3. Introduction to Unix Systems Programming: Unix File I/O System Calls

Lecture 3. Introduction to Unix Systems Programming: Unix File I/O System Calls Lecture 3 Introduction to Unix Systems Programming: Unix File I/O System Calls 1 Unix File I/O 2 Unix System Calls System calls are low level functions the operating system makes available to applications

More information

UNIX input and output

UNIX input and output UNIX input and output Disk files In UNIX a disk file is a finite sequence of bytes, usually stored on some nonvolatile medium. Disk files have names, which are called paths. We won t discuss file naming

More information

Copying and Concatenating C Strings with the str5 Functions

Copying and Concatenating C Strings with the str5 Functions Copying and Concatenating C Strings with the str5 Functions Eric Sanchis University of Toulouse Capitole France ABSTRACT The copy and the concatenation of strings constitute a recurring subject of polemics

More information

File Descriptors and Piping

File Descriptors and Piping File Descriptors and Piping CSC209: Software Tools and Systems Programming Furkan Alaca & Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Week 8 Today s topics File Descriptors

More information

Processes. Processes (cont d)

Processes. Processes (cont d) Processes UNIX process creation image-file arg1 arg2 Shell command line example ls -l Equivalent to /bin/ls -l Why? How do you find out where the image file is? Background processes ls -l & Execute a process

More information

CSE 565 Computer Security Fall 2018

CSE 565 Computer Security Fall 2018 CSE 565 Computer Security Fall 2018 Lecture 16: Building Secure Software Department of Computer Science and Engineering University at Buffalo 1 Review A large number of software vulnerabilities various

More information

ECE 435 Network Engineering Lecture 5

ECE 435 Network Engineering Lecture 5 ECE 435 Network Engineering Lecture 5 Vince Weaver http://web.eece.maine.edu/~vweaver vincent.weaver@maine.edu 18 September 2018 HW#2 was posted. Announcements 1 HW#1 Review Sockets Code Need to clear

More information

Reading Assignment. Strings. K.N. King Chapter 13. K.N. King Sections 23.4, Supplementary reading. Harbison & Steele Chapter 12, 13, 14

Reading Assignment. Strings. K.N. King Chapter 13. K.N. King Sections 23.4, Supplementary reading. Harbison & Steele Chapter 12, 13, 14 Reading Assignment Strings char identifier [ size ] ; char * identifier ; K.N. King Chapter 13 K.N. King Sections 23.4, 23.5 Supplementary reading Harbison & Steele Chapter 12, 13, 14 Strings are ultimately

More information

COMP3441 Lecture 7: Software Vulnerabilities

COMP3441 Lecture 7: Software Vulnerabilities COMP3441 Lecture 7: Software Vulnerabilities Ron van der Meyden (University of New South Wales Sydney, Australia) April 22, 2013 Overview Buffer overflow attacks SQL injection attacks Defensive measures

More information

Other array problems. Integer overflow. Outline. Integer overflow example. Signed and unsigned

Other array problems. Integer overflow. Outline. Integer overflow example. Signed and unsigned Other array problems CSci 5271 Introduction to Computer Security Day 4: Low-level attacks Stephen McCamant University of Minnesota, Computer Science & Engineering Missing/wrong bounds check One unsigned

More information

CSC209 Review. Yeah! We made it!

CSC209 Review. Yeah! We made it! CSC209 Review Yeah! We made it! 1 CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files 2 ... and C programming... C basic syntax functions

More information

CIS Operating Systems File Systems Security. Professor Qiang Zeng Fall 2017

CIS Operating Systems File Systems Security. Professor Qiang Zeng Fall 2017 CIS 5512 - Operating Systems File Systems Security Professor Qiang Zeng Fall 2017 Previous class File and directory Hard link and soft link Mount Layered structure File system design Naïve: linked list

More information

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo I/O OPERATIONS UNIX Programming 2014 Fall by Euiseong Seo Files Files that contain a stream of bytes are called regular files Regular files can be any of followings ASCII text Data Executable code Shell

More information

CMPSC 497: Midterm Review

CMPSC 497: Midterm Review CMPSC 497: Midterm Review Trent Jaeger Systems and Internet Infrastructure Security (SIIS) Lab Computer Science and Engineering Department Pennsylvania State University Page 1 Midterm Format True/False

More information

Symlink attacks. Do not assume that symlinks are trustworthy: Example 1

Symlink attacks. Do not assume that symlinks are trustworthy: Example 1 Symlink attacks Do not assume that symlinks are trustworthy: Example 1 Application A creates a file for writing in /tmp. It assumes that since the file name is unusual, or because it encodes A's name or

More information

Secure Programming. Input Validation. Learning objectives Code Injection: Outline. 4 Code Injection

Secure Programming. Input Validation. Learning objectives Code Injection: Outline. 4 Code Injection Secure Programming Input Validation 2 Learning objectives Understand the definition of code injection Know how code injection happens Learn how to perform input validation and cleansing 1 Ahmet Burak Can

More information

Finding Vulnerabilities in Source Code

Finding Vulnerabilities in Source Code Finding Vulnerabilities in Source Code Jason Miller CSCE 813 Fall 2012 Outline Approaches to code review Signatures of common vulnerabilities Language-independent considerations Tools for code browsing

More information

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring 2009 Topic Notes: C and Unix Overview This course is about computer organization, but since most of our programming is

More information

Taming Bugs. Paul Böhm. The Art and Science of writing secure Code.

Taming Bugs. Paul Böhm. The Art and Science of writing secure Code. Taming Bugs The Art and Science of writing secure Code Paul Böhm http://www.sec-consult.com/ Overview This talk is about code-based Defense Strategies against Security Vulnerabilties If your Code is broken,

More information

CS167 Programming Assignment 1: Shell

CS167 Programming Assignment 1: Shell CS167 Programming Assignment 1: Assignment Out: Sep. 5, 2007 Helpsession: Sep. 11, 2007 (8:00 pm, Motorola Room, CIT 165) Assignment Due: Sep. 17, 2007 (11:59 pm) 1 Introduction In this assignment you

More information

Fall 2015 COMP Operating Systems. Lab #3

Fall 2015 COMP Operating Systems. Lab #3 Fall 2015 COMP 3511 Operating Systems Lab #3 Outline n Operating System Debugging, Generation and System Boot n Review Questions n Process Control n UNIX fork() and Examples on fork() n exec family: execute

More information

Taming Bugs. Paul Böhm. The Art and Science of writing secure Code.

Taming Bugs. Paul Böhm. The Art and Science of writing secure Code. Taming Bugs The Art and Science of writing secure Code Paul Böhm http://www.sec-consult.com/ Overview This talk is about code-based Defense Strategies against Security Vulnerabilties If your Code is broken,

More information

Is stack overflow still a problem?

Is stack overflow still a problem? Morris Worm (1998) Code Red (2001) Secure Programming Lecture 4: Memory Corruption II (Stack Overflows) David Aspinall, Informatics @ Edinburgh 31st January 2017 Memory corruption Buffer overflow remains

More information

Secure Coding in C and C++

Secure Coding in C and C++ Secure Coding in C and C++ Robert C. Seacord AAddison-Wesley Upper Saddle River, NJ Boston Indianapolis San Francisco New York Toronto Montreal London Munich Paris Madrid Capetown Sydney Tokyo Singapore

More information