galaxy description and tags

This commit is contained in:
Terrtia 2018-05-29 08:47:46 +02:00
parent f5cae0d99c
commit f3f6b76428
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
4 changed files with 498 additions and 2 deletions

View file

@ -84,7 +84,6 @@ for module_name, txt in list(to_add_to_header_dico.items()):
to_add_to_header = [] to_add_to_header = []
for module_name, txt in to_add_to_header_dico.items(): for module_name, txt in to_add_to_header_dico.items():
to_add_to_header.append(txt) to_add_to_header.append(txt)
print(to_add_to_header)
modified_header = modified_header.replace('<!--insert here-->', '\n'.join(to_add_to_header)) modified_header = modified_header.replace('<!--insert here-->', '\n'.join(to_add_to_header))

View file

@ -12,6 +12,7 @@ import json
import Paste import Paste
from pytaxonomies import Taxonomies from pytaxonomies import Taxonomies
from pymispgalaxies import Galaxies, Clusters
# ============ VARIABLES ============ # ============ VARIABLES ============
import Flask_config import Flask_config
@ -25,6 +26,21 @@ max_preview_modal = Flask_config.max_preview_modal
Tags = Blueprint('Tags', __name__, template_folder='templates') Tags = Blueprint('Tags', __name__, template_folder='templates')
galaxies = Galaxies()
clusters = Clusters(skip_duplicates=True)
list_all_tags = {}
for name, c in clusters.items(): #galaxy name + tags
list_all_tags[name] = c
list_galaxies = []
for g in galaxies.values():
list_galaxies.append(g.to_json())
list_clusters = []
for c in clusters.values():
list_clusters.append(c.to_json())
# ============ FUNCTIONS ============ # ============ FUNCTIONS ============
def one(): def one():
return 1 return 1
@ -336,7 +352,6 @@ def taxonomies():
version = version, version = version,
enabled = enabled, enabled = enabled,
n_tags=n_tags) n_tags=n_tags)
#return 'O'
@Tags.route("/Tags/edit_taxonomie") @Tags.route("/Tags/edit_taxonomie")
def edit_taxonomie(): def edit_taxonomie():
@ -467,7 +482,204 @@ def edit_taxonomie_tag():
else: else:
return "INCORRECT INPUT" return "INCORRECT INPUT"
@Tags.route("/Tags/galaxies")
def galaxies():
active_galaxies = r_serv_tags.smembers('active_galaxies')
total_tags = {}
for name, tags in clusters.items(): #galaxie name + tags
total_tags[name] = len(tags)
name = []
icon = []
version = []
all_type = []
namespace = []
description = []
enabled = []
n_tags = []
for galaxie_json in list_galaxies:
galaxie = json.loads(galaxie_json)
name.append(galaxie['name'])
icon.append(galaxie['icon'])
version.append(galaxie['version'])
type = galaxie['type']
if type == 'mitre-pre-attack-relashipship':
type = 'mitre-pre-attack-relationship'
all_type.append(type)
namespace.append(galaxie['namespace'])
description.append(galaxie['description'])
if type in active_galaxies:
enabled.append(True)
else:
enabled.append(False)
n = str(r_serv_tags.scard('active_tag_galaxies_' + type))
n_tags.append(n + '/' + str(total_tags[type]) )
return render_template("galaxies.html",
name=name,
icon = icon,
version = version,
description = description,
namespace = namespace,
all_type = all_type,
enabled = enabled,
n_tags=n_tags)
@Tags.route("/Tags/edit_galaxy")
def edit_galaxy():
id = request.args.get('galaxy')
for clusters_json in list_clusters:
#get clusters
cluster = json.loads(clusters_json)
if cluster['type'] == id:
type = id
active_tag = r_serv_tags.smembers('active_tag_galaxies_' + type)
name = cluster['name']
description = cluster['description']
version = cluster['version']
source = cluster['source']
val = cluster['values']
tags = []
for data in val:
try:
meta = data['meta']
'''synonyms = meta['synonyms']
logo = meta['logo']
refs = meta['refs']'''
except KeyError:
meta = []
tag_name = data['value']
tag_name = 'misp-galaxy:{}="{}"'.format(type, tag_name)
try:
tag_description = data['description']
except KeyError:
tag_description = ''
tags.append( (tag_name, tag_description, meta) )
status = []
for tag in tags:
if tag[0] in active_tag:
status.append(True)
else:
status.append(False)
active_galaxies = r_serv_tags.smembers('active_galaxies')
if id in active_galaxies:
active = True
else:
active = False
return render_template("edit_galaxy.html",
id = type,
name = name,
description = description,
version = version,
active = active,
tags = tags,
status = status)
return 'INVALID GALAXY'
@Tags.route("/Tags/active_galaxy")
def active_galaxy():
id = request.args.get('galaxy')
# verify input
try:
l_tags = list_all_tags[id]
except KeyError:
return "INCORRECT INPUT"
r_serv_tags.sadd('active_galaxies', id)
for tag in l_tags:
r_serv_tags.sadd('active_tag_galaxies_' + id, 'misp-galaxy:{}="{}"'.format(id, tag))
return redirect(url_for('Tags.galaxies'))
@Tags.route("/Tags/disable_galaxy")
def disable_galaxy():
id = request.args.get('galaxy')
# verify input
try:
l_tags = list_all_tags[id]
except KeyError:
return "INCORRECT INPUT"
r_serv_tags.srem('active_galaxies', id)
for tag in l_tags:
r_serv_tags.srem('active_tag_galaxies_' + id, 'misp-galaxy:{}="{}"'.format(id, tag))
return redirect(url_for('Tags.galaxies'))
@Tags.route("/Tags/edit_galaxy_tag")
def edit_galaxy_tag():
arg1 = request.args.getlist('tag_enabled')
arg2 = request.args.getlist('tag_disabled')
id = request.args.get('galaxy')
#verify input
try:
l_tags = list_all_tags[id]
except KeyError:
return "INCORRECT INPUT"
#get full tags
list_tag = []
for tag in l_tags:
list_tag.append('misp-galaxy:{}="{}"'.format(id, tag))
#check tags validity
if ( all(elem in list_tag for elem in arg1) or (len(arg1) == 0) ) and ( all(elem in list_tag for elem in arg2) or (len(arg2) == 0) ):
active_tag = r_serv_tags.smembers('active_tag_galaxies_' + id)
diff = list(set(arg1) ^ set(list_tag))
#remove tags
for tag in diff:
r_serv_tags.srem('active_tag_galaxies_' + id, tag)
#all tags unchecked
if len(arg1) == 0 and len(arg2) == 0:
r_serv_tags.srem('active_galaxies', id)
#add new tags
for tag in arg2:
r_serv_tags.sadd('active_galaxies', id)
r_serv_tags.sadd('active_tag_galaxies_' + id, tag)
return redirect(url_for('Tags.galaxies'))
else:
return "INCORRECT INPUT"
# ========= REGISTRATION ========= # ========= REGISTRATION =========
app.register_blueprint(Tags) app.register_blueprint(Tags)

