SlideShare une entreprise Scribd logo
1  sur  33
Be careful when dealing
with C/C++
Think Twice, Code Once
Mykhailo Zarai (April 2017)
Why do we care?
Almost every day we hear about :
•vulnerabilities
•data breech
Vulnerabilities examples
•Windows Remote Code
execution (MS15-115)
•NDIS Privilege of Elevation
(MS15-17)
•Kernel-Mode Drivers Privilege
(MS15-135)
Data breach 2016
•Apple Health Medicaid
•Central Coast Credit Union
•Commission on Elections
•Department of Homeland
Security
What we are going to do?
•Talk about secure programming
•Programming toolbox
•Some references and
recommendations
Common Vulnerabilities
•Buffer overflow
•Integers
•Null pointer dereferencing
Homework:
•Strings
•Arrays
•Exceptions
Look inside buffer overflow
problem
Return Address
ESP - Extended
Stack Pointer (topo)
Parent Routine Stack
EBP - Extended Base
Pointer (base)
Char *bar
Char c[12]
StackGrowth
MemoryAddresses
The data is put on
reverse order onto buffer
Return Address
ESP - Extended
Stack Pointer (topo)
Parent Routine Stack
EBP - Extended Base
Pointer (base)
Char *bar
Char c[12]
StackGrowth
MemoryAddresses
H E L L O
H E L L O
H E L L O
H E L L O
H E L L O
BOOM!
Buffer Overflow!
H E L L O
Return Address
ESP - Extended
Stack Pointer (topo)
Parent Routine Stack
EBP - Extended Base
Pointer (base)
Char *bar
Char c[12]
StackGrowth
MemoryAddresses
Canary Word
Integers – Unsigned integer
Wrap
Must not be allowed to wrap:
• Integer operands of any point arithmetic and
array indexing
• The assignment expression for declaration of a
variable length array
• The postfix expression preceding square
brackets []
• Function arguments of type size_t or rsize_t
• In security-critical code
Integers – Unsigned integer
Wrap
Operat
or
Wrap Operat
or
Wrap Operat
or
Wrap Operat
or
Wrap
+ Yes -= Yes << Yes < No
- Yes *= Yes >> No > No
* Yes /= No & No >= No
/ No %= No | No <= No
% No <<= Yes ^ No == No
++ Yes >>= No ~ No != No
-- Yes &= No ! No && No
= No |= No un + No || No
+= Yes ^= No un - Yes ?: No
Unsigned integer operation
shouldn't wrap
Heap Buffer overflow in
Mozilla SVG
Multiplication of the signed int pen-
>num_vertices and the size_t value:
Heap Buffer overflow in
Mozilla SVG
Compliant solution:
Converting a pointer to
integer or integer to pointer
Do not convert a pointer type to an
integer type if the result cannot be
represented in the integer type
(undefined behavior)
Converting a pointer to
integer or integer to pointer
Compliant solution: any valid pointer to
void can be converted to intptr_t or
uintptr_t and back with no change in
value.
Null pointer dereferencing
(CWE-476)
std::string::c_str() is being called on a
temporary std::string object. The
resulting pointer will point to released
memory at the end of the assignment
expression. Result is undefined behavior
when accessing elements on that pointer
In the compliant solution, a local copy of
the string returned by str_func() is made
to ensure that string str will be valid
when the call display_string() is made.
null pointer dereferencing
The operand of the unary & operator shall be
either a function designator, the result of a [] or
unary * operator, or an lvalue that designates
an object that is not a bit-field and not declared
with the register storage-class specifier.
MS C++ Security Features
•/guard (Enable Control Flow Guard)
•/GS (Buffer Security Check)
•/SAFESEH (Image has Safe Exception
Handlers)
•/NXCOMPAT (Data execution prevention
support)
•/DYNAMICBASE (Use address space
layout randomization)(ASLR)
GCC & Clang Security
Features
Universal solution?
Toolbox
•External code analysis tools:
• PVS Studio
• Cpp-Check
• clang
•Windows application verifier
•Reversing:
• Radare2
• IDA Pro
Application Verifier
• Exceptions Stop Details - Ensures that applications do not hide access violations
using structured exception handling
• Handles Stop Details - Tests to ensure the application is not attempting to use invalid
handles
• Heaps Stop Details - Checks for memory corruptions issues in the heap
• Input/Output Stop Details - Monitors the execution of asynchronous IO, and
performs various validations
• Leak Stop Details - Detects leaks by tracking the resources made by a dll that are not
freed by the time the dll was unloaded
• Locks Stop Details - Verifies the correct usage for critical sections
• Memory Stop Details - Ensures APIs for virtual space manipulations are used
correctly (for example, VirtualAlloc, MapViewOfFile)
• TLS Stop Details - Ensures that Thread Local Storage APIs are used correctly
• Threadpool Stop Details - Ensures correct usage of threadpool APIs and enforces
consistency checks on worker-thread-states after a callback
References - Double Agent
• Attacking Antivirus & Next Generation Antivirus – Taking full control of
any antivirus by injecting code into it while bypassing all of its self-
protection mechanism. The attack has been verified and works on all
the major antiviruses including but not limited to: Avast, AVG, Avira,
Bitdefender, Comodo, ESET, F-Secure, Kaspersky, Malwarebytes,
McAfee, Norton, Panda, Quick Heal and Trend Micro.
• Installing Persistent Malware – Installing malware that can “survive”
reboots and are automatically executed once the operating system
boots.
• Hijacking Permissions – Hijacking the permissions of an existing trusted
process to perform malicious operations in disguise of the trusted
process. e.g. Exfiltrating data, C&C communication, lateral movement,
stealing and encrypting sensitive data.
• Altering Process Behavior – Modifying the behavior of the process. e.g.
Installing backdoors, weakening encryption algorithms, etc.
• Attacking Other Users/Sessions – Injecting code to processes of other
users/sessions (SYSTEM/Admin/etc.).
Application Verifier -
Double Agent
Zero-Day Code Injection and Persistence
Technique
https://cybellum.com/doubleagentzero-
day-code-injection-and-persistence-
technique/
References
SEI CERT C++ Coding Standard
https://www.securecoding.cert.org
References
Secure Programming Cookbook for C and
C++ Recipes for Cryptography,
Authentication, Input Validation & More
By John Viega, Matt Messier
References
Secure Coding in C and C++ (2nd Edition)
(SEI Series in Software Engineering) 2nd
Edition by Robert C. Seacord
You can avoid all this pain
Ask this guy how to do it
Mykhailo Zarai "Be careful when dealing with C++" at Rivne IT Talks

