Secure Coding in C and C Chapter 1

  • Slides: 44
Download presentation
Secure Coding in C and C++ Chapter 1 Running with Scissors

Secure Coding in C and C++ Chapter 1 Running with Scissors

Secure Coding with C and C++ 1. 2. 3. 4. Gauging the Threat Security

Secure Coding with C and C++ 1. 2. 3. 4. Gauging the Threat Security Concepts C and C++ Development Platforms

Running With Scissors n The W 32. Blaster. Worm Discovered on August 11, 2003.

Running With Scissors n The W 32. Blaster. Worm Discovered on August 11, 2003. n Infected unpatched system connected to the Internet without user involvement. n At least eight million Windows systems have been infected by this worm [Lemos 04]. n Economic Damage > $500 M$ n

The W 32. Blaster. Worm n Blaster: n Checks to see if the computer

The W 32. Blaster. Worm n Blaster: n Checks to see if the computer is already infected. n n n Adds “windows auto update” = “msblast. exe” to registry key HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows Current. VersionRun Runs when Windows starts. Generates a random IP address. Attempts to infect the computer with that address. Sends data on TCP port 135 to exploit the DCOM RPC vulnerability on either Windows XP or Windows 2000.

Gauging the Threat The risk of producing insecure software systems can be evaluated by

Gauging the Threat The risk of producing insecure software systems can be evaluated by n n Looking at historic risk. The potential for future attacks. Historic risk can be measured by n n Looking at the type. Cost of perpetrated crimes. The potential for future attacks can be partially gauged by: n n n Evaluating emerging threats. The security of existing software systems.

What is the Cost? Based on conservative projections, about 100, 000 new software vulnerabilities

What is the Cost? Based on conservative projections, about 100, 000 new software vulnerabilities will be identified in 2010 alone. n. The number of security incidents worldwide will swell to about 400, 000 a year, or 8, 000 per work week [Berinato 04]. n

Who is the Threat? Threat is a person, group, organization, or foreign power that

Who is the Threat? Threat is a person, group, organization, or foreign power that has been the source of past attacks or may be the source of future attacks. n. Threats include: n n n n Hackers Insiders Criminals Competitive Intelligence Professionals Terrorists Information Warriors.

Hackers Motivated by curiosity and peer recognition from other hackers. n. Write programs that

Hackers Motivated by curiosity and peer recognition from other hackers. n. Write programs that expose vulnerabilities in computer software. n. The methods used to disclose these vulnerabilities varies from a policy of responsible disclosure to a policy of full disclosure. n

Insiders The threat comes from a current or former employee or contractor of an

Insiders The threat comes from a current or former employee or contractor of an organization. n. Has legitimate access to the information that was compromised. n. Do not need to be technically sophisticated to carry out attacks. n. Technically sophisticated insiders can launch attacks with immediate and widespread impact. n. Technical insiders can cover their tracks. n

Criminals n Common crimes include: n n Identity theft. Extortion. Phishing n n Auction

Criminals n Common crimes include: n n Identity theft. Extortion. Phishing n n Auction fraud, Lure victims to fake website to gather account data. Pfarming n Exploit DNS vulnerabilities to redirect web traffic to malicious site.

Competitive Intelligence Professionals (CIP) n Corporate spies: n n Call themselves competitive intelligence professionals.

Competitive Intelligence Professionals (CIP) n Corporate spies: n n Call themselves competitive intelligence professionals. Have their own professional association—the Society for Competitive Intelligence Professionals (SCIP). May work from inside a target organization, obtaining employment to steal and market trade secrets. Conduct other forms of corporate espionage.

Terrorists Cyber-terrorism can be defined as unlawful attacks or threats of attack against computers,

Terrorists Cyber-terrorism can be defined as unlawful attacks or threats of attack against computers, networks, and other information systems to intimidate or coerce a government or its people to further a political or social objective [Denning 00]. n

Information Warriors Eight nations have developed cyberwarfare capabilities comparable to that of the United

Information Warriors Eight nations have developed cyberwarfare capabilities comparable to that of the United States. n. More than 100 countries are trying to develop them. n. Twenty-three nations have targeted U. S. systems. n

Software Security The CERT/CC monitors public sources of vulnerability information and regularly receives reports

Software Security The CERT/CC monitors public sources of vulnerability information and regularly receives reports of vulnerabilities. n

