|
| 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 json |
| 25 | +from urllib.request import urlopen |
| 26 | + |
| 27 | + |
| 28 | +ARCHLINUX_TRACKER_URL = 'https://security.archlinux.org/json' |
| 29 | + |
| 30 | + |
| 31 | +def extract_vulnerabilities(arch_data): |
| 32 | + """ |
| 33 | + Return a series of mappings for each record of arch linux security tracker |
| 34 | + data. |
| 35 | + """ |
| 36 | + for item in arch_data: |
| 37 | + package_vulnerabilities = [] |
| 38 | + cves = item['issues'] |
| 39 | + advisories = set(item['advisories']) |
| 40 | + vulnerabilities = cves + list(advisories) |
| 41 | + vulnerabilities.append(item['name']) |
| 42 | + packages_name = item['packages'] |
| 43 | + |
| 44 | + if not vulnerabilities or not packages_name: |
| 45 | + continue |
| 46 | + |
| 47 | + affected_version = item['affected'] |
| 48 | + fixed_version = item['fixed'] |
| 49 | + if not fixed_version: |
| 50 | + fixed_version = 'None' |
| 51 | + |
| 52 | + package_vulnerabilities = { |
| 53 | + 'packages_name': packages_name, |
| 54 | + 'vulnerability_id': vulnerabilities, |
| 55 | + 'description': item['type'], |
| 56 | + 'status': item['status'], |
| 57 | + 'severity': item['severity'], |
| 58 | + 'version': [affected_version,fixed_version] |
| 59 | + } |
| 60 | + yield package_vulnerabilities |
| 61 | + |
| 62 | + |
| 63 | +def scrape_vulnerabilities(): |
| 64 | + """ |
| 65 | + Scrape arch linux' security tracker. |
| 66 | + """ |
| 67 | + json_content = urlopen(ARCHLINUX_TRACKER_URL).read() |
| 68 | + return extract_vulnerabilities(json.loads(json_content)) |
0 commit comments