Contenu connexe

Tendances

CNIT 126 5: IDA Pro
CNIT 126 5: IDA Pro CNIT 126 5: IDA Pro
CNIT 126 5: IDA Pro Sam Bowne
 
CNIT 126 5: IDA Pro
CNIT 126 5: IDA ProCNIT 126 5: IDA Pro
CNIT 126 5: IDA ProSam Bowne
 
Practical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA ProPractical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA ProSam Bowne
 
An Introduction to ANTLR
An Introduction to ANTLRAn Introduction to ANTLR
An Introduction to ANTLRMorteza Zakeri
 
Whats new in .NET for 2019
Whats new in .NET for 2019Whats new in .NET for 2019
Whats new in .NET for 2019Rory Preddy
 
CNIT 126: 13: Data Encoding
CNIT 126: 13: Data EncodingCNIT 126: 13: Data Encoding
CNIT 126: 13: Data EncodingSam Bowne
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & LoopsAkhil Kaushik
 
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly Sam Bowne
 
Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019Christian Nagel
 
CNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you BeginCNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you BeginSam Bowne
 
CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)
CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)
CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)Sam Bowne
 
CNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: ShellcodeCNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: ShellcodeSam Bowne
 
CNIT 127 Ch Ch 1: Before you Begin
CNIT 127 Ch Ch 1: Before you BeginCNIT 127 Ch Ch 1: Before you Begin
CNIT 127 Ch Ch 1: Before you BeginSam Bowne
 
Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)
Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)
Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)Bhasker Kode
 
