Secure coding in C++

CYDCpp3d
3 days
On-site or online
Hands-on
C
C++
Developer
Instructor-led
labs

25 Labs

case_study

5 Case Studies

Audience

C/C++ developers

Preparedness

General C++ and C development

Standards and references

SEI CERT, CWE and Fortify Taxonomy

Group size

12 participants

Outline

  • Cyber security basics
  • Memory management vulnerabilities
  • Memory management hardening
  • Common software security weaknesses
  • Wrap up

What you will learn

  • Getting familiar with essential cyber security concepts
  • Correctly implementing various security features
  • Identify vulnerabilities and their consequences
  • Learn the security best practices in C and C++
  • Input validation approaches and principles

Description

Embark on a comprehensive exploration of cybersecurity and secure coding practices in this intensive three-day course. It is primarily focusing on C++, but also integrates some C concepts. Based on a primer on machine code, assembly, and memory overlay (Intel and ARM versions available), the curriculum addresses critical security issues related to memory management. Various protection techniques on the level of source code, compiler, OS or hardware are discussed – such as stack smashing protection, ASLR or the non-execution bit – to understand how they work and make clear what we can and what we can’t expect from them.

The various secure coding subjects are aligned to common software security weakness categories, such as security features, error handling or code quality. Many of the weaknesses are, however, linked to missing or improper input validation. In this category you’ll learn about injection, the surprising world of integer overflows, and about handling file names correctly to avoid path traversal.

Through hands-on labs and real-world case studies, you will navigate the details of secure coding practices to get essential approaches and skills in cybersecurity.

So that you are prepared for the forces of the dark side.

So that nothing unexpected happens.

Nothing.

Table of contents

  • Cyber security basics
  • Memory management vulnerabilities
    • 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 convention on x64
        • The stack frame
        • Stacked function calls
    • Buffer overflow
      • Memory management and security
      • 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
      • Buffer overflow on the heap
        • Unsafe unlinking
        • Case study – Heartbleed
      • Pointer manipulation
        • Modification of jump tables
        • Overwriting function pointers
    • Best practices and some typical mistakes
      • Unsafe functions
      • Dealing with unsafe functions
      • Lab – Fixing buffer overflow
      • Using std::string in C++
      • Manipulating C-style strings in C++
      • Malicious string termination
      • Lab – String termination confusion
      • String length calculation mistakes
      • Off-by-one errors
      • Allocating nothing
  • Memory management hardening
    • Securing the toolchain
      • Securing the toolchain in C and C++
      • Using FORTIFY_SOURCE
      • Lab – Effects of FORTIFY
      • AddressSanitizer (ASan)
        • Using AddressSanitizer (ASan)
        • Lab – Using AddressSanitizer
      • Stack smashing protection
        • Detecting BoF with a stack canary
        • Argument cloning
        • Stack smashing protection on various platforms
        • SSP changes to the prologue and epilogue
        • Lab – Effects of stack smashing protection
    • Runtime protections
      • Runtime instrumentation
      • Address Space Layout Randomization (ASLR)
        • ASLR on various platforms
        • Lab – Effects of ASLR
        • Circumventing ASLR – NOP sleds
        • Circumventing ASLR – memory leakage
      • 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
  • Common software security weaknesses
    • Security features
    • Code quality
      • Code quality and security
      • Data handling
        • Type mismatch
        • Lab – Type mismatch
        • Initialization and cleanup
          • Constructors and destructors
          • Initialization of static objects
          • Lab – Initialization cycles
        • Unreleased resource
          • Array disposal in C++
          • Lab – Mixing delete and delete[]
      • Object oriented programming pitfalls
        • Accessibility modifiers
          • Are accessibility modifiers a security feature?
        • Inheritance and object slicing
        • Implementing the copy operator
        • The copy operator and mutability
        • Mutability
          • Mutable predicate function objects
          • Lab – Mutable predicate function object
  • Common software security weaknesses
    • Input validation
      • Input validation principles
      • Denylists and allowlists
      • What to validate – the attack surface
      • Where to validate – defense in depth
      • When to validate – validation vs transformations
      • Validation with regex
      • Injection
        • 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
      • 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
          • UBSan changes to arithmetics
          • Lab – Handling integer overflow on the toolchain level in C and C++
          • Best practices in C++
          • Lab – Integer handling best practices in C++
      • Files and streams
        • Path traversal
        • Lab – Path traversal
        • Path traversal best practices
        • Lab – Path canonicalization
    • Errors
      • Error and exception handling principles
      • Error handling
        • Returning a misleading status code
        • Error handling in C++
        • Using std::optional safely
        • Information exposure through error reporting
      • Exception handling
        • In the catch block. And now what?
        • Empty catch block
        • Lab – Exception handling mess
  • Wrap up
    • Secure coding principles
      • Principles of robust programming by Matt Bishop
      • Secure design principles of Saltzer and Schroeder
    • And now what?
      • Software security sources and further reading
      • C and C++ resources

Pricing

3 days Session Price

2250 EUR / person

  • Live, instructor led classroom training
  • Discussion and insight into the hacker’s mindset
  • Hands-on practice using case studies based on high-profile hacks and live lab exercises
Customized course

Tailor a course to your preferences

  • Send us a brief description of your business’s training needs
  • Include your contact information
  • One of our colleagues will be in touch to schedule a free consultation about training requirements

Inquiry

Interested in the trainings but still have some questions? Curious about how you can customize a training for your team? Send us a message and a team member will be in touch within 24 hours.

This field is required

This field is required

Send us your phone number if you prefer to discuss further on a call

This field is required

This field is required

This field is required

This field is required