Security testing C and C++ applications

Your application written in C and C++ is tested functionally, so you are done, right? But did you consider feeding in incorrect values? 16Gbs of data? A null? An apostrophe? Negative numbers, or specifically -2^32? Because that's what the bad guys will do – and the list is far from complete.Testing for security needs a remarkable software security expertise and a healthy level of paranoia, and this is what this course provides: a strong emotional engagement by lots of hands on labs and stories from real life.A special focus is given to finding all discussed issues during testing, and an overview is provided on security testing methodology, techniques and tools.So that you are prepared for the forces of the dark side.So that nothing unexpected happens.Nothing.

Outline:

  • Cyber security basics
  • Buffer overflow
  • Security testing
  • Common software security weaknesses
  • Using vulnerable components
  • Wrap up

Objective list:

  • Getting familiar with essential cyber security concepts
  • Understanding security testing methodology and approaches
  • Getting familiar with common security testing techniques and tools
  • Handling security challenges in your C and C++ code
  • Identify vulnerabilities and their consequences

Audience:

C/C++ developers and testers

Prerequisites:

General C/C++ development

Course outline:

Cyber security basics

  • What is security?
  • Threat and risk
  • Cyber security threat types

Consequences of insecure software

  • Constraints and the market
  • The dark side

Categorization of bugs

  • The Seven Pernicious Kingdoms
  • SEI Cert Secure Coding Guidelines

Buffer overflow

Assembly basics and calling conventions

  • x64 assembly essentials
  • Registers and addressing
  • Most common instructions
  • Calling conventions on x64
    • Calling convention – what it is all about
    • Calling conventions on x64
    • The stack frame
    • Stacked function calls

Memory management vulnerabilities

  • Memory management and security
  • Vulnerabilities in the real world
  • Buffer security issues
  • Buffer overflow on the stack
  • Buffer overflow on the stack – stack smashing
  • Exploitation – Hijacking the control flow
  • Lab – Buffer overflow 101, code reuse
  • Exploitation – Arbitrary code execution
  • Injecting shellcode
  • Lab – Code injection, exploitation with shellcode
  • Pointer manipulation
  • Modification of jump tables
  • Overwriting virtual function tables

Best practices and some typical mistakes

  • Unsafe functions
  • Dealing with unsafe functions
  • Lab – Fixing buffer overflow
  • What's the problem with asctime()?
  • Using std::string in C++
  • Unterminated strings
  • readlink() and string termination
  • Manipulating C-style strings in C++
  • Malicious string termination
  • Lab – String termination confusion
  • String length calculation mistakes
  • Off-by-one errors
  • Allocating nothing
  • Testing for typical mistakes
  • Memory management hardening
    • Address Space Layout Randomization (ASLR)
      • ASLR on various platforms
      • Lab – Effects of ASLR
      • Circumventing ASLR – NOP sleds
      • Non-executable memory areas
        • The NX bit
        • Write XOR Execute (W^X)
        • NX on various platforms
        • Lab – Effects of NX
        • NX circumvention – Code reuse attacks
          • Return-to-libc / arc injection
        • Return Oriented Programming (ROP)
          • Protection against ROP

Security testing

  • Security testing vs functional testing
  • Manual and automated methods
  • Security testing methodology
    • Security testing – goals and methodologies
    • Overview of security testing processes
    • Identifying and rating assets
      • Preparation
      • Identifying assets
      • Identifying the attack surface
      • Assigning security requirements
      • Lab – Identifying and rating assets
    • Threat modeling
      • SDL threat modeling
      • Mapping STRIDE to DFD
      • DFD example
      • Attack trees
      • Attack tree example
      • Lab – Crafting an attack tree
      • Misuse cases
      • Misuse case examples
      • Risk analysis
      • Lab – Risk analysis
    • Security testing approaches
      • Reporting, recommendations, and review

Common software security weaknesses

  • Security features
    • Authentication
      • Authentication basics
      • Multi-factor authentication
      • Authentication weaknesses – spoofing
      • Case study – PayPal 2FA bypass
    • Password management
      • Inbound password management
  • Time and state
    • Race conditions
      • File race condition
        • Time of check to time of usage – TOCTTOU
        • Lab – TOCTTOU
        • Insecure temporary file

Using vulnerable components

  • Assessing the environment
  • Hardening
  • Vulnerability management
    • Patch management
    • Vulnerability databases
    • Lab – Finding vulnerabilities in third-party components

Common software security weaknesses

  • Input validation
    • Input validation principles
      • Blacklists and whitelists
      • Data validation techniques
      • What to validate – the attack surface
      • Where to validate – defense in depth
      • How to validate – validation vs transformations
      • Output sanitization
      • Encoding challenges
      • Validation with regex
    • Injection
      • Injection principles
      • Injection attacks
      • Code injection
        • OS command injection
          • Lab – Command injection
          • OS command injection best practices
          • Avoiding command injection with the right APIs
          • Lab – Command injection best practices
          • Case study – Shellshock
          • Lab – Shellshock
          • Testing for command injection
        • Process control – library injection
          • DLL hijacking
          • Lab – DLL hijacking
    • Integer handling problems
      • Representing signed numbers
      • Integer visualization
      • Integer promotion
      • Integer overflow
      • Lab – Integer overflow
      • Signed / unsigned confusion
      • Case study – The Stockholm Stock Exchange
      • Lab – Signed / unsigned confusion
      • Integer truncation
      • Lab – Integer truncation
      • Case study – WannaCry
      • Best practices
        • Upcasting
        • Precondition testing
        • Postcondition testing
        • Using big integer libraries
        • Best practices in C
        • UBSan changes to arithmetics
        • Lab – Handling integer overflow on the toolchain level in C/C++
        • Best practices in C++
        • Lab – Integer handling best practices in C++
      • Testing for numeric problems
    • Files and streams
      • Path traversal
      • Path traversal-related examples
      • Lab – Path traversal
      • Path traversal best practices
      • Lab – Path canonicalization
      • Testing for path traversal

Security testing

  • Security testing techniques and tools
    • Code analysis
      • Security aspects of code review
      • Static Application Security Testing (SAST)
      • Lab – Using static analysis tools
    • Dynamic analysis
      • Security testing at runtime
      • Penetration testing
      • Stress testing
      • Dynamic analysis tools
        • Dynamic Application Security Testing (DAST)
      • Fuzzing
        • Fuzzing techniques
        • Fuzzing – Observing the process

Wrap up

  • Secure coding principles
    • Principles of robust programming by Matt Bishop
    • Secure design principles of Saltzer and Schröder
  • And now what?
    • Software security sources and further reading
    • C and C++ resources
    • Security testing resources

Other relevant courses

25. November
5 days
Classroom Virtual
2. December
5 days
Classroom Virtual
9. December
5 days
Classroom Virtual
16. December
3 days
Classroom Virtual