CNIT 126 4: A Crash Course in x86 Disassembly
CNIT 126 4: A Crash Course in x86 DisassemblyCNIT 126 4: A Crash Course in x86 Disassembly
CNIT 126 4: A Crash Course in x86 DisassemblySam Bowne
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity CalculationAkhil Kaushik
 
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)Binary Studio
 
C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)Christian Nagel
 
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)Sam Bowne
 

Tendances (20)

CNIT 126 5: IDA Pro
CNIT 126 5: IDA Pro CNIT 126 5: IDA Pro
CNIT 126 5: IDA Pro
 
CNIT 126 5: IDA Pro
CNIT 126 5: IDA ProCNIT 126 5: IDA Pro
CNIT 126 5: IDA Pro
 
Practical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA ProPractical Malware Analysis: Ch 5: IDA Pro
Practical Malware Analysis: Ch 5: IDA Pro
 
An Introduction to ANTLR
An Introduction to ANTLRAn Introduction to ANTLR
An Introduction to ANTLR
 
Whats new in .NET for 2019
Whats new in .NET for 2019Whats new in .NET for 2019
Whats new in .NET for 2019
 
CNIT 126: 13: Data Encoding
CNIT 126: 13: Data EncodingCNIT 126: 13: Data Encoding
CNIT 126: 13: Data Encoding
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & Loops
 
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly
Practical Malware Analysis: Ch 4 A Crash Course in x86 Disassembly
 
Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019Reference Semantik mit C# und .NET Core - BASTA 2019
Reference Semantik mit C# und .NET Core - BASTA 2019
 
CNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you BeginCNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you Begin
 
CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)
CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)
CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)
 
CNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: ShellcodeCNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: Shellcode
 
CNIT 127 Ch Ch 1: Before you Begin
CNIT 127 Ch Ch 1: Before you BeginCNIT 127 Ch Ch 1: Before you Begin
CNIT 127 Ch Ch 1: Before you Begin
 
Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)
Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)
Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)
 
CNIT 126 4: A Crash Course in x86 Disassembly
CNIT 126 4: A Crash Course in x86 DisassemblyCNIT 126 4: A Crash Course in x86 Disassembly
CNIT 126 4: A Crash Course in x86 Disassembly
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity Calculation
 
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 1)
 
C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)C# What's next? (7.x and 8.0)
C# What's next? (7.x and 8.0)
 
Finalproj
FinalprojFinalproj
Finalproj
 
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
 

En vedette (12)

Equivalence partinioning and boundary value analysis
Equivalence partinioning and boundary value analysisEquivalence partinioning and boundary value analysis
Equivalence partinioning and boundary value analysis
 
verification and validation
verification and validationverification and validation
verification and validation
 
Presentation
PresentationPresentation
Presentation
 
Boundary value analysis
Boundary value analysisBoundary value analysis
Boundary value analysis
 
Test management
Test managementTest management
Test management
 
Verification & Validation
Verification & ValidationVerification & Validation
Verification & Validation
 
Software design
Software designSoftware design
Software design
 
liquid crystal display
liquid crystal displayliquid crystal display
liquid crystal display
 
Design concepts and principles
Design concepts and principlesDesign concepts and principles
Design concepts and principles
 
Test techniques
Test techniquesTest techniques
Test techniques
 
Black & White Box testing
Black & White Box testingBlack & White Box testing
Black & White Box testing
 
Whitebox testing
Whitebox testingWhitebox testing
Whitebox testing
 

Similaire à Mykhailo Zarai "Be careful when dealing with C++" at Rivne IT Talks

Getting started with RISC-V verification what's next after compliance testing
Getting started with RISC-V verification what's next after compliance testingGetting started with RISC-V verification what's next after compliance testing
Getting started with RISC-V verification what's next after compliance testingRISC-V International
 
Secure Coding Practices for Middleware
Secure Coding Practices for MiddlewareSecure Coding Practices for Middleware
Secure Coding Practices for MiddlewareManuel Brugnoli
 
Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1Cysinfo Cyber Security Community
 
running stable diffusion on android
running stable diffusion on androidrunning stable diffusion on android
running stable diffusion on androidKoan-Sin Tan
 
