Skip to content

Commit

Permalink
happy with this. Not perfect, but good.
Browse files Browse the repository at this point in the history
  • Loading branch information
avuko committed Sep 6, 2019
1 parent 60bd1bb commit ab837df
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
16 changes: 9 additions & 7 deletions web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def return_search_results(rdb, cachename, allssdeepnodes,
"linkcount": '{}'.format(len(allssdeeplinks)),
"sample": '{}'.format(sampled).lower()}

rv = {'info': selectioninfo,
rv = {'_info': selectioninfo,
'nodes': list(allssdeepnodes),
'links': list(allssdeeplinks),
'contexts': list(allssdeepcontexts)
Expand Down Expand Up @@ -411,7 +411,7 @@ def build_graph(rdb, contexts, cachename):
fullcontextlist = ('|').join(context)
groupid = rdb.zrank(allcontexts, contexts[0])
newnode = {'id': rdb.zrank(cachename, ssdeep),
'inputname': return_inputname,
'inputname': f'{contexts[0]} | {return_inputname}' ,
'sha256': return_sha256,
'ssdeep': f'{ssdeep}',
'main_context': contexts[0],
Expand All @@ -431,9 +431,10 @@ def build_graph(rdb, contexts, cachename):

allssdeepcontexts = contexts
for context in contexts:
print(context)
groupid = rdb.zrank(allcontexts, context)
context = {context: {"color": aphash_color(groupid), "groupid": groupid}}
# print(context)
# groupid = rdb.zrank(allcontexts, context)
# we won't be using the colors, but we want a count
context = {context: {}}
allssdeepcontexts, allssdeepcontextcount = cache_action(rdb,
cachename,
'contexts',
Expand Down Expand Up @@ -461,8 +462,8 @@ def build_graph(rdb, contexts, cachename):
allssdeepnodes = list([ast.literal_eval(x) for x in list(rdb.smembers(allssdeepnodes))])
allssdeeplinks = list([ast.literal_eval(x) for x in list(rdb.smembers(allssdeeplinks))])
allssdeepcontexts = list(kathe.zrange_to_json(rdb.zrangebyscore(allssdeepcontexts,
min=0, max="+inf",
withscores=True)))
min=0, max="+inf",
withscores=True)))

return allssdeepnodes, allssdeeplinks, allssdeepcontexts

Expand Down Expand Up @@ -495,6 +496,7 @@ def get_cached_graph(rdb, cachename):
# reminder, cache function (accepts 'add' and 'delete'):
# def cache_action(rdb, cachename, cachetype=None, info=None, action=None):


# web service routes begin here
@route('/')
def hello():
Expand Down
3 changes: 2 additions & 1 deletion web/flushcache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import redis
import defaults
import sys
try:
REDISDB = sys.argv[1]
Expand All @@ -8,7 +9,7 @@
# REDISDB = 13
print('give a redis db number to flush')
exit()
rdb = redis.StrictRedis(host='localhost', db=REDISDB, decode_responses=True)
rdb = redis.StrictRedis(password=defaults.REDIS_PASS, host='localhost', db=REDISDB, decode_responses=True)

cachemembers = rdb.smembers('cachecontrol')
for cache in cachemembers:
Expand Down
27 changes: 26 additions & 1 deletion web/static/2d/kathe.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,29 @@ function getsetinfo(setinfodata) {
}
};

function contextselect(contextslist) {

let dropdown = document.getElementById('contextselect');
dropdown.length = 0;

let defaultOption = document.createElement('option');
defaultOption.text = 'select a context';
defaultOption.value = '';
defaultOption.disabled = true;

dropdown.add(defaultOption);
dropdown.selectedIndex = 0;

let option;

for (let i = 0; i < contextslist.length; i++) {
option = document.createElement('option');
option.text = contextslist[i][0] + ' (' + contextslist[i][1].count + ')' ;
option.value = contextslist[i][0] ;
dropdown.add(option);
}
};

var graphDiv = document.getElementById("graph");
// we need to grab these to set them hard, otherwise the graph is window.height
// var graphwidth = window.innerWidth;
Expand All @@ -132,7 +155,9 @@ fetch("/search/?search=" + unescaped_searchvalue, { cache: "no-store" })
.then((out) => {
{
var myData = out;
var setinfo = JSON.parse(JSON.stringify(myData.info));
var setinfo = JSON.parse(JSON.stringify(myData._info));
var contextinfo = JSON.parse(JSON.stringify(myData.contexts));
contextselect(contextinfo);
getsetinfo(setinfo);
const elem = document.getElementById('graph');
const Graph = ForceGraph({ alpha: true })
Expand Down
9 changes: 1 addition & 8 deletions web/templates/kathe.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<div class="navbar bg-light">

<form action="/kathe/" method="get" class="form-inline col-md-5">
<form action="/kathe/" method="get" class="form-inline col-md-6">
<input type="text" class="form-control col-sm-6" name="search" id="search" value="{{querystring}}"
placeholder="Please enter a ssdeep|sha256|context string" onBlur="this.value=searchparam" />
<label class="text-muted col-sm-6"> |
Expand All @@ -31,13 +31,6 @@
<label for="contextform" class="text-muted col-sm-6">Contexts in this graph:</label>
<select name="search" id="contextselect" class="form-control col-sm-6" form="contextform"
onclick='this.form.submit()'>
<option value="" disabled selected>Select a context</option>
<!-- XXX we'll build the context dropdown here -->
<option>win.emotet</option>
<option>win.dorshel</option>
<option>win.isfb</option>
<option>win.dreambot</option>
<option>win.doesnotexist</option>
</select>
</form>

Expand Down

0 comments on commit ab837df

Please sign in to comment.