SlideShare ist ein Scribd-Unternehmen logo
1 von 5
Downloaden Sie, um offline zu lesen
PVS-Studio Static Analyzer as a Tool for
Protection against Zero-Day Vulnerabilities
Author: Ekaterina Nikiforova
Date: 28.11.2019
Tags: StaticAnalysis, Security
A Zero-day (0-day) vulnerability is a computer-software vulnerability introduced during the development
process and not yet discovered by the developers. Zero-day vulnerabilities can be exploited by hackers,
thus affecting the company's reputation. Developers should seek to minimize the number of defects
leading to such vulnerabilities. PVS-Studio, a static code analyzer for C, C++, C#, and Java code, is one of
the tools capable of detecting security issues.
Zero-day vulnerabilities
A Zero-day vulnerability (also known as 0-day vulnerability) is a computer-software vulnerability that is
unknown to, or unaddressed by, those who should be interested in mitigating the vulnerability
(including the vendor of the target software). Until the vulnerability is mitigated, hackers can exploit it
to adversely affect computer programs, data, additional computers or a network. The term means the
developers don't have a single day to fix the defect because no one knows about it yet. Some of the
well-known vendors and software products such as Adobe, Windows, Tor browser, and many others,
were affected by zero-day vulnerabilities in the past.
Some were lucky to have a vulnerability found and reported by people who were not going to exploit it.
The case of MacOS is one such example. In some other cases, the developers themselves produced a
patch with which, while adding new features, they also fixed a zero-day vulnerability without knowing it.
Others were less lucky though. For instance, not so long ago, Google Chrome had to urgently fix a
vulnerability that could be exploited to remotely execute arbitrary code.
The problem is you can't guarantee 100% protection against these vulnerabilities as you can't effectively
fight a threat you don't even know of. However, there are ways to make such defects less likely to occur
in your program – this will be the topic of this article, but we should take a look at some theory first.
Static analysis
Static analysis is a method of checking the source code of a software program using an analyzer without
executing the program itself and can be viewed as automated code review. Sometimes static analysis
can be much more effective than peer code review but can't completely replace it. I tried to summarize
the pros and cons of code review and static analysis relative to each other in the following table:
Code review Static analysis
Helps find not only trivial but also high-level bugs Helps find unfamiliar defects or vulnerabilities
Helps improve the program's architecture and
work out a consistent coding style
Helps find bugs not easily noticeable to the
human eye (e.g. typos)
Expensive Cheaper than code review
Takes up a lot of programmers' time. Breaks are
necessary as the reviewer's attention tends to
weaken quickly
False positives are unavoidable; the user has to
customize the analyzer
CVE and CWE
Common Vulnerabilities and Exposures (CVE) is a database of information-security vulnerabilities and
exposures. Its initial purpose was to organize known software defects into a coherent list. In the past,
most information-security tools were using their own databases and names for such defects, and it was
to bring order to that chaos and establish compatibility between different tools that the MITRE
Corporation developed CVE in 1999. However, CVE turned out to be insufficient for estimating code
security. Some other system was needed, with finer classification and more detailed descriptions. That's
how the Common Weakness Enumeration (CWE) came into existence. If a defect is listed in the CWE, it
may cause an exploitable vulnerability and get added to the CVE list as well. The Euler diagram below
shows the relations between the standards.
Some static analyzers can inform you if, for example, your project employs a library containing a
vulnerability. Knowing this, you can download a newer version of the library, with the defect fixed, to
make your code less susceptible to security threats caused by a mistake in someone else's code.
As the CVE and CWE standards were embraced by the developer community, they were also supported
by many information-security tools including static analyzers. Analyzers that support these
classifications can be viewed as SAST solutions. SAST (Static Application Security Testing) allows
developers to detect vulnerabilities in the source code of programs at the earliest stages of the software
development life cycle.
SAST is yet another practice to minimize the probability of zero-day vulnerabilities occurring in your
project. An analyzer supporting the CWE standard can tell you where a potential vulnerability is lurking
so that you could fix it to make your application more reliable and less likely to contain a 0-day threat.
There is a variety of SAST tools. I'll take the PVS-Studio analyzer as an example to show how these tools
can help fight vulnerabilities. Warnings of this analyzer are classified as CWE. Some examples are given
below.
PVS-Studio diagnostic message: CWE-561: Dead Code (V3021).
public string EncodeImage(....)
{
if (string.IsNullOrWhiteSpace(inputPath))
{
throw new ArgumentNullException("inputPath");
}
if (string.IsNullOrWhiteSpace(inputPath))
{
throw new ArgumentNullException("outputPath");
}
....
}
This code contains a typo: the conditions of both if statements check the same variable. The message
accompanying the exception suggests that the second condition should check the outputPath variable
instead. This mistake has made some part of the code unreachable.
Bugs like that might seem harmless, but this impression is wrong. Let's take a look at another trivial and
seemingly harmless bug that has to do with a duplicate goto statement.
This bug once caused a vulnerability in iOS.
The CVE-2014-1266 vulnerability: The SSLVerifySignedServerKeyExchange function in
libsecurity_ssl/lib/sslKeyExchange.c in the Secure Transport feature in the Data Security component in
Apple iOS 6.x before 6.1.6 and 7.x before 7.0.6, Apple TV 6.x before 6.0.2, and Apple OS X 10.9.x before
10.9.2 does not check the signature in a TLS Server Key Exchange message, which allows man-in-the-
middle attackers to spoof SSL servers by using an arbitrary private key for the signing step or omitting
the signing step.
static OSStatus
SSLVerifySignedServerKeyExchange(SSLContext *ctx,
bool isRsa,
SSLBuffer signedParams,
uint8_t *signature,
UInt16 signatureLen)
{
OSStatus err;
....
if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0)
goto fail;
if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
goto fail;
goto fail;
if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0)
goto fail;
....
fail:
SSLFreeBuffer(&signedHashes);
SSLFreeBuffer(&hashCtx);
return err;
}
Like in the first example, the duplicate goto here led to unreachable code: whatever the conditions of
the if statements, the second goto statement would be executed anyway. As a result, the signature
wouldn't be checked, the function would return 0, meaning the signature was OK, and the program
would receive a key from the server even if the signature check failed. This key is used to encrypt the
data being transmitted.
This trivial bug had drastic implications. The incident illustrates why there's no point speculating if this
or that CWE defect is dangerous or not – you just have to fix it for the sake of your code's safety.
By the way, PVS-Studio could have easily found this bug, reporting it with two CWE warnings at once:
• CWE-561 (V779): Dead Code
• CWE-483 (V640): Incorrect Block Delimitation
Here's another example. Long ago, in 2012, a security issue was discovered in MySQL, which could be
exploited by an attacker to enter the MySQL database. Below you will see the flawed code fragment,
where the vulnerability occurred.
The CVE-2012-2122 vulnerability: sql/password.c in Oracle MySQL 5.1.x before 5.1.63, 5.5.x before
5.5.24, and 5.6.x before 5.6.6, and MariaDB 5.1.x before 5.1.62, 5.2.x before 5.2.12, 5.3.x before 5.3.6,
and 5.5.x before 5.5.23, when running in certain environments with certain implementations of the
memcmp function, allows remote attackers to bypass authentication by repeatedly authenticating with
the same incorrect password, which eventually causes a token comparison to succeed due to an
improperly-checked return value.
typedef char my_bool;
my_bool
check_scramble(const char *scramble_arg, const char *message,
const uint8 *hash_stage2)
{
....
return memcmp(hash_stage2, hash_stage2_reassured, SHA1_HASH_SIZE);
}
The memcmp function returns a value of type int, while the check_scramble function returns a value of
type my_bool, which is in fact char. The int value gets implicitly cast to char, with the most significant
bits truncated. This caused about 1 out of 256 attempts to log in with an arbitrary password for a known
username to succeed.
Again, this CWE defect could have been neutralized and prevented from becoming a CVE vulnerability
much earlier, at the coding stage. For example, PVS-Studio reports it as CWE-197 (V642): Numeric
Truncation Error.
See the article "How Can PVS-Studio Help in the Detection of Vulnerabilities?" for further reading on the
topic.
Conclusion
You can't be 100% sure your program is safe from 0-day vulnerabilities. But you can still make them
much less likely to occur. This is done by using specialized SAST tools such as PVS-Studio. If your project
is found to contain defects classified as CWE issues, make sure to fix them. Even though few of CWE
defects end up on the CVE list, fixing them helps to secure your program from many potential threats.
References
1. Download and evaluate PVS-Studio
2. Technologies used in the PVS-Studio code analyzer for finding bugs and potential vulnerabilities
3. Classification of PVS-Studio warnings according to the Common Weakness Enumeration (CWE)
4. Classification of PVS-Studio warnings according to the SEI CERT Coding Standard

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