RIoT (Raiding Internet of Things) by Jacob Holcomb
RIoT  (Raiding Internet of Things)  by Jacob HolcombRIoT  (Raiding Internet of Things)  by Jacob Holcomb
RIoT (Raiding Internet of Things) by Jacob HolcombPriyanka Aash
 
The Hacking Games - Operation System Vulnerabilities Meetup 29112022
The Hacking Games - Operation System Vulnerabilities Meetup 29112022The Hacking Games - Operation System Vulnerabilities Meetup 29112022
The Hacking Games - Operation System Vulnerabilities Meetup 29112022lior mazor
 
Search for Vulnerabilities Using Static Code Analysis
Search for Vulnerabilities Using Static Code AnalysisSearch for Vulnerabilities Using Static Code Analysis
Search for Vulnerabilities Using Static Code AnalysisAndrey Karpov
 
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1  Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1 securityxploded
 
Typhoon Managed Execution Toolkit
Typhoon Managed Execution ToolkitTyphoon Managed Execution Toolkit
Typhoon Managed Execution ToolkitDimitry Snezhkov
 
Java platform
Java platformJava platform
Java platformVisithan
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...Sang Don Kim
 
Deep Dive Time Series Anomaly Detection in Azure with dotnet
Deep Dive Time Series Anomaly Detection in Azure with dotnetDeep Dive Time Series Anomaly Detection in Azure with dotnet
Deep Dive Time Series Anomaly Detection in Azure with dotnetMarco Parenzan
 
Using Static Binary Analysis To Find Vulnerabilities And Backdoors in Firmware
Using Static Binary Analysis To Find Vulnerabilities And Backdoors in FirmwareUsing Static Binary Analysis To Find Vulnerabilities And Backdoors in Firmware
Using Static Binary Analysis To Find Vulnerabilities And Backdoors in FirmwareLastline, Inc.
 
Code Analysis-run time error prediction
Code Analysis-run time error predictionCode Analysis-run time error prediction
Code Analysis-run time error predictionNIKHIL NAWATHE
 
SAST, CWE, SEI CERT and other smart words from the information security world
SAST, CWE, SEI CERT and other smart words from the information security worldSAST, CWE, SEI CERT and other smart words from the information security world
SAST, CWE, SEI CERT and other smart words from the information security worldAndrey Karpov
 
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017Andrey Karpov
 

Similaire à Mykhailo Zarai "Be careful when dealing with C++" at Rivne IT Talks (20)

CodeChecker Overview Nov 2019
CodeChecker Overview Nov 2019CodeChecker Overview Nov 2019
CodeChecker Overview Nov 2019
 
Getting started with RISC-V verification what's next after compliance testing
Getting started with RISC-V verification what's next after compliance testingGetting started with RISC-V verification what's next after compliance testing
Getting started with RISC-V verification what's next after compliance testing
 
Secure Coding Practices for Middleware
Secure Coding Practices for MiddlewareSecure Coding Practices for Middleware
Secure Coding Practices for Middleware
 
Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1
 
running stable diffusion on android
running stable diffusion on androidrunning stable diffusion on android
running stable diffusion on android
 
RIoT (Raiding Internet of Things) by Jacob Holcomb
RIoT  (Raiding Internet of Things)  by Jacob HolcombRIoT  (Raiding Internet of Things)  by Jacob Holcomb
RIoT (Raiding Internet of Things) by Jacob Holcomb
 
The Hacking Games - Operation System Vulnerabilities Meetup 29112022
The Hacking Games - Operation System Vulnerabilities Meetup 29112022The Hacking Games - Operation System Vulnerabilities Meetup 29112022
The Hacking Games - Operation System Vulnerabilities Meetup 29112022
 
Search for Vulnerabilities Using Static Code Analysis
Search for Vulnerabilities Using Static Code AnalysisSearch for Vulnerabilities Using Static Code Analysis
Search for Vulnerabilities Using Static Code Analysis
 
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1  Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
 
CodeChecker summary 21062021
CodeChecker summary 21062021CodeChecker summary 21062021
CodeChecker summary 21062021
 
