Code responsibly with generative AI in C++

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.

Audience & Prerequisits:

  • C/C++ developers
  • General C++ and C development

Standards and references:

  • SEI CERT, CWE and Fortify Taxonomy
  • 29 Labs and 8 Case Studies

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++
  • Managing vulnerabilities in third party components
  • Input validation approaches and principles

Outline

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

Note:

This variant of the course deals extensively with how certain security problems in code are handled by GitHub Copilot.

Through a number of hands-on labs participants will get first hand experience about how to use Copilot responsibly, and how to prompt it to generate the most secure code. In some cases it is trivial, but in most of the cases it is not; and in yet some other cases it is basically impossible.

At the same time, the labs provide general experience with using Copilot in everyday coding practice - what you can expect from it, and what are those areas where you shouldn't rely on it.

About The instructor Kiss Balazs

Balázs started in software security two decades ago as a researcher in various EU projects (FP6, FP7, H2020) while also taking part in over 25 commercial security evaluations: threat modeling, design review, manual testing, fuzzing. While breaking things was admittedly more fun, he's now on the other side, helping developers stop attacks at the (literal) source.

To date, he has held over 100 secure coding training courses all over the world about typical code vulnerabilities, protection techniques, and best practices.

His most recent passion is the (ab)use of AI systems, the security of machine learning, and the effect of generative AI on code security.

 

  • 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 – Heap BOF in WinRAR
      • 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
      • Lab – Experimenting with buffer overflow in Copilot
      • 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++
      • 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
          • Case study – Systematic exploitation of a MediaTek buffer overflow
  • 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
  • Using vulnerable components

    • Security of AI generated code
      • Practical attacks against code generation tools
      • Dependency hallucination via generative AI
      • Case study – A history of GitHub Copilot weaknesses (up to mid 2024)
  • 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
      • 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
            • Lab – Experimenting with command injection in Copilot
            • Case study – Command injection in Zyxel IKE packet decoder
      • Integer handling problems
        • Representing signed numbers
        • Integer visualization
        • Integer promotion
        • Integer overflow
        • Lab – Integer overflow
        • Lab – Experimenting with integer overflow in Copilot
        • Case study – Integer underflows in IPv6 handling of tcpip.sys
        • Signed / unsigned confusion
        • Case study – Signed/unsigned confusion DoS in DrayTek Vigor routers
        • Lab – Signed / unsigned confusion
        • Lab – Experimenting with signed / unsigned confusion in Copilot
        • Integer truncation
        • Lab – Integer truncation
        • Lab – Experimenting with integer truncation in Copilot
        • Case study – WannaCry
        • Best practices
          • Upcasting
          • Precondition testing
          • Postcondition testing
          • UBSan changes to arithmetics
          • Lab – Handling integer overflow on the toolchain level in C++
          • Best practices in C++
          • Lab – Integer handling best practices in C++
          • Case study – Integer check failure in Skia
      • Files and streams
        • Path traversal
        • Lab – Path traversal
        • Path traversal best practices
        • Lab – Path canonicalization
        • Lab – Experimenting with path traversal in Copilot
  • 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

Andre relevante kurs

9. april
3 dager
Classroom Virtual
21. mai
3 dager
Classroom Virtual
26. februar
3 dager
Classroom Virtual