View file

@ -0,0 +1,164 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Analysis Information Leak framework Dashboard</title>
<!-- Core CSS -->
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='font-awesome/css/font-awesome.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/sb-admin-2.css') }}" rel="stylesheet">
<link href="/static//css/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
<!-- JS -->
<script type="text/javascript" src="{{ url_for('static', filename='js/dygraph-combined.js') }}"></script>
<script language="javascript" src="{{ url_for('static', filename='js/jquery.js')}}"></script>
<script src="/static//js/bootstrap.min.js"></script>
<script src="/static//js/jquery.dataTables.min.js"></script>
<script src="/static//js/dataTables.bootstrap.js"></script>
<style>
.tooltip-inner {
text-align: left;
height: 200%;
width: 200%;
max-width: 500px;
max-height: 500px;
font-size: 13px;
}
xmp {
white-space:pre-wrap;
word-wrap:break-word;
}
.test thead{
background: #d91f2d;
color: #fff;
}
</style>
</head>
<body>
{% include 'navbar.html' %}
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<a href="/Tags/galaxies" class="btn btn-light pull-left">
<i class="fa fa-arrow-left fa"></i> List Galaxies
</a>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="panel panel-primary">
<div class="panel-heading">{{ name }}
{% if active %}
<span class="label label-success pull-right"> Enabled</span>
{% endif %}
{% if not active %}
<span class="label label-danger pull-right"> Disabled</span>
{% endif %}
</div>
<div class="panel-body">
{{ description }}
<br><br>
Version: {{ version }}
{% if active %}
<a href="{{ url_for('Tags.disable_galaxy') }}?galaxy={{ id }}" class="btn btn-danger pull-right">
<i class="fa fa-times fa"></i> Disable Galaxy
</a>
{% endif %}
{% if not active %}
<a href="{{ url_for('Tags.active_galaxy') }}?galaxy={{ id }}" class="btn btn-success pull-right">
<i class="fa fa-check-square-o fa"></i> Enable Galaxy
</a>
{% endif %}
</div>
</div>
<form action="/Tags/edit_galaxy_tag" id="checkboxForm">
<input type="hidden" value="{{ id }}" name="galaxy" />
<table class="test table table-striped table-bordered table-hover table-responsive " id="myTable_">
<thead>
<tr>
<th></th>
<th style="max-width: 800px;">Tag</th>
<th style="max-width: 800px;">Description</th>
<th>Enabled</th>
</tr>
</thead>
<tbody>
{% for tag in tags %}
<tr>
<td>
{% if status[loop.index0] %}
<div style="display:none;">Enabled</div>
<input type="checkbox" value="{{ tag[0] }}" id="{{ tag[0] }}" name="tag_enabled" checked>
{% endif %}
{% if not status[loop.index0] %}
<div style="display:none;">Disabled</div>
<input type="checkbox" value="{{ tag[0] }}" id="{{ tag[0] }}" name="tag_disabled" >
{% endif %}
</td>
<td>{{ tag[0] }}</td>
<td>{{ tag[1] }}</td>
<td style="text-align: center;">
{% if status[loop.index0] %}
<div style="display:none;">Enabled</div>
<div style="color:Green; display:inline-block"><i class="fa fa-check-circle fa-2x"></i></div>
{% endif %}
{% if not status[loop.index0] %}
<div style="display:none;">Disabled</div>
<div style="color:Red; display:inline-block"><i class="fa fa-times-circle fa-2x"></i></div>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="input-group-btn">
<button class="btn btn-primary btn-lg">
<i class="fa fa-check-square-o fa"></i>
Update Tags
</button>
</div>
</form>
</div>
<!-- /#page-wrapper -->
</body>
<script>
$(document).ready(function(){
$('#myTable_').DataTable(
{
"aLengthMenu": [[5, 10, 15, 20, -1], [5, 10, 15, 20, "All"]],
"iDisplayLength": 10,
//"order": [[ 1, "asc" ]]
}
);
});
</script>
<script>
function submitActiveTags(){
document.getElementById("checkboxForm").submit();
}
</script>
</html>

