|
| 1 | +# |
| 2 | +# Copyright (c) 2017 nexB Inc. and others. All rights reserved. |
| 3 | +# http://nexb.com and https://github.com/nexB/vulnerablecode/ |
| 4 | +# The VulnerableCode software is licensed under the Apache License version 2.0. |
| 5 | +# Data generated with VulnerableCode require an acknowledgment. |
| 6 | +# |
| 7 | +# You may not use this software except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0 |
| 9 | +# Unless required by applicable law or agreed to in writing, software distributed |
| 10 | +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 11 | +# CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 12 | +# specific language governing permissions and limitations under the License. |
| 13 | +# |
| 14 | +# When you publish or redistribute any data created with VulnerableCode or any VulnerableCode |
| 15 | +# derivative work, you must accompany this data with the following acknowledgment: |
| 16 | +# |
| 17 | +# Generated with VulnerableCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES |
| 18 | +# OR CONDITIONS OF ANY KIND, either express or implied. No content created from |
| 19 | +# VulnerableCode should be considered or used as legal advice. Consult an Attorney |
| 20 | +# for any legal advice. |
| 21 | +# VulnerableCode is a free software code scanning tool from nexB Inc. and others. |
| 22 | +# Visit https://github.com/nexB/vulnerablecode/ for support and download. |
| 23 | + |
| 24 | +import bs4 as bs |
| 25 | +import re |
| 26 | +from urllib.request import urlopen |
| 27 | + |
| 28 | + |
| 29 | +def ubuntu_data(): |
| 30 | + cve_id = [] |
| 31 | + package_name = [] |
| 32 | + vulnerability_status = [] |
| 33 | + |
| 34 | + url = urlopen("https://people.canonical.com/~ubuntu-security/cve/main.html") |
| 35 | + soup = bs.BeautifulSoup (url, "lxml") |
| 36 | + |
| 37 | + """ |
| 38 | + Scrape vulnerability status. |
| 39 | + Ubuntu provides a general vulnerability |
| 40 | + status of a package across all it's releases. |
| 41 | + """ |
| 42 | + for tag in soup.find_all('tr'): |
| 43 | + if re.match('<\w+\s\w+="(\w+)">', str(tag)): |
| 44 | + status = re.findall('<\w+\s\w+="(\w+)">', str(tag)) |
| 45 | + vulnerability_status.append(status[0]) |
| 46 | + |
| 47 | + for tag in soup.find_all('a'): |
| 48 | + href = tag.get ('href', None) |
| 49 | + |
| 50 | + if re.findall ('^CVE.+', href): |
| 51 | + cve_id.append(href) |
| 52 | + |
| 53 | + if re.match('\pkg+.*', href): |
| 54 | + pkg = re.findall ('pkg/(.+)\.html', href) |
| 55 | + package_name.append(pkg[0]) |
| 56 | + |
| 57 | + return cve_id, package_name, vulnerability_status |
0 commit comments