2018-12-16 01:22:02 +08:00
|
|
|
try:
|
2019-01-11 10:09:47 +08:00
|
|
|
from datetime import datetime
|
2018-12-16 01:22:02 +08:00
|
|
|
import plotly.graph_objs as go
|
|
|
|
import plotly.plotly as py
|
|
|
|
import plotly
|
|
|
|
import stash
|
|
|
|
try:
|
2019-01-11 10:09:47 +08:00
|
|
|
db = stash.stash_manager()
|
2018-12-16 01:22:02 +08:00
|
|
|
db.do_init()
|
|
|
|
except Exception as e:
|
|
|
|
pass
|
|
|
|
|
|
|
|
class graphgenerator:
|
|
|
|
|
|
|
|
def __init__(self, domain):
|
|
|
|
self.domain = domain
|
|
|
|
self.bardata = []
|
|
|
|
self.barcolumns = []
|
2018-12-17 00:37:36 +08:00
|
|
|
self.scatterxdata = []
|
|
|
|
self.scattercountemails = []
|
|
|
|
self.scattercounthosts = []
|
|
|
|
self.scattercountips = []
|
|
|
|
self.scattercountshodans = []
|
|
|
|
self.scattercountvhosts = []
|
2018-12-16 01:22:02 +08:00
|
|
|
|
|
|
|
def drawlatestscangraph(self,domain,latestscandata):
|
2018-12-18 04:36:30 +08:00
|
|
|
try:
|
2018-12-28 06:37:11 +08:00
|
|
|
self.barcolumns= ['email', 'host', 'ip', 'shodan', 'vhost']
|
2018-12-18 04:36:30 +08:00
|
|
|
self.bardata.append(latestscandata['email'])
|
|
|
|
self.bardata.append(latestscandata['host'])
|
|
|
|
self.bardata.append(latestscandata['ip'])
|
|
|
|
self.bardata.append(latestscandata['shodan'])
|
|
|
|
self.bardata.append(latestscandata['vhost'])
|
2019-01-13 14:17:06 +08:00
|
|
|
layout = dict(title = 'Latest scan - number of targets identified for ' + domain,
|
2018-12-18 04:36:30 +08:00
|
|
|
xaxis = dict(title = 'Targets'),
|
|
|
|
yaxis = dict(title = 'Hits'),)
|
|
|
|
barchartcode = plotly.offline.plot({
|
2019-01-13 14:17:06 +08:00
|
|
|
'data': [go.Bar(x=self.barcolumns, y=self.bardata)],
|
|
|
|
'layout': layout,
|
|
|
|
}, auto_open=False, include_plotlyjs=False, filename='report.html', output_type='div')
|
2018-12-18 04:36:30 +08:00
|
|
|
return barchartcode
|
|
|
|
except Exception as e:
|
2019-01-12 05:01:52 +08:00
|
|
|
print('Error generating HTML bar graph code for domain: ' + str(e))
|
2018-12-16 01:22:02 +08:00
|
|
|
|
2018-12-17 00:37:36 +08:00
|
|
|
def drawscattergraphscanhistory(self,domain,scanhistorydomain):
|
2018-12-18 04:36:30 +08:00
|
|
|
try:
|
|
|
|
scandata = scanhistorydomain
|
|
|
|
for i in scandata:
|
2018-12-28 06:37:11 +08:00
|
|
|
self.scatterxdata.append(datetime.date(datetime.strptime(i['date'], '%Y-%m-%d')))
|
2018-12-18 04:36:30 +08:00
|
|
|
self.scattercountemails.append(int(i['email']))
|
|
|
|
self.scattercounthosts.append(int(i['hosts']))
|
|
|
|
self.scattercountips.append(int(i['ip']))
|
|
|
|
self.scattercountshodans.append(int(i['shodan']))
|
|
|
|
self.scattercountvhosts.append(int(i['vhost']))
|
2018-12-16 01:22:02 +08:00
|
|
|
|
2018-12-18 04:36:30 +08:00
|
|
|
trace0 = go.Scatter(
|
|
|
|
x=self.scatterxdata,
|
|
|
|
y=self.scattercounthosts,
|
|
|
|
mode = 'lines+markers',
|
|
|
|
name = 'hosts')
|
2018-12-16 01:22:02 +08:00
|
|
|
|
2018-12-18 04:36:30 +08:00
|
|
|
trace1 = go.Scatter(
|
|
|
|
x=self.scatterxdata,
|
|
|
|
y=self.scattercountips,
|
|
|
|
mode = 'lines+markers',
|
|
|
|
name = 'IP address')
|
2018-12-16 01:22:02 +08:00
|
|
|
|
2018-12-18 04:36:30 +08:00
|
|
|
trace2 = go.Scatter(
|
|
|
|
x=self.scatterxdata,
|
|
|
|
y=self.scattercountvhosts,
|
|
|
|
mode = 'lines+markers',
|
|
|
|
name = 'vhost')
|
2018-12-16 01:22:02 +08:00
|
|
|
|
2018-12-18 04:36:30 +08:00
|
|
|
trace3 = go.Scatter(
|
|
|
|
x=self.scatterxdata,
|
|
|
|
y=self.scattercountshodans,
|
2019-01-11 10:09:47 +08:00
|
|
|
mode='lines+markers',
|
|
|
|
name='shodan')
|
2018-12-16 01:22:02 +08:00
|
|
|
|
2018-12-18 04:36:30 +08:00
|
|
|
trace4 = go.Scatter(
|
|
|
|
x=self.scatterxdata,
|
|
|
|
y=self.scattercountemails,
|
2019-01-11 10:09:47 +08:00
|
|
|
mode='lines+markers',
|
|
|
|
name='email')
|
2018-12-16 01:22:02 +08:00
|
|
|
|
2018-12-18 04:36:30 +08:00
|
|
|
data = [trace0, trace1, trace2, trace3, trace4]
|
2019-01-13 14:17:06 +08:00
|
|
|
layout = dict(title = 'Scanning history for ' + domain,
|
2018-12-18 04:36:30 +08:00
|
|
|
xaxis = dict(title = 'Date'),
|
|
|
|
yaxis = dict(title = 'Results'),
|
|
|
|
)
|
|
|
|
scatterchartcode = plotly.offline.plot({
|
2019-01-13 14:17:06 +08:00
|
|
|
'data': data,
|
|
|
|
'layout': layout}, auto_open=False, include_plotlyjs=False, filename='report.html', output_type='div')
|
2018-12-18 04:36:30 +08:00
|
|
|
return scatterchartcode
|
|
|
|
except Exception as e:
|
2019-01-12 05:01:52 +08:00
|
|
|
print('Error generating HTML for the historical graph for domain: ' + str(e))
|
2018-12-16 01:22:02 +08:00
|
|
|
|
|
|
|
except Exception as e:
|
2019-01-12 05:01:52 +08:00
|
|
|
print('Error in the reportgraph module: ' + str(e))
|