How to Use FlawFinder-python Tool to Find Vulnerabilities in C/C++ Code?
Last Updated :
07 Mar, 2022
FlawFinder is a python based tool that helps in finding vulnerabilities in a C/C++ source code. It examines the source code and gives the list of possible vulnerabilities/flaws in the code as the output.
Installation
There is a pre-packaged version of this tool for Unix systems like Debian, Fedora, Ubuntu, etc. For Ubuntu, this tool can be installed using the following command-
sudo apt-get install flawfinder
For Windows OS, this tool can be directly installed using the pip command-
pip install flawfinder
It is recommended to use the Anaconda environment to implement this tool.
Anaconda Installation:
For installing Anaconda refer to the following steps-
Step 1: Download the Anaconda using this link:https://www.anaconda.com/products/individual#windows
Step 2: Once installed click on Launch.
Step 3: Click Next.
Step 4: Read the licensing terms and click “I Agree”.
Step 5: Select an install for “Just Me” and click Next.
Step 6- Select a destination folder to install Anaconda and click the Next button.
Step 7: Under the Advanced Installation Options. Select the Register option and then install.
Step 8: It is recommended to install Pycharm.
Step 9: After the installation is completed, click the Finish button.
Implementation: Write a basic C code in a text file of copying a string into another variable.
C
// C program to demonstrate
// Flawfinder
#include <stdio.h>
#include <string.h>
// Driver code
int main()
{
char temp[100];
char str[] = "hello";
strcpy(temp, str);
printf("%s", temp);
return 0;
}
Output:
Step 1: Save the code with .c extension inside the folder where the flawfinder is installed.
Step 2: Open Anaconda Prompt from the Start menu.
Step 3: Once the window opens, navigate to the directory where the code file is saved. Here the path is flawfinder\Test.
Step 4: Run this command
flawfinder your_program_name.c
The tool produces two hits i.e. potential risks.
- One is due to the use of strcpy function. It does not check for buffer overflows when copying to the destination. The tool also suggests alternatives such as using inbuilt functions such as snprintf, strcpy_s, or strlcpy.
- Another vulnerability is the use of a char array. Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues. Instead, functions can be used to check the limit length and ensure that size is larger than the maximum possible length.
Pros of Flawfinder Tool:
- Determines level of risk- Flawfinder renders a list of potential security vulnerabilities which are sorted by risk. Functions and parameters used in the code determine the level of risk. For example, constant string values are less risky in comparison to variable strings. In some cases, FlawFinder may be able to determine that the construct isn’t risky at all, reducing false positives.
- Provides analysis summary- It produces an analysis summary as output and mentions the no. of hits i.e. vulnerabilities found in the code.
- Code is not compiled- The source code is never compiled and hence even if the code is not working the tool will still render the list of vulnerabilities almost immediately.
Cons of FlawFinder Tool-
- Does not guarantee to find all the vulnerabilities- Every hit produced doesn't imply a security vulnerability and neither is every vulnerability found. For instance, in a simple division program, a number is divided by 0. Ideally, the tool should show division by 0 as a hit but it fails to do so. This is because the tool cannot understand the logic of the program.
- Cannot detect malicious codes- Flawfinder looks for specific patterns known to be common mistakes in application code. Thus, it is likely to be less effective in analyzing programs that might contain malicious codes.
Similar Reads
Vulnerability in input() function â Python 2.x
This article aims to explain and explore the vulnerability in the input() function in Python 2.x. In Python 3, the raw_input() function was erased, and its functionality was transferred to a new built-in function known as input(). Different Ways to Input Data in Python 2.xThere are two common method
5 min read
How to Setup VSCode with C, C++ and Python for Competitive Programming
VSCode is a Text editor that provides support for development operations and version control systems. It provides tools for a user to build hassle-free codes. VSCode can be downloaded and installed from visualstudio.com This article will show you how to, fetch test cases directly from the browser wi
5 min read
How to Use Pytest for Efficient Testing in Python
Writing, organizing, and running tests is made easier with Pytest, a robust and adaptable testing framework for Python. Developers looking to guarantee code quality and dependability love it for its many capabilities and easy-to-use syntax. A critical component of software development is writing tes
5 min read
How to use the Live Coding Feature of Python in Eclipse?
In this article, we'll be talking about how to use the Live Coding features of Python in Eclipse. Every time the programmer has to spend a lot of time debugging their code. And still, they failed to debug. This extension will help the coders or programmers to reduce their debugging time. This extens
2 min read
How to find Segmentation Error in C & C++ ? (Using GDB)
What is Segmentation Error ? - It is the runtime error caused because of the memory access violation. For Eg :-Stackoverflow, read violation etc.. We often face this problem when working out with pointers in c++/c. In this example we will see how to find the segmentation error in the program. We wil
3 min read
How to get value from address in Python ?
In this article, we will discuss how to get the value from the address in Python. First, we have to calculate the memory address of the variable or python object which can be done by using the id() function. Syntax: id(python_object) where, python_object is any python variable or data structure like
4 min read
Issues with using C code in Python | Set 1
Prerequisite: Using C codes in Python | Set 1, Set 2 Issue #1 : If using ctypes then there is a problem that the original C code may use language that donât map cleanly to Python. Let's take the example of divide() function as it returns a value through one of its arguments. It is a common C techniq
2 min read
Creating a C/C++ Code Formatting tool with help of Clang tools
Today we are going to discuss formatting files in the user's workspace by their extension. For this we are going to make use of Clang's format tools. Prerequisites: Linux Machine Python Clang Tool Setup: Install Python using the following command: sudo apt-get install python Install Clang Format Too
2 min read
Issues with using C code in Python | Set 2
Prerequisite: Issues with using C code in Python | Set 1 The DoubleArrayType class can handle the situation of Python having different forms like array, numpy array, list, tuple. In this class, a single method from_param() is defined. This method takes a single parameter and narrow it down to a comp
3 min read
How to Print Exception Stack Trace in Python
In Python, when an exception occurs, a stack trace provides details about the error, including the function call sequence, exact line and exception type. This helps in debugging and identifying issues quickly.Key Elements of a Stack Trace:Traceback of the most recent callLocation in the programLine
3 min read