Skip to content

Commit 65ca798

Browse files
committed
Collect vulnerabilities from arch linux #20
Signed-off-by: Ayush Lohani <lohani.ayush01@gmail.com>
1 parent 55a633d commit 65ca798

2 files changed

Lines changed: 112 additions & 0 deletions

File tree

vulnerabilities/data_dump.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# Visit https://github.com/nexB/vulnerablecode/ for support and download.
2323

2424
from vulnerabilities.models import ImpactedPackage
25+
from vulnerabilities.models import ResolvedPackage
2526
from vulnerabilities.models import Package
2627
from vulnerabilities.models import Vulnerability
2728
from vulnerabilities.models import VulnerabilityReference
@@ -68,3 +69,46 @@ def ubuntu_dump(html):
6869
vulnerability=vulnerability,
6970
package=package
7071
)
72+
73+
74+
def archlinux_dump(extract_data):
75+
"""
76+
Save data scraped from archlinux' security tracker.
77+
Args:
78+
extract_data(generator): data collected from archlinux' security tracker
79+
"""
80+
for data in extract_data:
81+
print(data)
82+
packages_name = data['packages_name']
83+
vulnerabilities = data['vulnerability_id']
84+
affected_version = data['version'][0]
85+
fixed_version = data['version'][1]
86+
87+
vulnerability = Vulnerability.objects.create(
88+
summary=data['description'],
89+
)
90+
91+
for vulnerability_id in vulnerabilities:
92+
VulnerabilityReference.objects.create(
93+
vulnerability=vulnerability,
94+
reference_id=vulnerability_id,
95+
source='archlinux',
96+
)
97+
98+
for package_name in packages_name:
99+
package_affected = Package.objects.create(
100+
name=package_name,
101+
version=fixed_version
102+
)
103+
ImpactedPackage.objects.create(
104+
vulnerability=vulnerability,
105+
package=package_affected
106+
)
107+
package_fixed = Package.objects.create(
108+
name=package_name,
109+
version=affected_version
110+
)
111+
ResolvedPackage.objects.create(
112+
vulnerability=vulnerability,
113+
package=package_fixed
114+
)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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

Comments
 (0)