Adding infos related to the capture in the generated report
This commit is contained in:
parent
68bcf39451
commit
f465d46d92
@ -20,7 +20,8 @@ class Report(object):
|
|||||||
capture_directory, "assets/conns.json"))
|
capture_directory, "assets/conns.json"))
|
||||||
self.device = self.read_json(os.path.join(
|
self.device = self.read_json(os.path.join(
|
||||||
capture_directory, "assets/device.json"))
|
capture_directory, "assets/device.json"))
|
||||||
|
self.capinfos = self.read_json(os.path.join(
|
||||||
|
capture_directory, "assets/capinfos.json"))
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(self.capture_directory, "capture.pcap"), "rb") as f:
|
with open(os.path.join(self.capture_directory, "capture.pcap"), "rb") as f:
|
||||||
self.capture_sha1 = hashlib.sha1(f.read()).hexdigest()
|
self.capture_sha1 = hashlib.sha1(f.read()).hexdigest()
|
||||||
@ -184,7 +185,10 @@ class Report(object):
|
|||||||
self.device["mac_address"])
|
self.device["mac_address"])
|
||||||
header += "Report generated on {}<br />".format(
|
header += "Report generated on {}<br />".format(
|
||||||
datetime.now().strftime("%d/%m/%Y at %H:%M:%S"))
|
datetime.now().strftime("%d/%m/%Y at %H:%M:%S"))
|
||||||
|
header += "Capture duration: {}<br />".format(
|
||||||
|
self.capinfos["Capture duration"])
|
||||||
|
header += "Number of packets: {}<br />".format(
|
||||||
|
self.capinfos["Number of packets"])
|
||||||
header += "Capture SHA1: {}<br />".format(self.capture_sha1)
|
header += "Capture SHA1: {}<br />".format(self.capture_sha1)
|
||||||
header += "</p>"
|
header += "</p>"
|
||||||
header += "</div>"
|
header += "</div>"
|
||||||
|
@ -7,6 +7,7 @@ from os import mkdir, path
|
|||||||
from flask import send_file, jsonify
|
from flask import send_file, jsonify
|
||||||
import datetime
|
import datetime
|
||||||
import shutil
|
import shutil
|
||||||
|
import json
|
||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
@ -15,9 +16,6 @@ import re
|
|||||||
class Capture(object):
|
class Capture(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.capture_dir = False
|
|
||||||
self.assets_dir = False
|
|
||||||
self.capture_token = False
|
|
||||||
self.random_choice_alphabet = "ABCDEF1234567890"
|
self.random_choice_alphabet = "ABCDEF1234567890"
|
||||||
|
|
||||||
def start_capture(self):
|
def start_capture(self):
|
||||||
@ -98,14 +96,33 @@ class Capture(object):
|
|||||||
|
|
||||||
def stop_capture(self):
|
def stop_capture(self):
|
||||||
"""
|
"""
|
||||||
Stoping tshark if any instance present.
|
Stop tshark if any instance present & ask create_capinfos.
|
||||||
:return: dict as a small confirmation.
|
:return: dict as a small confirmation.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Kill instance of tshark if any.
|
|
||||||
if terminate_process("tshark"):
|
if terminate_process("tshark"):
|
||||||
|
self.create_capinfos()
|
||||||
return {"status": True,
|
return {"status": True,
|
||||||
"message": "Capture stopped"}
|
"message": "Capture stopped"}
|
||||||
else:
|
else:
|
||||||
return {"status": False,
|
return {"status": False,
|
||||||
"message": "No active capture"}
|
"message": "No active capture"}
|
||||||
|
|
||||||
|
def create_capinfos(self):
|
||||||
|
"""
|
||||||
|
Creates a capinfo json file.
|
||||||
|
:return: dict as a small confirmation.
|
||||||
|
"""
|
||||||
|
infos = sp.Popen(["capinfos", self.pcap],
|
||||||
|
stdout=sp.PIPE, stderr=sp.PIPE)
|
||||||
|
infos = infos.communicate()[0]
|
||||||
|
data = {}
|
||||||
|
for l in infos.decode().splitlines():
|
||||||
|
try:
|
||||||
|
l = l.split(": ") if ": " in l else l.split("= ")
|
||||||
|
if len(l[0]) and len(l[1]):
|
||||||
|
data[l[0].strip()] = l[1].strip()
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
with open("{}capinfos.json".format(self.assets_dir), 'w') as f:
|
||||||
|
json.dump(data, f)
|
||||||
|
return True
|
||||||
|
Loading…
Reference in New Issue
Block a user