Vulnerabilities reported to CERT/CC (1995 -2004)

Vulnerabilities reported to CERT/CC (1995 -2004)

Secure Coding with C and C++ 1. 2. 3. 4. Gauging the Threat Security

Secure Coding with C and C++ 1. 2. 3. 4. Gauging the Threat Security Concepts C and C++ Development Platforms

Security Concepts n Computer security is preventing attackers from achieving objectives through unauthorized access

Security Concepts n Computer security is preventing attackers from achieving objectives through unauthorized access or unauthorized use of computers and networks [Howard 97]. n. A programmer is concerned with properties of source code such as correctness, performance, and security.

Security Concepts A system integrator is responsible for integrating new and existing software components

Security Concepts A system integrator is responsible for integrating new and existing software components to create programs or systems that satisfy a particular set of customer requirements. n. System administrators are responsible for managing and securing one or more systems including installing and removing software, installing patches, and managing system privileges. n

Security Concepts n Network administrators are responsible for managing the secure operations of networks.

Security Concepts n Network administrators are responsible for managing the secure operations of networks. n. A security analyst is concerned with properties of security flaws and how to identify them. n. A vulnerability analyst is concerned with analyzing vulnerabilities in existing and deployed programs.

Security Concepts A security researcher develops mitigation strategies and solutions and who may be

Security Concepts A security researcher develops mitigation strategies and solutions and who may be employed in industry, academia, or government. n The attacker: n Is a malicious actor who exploits vulnerabilities to achieve an objective. n These objectives vary depending on the threat. n The attacker can also be referred to as the adversary, malicious user, hacker, or other alias. n

Security Concepts Programmer may contain Program may contain resolved by applied to composed of

Security Concepts Programmer may contain Program may contain resolved by applied to composed of Computer composed of System may possess may contain can lead to Security flaw Security analyst System administrator System integrator Source composed of Software composed of code component Security policy Network administrator Network may possess Vulnerability addressed by attacked by Mitigation Security researcher Exploit Attacker Vulnerability analyst

Security Policy A Security Policy is a set of rules and practices that specify

Security Policy A Security Policy is a set of rules and practices that specify or regulate how a system or organization provides security services to protect sensitive and critical system resources [Internet Society 00]. n

Security Flaws n Software Defects: n A software defect is the encoding of a

Security Flaws n Software Defects: n A software defect is the encoding of a human error into the software, including omissions. Security Flaw: n n A security flaw is a software defect that poses a potential security risk. Eliminating software defects eliminate security flaws.

Vulnerabilities A vulnerability is a set of conditions that allows an attacker to violate

Vulnerabilities A vulnerability is a set of conditions that allows an attacker to violate an explicit or implicit security policy. n n Not all security flaws lead to vulnerabilities. A security flaw can cause a program to be vulnerable to attack. n n Vulnerabilities can also exist without a security flaw.

Exploits n Exploit: An exploit is a piece of software or technique that takes

Exploits n Exploit: An exploit is a piece of software or technique that takes advantage of a security vulnerability to violate an explicit or implicit security policy. n Vulnerabilities in software subject to exploitation. n Exploits can take many forms, including worms, viruses, and trojans. n

Exploits n Exploit: Proof-of-concept exploits are developed to prove the existence of a vulnerability.

Exploits n Exploit: Proof-of-concept exploits are developed to prove the existence of a vulnerability. n Proof-of-concept exploits are beneficial when properly managed. n Proof-of-concept exploit in the wrong hands can be quickly transformed into a worm or virus or used in an attack. n

Mitigations n Mitigation: n n n Mitigations are methods, techniques, processes, tools, or runtime

Mitigations n Mitigation: n n n Mitigations are methods, techniques, processes, tools, or runtime libraries that can prevent or limit exploits against vulnerabilities. At the source code level, a mitigation might be replacing an unbounded string copy operation with a bounded one. At a system or network level, a mitigation might involve turning off a port or filtering traffic to prevent an attacker from accessing a vulnerability.

Secure Coding with C and C++ 1. 2. 3. 4. Gauging the Threat Security

Secure Coding with C and C++ 1. 2. 3. 4. Gauging the Threat Security Concepts C and C++ Development Platforms

C and C++ n C and C++: Popular programming languages. n The vast majority

