-
-
Notifications
You must be signed in to change notification settings - Fork 328
Scrapes data from scrapers and dump in the database #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ea36954
b007cb2
7825f98
49d0a2c
f1a1e99
0334beb
9c413dc
58e33db
d3850bb
0a08cc4
4f2ffa3
f6cad6e
cc42000
ce03b49
d5177f7
a23d916
f56a019
bd66de2
6bcf992
184266f
218fffb
931d539
4e4dcff
4698df0
9906a43
a994a23
85bd950
26fa349
20ee1f9
efedb24
1716de9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,3 +103,6 @@ ENV/ | |
|
|
||
| # PyCharm | ||
| .idea/ | ||
|
|
||
| # Database | ||
| *.sqlite3* | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,12 +12,13 @@ Clone the source code: | |
| git clone https://github.com/nexB/vulnerablecode.git && cd vulnerablecode | ||
| ``` | ||
|
|
||
| Activate a virtualenv and install dependencies: | ||
| Activate a virtualenv, install dependencies, and run the database migrations: | ||
|
|
||
| ``` | ||
| python3.6 -m venv . | ||
| source bin/activate | ||
| pip install -r requirements.txt | ||
| app/manage.py migrate | ||
| ``` | ||
|
|
||
| Tests | ||
|
|
@@ -28,18 +29,28 @@ pycodestyle --exclude=migrations,settings.py,lib,tests --max-line-length=100 . | |
| cd app/ | ||
| python3.6 -m pytest -v tests/ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here too, we should only use one way to run tests. Not two |
||
| ``` | ||
|
|
||
| For Django based tests | ||
| ``` | ||
| cd app/ | ||
| python3 manage.py test | ||
| ./manage.py test | ||
| ``` | ||
|
|
||
| Scrape | ||
| ------ | ||
| Scrape and save to the database | ||
| ------------------------------- | ||
|
|
||
| ``` | ||
| cd app/ | ||
| ./manage.py shell | ||
| ``` | ||
|
|
||
| ``` | ||
| from scraper import debian, ubuntu | ||
| from vulncode_app.data_dump import debian_dump, ubuntu_dump | ||
|
|
||
| debian_vulnerabilities = debian.scrape_vulnerabilities() | ||
| ubuntu_cves = ubuntu.scrape_cves() | ||
|
|
||
| debian.scrape_cves() | ||
| ubuntu.scrape_cves() | ||
| debian_dump(debian_vulnerabilities) | ||
| ubuntu_dump(ubuntu_cves) | ||
| ``` | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # | ||
| # Copyright (c) 2017 nexB Inc. and others. All rights reserved. | ||
| # http://nexb.com and https://github.com/nexB/vulnerablecode/ | ||
| # The VulnerableCode software is licensed under the Apache License version 2.0. | ||
| # Data generated with VulnerableCode require an acknowledgment. | ||
| # | ||
| # You may not use this software except in compliance with the License. | ||
| # You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0 | ||
| # Unless required by applicable law or agreed to in writing, software distributed | ||
| # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
| # CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations under the License. | ||
| # | ||
| # When you publish or redistribute any data created with VulnerableCode or any VulnerableCode | ||
| # derivative work, you must accompany this data with the following acknowledgment: | ||
| # | ||
| # Generated with VulnerableCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES | ||
| # OR CONDITIONS OF ANY KIND, either express or implied. No content created from | ||
| # VulnerableCode should be considered or used as legal advice. Consult an Attorney | ||
| # for any legal advice. | ||
| # VulnerableCode is a free software code scanning tool from nexB Inc. and others. | ||
| # Visit https://github.com/nexB/vulnerablecode/ for support and download. | ||
|
|
||
| from vulncode_app.models import Vulnerability | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove un-used imports |
||
| from vulncode_app.models import VulnerabilityReference | ||
| from vulncode_app.models import Package | ||
|
|
||
|
|
||
| def debian_dump(extract_data): | ||
| """ | ||
| Save data scraped from Debian' security tracker. | ||
| """ | ||
| for data in extract_data: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I doubt the following objects creation works, the required fields are not properly set.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tdruez Could you elaborate this? Are you talking in context to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tdruez Yes, I get your point. I'll add the updated models along the next commit. |
||
| vulnerability = Vulnerability.objects.create( | ||
| summary=data.get('description', ''), | ||
| ) | ||
| VulnerabilityReference.objects.create( | ||
| vulnerability=vulnerability, | ||
| reference_id=data.get('vulnerability_id', ''), | ||
| ) | ||
| Package.objects.create( | ||
| name=data.get('package_name', ''), | ||
| version=data.get('fixed_version', ''), | ||
| ) | ||
|
|
||
|
|
||
| def ubuntu_dump(html): | ||
| """ | ||
| Dump data scraped from Ubuntu's security tracker. | ||
| """ | ||
| for data in html: | ||
| vulnerability = Vulnerability.objects.create( | ||
| summary='', | ||
| ) | ||
| VulnerabilityReference.objects.create( | ||
| vulnerability=vulnerability, | ||
| reference_id=data.get('cve_id'), | ||
| ) | ||
| Package.objects.create( | ||
| name=data.get('package_name'), | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # Generated by Django 1.11.4 on 2017-08-08 09:11 | ||
| from __future__ import unicode_literals | ||
|
|
||
| from django.db import migrations, models | ||
| import django.db.models.deletion | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| initial = True | ||
|
|
||
| dependencies = [ | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='ImpactedPackage', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ], | ||
| ), | ||
| migrations.CreateModel( | ||
| name='Package', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('platform', models.CharField(blank=True, help_text='Package platform eg:maven', max_length=50)), | ||
| ('name', models.CharField(blank=True, help_text='Package name', max_length=50)), | ||
| ('version', models.CharField(blank=True, help_text='Package version', max_length=50)), | ||
| ], | ||
| ), | ||
| migrations.CreateModel( | ||
| name='PackageReference', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('repository', models.CharField(blank=True, help_text='Repository URL eg:http://central.maven.org', max_length=50)), | ||
| ('platform', models.CharField(blank=True, help_text='Platform eg:maven', max_length=50)), | ||
| ('name', models.CharField(blank=True, help_text='Package reference name eg:org.apache.commons.io', max_length=50)), | ||
| ('version', models.CharField(blank=True, help_text='Reference version', max_length=50)), | ||
| ('package', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='vulncode_app.Package')), | ||
| ], | ||
| ), | ||
| migrations.CreateModel( | ||
| name='ResolvedPackage', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('package', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='vulncode_app.Package')), | ||
| ], | ||
| ), | ||
| migrations.CreateModel( | ||
| name='Vulnerability', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('summary', models.CharField(blank=True, help_text='Summary of the vulnerability', max_length=50)), | ||
| ('cvss', models.FloatField(help_text='CVSS Score', max_length=50, null=True)), | ||
| ], | ||
| ), | ||
| migrations.CreateModel( | ||
| name='VulnerabilityReference', | ||
| fields=[ | ||
| ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
| ('source', models.CharField(blank=True, help_text="Source's name eg:NVD", max_length=50)), | ||
| ('reference_id', models.CharField(blank=True, help_text='Reference ID, eg:CVE-ID', max_length=50)), | ||
| ('url', models.URLField(blank=True, help_text='URL of Vulnerability data', max_length=1024)), | ||
| ('vulnerability', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='vulncode_app.Vulnerability')), | ||
| ], | ||
| ), | ||
| migrations.AddField( | ||
| model_name='resolvedpackage', | ||
| name='vulnerability', | ||
| field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='vulncode_app.Vulnerability'), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='impactedpackage', | ||
| name='package', | ||
| field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='vulncode_app.Package'), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='impactedpackage', | ||
| name='vulnerability', | ||
| field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='vulncode_app.Vulnerability'), | ||
| ), | ||
| migrations.AlterUniqueTogether( | ||
| name='vulnerabilityreference', | ||
| unique_together=set([('vulnerability', 'source', 'reference_id')]), | ||
| ), | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use one or the other for running tests.... do not run tests twice