Skip to content

Commit 95f725f

Browse files
authored
Merge pull request #25 from nexB/data_dump
Scrapes data from scrapers and dump in the database
2 parents 404c203 + 1716de9 commit 95f725f

22 files changed

Lines changed: 417 additions & 81 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,6 @@ ENV/
103103

104104
# PyCharm
105105
.idea/
106+
107+
# Database
108+
*.sqlite3*

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ install:
77

88
before_script:
99
- pycodestyle --exclude=migrations,settings.py,lib,tests --max-line-length=100 .
10+
- cd app/
11+
- python3 manage.py migrate
1012

1113
script:
1214
- python3.6 -m pytest -v tests/
15+
- python3.6 manage.py test
1316

1417
notifications:
1518
email: false

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ Clone the source code:
1212
git clone https://github.com/nexB/vulnerablecode.git && cd vulnerablecode
1313
```
1414

15-
Activate a virtualenv and install dependencies:
15+
Activate a virtualenv, install dependencies, and run the database migrations:
1616

1717
```
1818
python3.6 -m venv .
1919
source bin/activate
2020
pip install -r requirements.txt
21+
app/manage.py migrate
2122
```
2223

2324
Tests
@@ -28,18 +29,28 @@ pycodestyle --exclude=migrations,settings.py,lib,tests --max-line-length=100 .
2829
cd app/
2930
python3.6 -m pytest -v tests/
3031
```
32+
3133
For Django based tests
3234
```
3335
cd app/
34-
python3 manage.py test
36+
./manage.py test
3537
```
3638

37-
Scrape
38-
------
39+
Scrape and save to the database
40+
-------------------------------
41+
42+
```
43+
cd app/
44+
./manage.py shell
45+
```
3946

4047
```
4148
from scraper import debian, ubuntu
49+
from vulncode_app.data_dump import debian_dump, ubuntu_dump
50+
51+
debian_vulnerabilities = debian.scrape_vulnerabilities()
52+
ubuntu_cves = ubuntu.scrape_cves()
4253
43-
debian.scrape_cves()
44-
ubuntu.scrape_cves()
54+
debian_dump(debian_vulnerabilities)
55+
ubuntu_dump(ubuntu_cves)
4556
```

app/app/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# Application definition
3232

3333
INSTALLED_APPS = [
34+
'vulncode_app.apps.VulncodeAppConfig',
3435
'django.contrib.admin',
3536
'django.contrib.auth',
3637
'django.contrib.contenttypes',

app/app/urls.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
1. Import the include() function: from django.conf.urls import url, include
1414
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
1515
"""
16+
1617
from django.conf.urls import url, include
17-
from django.contrib import admin
1818

1919
urlpatterns = [
2020
url(r'^vulncode_app/', include('vulncode_app.urls')),
21-
url(r'^admin/', admin.site.urls),
2221
]
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,16 @@
2424
import json
2525
from urllib.request import urlopen
2626

27-
2827
DEBIAN_TRACKER_URL = 'https://security-tracker.debian.org/tracker/data/json'
2928

3029

31-
def json_data(url=DEBIAN_TRACKER_URL):
32-
"""
33-
Return Debian vulnerabilities data fetched from `url`.
34-
"""
35-
debian_data = urlopen(url).read()
36-
return json.loads(debian_data)
37-
38-
39-
def extract_data(debian_data, base_release='jessie'):
30+
def extract_vulnerabilities(debian_data, base_release='jessie'):
4031
"""
4132
Return a sequence of mappings for each existing combination of
4233
package and vulnerability from a mapping of Debian vulnerabilities
4334
data.
4435
"""
45-
package_vulns = []
36+
package_vulnerabilities = []
4637

4738
for package_name, vulnerabilities in debian_data.items():
4839
if not vulnerabilities or not package_name:
@@ -57,11 +48,21 @@ def extract_data(debian_data, base_release='jessie'):
5748
if not release:
5849
continue
5950

60-
package_vulns.append({
51+
package_vulnerabilities.append({
6152
'package_name': package_name,
6253
'vulnerability_id': vulnerability,
63-
'status': release.get('status'),
64-
'urgency': release.get('urgency'),
65-
'fixed_version': release.get('fixed_version')
54+
'description': details.get('description', ''),
55+
'status': release.get('status', ''),
56+
'urgency': release.get('urgency', ''),
57+
'fixed_version': release.get('fixed_version', '')
6658
})
67-
return package_vulns
59+
60+
return package_vulnerabilities
61+
62+
63+
def scrape_vulnerabilities():
64+
"""
65+
Scrape debian' security tracker.
66+
"""
67+
json_content = urlopen(DEBIAN_TRACKER_URL).read()
68+
return extract_vulnerabilities(json.loads(json_content))
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import json
2525

26-
from api_data import extract_fields
26+
from vulncode_app.api_data import extract_fields
2727

2828

2929
test_data = """
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"CVE-2009-2458": {
44
"scope": "remote",
55
"debianbug": 537254,
6-
"description": "Multiple stack-based buffer overflows in mimetex.cgi in mimeTeX, when downloaded before 20090713, allow remote attackers to execute arbitrary code via a TeX file with long (1) picture, (2) circle, or (3) input tags.",
6+
"description": "Multiple stack-based buffer overflows in mimetex.cgi in mimeTeX",
77
"releases":
88
{"stretch":
99
{"status": "resolved",
@@ -34,7 +34,7 @@
3434
"CVE-2009-2459":
3535
{"scope": "un-remote",
3636
"debianbug": 537254,
37-
"description": "Multiple unspecified vulnerabilities in mimeTeX, when downloaded before 20090713, have unknown impact and attack vectors related to the (1) \\environ, (2) \\input, and (3) \\counter TeX directives.",
37+
"description": "Multiple unspecified vulnerabilities in mimeTeX.",
3838
"releases":
3939
{"stretch":
4040
{"status": "resolved",

0 commit comments

Comments
 (0)