A Boring Article About a Check of the OpenSSL Project
A Boring Article About a Check of the OpenSSL ProjectA Boring Article About a Check of the OpenSSL Project
A Boring Article About a Check of the OpenSSL Project
 
New Year PVS-Studio 6.00 Release: Scanning Roslyn
New Year PVS-Studio 6.00 Release: Scanning RoslynNew Year PVS-Studio 6.00 Release: Scanning Roslyn
New Year PVS-Studio 6.00 Release: Scanning Roslyn
 
Hacking ingress
Hacking ingressHacking ingress
Hacking ingress
 
Crash Analysis with Reverse Taint
Crash Analysis with Reverse TaintCrash Analysis with Reverse Taint
Crash Analysis with Reverse Taint
 
TestDrivenDeveloment
TestDrivenDevelomentTestDrivenDeveloment
TestDrivenDeveloment
 
17726 bypassing-phpids-0.6.5
17726 bypassing-phpids-0.6.517726 bypassing-phpids-0.6.5
17726 bypassing-phpids-0.6.5
 
Exception handling
Exception handlingException handling
Exception handling
 
Production Debugging at Code Camp Philly
Production Debugging at Code Camp PhillyProduction Debugging at Code Camp Philly
Production Debugging at Code Camp Philly
 
Selenium interview-questions-freshers
Selenium interview-questions-freshersSelenium interview-questions-freshers
Selenium interview-questions-freshers
 
