I am working on a project where I am looking into vulnerabilities for Redhat and CentOS systems. Throughout my time as a sysadmin I have always been a huge fan of command-line programs. This is one of the programs that I hacked together to make my job easier.
For a project I am working on, I am having to compare operating system vendor data against NVD data and have been working in a spreadsheet initially to record the results. I am looking to see if NVD has captured correct CPE data from the operating system vendors source. To start I was manually looking at CVE/Advisory postings from Redhat and comparing with what was on NVDs page for the given CVE. This grew tediuous rather quickly after I got through a handful of CVEs. I needed to write a tool that would query Redhat’s API and give me all the needed info on that CVE. My first step was to see if there was anything available that could do this quickly. After looking online and finding old, outdated programs, I thought it would be quicker if I hacked together something.
I am a big linux nerd and have always loved using different command-line programs. I have been using it for over 5 years now and I am always stumbling upon new command-line driven programs. Writing command-line programs is fun and this was an opportunity to write a new one.
This program will query Redhats Security API and spit back CVE data. I have taken some of the examples from the README document that is linked here with the source code.
We can query for CVE’s using two options:
Here are some examples:
This will give us json data back for multiple cves, in the order that we created them in our file. When we query with multiple cves in a file, we will split up the requests to groups of 500 cve ids.
Redhat will post a security advisory when a vulnerability comes out. These are in the schema RHSA-YEAR:ADVISORY_NUM. As an example: RHSA-2019:0997
Redhats Security API also posts a mapping of RPM packages to CVEs in a parseable XML file. This file can be downloaded here. This commandline program can also download a fresh XML file locally using the –refresh option.
I run this as a sanity check to make sure the cmd finished downloading the file succesfully
We can search for packages listed in this xml file by passing the –list option and piping to a standard unix search tool like grep
We can query packages in this xml file by querying the exact package name
We can query the Redhat security API for a specific pkg by querying the BASE pkg name. In this example we query the API and send bash as a param.
I hope somebody can make use of this program for easier system administration and security auditing purposes. I encourage all rhel/centos security admins to make use of it if you would like better insight into CVE data from the vendor source. You should be able to make use of the program by cloning my misc_rbtools directory from my Gitlab. I will be expanding this into its own Ruby gem in the coming days so please check back on this post. I will update the link to the Ruby Gem page once it has been ported to a Gem!
You should now have access to the ./rpm_pkg_audit.rb script, have fun auditing!