Skip to content

Commit

Permalink
#1 Query cve-search' db
Browse files Browse the repository at this point in the history
  • Loading branch information
kartiksibal committed Jun 9, 2017
1 parent 6e7f5d8 commit a973fb7
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
34 changes: 34 additions & 0 deletions api_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python

import json
from urllib import urlopen

def output_cve_id():
"""Takes as input, a package name, package version.
Queries cve-search' dataset for any reported
vulnerabilities of the requested package. If
vulnerability exists, outputs cve-id(s).
"""
package_name = raw_input('Enter package name: ')
user_choice = raw_input('Do you have a package version? (Y/N): ')

if user_choice == 'Y' or user_choice == 'y':
package_ver = raw_input('Enter package version: ')
url = 'https://cve.circl.lu/api/search/' + package_name + package_ver

else:
url = 'https://cve.circl.lu/api/search/' + package_name

raw_data = urlopen(url).read()
data = json.loads(raw_data)

if len(data) > 0:
print 'Vulnerabilties Found:\n'

for item in data['data']:
print item['id']
else:
print 'No vulnerabilites found'

if __name__ == '__main__':
output_cve_id()
50 changes: 50 additions & 0 deletions test_api_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import api_data as api

from mock import Mock
import pytest
from urllib import urlopen

test_data = '''
{ "data": [
{
"Modified": "2008-11-15T00:00:00",
"Published": "2007-02-19T21:28:00",
"access": {
"authentication": "NONE",
"complexity": "MEDIUM",
"vector": "NETWORK"
},
"cvss": 4.3,
"cvss-time": "2007-02-20T14:55:00",
"id": CVE-2007-1004"
"impact": {
"availability": "NONE",
"confidentiality": "NONE",
"integrity": "PARTIAL"
},
"reason": "Link",
"references": [
"http://securityreason.com/securityalert/2264",
"http://www.securityfocus.com/archive/1/archive/1/460369/100/0/threaded",
"http://www.securityfocus.com/archive/1/archive/1/460412/100/0/threaded",
"http://www.securityfocus.com/archive/1/archive/1/460617/100/0/threaded",
"http://www.securityfocus.com/bid/22601",
"http://xforce.iss.net/xforce/xfdb/32580"
],
"summary": "Mozilla Firefox might allow remote attackers to conduct spoofing and phishing attacks by writing to an about:blank tab and overlaying the location bar.",
"vulnerable_configuration": [
"cpe:2.3:a:mozilla:firefox:2.0:rc3"
],
"vulnerable_configuration_cpe_2_2": [
"cpe:/a:mozilla:firefox:2.0:rc3"
]}]}
'''

def test_output_cve_id():

##BUG##
api.urlopen = Mock()
api.urlopen.return_value = test_data
api.output_cve_id()

assert api.output_cve_id.data["data"]["item"] == "CVE-2007-1004"

0 comments on commit a973fb7

Please sign in to comment.