Java code coverage with JCov. Implementation details and use cases.
Java code coverage with JCov. Implementation details and use cases.Java code coverage with JCov. Implementation details and use cases.
Java code coverage with JCov. Implementation details and use cases.
 
PVS-Studio for Visual C++
PVS-Studio for Visual C++PVS-Studio for Visual C++
PVS-Studio for Visual C++
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
 
Selenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersSelenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And Answers
 
Junit and cactus
Junit and cactusJunit and cactus
Junit and cactus
 
Asynchronyin net
Asynchronyin netAsynchronyin net
Asynchronyin net
 
Popular Approaches to Preventing Code Injection Attacks are Dangerously Wrong
Popular Approaches to Preventing Code Injection Attacks are Dangerously WrongPopular Approaches to Preventing Code Injection Attacks are Dangerously Wrong
Popular Approaches to Preventing Code Injection Attacks are Dangerously Wrong
 
Top trending selenium interview questions
Top trending selenium interview questionsTop trending selenium interview questions
Top trending selenium interview questions
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
How PVS-Studio does the bug search: methods and technologies
How PVS-Studio does the bug search: methods and technologiesHow PVS-Studio does the bug search: methods and technologies
How PVS-Studio does the bug search: methods and technologies
 
Effectiveness of AV in Detecting Web Application Backdoors
Effectiveness of AV in Detecting Web Application BackdoorsEffectiveness of AV in Detecting Web Application Backdoors
Effectiveness of AV in Detecting Web Application Backdoors
 

