SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Mais procurados (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)
 

Destaque (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
 

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

CodeChecker Overview Nov 2019
CodeChecker Overview Nov 2019CodeChecker Overview Nov 2019
CodeChecker Overview Nov 2019
Olivera Milenkovic
 
Secure Coding Practices for Middleware
Secure Coding Practices for MiddlewareSecure Coding Practices for Middleware
Secure Coding Practices for Middleware
Manuel Brugnoli
 
[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
 
Code Analysis-run time error prediction
Code Analysis-run time error predictionCode Analysis-run time error prediction
Code Analysis-run time error prediction
NIKHIL NAWATHE
 

Semelhante a 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
 

Mais de Vadym Muliavka

Mais 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 - якість процесів розробки
 

Último

"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
Health
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Último (20)

Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
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
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
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...
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
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
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 

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