galaxy tag info + fix

This commit is contained in:
Terrtia 2018-05-30 16:18:58 +02:00
parent dbe67e094b
commit 8a87b7b082
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
7 changed files with 229 additions and 16 deletions

View file

@ -123,10 +123,16 @@ r_serv_tags = redis.StrictRedis(
decode_responses=True) decode_responses=True)
# add default ail taxonomies # add default ail taxonomies
r_serv_tags.sadd('active_taxonomies', 'infoleak') r_serv_tags.sadd('active_taxonomies', 'infoleak')
r_serv_tags.sadd('active_taxonomies', 'gdpr')
r_serv_tags.sadd('active_taxonomies', 'fpf')
# add default tags # add default tags
taxonomies = Taxonomies() taxonomies = Taxonomies()
for tag in taxonomies.get('infoleak').machinetags(): for tag in taxonomies.get('infoleak').machinetags():
r_serv_tags.sadd('active_tag_infoleak', tag) r_serv_tags.sadd('active_tag_infoleak', tag)
for tag in taxonomies.get('gdpr').machinetags():
r_serv_tags.sadd('active_tag_infoleak', tag)
for tag in taxonomies.get('fpf').machinetags():
r_serv_tags.sadd('active_tag_infoleak', tag)
# ============ MAIN ============ # ============ MAIN ============

View file