C and C++ n C and C++: Popular programming languages. n The vast majority of vulnerabilities that have been reported to the CERT/CC have occurred in programs written in one of these two languages. n

What is the Problem with C? n C does not protect programmers. n Problems

What is the Problem with C? n C does not protect programmers. n Problems arise from an imprecise understanding of the semantics of logical abstractions and how they translate into machine-level instructions.

What is the Problem with C? n Programmer errors n n n Failing to

What is the Problem with C? n Programmer errors n n n Failing to prevent writing beyond the boundaries of an array, Failing to catch integer overflows and truncations, Calling functions with the wrong number of arguments. Lack of type safety. n Operations can legally act on signed and unsigned integers of differing lengths using implicit conversions and producing unrepresentable results.

What is the Problem with C? n Short term solutions: n n Educating developers

What is the Problem with C? n Short term solutions: n n Educating developers in how to program securely by recognizing common security flaws and applying appropriate mitigations. Long term solutions: n Language standard, compilers, and tools evolve.

Legacy Code A significant amount of legacy C code was created (and passed on)

Legacy Code A significant amount of legacy C code was created (and passed on) before the standardization of the language. n. Legacy C code is at higher risk for security flaws because of the looser compiler standards and is harder to secure because of the resulting coding style. n

Other Languages Many security professionals recommend using other languages, such as Java. n Adopting

Other Languages Many security professionals recommend using other languages, such as Java. n Adopting Java is often not a viable option because of: n n Existing investment in C source code, Programming expertise, Development environments.

Other Languages -2 Another alternative to using C is to use a C dialect,

Other Languages -2 Another alternative to using C is to use a C dialect, such as Cyclone [Jim 02]. n Cyclone is currently supported on x 86 Linux, and on Windows using Cygwin. n

Secure Coding with C and C++ 1. 2. 3. 4. Gauging the Threat Security

Secure Coding with C and C++ 1. 2. 3. 4. Gauging the Threat Security Concepts C and C++ Development Platforms

Development Platforms Software vulnerabilities can be viewed at varying levels of abstraction. n. At

Development Platforms Software vulnerabilities can be viewed at varying levels of abstraction. n. At higher levels of abstraction, software vulnerabilities can be common to multiple languages and multiple operating system environments. n. Differences in compilation, linkage, and execution can lead to significantly different exploits and significantly different mitigation strategies. n

Development Platforms Figure 1 -6 Windows 98 and Windows XP vulnerabilities (July 98 -Jan.

Development Platforms Figure 1 -6 Windows 98 and Windows XP vulnerabilities (July 98 -Jan. 04)

Development Platforms Figure 1 -6 Windows Vulnerabilities (March 2000 -November 2004)

Development Platforms Figure 1 -6 Windows Vulnerabilities (March 2000 -November 2004)

Compilers Microsoft’s Visual C++ is the predominant C and C++ compiler on Windows platforms.

Compilers Microsoft’s Visual C++ is the predominant C and C++ compiler on Windows platforms. n. Visual C++ includes n n n Visual C++ C++ 6. 0. NET 2002. NET 2003 2005 Beta 1 and Beta 2 The GCC compilers are the predominant C and C++ compilers for Linux platforms. n

Secure Coding with C and C++ 1. 2. 3. 4. Gauging the Threat Security

Secure Coding with C and C++ 1. 2. 3. 4. Gauging the Threat Security Concepts C and C++ Development Platforms

Summary Everyday software defects cause the majority of software vulnerabilities. n. C and C++

Summary Everyday software defects cause the majority of software vulnerabilities. n. C and C++ assume a level of expertise from developers that is not always present. n. The result is numerous delivered defects, some of which can lead to vulnerabilities. n

Summary The most widely used operating systems have from one to two defects per

Summary The most widely used operating systems have from one to two defects per thousand lines of code, contain several million lines of code, and typically have thousands of defects. n Everything on the [SANS Institute Top 20 Internet Security] vulnerability list is a result of poor coding, testing and sloppy software engineering. n

Summary Understanding the sources of vulnerabilities and learning to program securely is imperative to

Summary Understanding the sources of vulnerabilities and learning to program securely is imperative to protecting the Internet and ourselves from attack. n. Reducing security defects requires a disciplined engineering approach based on sound design principles and effective quality management practices. n