Skip to content
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

Team#2 Patch 4 update the transfer-ASCII directory #40

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 0 additions & 83 deletions README.md

This file was deleted.

37 changes: 37 additions & 0 deletions projects/Team-2-EtherEdge/NVD-Chainlink-Adapter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Chainlink Python External Adapter for NVD Impact Score and vulnerability description.

This repository implemented chanlink external adapter for getting impact score and vulnerability description from Nation vulnerability database. It is coded by Python and chainlink official template.
Install

pip3 install -r requirements.txt

Run locally:

python3 app.py

open another terminel :

cat test.sh

#!/bin/bash

curl -X POST -H "Content-Type: application/json" http://localhost:8080 -d '{ "id": "CVE-2010-4662" }'
curl -X POST -H "Content-Type: application/json" http://localhost:8080 -d '{ "id": "cve-2021-1675" }'


$ bash test.sh


Example JSON Response:
{
"Description": "PmWiki before 2.2.21 has XSS.",
"baseScore": 6.1,
"jobRunID": "CVE-2010-4662",
"statusCode": 200
}
{
"Description": "Windows Print Spooler Elevation of Privilege Vulnerability",
"baseScore": 8.8,
"jobRunID": "cve-2021-1675",
"statusCode": 200
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
36 changes: 36 additions & 0 deletions projects/Team-2-EtherEdge/NVD-Chainlink-Adapter/adapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from bridge import Bridge
#from elonmusk import SpaceX
from nvd import CVE
import requests

class Adapter:

def __init__(self, input):
self.id = input.get('id', '1')
self.bridge = Bridge()
self.create_request()

def create_request(self):
try:
data = CVE().get_launch_info(self.id)
self.result_success(data)
except Exception as e:
self.result_error(e)
finally:
self.bridge.close()

def result_success(self, data):
self.result = {
'jobRunID' : self.id,
'baseScore' : data["baseScore"],
'Description' : data["Description"],
'statusCode' : 200,
}

def result_error(self, error):
self.result = {
'jobRunID': self.id,
'status': 'errored',
'error': f'There was an error: {error}',
'statusCode': 500,
}
20 changes: 20 additions & 0 deletions projects/Team-2-EtherEdge/NVD-Chainlink-Adapter/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from flask import Flask, request, jsonify
from adapter import Adapter

app = Flask(__name__)

@app.before_request
def log_request_info():
app.logger.debug('Headers: %s', request.headers)
app.logger.debug('Body: %s', request.get_data())

@app.route('/', methods=['POST'])
def call_adapter():
data = request.get_json()
if data == '':
data = {}
adapter = Adapter(data)
return jsonify(adapter.result)

if __name__ == '__main__':
app.run(debug=True, host='127.0.0.1', port='8080', threaded=True)
36 changes: 36 additions & 0 deletions projects/Team-2-EtherEdge/NVD-Chainlink-Adapter/bridge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry

class Bridge(object):

def __init__(
self,
retries=3,
backoff_factor=0.3,
status_forcelist=(500, 502, 504),
):
self.session = requests.Session()
retry = Retry(
total=retries,
read=retries,
connect=retries,
backoff_factor=backoff_factor,
status_forcelist=status_forcelist,
)
adapter = HTTPAdapter(max_retries=retry)
self.session.mount('http://', adapter)
self.session.mount('https://', adapter)

def request(self, url, headers={}, timeout=15):
try:
return self.session.get(
url,
headers=headers,
timeout=timeout
)
except Exception as e:
raise e

def close(self):
self.session.close()
2 changes: 2 additions & 0 deletions projects/Team-2-EtherEdge/NVD-Chainlink-Adapter/cve.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cve-2021-1675
CVE-2010-4662
9 changes: 9 additions & 0 deletions projects/Team-2-EtherEdge/NVD-Chainlink-Adapter/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from adapter import Adapter

def lambda_handler(event, context):
adapter = Adapter(event)
return adapter.result

def gcs_handler(request):
adapter = Adapter(request.json)
return json.dumps(adapter.result)
17 changes: 17 additions & 0 deletions projects/Team-2-EtherEdge/NVD-Chainlink-Adapter/nvd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import requests

class CVE:

def __init__(self):
self._api_endpoint = "https://plasticuproject.pythonanywhere.com/nvd-api/v1/"

def get_launch_info(self,cve):
response = requests.get(self._api_endpoint + cve).json()
try:
cve ={
"baseScore" : response['impact']['baseMetricV3']['cvssV3']['baseScore'],
"Description": response['cve']['description']['description_data'][0]['value']
}
return cve
except Exception as error:
return error
12 changes: 12 additions & 0 deletions projects/Team-2-EtherEdge/NVD-Chainlink-Adapter/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-i https://pypi.org/simple
certifi==2020.4.5.1
chardet==3.0.4
click==7.1.1
flask==1.1.1
idna==2.9
itsdangerous==1.1.0
jinja2==2.11.1
markupsafe==1.1.1
requests==2.23.0
urllib3==1.25.8
werkzeug==1.0.1
5 changes: 5 additions & 0 deletions projects/Team-2-EtherEdge/NVD-Chainlink-Adapter/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

curl -X POST -H "Content-Type: application/json" http://localhost:8080 -d '{ "id": "CVE-2010-4662" }'
curl -X POST -H "Content-Type: application/json" http://localhost:8080 -d '{ "id": "cve-2021-1675" }'

37 changes: 37 additions & 0 deletions projects/Team-2-EtherEdge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Chainlink Python External Adapter for NVD Impact Score and vulnerability description.

This repository implemented chanlink external adapter for getting impact score and vulnerability description from Nation vulnerability database. It is coded by Python and chainlink official template.
Install

pip3 install -r requirements.txt

Run locally:

python3 app.py

open another terminel :

cat test.sh

#!/bin/bash

curl -X POST -H "Content-Type: application/json" http://localhost:8080 -d '{ "id": "CVE-2010-4662" }'
curl -X POST -H "Content-Type: application/json" http://localhost:8080 -d '{ "id": "cve-2021-1675" }'


$ bash test.sh


Example JSON Response:
{
"Description": "PmWiki before 2.2.21 has XSS.",
"baseScore": 6.1,
"jobRunID": "CVE-2010-4662",
"statusCode": 200
}
{
"Description": "Windows Print Spooler Elevation of Privilege Vulnerability",
"baseScore": 8.8,
"jobRunID": "cve-2021-1675",
"statusCode": 200
}
Binary file not shown.
15 changes: 15 additions & 0 deletions projects/Team-2-EtherEdge/transfer-ASCII/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"extends": [
"google"
],
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
}
}
2 changes: 2 additions & 0 deletions projects/Team-2-EtherEdge/transfer-ASCII/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
Loading