Ähnlich wie PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerabilities

Ähnlich wie PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerabilities (20)

How Can PVS-Studio Help in the Detection of Vulnerabilities?
How Can PVS-Studio Help in the Detection of Vulnerabilities?How Can PVS-Studio Help in the Detection of Vulnerabilities?
How Can PVS-Studio Help in the Detection of Vulnerabilities?
 
What's the Difference Between Static Analysis and Compiler Warnings?
What's the Difference Between Static Analysis and Compiler Warnings?What's the Difference Between Static Analysis and Compiler Warnings?
What's the Difference Between Static Analysis and Compiler Warnings?
 
PVS-Studio advertisement - static analysis of C/C++ code
PVS-Studio advertisement - static analysis of C/C++ codePVS-Studio advertisement - static analysis of C/C++ code
PVS-Studio advertisement - static analysis of C/C++ code
 
Static Analysis: From Getting Started to Integration
Static Analysis: From Getting Started to IntegrationStatic Analysis: From Getting Started to Integration
Static Analysis: From Getting Started to Integration
 
We continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShellWe continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShell
 
Secure coding-guidelines
Secure coding-guidelinesSecure coding-guidelines
Secure coding-guidelines
 
An Ideal Way to Integrate a Static Code Analyzer into a Project
An Ideal Way to Integrate a Static Code Analyzer into a ProjectAn Ideal Way to Integrate a Static Code Analyzer into a Project
An Ideal Way to Integrate a Static Code Analyzer into a Project
 
HPX and PVS-Studio
HPX and PVS-StudioHPX and PVS-Studio
HPX and PVS-Studio
 
nullcon 2011 - Reversing MicroSoft patches to reveal vulnerable code
nullcon 2011 - Reversing MicroSoft patches to reveal vulnerable codenullcon 2011 - Reversing MicroSoft patches to reveal vulnerable code
nullcon 2011 - Reversing MicroSoft patches to reveal vulnerable code
 
Generic attack detection engine
Generic attack detection engineGeneric attack detection engine
Generic attack detection engine
 
Difficulties of comparing code analyzers, or don't forget about usability
Difficulties of comparing code analyzers, or don't forget about usabilityDifficulties of comparing code analyzers, or don't forget about usability
Difficulties of comparing code analyzers, or don't forget about usability
 
Difficulties of comparing code analyzers, or don't forget about usability
Difficulties of comparing code analyzers, or don't forget about usabilityDifficulties of comparing code analyzers, or don't forget about usability
Difficulties of comparing code analyzers, or don't forget about usability
 
Difficulties of comparing code analyzers, or don't forget about usability
Difficulties of comparing code analyzers, or don't forget about usabilityDifficulties of comparing code analyzers, or don't forget about usability
Difficulties of comparing code analyzers, or don't forget about usability
 
VCCFinder: Finding Potential Vulnerabilities in Open-Source Projects to Assis...
VCCFinder: Finding Potential Vulnerabilities in Open-Source Projects to Assis...VCCFinder: Finding Potential Vulnerabilities in Open-Source Projects to Assis...
VCCFinder: Finding Potential Vulnerabilities in Open-Source Projects to Assis...
 
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
Microsoft opened the source code of Xamarin.Forms. We couldn't miss a chance ...
 
PVS-Studio advertisement - static analysis of C/C++ code
PVS-Studio advertisement - static analysis of C/C++ codePVS-Studio advertisement - static analysis of C/C++ code
PVS-Studio advertisement - static analysis of C/C++ code
 
Looking for Bugs in MonoDevelop
Looking for Bugs in MonoDevelopLooking for Bugs in MonoDevelop
Looking for Bugs in MonoDevelop
 
Accord.Net: Looking for a Bug that Could Help Machines Conquer Humankind
Accord.Net: Looking for a Bug that Could Help Machines Conquer HumankindAccord.Net: Looking for a Bug that Could Help Machines Conquer Humankind
Accord.Net: Looking for a Bug that Could Help Machines Conquer Humankind
 
