-
-
Notifications
You must be signed in to change notification settings - Fork 328
Database Model #5 #15
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
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
05ec4d6
Style changes in Debian #6
kartiksibal e7e8997
Style changes iUbuntu #7
kartiksibal a3dc2c4
Style changes in Ubuntu #7
kartiksibal 2a86790
Merge branch 'scraper' of https://github.com/nexB/vulnerablecode into…
kartiksibal e62ce1a
Merge branch 'develop' into scraper
tdruez 988726b
File name change
kartiksibal cdac54a
Merge branch 'develop' of https://github.com/nexB/vulnerablecode into…
kartiksibal 525d139
Merge branch 'scraper' of https://github.com/nexB/vulnerablecode into…
kartiksibal 3d1b938
Minor changes #5
kartiksibal 3f4ee4c
Merge branch 'models_db' of https://github.com/nexB/vulnerablecode i…
kartiksibal 2285036
Add test cases for #6 Debian and #7 Ubuntu
kartiksibal ff5739e
Merge branch 'develop' into models_db
tdruez 5cddc89
Merge branch 'develop' into scraper
tdruez 980265c
Add lxml in the requirements.txt #6
tdruez e7af960
Debian test case and style changes #6
kartiksibal 84b4a2c
yMerge branch 'scraper' of https://github.com/nexB/vulnerablecode int…
kartiksibal 9b34f7a
Minor changes #6
kartiksibal fee110a
Minor style changes #5
kartiksibal f366133
Merge branch 'models_db' of https://github.com/nexB/vulnerablecode in…
kartiksibal 0b70285
Minor changes #5
kartiksibal b5e5ba3
Merge branch 'develop' into scraper
tdruez 6569bb2
Move tests files in a tests/ directory #6
tdruez 70711c0
Merge branch 'models_db' into scraper
tdruez 4abd00b
Refactor and refine the code and structure for scrapers #6
tdruez 11c7954
Merge branch 'models_db' of github.com:nexB/vulnerablecode into model…
tdruez f0e46ce
Simplify status condition in extract_cves_from_tracker #6
tdruez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| beautifulsoup4==4.6.0 | ||
| lxml==3.8.0 | ||
|
|
||
| # Tests | ||
| pytest==3.1.3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # | ||
| # 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. | ||
|
|
||
| import logging | ||
| import re | ||
| from urllib.request import urlopen | ||
|
|
||
| import bs4 | ||
|
|
||
|
|
||
| DEBIAN_ROOT_URL = 'https://security-tracker.debian.org' | ||
|
|
||
|
|
||
| def extract_tracker_paths(html): | ||
| """ | ||
| Return a list of tracker URL paths extracted from the given `html` input. | ||
| """ | ||
| soup = bs4.BeautifulSoup(html, 'lxml') | ||
| tracker_links = soup.findAll('a', href=re.compile('^/track+.*')) | ||
| return [link.get('href') for link in tracker_links] | ||
|
|
||
|
|
||
| def extract_cves_from_tracker(html): | ||
| """ | ||
| Return all CVEs extracted from the given `html` input. | ||
| """ | ||
| cve_id = [] | ||
| package_name = [] | ||
| vulnerability_status = [] | ||
| soup = bs4.BeautifulSoup(html, 'lxml') | ||
|
|
||
| for tag in soup.find_all('a'): | ||
| href = tag.get('href') | ||
|
|
||
| if re.search('/tracker/CVE-(.+)', href): | ||
| id = re.findall('(?<=/tracker/).*', href) | ||
| cve_id.append(id[0]) | ||
|
|
||
| if re.search('^/tracker/TEMP-+.*', href): | ||
| id = re.findall('(?<=/tracker/).*', href) | ||
| cve_id.append(id[0]) | ||
|
|
||
| if re.search('/tracker/source-package/(.+)', href): | ||
| pkg = re.findall('(?<=/tracker/source-package/).*', href) | ||
| package_name.append(pkg[0]) | ||
|
|
||
| # if package name is empty, use the previous package name | ||
| if href == '/tracker/source-package/': | ||
| package_name.append(pkg) | ||
|
|
||
| for tag in soup.find_all('td'): | ||
| if 'medium' in tag or 'low' in tag or 'not yet assigned' in tag: | ||
| vulnerability_status.append(tag.text) | ||
| elif tag.find_all('span', {'class': 'red'}) and tag.text == 'high**' or tag.text == 'high': | ||
| vulnerability_status.append(tag.text) | ||
|
|
||
| return cve_id, package_name, vulnerability_status | ||
|
|
||
|
|
||
| def scrape_cves(): | ||
| """ | ||
| Runs the full scraping process of Debian CVEs. | ||
| """ | ||
| tracker_root_html = urlopen(f'{DEBIAN_ROOT_URL}/tracker/').read() | ||
| tracker_paths = extract_tracker_paths(tracker_root_html) | ||
|
|
||
| cves = [] | ||
| for tracker_path in tracker_paths: | ||
| tracker_url = f'{DEBIAN_ROOT_URL}{tracker_path}/' | ||
| logging.info(f'Visiting: {tracker_url}') | ||
| html = urlopen(tracker_url).read() | ||
| cves.append(extract_cves_from_tracker(html)) | ||
|
|
||
| return cves |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 are missing a FK to the Package model.