@ -41,6 +41,11 @@ list_clusters = []
for c in clusters.values(): for c in clusters.values():
list_clusters.append(c.to_json()) list_clusters.append(c.to_json())
# tags numbers in galaxies
total_tags = {}
for name, tags in clusters.items(): #galaxie name + tags
total_tags[name] = len(tags)
# ============ FUNCTIONS ============ # ============ FUNCTIONS ============
def one(): def one():
return 1 return 1
@ -174,6 +179,9 @@ def get_tagged_paste():
tags = request.args.get('ltags') tags = request.args.get('ltags')
list_tags = tags.split(',') list_tags = tags.split(',')
list_tag = []
for tag in list_tags:
list_tag.append(tag.replace('"','\"'))
# TODO verify input # TODO verify input
@ -249,6 +257,7 @@ def get_tagged_paste():
year=currentSelectYear, year=currentSelectYear,
all_path=all_path, all_path=all_path,
tags=tags, tags=tags,
list_tag = list_tag,
paste_tags=paste_tags, paste_tags=paste_tags,
bootstrap_label=bootstrap_label, bootstrap_label=bootstrap_label,
content=all_content, content=all_content,
@ -339,13 +348,10 @@ def addTags():
# verify input # verify input
gal = tag.split(':')[1] gal = tag.split(':')[1]
gal = gal.split('=')[0] gal = gal.split('=')[0]
print(tag)
print(gal)
print(active_galaxies)
if gal in active_galaxies: if gal in active_galaxies:
if tag in r_serv_tags.smembers('active_tag_galaxies_' + gal): if tag in r_serv_tags.smembers('active_tag_galaxies_' + gal):
print('adding ...')
#add tag #add tag
r_serv_metadata.sadd('tag:'+path, tag) r_serv_metadata.sadd('tag:'+path, tag)
r_serv_tags.sadd(tag, path) r_serv_tags.sadd(tag, path)
@ -416,6 +422,9 @@ def edit_taxonomie():
else: else:
active = False active = False
n = str(r_serv_tags.scard('active_tag_' + id))
badge = n + '/' + str(len(taxonomies.get(id).machinetags()))
name = taxonomies.get(id).name name = taxonomies.get(id).name
description = taxonomies.get(id).description description = taxonomies.get(id).description
version = taxonomies.get(id).version version = taxonomies.get(id).version
@ -430,6 +439,7 @@ def edit_taxonomie():
return render_template("edit_taxonomie.html", return render_template("edit_taxonomie.html",
id=id, id=id,
name=name, name=name,
badge = badge,
description = description, description = description,
version = version, version = version,
active=active, active=active,
@ -526,10 +536,6 @@ def galaxies():
active_galaxies = r_serv_tags.smembers('active_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 = [] name = []
icon = [] icon = []
version = [] version = []
@ -588,6 +594,9 @@ def edit_galaxy():
type = id type = id
active_tag = r_serv_tags.smembers('active_tag_galaxies_' + type) active_tag = r_serv_tags.smembers('active_tag_galaxies_' + type)
n = str(r_serv_tags.scard('active_tag_galaxies_' + type))
badge = n + '/' + str(total_tags[type])
name = cluster['name'] name = cluster['name']
description = cluster['description'] description = cluster['description']
version = cluster['version'] version = cluster['version']
@ -629,6 +638,7 @@ def edit_galaxy():
return render_template("edit_galaxy.html", return render_template("edit_galaxy.html",
id = type, id = type,
name = name, name = name,
badge = badge,
description = description, description = description,
version = version, version = version,
active = active, active = active,
@ -775,11 +785,77 @@ def edit_galaxy_tag():
else: else:
return "INCORRECT INPUT" return "INCORRECT INPUT"
@Tags.route("/Tags/test") @Tags.route("/Tags/tag_galaxy_info")
def test(): def tag_galaxy_info():
return render_template("test.html", galaxy = request.args.get('galaxy')
id = '1') tag = request.args.get('tag')
full_tag = tag
title = tag.split(':')[1]
tag = tag.split('=')[1]
tag = tag[1:-1]
#get clusters
for clusters_json in list_clusters:
cluster = json.loads(clusters_json)
if cluster['type'] == galaxy:
val = cluster['values']
source = cluster['source']
for data in val:
if tag == data['value']:
try:
description = data['description']
except KeyError:
description = ''
if r_serv_tags.sismember('active_tag_galaxies_' + galaxy, full_tag):
active = True
else:
active = False
synonyms = []
metadata = []
try:
meta = data['meta']
list_metadata = []
for key in meta:
if key != 'synonyms':
if type(meta[key]) is list:
for item in meta[key]:
list_metadata.append(key + ' : ' + item)
else:
list_metadata.append(key + ' : ' + meta[key])
try:
synonyms = meta['synonyms']
bool_synonyms = True
except KeyError:
synonyms = []
bool_synonyms = False
except KeyError:
pass
if synonyms:
bool_synonyms = True
else:
bool_synonyms = False
if list_metadata:
metadata = True
else:
metadata = False
return render_template("tag_galaxy_info.html",
title = title,
description = description,
source = source,
active = active,
synonyms = synonyms,
bool_synonyms = bool_synonyms,
metadata = metadata,
list_metadata = list_metadata)
return 'INVALID INPUT'
# ========= REGISTRATION ========= # ========= REGISTRATION =========
app.register_blueprint(Tags) app.register_blueprint(Tags)

View file

@ -72,6 +72,8 @@
<script> <script>
var ltags var ltags
$(document).ready(function(){ $(document).ready(function(){
activePage = "page-Tags"
$("#"+activePage).addClass("active");
$.getJSON('/Tags/get_all_tags', $.getJSON('/Tags/get_all_tags',
function(data) { function(data) {

View file

@ -58,6 +58,8 @@
<div class="panel-heading">{{ name }} <div class="panel-heading">{{ name }}
{% if active %} {% if active %}
<span class="label label-success pull-right"> Enabled</span> <span class="label label-success pull-right"> Enabled</span>
<span class="pull-right">&nbsp;&nbsp;&nbsp;</span>
<span class="badge badge-light pull-right">{{ badge }}</span>
{% endif %} {% endif %}
{% if not active %} {% if not active %}
<span class="label label-danger pull-right"> Disabled</span> <span class="label label-danger pull-right"> Disabled</span>
@ -107,7 +109,9 @@
<input type="checkbox" value="{{ tag[0] }}" id="{{ tag[0] }}" name="tag_disabled" > <input type="checkbox" value="{{ tag[0] }}" id="{{ tag[0] }}" name="tag_disabled" >
{% endif %} {% endif %}
</td> </td>
<td>{{ tag[0] }}</td> <td>
<a href="{{ url_for('Tags.tag_galaxy_info') }}?galaxy={{ request.args.get('galaxy') }}&tag={{ tag[0] }}">{{ tag[0] }}</a>
</td>
<td>{{ tag[1] }}</td> <td>{{ tag[1] }}</td>
<td style="text-align: center;"> <td style="text-align: center;">
{% if status[loop.index0] %} {% if status[loop.index0] %}

View file

@ -58,6 +58,8 @@
<div class="panel-heading">{{ name }} <div class="panel-heading">{{ name }}
{% if active %} {% if active %}
<span class="label label-success pull-right"> Enabled</span> <span class="label label-success pull-right"> Enabled</span>
<span class="pull-right">&nbsp;&nbsp;&nbsp;</span>
<span class="badge badge-light pull-right">{{ badge }}</span>
{% endif %} {% endif %}
{% if not active %} {% if not active %}
<span class="label label-danger pull-right"> Disabled</span> <span class="label label-danger pull-right"> Disabled</span>

View file

@ -0,0 +1,116 @@
<!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="{{ url_for('Tags.edit_galaxy') }}?galaxy={{ request.args.get('galaxy') }}" class="btn btn-light pull-left">
<i class="fa fa-arrow-left fa"></i> {{ request.args.get('galaxy') }} Galaxy
</a>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="panel panel-primary">
<div class="panel-heading">{{ title }}
{% 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>
Source: {{ source }}
{% if metadata %}
<div class="panel panel-info pull-right" style="width: 60%;">
<div class="panel-heading"> Metadata :
<ul class="list-group">
{% for meta in list_metadata %}
<li class="list-group-item">{{ meta }}</li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
{% if bool_synonyms %}
<br><br>
<ul class="list-group" style="width: 30%;">
<li class="list-group-item active">synonyms :</li>
{% for synonym in synonyms %}
<li class="list-group-item">{{ synonym }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
</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>

View file

@ -178,17 +178,25 @@ $(document).ready(function(){
$.getJSON('/Tags/get_all_tags', $.getJSON('/Tags/get_all_tags',
function(data) { function(data) {
activePage = "page-Tags"
$("#"+activePage).addClass("active");
//var valueData = ["infoleak:automatic-detection=\"bitcoin-address\"","infoleak:automatic-detection=\"aws-key\"",'misp-galaxy:botnet="Marina Botnet"'];
var valueData = [
{% for tag in list_tag %}
'{{tag|safe}}',
{% endfor %}
];
ltags = $('#ltags').tagSuggest({ ltags = $('#ltags').tagSuggest({
data: data, data: data,
//value: ["infoleak:automatic-detection=\"bitcoin-address\"","infoleak:automatic-detection=\"aws-key\""], value: valueData,
sortOrder: 'name', sortOrder: 'name',
maxDropHeight: 200, maxDropHeight: 200,
name: 'ltags', name: 'ltags',
}); });
//ltags.setValue(["{{ tags }}"]); //ltags.setValue(["{{ tags }}"]);
ltags.setValue(["infoleak:automatic-detection='bitcoin-address'","infoleak:automatic-detection='aws-key'"]); //ltags.setValue([{id:"infoleak:automatic-detection='bitcoin-address'",name:"infoleak:automatic-detection='bitcoin-address'"}}]);
}); });
}); });
@ -200,7 +208,6 @@ $(document).ready(function(){
window.location.replace("{{ url_for('Tags.get_tagged_paste') }}?ltags=" + data); window.location.replace("{{ url_for('Tags.get_tagged_paste') }}?ltags=" + data);
} }
function emptyTags() { function emptyTags() {
console.log('b');
ltags.clear(); ltags.clear();
} }
</script> </script>