I am investigating vulnerabilities in the NVD database. I would like to have a list of vulnerabilities that Cppcheck can find / can not find with the bug hunting. And if we find false negatives in Cppcheck, I want to fix those.
If anybody wants to join feel free to do it.
The bug hunting should be able to detect buffer overflows, array index out of bounds, uninitialized variables, and division by zero.
Rough procedure:
1. Open vulnerability details https://nvd.nist.gov/vuln/detail/CVE-2020-26572
2. We need to know what source code repo it is, which specific revision fixed the bug, and understand what the bug is just so we know what cppcheck should warn about. Look in the vulnerability details for a link to some issue or fix. In this case it says: https://github.com/OpenSC/OpenSC/commit/9d294de90d1cc66956389856e60b6944b27b4817
3. clone repo: git clone https://github.com/OpenSC/OpenSC.git
4. goto fix: git reset --hard 9d294de9
5. goto buggy code: git reset --hard HEAD^1
6. check if bug is found: cppcheck --bug-hunting src/libopensc/card-tcos.c
7. In this case the bug is found... but if it is not found then use --check-config and ensure that local include paths are set.
8. report if bug is found or not.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
yes .. we have some tests in cppcheck/test/bug-hunting/cve already.. but well it's a bit clumpsy to work with those. for instance you are supposed to copy headers and stuff to the cppcheck repo. maybe we can make some new testing that is less clumpsy..
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
we could create a script. we put these commands in that script. when that is executed it generates some nice html report.. and we could show that on our webpage. I would like to see a table where each CVE has 1 row and we will indicate with a green or red background color if cppcheck does detect it or not.. for each cve we can write which CVE-id it has, what CWE it is, if it is c or c++ code, .. and not sure if something more is interesting.
Last edit: Daniel Marjamäki 2020-12-09
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Very good idea to demonstrate that we are able to detect specific known issues.
In additon, we could activate bug-hunting on daca to see what it brings up?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This will give us a list of links to all pull requests and issues listed in NVD reports.
Next, the problem is that their data contains entries for all programming languages, not only C/C++. So, the next step should be detection of the language for the given repository. This could be achieved through github/gitlab API, I'll take a look.
Last edit: Georgiy Komarov 2020-12-10
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Parses Github repositories for which the commit hash is specified.
Uses Github API to filter C and C++ repositories.
Then it clones repository in /tmp and runs cppcheck on the required repository commit. It does exactly what you specified in the first post. It will be easier to read the source of the script. 🙂
Here is an example output:
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
but if I just get all the results then I don't know what to look for. I can't say if the CVE is detected or not.
I think it's necessary to manually look at the commit message and/or the issue.. and understand what the issue is and how the changes fixes that problem.
Can the script print out some such info about each C/C++ CVE:
I guess there are use cases when we would like the script to execute cppcheck .. so feel free to keep the code. maybe a "-s" could mean that the commands are only written on the screen..
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think it's necessary to manually look at the commit message and/or the issue.. and understand what the issue is and how the changes fixes that problem.
Yes. I believe we need to manually find the corresponding "bughunting" warning in the output. So we will need both diff for this commit and the full Cppcheck output on modified files.
Since the report of Cppcheck can be enormous, it makes sense to save diff and the output as the files and print to user only the brief summary with paths to these files.
I think we can use this scenario when script is running with -s argument. Otherwise we can just print summaries with formatted data from the json database. And possible clone and hard-reset the repositories, if an additional argument was set, say -c.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Fantastic. So now the question is if we could coordinate the investigation online..
For each CVE I would like to document additional cppcheck flags needed and the location and expected cppcheck error id that Cppcheck should warn about. then maybe your script can be used to check if those CVEs are detected or not..
The CVE => cppcheck flags, location, error-id can be a simple text document in the wiki that anybody can edit .. or does anybody have a better idea..
Last edit: Daniel Marjamäki 2020-12-10
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am investigating vulnerabilities in the NVD database. I would like to have a list of vulnerabilities that Cppcheck can find / can not find with the bug hunting. And if we find false negatives in Cppcheck, I want to fix those.
If anybody wants to join feel free to do it.
The bug hunting should be able to detect buffer overflows, array index out of bounds, uninitialized variables, and division by zero.
Here is an example search:
https://nvd.nist.gov/vuln/search/results?cwe_id=CWE-787&pub_start_date=01%2F01%2F2020
Rough procedure:
1. Open vulnerability details https://nvd.nist.gov/vuln/detail/CVE-2020-26572
2. We need to know what source code repo it is, which specific revision fixed the bug, and understand what the bug is just so we know what cppcheck should warn about. Look in the vulnerability details for a link to some issue or fix. In this case it says: https://github.com/OpenSC/OpenSC/commit/9d294de90d1cc66956389856e60b6944b27b4817
3. clone repo:
git clone https://github.com/OpenSC/OpenSC.git
4. goto fix:
git reset --hard 9d294de9
5. goto buggy code:
git reset --hard HEAD^1
6. check if bug is found:
cppcheck --bug-hunting src/libopensc/card-tcos.c
7. In this case the bug is found... but if it is not found then use
--check-config
and ensure that local include paths are set.8. report if bug is found or not.
Two CVEs that are found:
Last edit: Daniel Marjamäki 2020-12-09
For information.. I want to have the commands that are used so it will be possible to reproduce and check for regressions etc later..
One more CVE:
Last edit: Daniel Marjamäki 2020-12-09
A CVE that is not found:
Comment: The bug hunting does not have proper checking of
pointer[index]
yet.Good idea search for CVEs and improve the checker. Are there plans to create tests, demonstrating that specific CVEs are detected?
yes .. we have some tests in
cppcheck/test/bug-hunting/cve
already.. but well it's a bit clumpsy to work with those. for instance you are supposed to copy headers and stuff to the cppcheck repo. maybe we can make some new testing that is less clumpsy..we could create a script. we put these commands in that script. when that is executed it generates some nice html report.. and we could show that on our webpage. I would like to see a table where each CVE has 1 row and we will indicate with a green or red background color if cppcheck does detect it or not.. for each cve we can write which CVE-id it has, what CWE it is, if it is c or c++ code, .. and not sure if something more is interesting.
Last edit: Daniel Marjamäki 2020-12-09
Very good idea to demonstrate that we are able to detect specific known issues.
In additon, we could activate bug-hunting on daca to see what it brings up?
I think we can discuss what we want to have first and then see how we can achieve that in the best way.
One more CVE that we do detect:
One more CVE that we detect:
Last edit: Daniel Marjamäki 2020-12-10
This CVE is not detected:
This is very interesting. I believe we can fix this if we add special handling for zero terminated strings.
Last edit: Daniel Marjamäki 2020-12-09
This CVE is detected:
Does anybody volounteer to write a python/bash script that would run these cases and produce some nice html report?
One more CVE that we detect:
This is an interesting idea.
NVD provides access to their data in JSON format: https://nvd.nist.gov/vuln/data-feeds#JSON_FEED. This allows us to automate the loading and analysis the latest data.
We can start with something simple like:
This will give us a list of links to all pull requests and issues listed in NVD reports.
Next, the problem is that their data contains entries for all programming languages, not only C/C++. So, the next step should be detection of the language for the given repository. This could be achieved through github/gitlab API, I'll take a look.
Last edit: Georgiy Komarov 2020-12-10
👍 👍 👍 !!!
It's already a super good start .. much better than the searches I've been doing.
I did some work on the automation. Here is my quick-and-dirty script: https://github.com/jubnzv/cppcheck-nvd-checker .
It does the following:
Here is an example output:
👍 I will try it out. if we make it this automated we could even run something similar in daca@home.
I think it is a good start...
but if I just get all the results then I don't know what to look for. I can't say if the CVE is detected or not.
I think it's necessary to manually look at the commit message and/or the issue.. and understand what the issue is and how the changes fixes that problem.
Can the script print out some such info about each C/C++ CVE:
Last edit: Daniel Marjamäki 2020-12-10
I guess there are use cases when we would like the script to execute cppcheck .. so feel free to keep the code. maybe a "-s" could mean that the commands are only written on the screen..
Yes. I believe we need to manually find the corresponding "bughunting" warning in the output. So we will need both diff for this commit and the full Cppcheck output on modified files.
Since the report of Cppcheck can be enormous, it makes sense to save diff and the output as the files and print to user only the brief summary with paths to these files.
I think we can use this scenario when script is running with
-s
argument. Otherwise we can just print summaries with formatted data from the json database. And possible clone and hard-reset the repositories, if an additional argument was set, say-c
.I implemented this in https://github.com/jubnzv/cppcheck-nvd-checker .
Now we can get the full report in the format you mentioned. 🙂
I added it to the attachments.
Last edit: Georgiy Komarov 2020-12-10
Fantastic. So now the question is if we could coordinate the investigation online..
For each CVE I would like to document additional cppcheck flags needed and the location and expected cppcheck error id that Cppcheck should warn about. then maybe your script can be used to check if those CVEs are detected or not..
The CVE => cppcheck flags, location, error-id can be a simple text document in the wiki that anybody can edit .. or does anybody have a better idea..
Last edit: Daniel Marjamäki 2020-12-10