Typhoon Managed Execution Toolkit
Typhoon Managed Execution ToolkitTyphoon Managed Execution Toolkit
Typhoon Managed Execution Toolkit
 
Java platform
Java platformJava platform
Java platform
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
 
Deep Dive Time Series Anomaly Detection in Azure with dotnet
Deep Dive Time Series Anomaly Detection in Azure with dotnetDeep Dive Time Series Anomaly Detection in Azure with dotnet
Deep Dive Time Series Anomaly Detection in Azure with dotnet
 
Using Static Binary Analysis To Find Vulnerabilities And Backdoors in Firmware
Using Static Binary Analysis To Find Vulnerabilities And Backdoors in FirmwareUsing Static Binary Analysis To Find Vulnerabilities And Backdoors in Firmware
Using Static Binary Analysis To Find Vulnerabilities And Backdoors in Firmware
 
embedded C.pptx
embedded C.pptxembedded C.pptx
embedded C.pptx
 
Code Analysis-run time error prediction
Code Analysis-run time error predictionCode Analysis-run time error prediction
Code Analysis-run time error prediction
 
Aspdot
AspdotAspdot
Aspdot
 
SAST, CWE, SEI CERT and other smart words from the information security world
SAST, CWE, SEI CERT and other smart words from the information security worldSAST, CWE, SEI CERT and other smart words from the information security world
SAST, CWE, SEI CERT and other smart words from the information security world
 
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
 

Plus de Vadym Muliavka

Roman Valchuk "Introducing to DevOps technologies"
Roman Valchuk "Introducing to DevOps technologies"Roman Valchuk "Introducing to DevOps technologies"
Roman Valchuk "Introducing to DevOps technologies"Vadym Muliavka
 
IT Talks "VR Tips for Engineers and Developers"
IT Talks "VR Tips for Engineers and Developers"IT Talks "VR Tips for Engineers and Developers"
IT Talks "VR Tips for Engineers and Developers"Vadym Muliavka
 
Rivne IT Talks How to programa Quantum Computer?
Rivne IT Talks How to programa Quantum Computer?Rivne IT Talks How to programa Quantum Computer?
Rivne IT Talks How to programa Quantum Computer?Vadym Muliavka
 
IT Talks The approach for solving impossible tasks (dynamic programming)
IT Talks The approach for solving impossible tasks (dynamic programming)IT Talks The approach for solving impossible tasks (dynamic programming)
IT Talks The approach for solving impossible tasks (dynamic programming)Vadym Muliavka
 
IT Talks The c++'s simplest smart pointers in depth
IT Talks The c++'s simplest smart pointers in depthIT Talks The c++'s simplest smart pointers in depth
IT Talks The c++'s simplest smart pointers in depthVadym Muliavka
 
Bug reporting and tracking
Bug reporting and trackingBug reporting and tracking
Bug reporting and trackingVadym Muliavka
 
Equivalence partitions analysis
Equivalence partitions analysisEquivalence partitions analysis
Equivalence partitions analysisVadym Muliavka
 
IT Talks Автоматизація тестування з допомогою Selenium
IT Talks Автоматизація тестування з допомогою SeleniumIT Talks Автоматизація тестування з допомогою Selenium
IT Talks Автоматизація тестування з допомогою SeleniumVadym Muliavka
 
IT Talks Тестування та аналіз вимог
IT Talks Тестування та аналіз вимогIT Talks Тестування та аналіз вимог
IT Talks Тестування та аналіз вимогVadym Muliavka
 
IT Talks QA - якість процесів розробки
IT Talks QA - якість процесів розробкиIT Talks QA - якість процесів розробки
IT Talks QA - якість процесів розробкиVadym Muliavka
 

Plus de Vadym Muliavka (10)

Roman Valchuk "Introducing to DevOps technologies"
Roman Valchuk "Introducing to DevOps technologies"Roman Valchuk "Introducing to DevOps technologies"
Roman Valchuk "Introducing to DevOps technologies"
 