Analysis of Godot Engine's Source Code
Analysis of Godot Engine's Source CodeAnalysis of Godot Engine's Source Code
Analysis of Godot Engine's Source Code
 
The Little Unicorn That Could
The Little Unicorn That CouldThe Little Unicorn That Could
The Little Unicorn That Could
 

Mehr von Andrey Karpov

Mehr von Andrey Karpov (20)

60 антипаттернов для С++ программиста
60 антипаттернов для С++ программиста60 антипаттернов для С++ программиста
60 антипаттернов для С++ программиста
 
60 terrible tips for a C++ developer
60 terrible tips for a C++ developer60 terrible tips for a C++ developer
60 terrible tips for a C++ developer
 
Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Ошибки, которые сложно заметить на code review, но которые находятся статичес...Ошибки, которые сложно заметить на code review, но которые находятся статичес...
Ошибки, которые сложно заметить на code review, но которые находятся статичес...
 
PVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesPVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error Examples
 
PVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature OverviewPVS-Studio in 2021 - Feature Overview
PVS-Studio in 2021 - Feature Overview
 
PVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибокPVS-Studio в 2021 - Примеры ошибок
PVS-Studio в 2021 - Примеры ошибок
 
PVS-Studio в 2021
PVS-Studio в 2021PVS-Studio в 2021
PVS-Studio в 2021
 
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
Make Your and Other Programmer’s Life Easier with Static Analysis (Unreal Eng...
 
Best Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' MistakesBest Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' Mistakes
 
Does static analysis need machine learning?
Does static analysis need machine learning?Does static analysis need machine learning?
Does static analysis need machine learning?
 
Typical errors in code on the example of C++, C#, and Java
Typical errors in code on the example of C++, C#, and JavaTypical errors in code on the example of C++, C#, and Java
Typical errors in code on the example of C++, C#, and Java
 
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
How to Fix Hundreds of Bugs in Legacy Code and Not Die (Unreal Engine 4)
 
Game Engine Code Quality: Is Everything Really That Bad?
Game Engine Code Quality: Is Everything Really That Bad?Game Engine Code Quality: Is Everything Really That Bad?
Game Engine Code Quality: Is Everything Really That Bad?
 
C++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical Reviewer
 
The Use of Static Code Analysis When Teaching or Developing Open-Source Software
The Use of Static Code Analysis When Teaching or Developing Open-Source SoftwareThe Use of Static Code Analysis When Teaching or Developing Open-Source Software
The Use of Static Code Analysis When Teaching or Developing Open-Source Software
 
Static Code Analysis for Projects, Built on Unreal Engine
Static Code Analysis for Projects, Built on Unreal EngineStatic Code Analysis for Projects, Built on Unreal Engine
Static Code Analysis for Projects, Built on Unreal Engine
 
Safety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
Safety on the Max: How to Write Reliable C/C++ Code for Embedded SystemsSafety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
Safety on the Max: How to Write Reliable C/C++ Code for Embedded Systems
 
The Great and Mighty C++
The Great and Mighty C++The Great and Mighty C++
The Great and Mighty C++
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?
 
Zero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for youZero, one, two, Freddy's coming for you
Zero, one, two, Freddy's coming for you
 

Kürzlich hochgeladen

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Kürzlich hochgeladen (20)

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 

PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerabilities

  • 1. PVS-Studio Static Analyzer as a Tool for Protection against Zero-Day Vulnerabilities Author: Ekaterina Nikiforova Date: 28.11.2019 Tags: StaticAnalysis, Security A Zero-day (0-day) vulnerability is a computer-software vulnerability introduced during the development process and not yet discovered by the developers. Zero-day vulnerabilities can be exploited by hackers, thus affecting the company's reputation. Developers should seek to minimize the number of defects leading to such vulnerabilities. PVS-Studio, a static code analyzer for C, C++, C#, and Java code, is one of the tools capable of detecting security issues. Zero-day vulnerabilities A Zero-day vulnerability (also known as 0-day vulnerability) is a computer-software vulnerability that is unknown to, or unaddressed by, those who should be interested in mitigating the vulnerability (including the vendor of the target software). Until the vulnerability is mitigated, hackers can exploit it to adversely affect computer programs, data, additional computers or a network. The term means the developers don't have a single day to fix the defect because no one knows about it yet. Some of the well-known vendors and software products such as Adobe, Windows, Tor browser, and many others, were affected by zero-day vulnerabilities in the past. Some were lucky to have a vulnerability found and reported by people who were not going to exploit it. The case of MacOS is one such example. In some other cases, the developers themselves produced a patch with which, while adding new features, they also fixed a zero-day vulnerability without knowing it.
  • 2. Others were less lucky though. For instance, not so long ago, Google Chrome had to urgently fix a vulnerability that could be exploited to remotely execute arbitrary code. The problem is you can't guarantee 100% protection against these vulnerabilities as you can't effectively fight a threat you don't even know of. However, there are ways to make such defects less likely to occur in your program – this will be the topic of this article, but we should take a look at some theory first. Static analysis Static analysis is a method of checking the source code of a software program using an analyzer without executing the program itself and can be viewed as automated code review. Sometimes static analysis can be much more effective than peer code review but can't completely replace it. I tried to summarize the pros and cons of code review and static analysis relative to each other in the following table: Code review Static analysis Helps find not only trivial but also high-level bugs Helps find unfamiliar defects or vulnerabilities Helps improve the program's architecture and work out a consistent coding style Helps find bugs not easily noticeable to the human eye (e.g. typos) Expensive Cheaper than code review Takes up a lot of programmers' time. Breaks are necessary as the reviewer's attention tends to weaken quickly False positives are unavoidable; the user has to customize the analyzer CVE and CWE Common Vulnerabilities and Exposures (CVE) is a database of information-security vulnerabilities and exposures. Its initial purpose was to organize known software defects into a coherent list. In the past, most information-security tools were using their own databases and names for such defects, and it was to bring order to that chaos and establish compatibility between different tools that the MITRE Corporation developed CVE in 1999. However, CVE turned out to be insufficient for estimating code security. Some other system was needed, with finer classification and more detailed descriptions. That's how the Common Weakness Enumeration (CWE) came into existence. If a defect is listed in the CWE, it may cause an exploitable vulnerability and get added to the CVE list as well. The Euler diagram below shows the relations between the standards.
  • 3. Some static analyzers can inform you if, for example, your project employs a library containing a vulnerability. Knowing this, you can download a newer version of the library, with the defect fixed, to make your code less susceptible to security threats caused by a mistake in someone else's code. As the CVE and CWE standards were embraced by the developer community, they were also supported by many information-security tools including static analyzers. Analyzers that support these classifications can be viewed as SAST solutions. SAST (Static Application Security Testing) allows developers to detect vulnerabilities in the source code of programs at the earliest stages of the software development life cycle. SAST is yet another practice to minimize the probability of zero-day vulnerabilities occurring in your project. An analyzer supporting the CWE standard can tell you where a potential vulnerability is lurking so that you could fix it to make your application more reliable and less likely to contain a 0-day threat. There is a variety of SAST tools. I'll take the PVS-Studio analyzer as an example to show how these tools can help fight vulnerabilities. Warnings of this analyzer are classified as CWE. Some examples are given below. PVS-Studio diagnostic message: CWE-561: Dead Code (V3021). public string EncodeImage(....) { if (string.IsNullOrWhiteSpace(inputPath)) { throw new ArgumentNullException("inputPath"); } if (string.IsNullOrWhiteSpace(inputPath)) { throw new ArgumentNullException("outputPath"); } .... } This code contains a typo: the conditions of both if statements check the same variable. The message accompanying the exception suggests that the second condition should check the outputPath variable instead. This mistake has made some part of the code unreachable. Bugs like that might seem harmless, but this impression is wrong. Let's take a look at another trivial and seemingly harmless bug that has to do with a duplicate goto statement. This bug once caused a vulnerability in iOS. The CVE-2014-1266 vulnerability: The SSLVerifySignedServerKeyExchange function in libsecurity_ssl/lib/sslKeyExchange.c in the Secure Transport feature in the Data Security component in Apple iOS 6.x before 6.1.6 and 7.x before 7.0.6, Apple TV 6.x before 6.0.2, and Apple OS X 10.9.x before 10.9.2 does not check the signature in a TLS Server Key Exchange message, which allows man-in-the- middle attackers to spoof SSL servers by using an arbitrary private key for the signing step or omitting the signing step. static OSStatus SSLVerifySignedServerKeyExchange(SSLContext *ctx, bool isRsa, SSLBuffer signedParams, uint8_t *signature, UInt16 signatureLen) {
  • 4. OSStatus err; .... if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0) goto fail; if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0) goto fail; goto fail; if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0) goto fail; .... fail: SSLFreeBuffer(&signedHashes); SSLFreeBuffer(&hashCtx); return err; } Like in the first example, the duplicate goto here led to unreachable code: whatever the conditions of the if statements, the second goto statement would be executed anyway. As a result, the signature wouldn't be checked, the function would return 0, meaning the signature was OK, and the program would receive a key from the server even if the signature check failed. This key is used to encrypt the data being transmitted. This trivial bug had drastic implications. The incident illustrates why there's no point speculating if this or that CWE defect is dangerous or not – you just have to fix it for the sake of your code's safety. By the way, PVS-Studio could have easily found this bug, reporting it with two CWE warnings at once: • CWE-561 (V779): Dead Code • CWE-483 (V640): Incorrect Block Delimitation Here's another example. Long ago, in 2012, a security issue was discovered in MySQL, which could be exploited by an attacker to enter the MySQL database. Below you will see the flawed code fragment, where the vulnerability occurred. The CVE-2012-2122 vulnerability: sql/password.c in Oracle MySQL 5.1.x before 5.1.63, 5.5.x before 5.5.24, and 5.6.x before 5.6.6, and MariaDB 5.1.x before 5.1.62, 5.2.x before 5.2.12, 5.3.x before 5.3.6, and 5.5.x before 5.5.23, when running in certain environments with certain implementations of the memcmp function, allows remote attackers to bypass authentication by repeatedly authenticating with the same incorrect password, which eventually causes a token comparison to succeed due to an improperly-checked return value. typedef char my_bool; my_bool check_scramble(const char *scramble_arg, const char *message, const uint8 *hash_stage2) { .... return memcmp(hash_stage2, hash_stage2_reassured, SHA1_HASH_SIZE); } The memcmp function returns a value of type int, while the check_scramble function returns a value of type my_bool, which is in fact char. The int value gets implicitly cast to char, with the most significant
  • 5. bits truncated. This caused about 1 out of 256 attempts to log in with an arbitrary password for a known username to succeed. Again, this CWE defect could have been neutralized and prevented from becoming a CVE vulnerability much earlier, at the coding stage. For example, PVS-Studio reports it as CWE-197 (V642): Numeric Truncation Error. See the article "How Can PVS-Studio Help in the Detection of Vulnerabilities?" for further reading on the topic. Conclusion You can't be 100% sure your program is safe from 0-day vulnerabilities. But you can still make them much less likely to occur. This is done by using specialized SAST tools such as PVS-Studio. If your project is found to contain defects classified as CWE issues, make sure to fix them. Even though few of CWE defects end up on the CVE list, fixing them helps to secure your program from many potential threats. References 1. Download and evaluate PVS-Studio 2. Technologies used in the PVS-Studio code analyzer for finding bugs and potential vulnerabilities 3. Classification of PVS-Studio warnings according to the Common Weakness Enumeration (CWE) 4. Classification of PVS-Studio warnings according to the SEI CERT Coding Standard