I tried to word my question as best I could since I'm not sure if that is exactly what I am looking for, sorry in advance for that.
I am parsing an RSS feed with feedparser
.
Based on the documentation, I was able to parse my results down to just the link to a certain vulnerability + its RSS post title.
Here is my code:
import feedparser
# product variables
ie = ['Internet Explorer', 'IE', 'Explorer', 'Internet_Explorer']
nix = ['Linux', 'SUSE', 'Red Hat', 'RHEL', 'Ubuntu', 'Debian_Linux']
win = ['Windows_']
# NVD RSS feed variable
d = feedparser.parse('https://nvd.nist.gov/feeds/xml/cve/misc/nvd-rss- analyzed.xml')
print("================================")
print(d['feed']['title'])
print("================================")
for entry in d.entries:
print(entry.title, entry.link)
this will return results that look like this:
CVE-2018-8132 (windows_10, windows_server_2016) https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2018-8132
I also tried just parsing the raw data, which is:
for entry in d.entries:
print(entry)
Now this shows me that title
is a key in a dictionary (I think) and the value is CVE-2018-8132 (windows_10, windows_server_2016)
What I want to do, is an if
statement that would be something like: if titlevalue contains a word (from the lists up top) then do something
I couldn't find in feedparser
's documentation how to do this. I'd really appreciate any help.
EDIT (2018-06-15):
I figured it out.
Here is my code for whoever is looking for it in the future:
# library imports
import feedparser
import re
import smtplib
import datetime
import time
# NVD RSS feed variable
d = feedparser.parse('https://nvd.nist.gov/feeds/xml/cve/misc/nvd-rss- analyzed.xml')
print("\n+++++++++++++++++++++++++++++++++++++++")
print(d['feed']['title'], 'Scanner')
print("+++++++++++++++++++++++++++++++++++++++\n")
# function for iterating through the entries and printing out how many vulns there are
def product_scan(product_name):
# vulnerability links list
vuln_list = []
# counter for how many vulns per product
count = 0
for entry in d.entries:
if product_name in entry.title:
count += 1
# here we append the hyperlinks of the CVEs to a pre-defined list so we can manipulate it later
vuln_list.append(entry.link)
# making it look nice
if count == 1:
print('===============================================================\nThere is', count, product_name,
'related vulnerability:')
elif count == 0:
print('')
else:
print('===============================================================\nThere are', count, product_name,
'related vulnerabilities:')
# this for loop is for enumerating the links for each product CVE code
for x in vuln_list:
print(x)
# calling the function and searching for vulns based on keyword(s)
product_list = ['mysql', 'windows', 'linux', 'explorer', 'php', 'webex', 'firefox', 'norton', 'mcafee', 'symantec']
for product in product_list:
product_scan(product)