IT Talks "VR Tips for Engineers and Developers"
IT Talks "VR Tips for Engineers and Developers"IT Talks "VR Tips for Engineers and Developers"
IT Talks "VR Tips for Engineers and Developers"
 
Rivne IT Talks How to programa Quantum Computer?
Rivne IT Talks How to programa Quantum Computer?Rivne IT Talks How to programa Quantum Computer?
Rivne IT Talks How to programa Quantum Computer?
 
IT Talks The approach for solving impossible tasks (dynamic programming)
IT Talks The approach for solving impossible tasks (dynamic programming)IT Talks The approach for solving impossible tasks (dynamic programming)
IT Talks The approach for solving impossible tasks (dynamic programming)
 
IT Talks The c++'s simplest smart pointers in depth
IT Talks The c++'s simplest smart pointers in depthIT Talks The c++'s simplest smart pointers in depth
IT Talks The c++'s simplest smart pointers in depth
 
Bug reporting and tracking
Bug reporting and trackingBug reporting and tracking
Bug reporting and tracking
 
Equivalence partitions analysis
Equivalence partitions analysisEquivalence partitions analysis
Equivalence partitions analysis
 
IT Talks Автоматизація тестування з допомогою Selenium
IT Talks Автоматизація тестування з допомогою SeleniumIT Talks Автоматизація тестування з допомогою Selenium
IT Talks Автоматизація тестування з допомогою Selenium
 
IT Talks Тестування та аналіз вимог
IT Talks Тестування та аналіз вимогIT Talks Тестування та аналіз вимог
IT Talks Тестування та аналіз вимог
 
IT Talks QA - якість процесів розробки
IT Talks QA - якість процесів розробкиIT Talks QA - якість процесів розробки
IT Talks QA - якість процесів розробки
 

Dernier

Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfRagavanV2
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...soginsider
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf203318pmpc
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 

Dernier (20)

Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 

