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

Fix/save metadata #145

Merged
merged 6 commits into from
Jan 12, 2022
Merged
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3.7-slim
MAINTAINER Patrowl.io "[email protected]"
LABEL Name="PatrowlHears" Version="1.0.15"
LABEL Name="PatrowlHears" Version="1.1.0"

ENV PYTHONUNBUFFERED 1
RUN mkdir -p /opt/patrowl-hears/
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.15 // Community Edition
1.1.0 // Community Edition
2 changes: 1 addition & 1 deletion backend_app/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.15
1.1.0
5 changes: 2 additions & 3 deletions backend_app/requirements.macos.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
aiohttp==3.8.1
amqp==2.5.2
asgiref==3.3.4
async-timeout==3.0.1
async-timeout==4.0.1
attrs==19.3.0
billiard==3.6.1.0
boto3==1.16.23
Expand Down Expand Up @@ -46,8 +46,7 @@ oauthlib==3.1.0
openapi-codec==1.3.2
ordered-set==3.1.1
packaging==20.3
psycopg2==2.8.4
psycopg2-binary==2.8.6
psycopg2==2.9.0
PyJWT==1.7.1
pymongo==3.10.1
pyparsing==2.4.6
Expand Down
2 changes: 1 addition & 1 deletion backend_app/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ oauthlib==3.1.0
openapi-codec==1.3.2
ordered-set==3.1.1
packaging==20.3
psycopg2==2.8.4
psycopg2==2.9.0
PyJWT==1.7.1
pymongo==3.10.1
pyparsing==2.4.6
Expand Down
81 changes: 80 additions & 1 deletion backend_app/vpratings/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from .models import VPRating, VPR_METRICS
from .serializers import VPRatingSerializer
from .utils import _refresh_vprating, _calc_vprating

from datetime import datetime, date
from itertools import chain

class VPRatingSet(viewsets.ModelViewSet):
"""API endpoint that allows ratings to be viewed or edited."""
Expand All @@ -24,6 +25,84 @@ def get_vprating_metrics(self):
return JsonResponse(VPR_METRICS)


@api_view(['GET'])
@permission_classes([IsAuthenticated])
def get_vuln_vector(self, vuln_id):

vuln = get_object_or_404(Vuln, id=vuln_id)
try:
org_id = self.session.get('org_id', None)
org = organization.get_current_organization(user=self.user, org_id=org_id)
except Exception:
return JsonResponse("error: unable to get the organization", safe=False, status=500)

today_date = date.today()

# Vulnerability
vector = "" + vuln.cvss_vector

if vuln.is_confirmed is True:
vector += "/CL:Y"

if type(vuln.published) is datetime:
published_date = vuln.published.date()
delta = today_date - published_date
vector += "/VX:" + str(delta.days)

ea_metrics = ['unknown', 'private', 'public']
em_metrics = ['unknown', 'unproven', 'poc', 'functional']
et_metrics = ['unknown', 'low', 'medium', 'high', 'trusted']
ea_idx = ea_max_idx = 0
em_idx = em_max_idx = 0
et_idx = et_max_idx = 0
ex_max_days = 0

exploits = list(
chain(
vuln.exploitmetadata_set.all(),
vuln.orgexploitmetadata_set.filter(organization=org)
)
)

for exploit in exploits:
e = model_to_dict(exploit)

ea_idx = ea_metrics.index(e['availability'])
if ea_idx > ea_max_idx:
ea_max_idx = ea_idx

em_idx = em_metrics.index(e['maturity'])
if em_idx > em_max_idx:
em_max_idx = em_idx

et_idx = et_metrics.index(e['trust_level'])
if et_idx > et_max_idx:
et_max_idx = et_idx

if type(e['published']) is datetime:
published_date = e['published'].date()
delta_published_date = today_date - published_date
if delta_published_date.days > ex_max_days:
ex_max_days = delta_published_date.days

ea_vectors = ['X', 'R', 'U']
em_vectors = ['X', 'U', 'P', 'F']
et_vectors = ['X', 'L', 'M', 'H', 'H']

vector += "/EA:" + str(ea_vectors[ea_max_idx])
vector += "/EM:" + str(em_vectors[em_max_idx])
vector += "/ET:" + str(et_vectors[et_max_idx])
vector += "/EX:" + str(ex_max_days)

if vuln.is_in_the_news:
vector += "/N:Y"

if vuln.is_in_the_wild:
vector += "/W:Y"

return JsonResponse(vector, safe=False)


@api_view(['GET'])
@permission_classes([IsAuthenticated])
def get_vprating_by_cveid(self, cve_id):
Expand Down
1 change: 1 addition & 0 deletions backend_app/vpratings/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
# path('calc/<int:vuln_id>', apis.refresh_vprating_by_id, name='refresh_vprating_by_id'),
path('metrics', apis.get_vprating_metrics, name='get_vprating_metrics'),
path('calc/<int:vuln_id>', apis.calc_vprating_by_vulnid, name='refresh_vprating_by_id'),
path('vector/<vuln_id>', apis.get_vuln_vector, name="get_vuln_vector"),
]
Loading