View file

@ -0,0 +1,121 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Analysis Information Leak framework Dashboard</title>
<!-- Core CSS -->
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='font-awesome/css/font-awesome.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/sb-admin-2.css') }}" rel="stylesheet">
<link href="/static//css/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
<!-- JS -->
<script type="text/javascript" src="{{ url_for('static', filename='js/dygraph-combined.js') }}"></script>
<script language="javascript" src="{{ url_for('static', filename='js/jquery.js')}}"></script>
<script src="/static//js/bootstrap.min.js"></script>
<script src="/static//js/jquery.dataTables.min.js"></script>
<script src="/static//js/dataTables.bootstrap.js"></script>
<style>
.tooltip-inner {
text-align: left;
height: 200%;
width: 200%;
max-width: 500px;
max-height: 500px;
font-size: 13px;
}
xmp {
white-space:pre-wrap;
word-wrap:break-word;
}
.test thead{
background: #d91f2d;
color: #fff;
}
</style>
</head>
<body>
{% include 'navbar.html' %}
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Galaxies</h1>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<table class="test table table-striped table-bordered table-hover table-responsive " id="myTable_">
<thead>
<tr>
<th>Name</th>
<th style="max-width: 800px;">Description</th>
<th>Namespace</th>
<th>Version</th>
<th>Enabled</th>
<th>Active Tags</th>
</tr>
</thead>
<tbody>
{% for type in all_type %}
<tr>
<td>
{{ name[loop.index0] }}
<div>
<i class="fa fa-{{ icon[loop.index0] }}"></i>
</div>
</td>
<td>{{ description[loop.index0] }}</td>
<td>{{ namespace[loop.index0] }}</td>
<td>{{ version[loop.index0] }}</td>
<td style="text-align: center;">
{% if enabled[loop.index0] %}
<div style="display:none;">Enabled</div>
<div style="color:Green; display:inline-block"><i class="fa fa-check-circle fa-2x"></i></div>
{% endif %}
{% if not enabled[loop.index0] %}
<div style="display:none;">Disabled</div>
<div style="color:Red; display:inline-block"><i class="fa fa-times-circle fa-2x"></i></div>
{% endif %}
</td>
<td style="text-align: center;">
<div style="display:none;">{{ n_tags[loop.index0] }}</div>
<a class="btn btn-primary" href="{{ url_for('Tags.edit_galaxy') }}?galaxy={{ type }}">Active Tags <span class="badge">{{ n_tags[loop.index0] }}</span></a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- /#page-wrapper -->
</body>
<script>
$(document).ready(function(){
//search_table = $('#myTable_').DataTable({ "order": [[ 2, "desc" ]] });
$('#myTable_').DataTable(
{
"aLengthMenu": [[5, 10, 15, 20, -1], [5, 10, 15, 20, "All"]],
"iDisplayLength": 15,
//"order": [[ 1, "asc" ]]
}
);
});
</script>
</html>