Mykhailo Zarai "Be careful when dealing with C++" at Rivne IT Talks

  • 1. Be careful when dealing with C/C++ Think Twice, Code Once Mykhailo Zarai (April 2017)
  • 2. Why do we care? Almost every day we hear about : •vulnerabilities •data breech
  • 3. Vulnerabilities examples •Windows Remote Code execution (MS15-115) •NDIS Privilege of Elevation (MS15-17) •Kernel-Mode Drivers Privilege (MS15-135)
  • 4. Data breach 2016 •Apple Health Medicaid •Central Coast Credit Union •Commission on Elections •Department of Homeland Security
  • 5. What we are going to do? •Talk about secure programming •Programming toolbox •Some references and recommendations
  • 6. Common Vulnerabilities •Buffer overflow •Integers •Null pointer dereferencing Homework: •Strings •Arrays •Exceptions
  • 7. Look inside buffer overflow problem
  • 8. Return Address ESP - Extended Stack Pointer (topo) Parent Routine Stack EBP - Extended Base Pointer (base) Char *bar Char c[12] StackGrowth MemoryAddresses The data is put on reverse order onto buffer
  • 9. Return Address ESP - Extended Stack Pointer (topo) Parent Routine Stack EBP - Extended Base Pointer (base) Char *bar Char c[12] StackGrowth MemoryAddresses H E L L O H E L L O H E L L O H E L L O H E L L O BOOM! Buffer Overflow! H E L L O
  • 10. Return Address ESP - Extended Stack Pointer (topo) Parent Routine Stack EBP - Extended Base Pointer (base) Char *bar Char c[12] StackGrowth MemoryAddresses Canary Word
  • 11. Integers – Unsigned integer Wrap Must not be allowed to wrap: • Integer operands of any point arithmetic and array indexing • The assignment expression for declaration of a variable length array • The postfix expression preceding square brackets [] • Function arguments of type size_t or rsize_t • In security-critical code
  • 12. Integers – Unsigned integer Wrap Operat or Wrap Operat or Wrap Operat or Wrap Operat or Wrap + Yes -= Yes << Yes < No - Yes *= Yes >> No > No * Yes /= No & No >= No / No %= No | No <= No % No <<= Yes ^ No == No ++ Yes >>= No ~ No != No -- Yes &= No ! No && No = No |= No un + No || No += Yes ^= No un - Yes ?: No
  • 14. Heap Buffer overflow in Mozilla SVG Multiplication of the signed int pen- >num_vertices and the size_t value:
  • 15. Heap Buffer overflow in Mozilla SVG Compliant solution:
  • 16. Converting a pointer to integer or integer to pointer Do not convert a pointer type to an integer type if the result cannot be represented in the integer type (undefined behavior)
  • 17. Converting a pointer to integer or integer to pointer Compliant solution: any valid pointer to void can be converted to intptr_t or uintptr_t and back with no change in value.
  • 19. std::string::c_str() is being called on a temporary std::string object. The resulting pointer will point to released memory at the end of the assignment expression. Result is undefined behavior when accessing elements on that pointer
  • 20. In the compliant solution, a local copy of the string returned by str_func() is made to ensure that string str will be valid when the call display_string() is made.
  • 21. null pointer dereferencing The operand of the unary & operator shall be either a function designator, the result of a [] or unary * operator, or an lvalue that designates an object that is not a bit-field and not declared with the register storage-class specifier.
  • 22. MS C++ Security Features •/guard (Enable Control Flow Guard) •/GS (Buffer Security Check) •/SAFESEH (Image has Safe Exception Handlers) •/NXCOMPAT (Data execution prevention support) •/DYNAMICBASE (Use address space layout randomization)(ASLR)
  • 23. GCC & Clang Security Features
  • 25. Toolbox •External code analysis tools: • PVS Studio • Cpp-Check • clang •Windows application verifier •Reversing: • Radare2 • IDA Pro
  • 26. Application Verifier • Exceptions Stop Details - Ensures that applications do not hide access violations using structured exception handling • Handles Stop Details - Tests to ensure the application is not attempting to use invalid handles • Heaps Stop Details - Checks for memory corruptions issues in the heap • Input/Output Stop Details - Monitors the execution of asynchronous IO, and performs various validations • Leak Stop Details - Detects leaks by tracking the resources made by a dll that are not freed by the time the dll was unloaded • Locks Stop Details - Verifies the correct usage for critical sections • Memory Stop Details - Ensures APIs for virtual space manipulations are used correctly (for example, VirtualAlloc, MapViewOfFile) • TLS Stop Details - Ensures that Thread Local Storage APIs are used correctly • Threadpool Stop Details - Ensures correct usage of threadpool APIs and enforces consistency checks on worker-thread-states after a callback
  • 27. References - Double Agent • Attacking Antivirus & Next Generation Antivirus – Taking full control of any antivirus by injecting code into it while bypassing all of its self- protection mechanism. The attack has been verified and works on all the major antiviruses including but not limited to: Avast, AVG, Avira, Bitdefender, Comodo, ESET, F-Secure, Kaspersky, Malwarebytes, McAfee, Norton, Panda, Quick Heal and Trend Micro. • Installing Persistent Malware – Installing malware that can “survive” reboots and are automatically executed once the operating system boots. • Hijacking Permissions – Hijacking the permissions of an existing trusted process to perform malicious operations in disguise of the trusted process. e.g. Exfiltrating data, C&C communication, lateral movement, stealing and encrypting sensitive data. • Altering Process Behavior – Modifying the behavior of the process. e.g. Installing backdoors, weakening encryption algorithms, etc. • Attacking Other Users/Sessions – Injecting code to processes of other users/sessions (SYSTEM/Admin/etc.).
  • 28. Application Verifier - Double Agent Zero-Day Code Injection and Persistence Technique https://cybellum.com/doubleagentzero- day-code-injection-and-persistence- technique/
  • 29. References SEI CERT C++ Coding Standard https://www.securecoding.cert.org
  • 30. References Secure Programming Cookbook for C and C++ Recipes for Cryptography, Authentication, Input Validation & More By John Viega, Matt Messier
  • 31. References Secure Coding in C and C++ (2nd Edition) (SEI Series in Software Engineering) 2nd Edition by Robert C. Seacord
  • 32. You can avoid all this pain Ask this guy how to do it