from __future__ import print_function import argparse from collections import Counter import shutil import os import sys """ MIT License Copyright (c) 2017 Chapin Bryce, Preston Miller Please share comments and questions at: https://github.com/PythonForensics/PythonForensicsCookbook or email pyforcookbook@gmail.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ __authors__ = ["Chapin Bryce", "Preston Miller"] __date__ = 20170815 __description__ = "Generates dashboard of sample acquisition information" try: from jinja2 import Template except ImportError: print("[-] Install required third-party module jinja2") sys.exit(1) DASH = Template(""" Light Bootstrap Dashboard

Custodians: {{num_custodians}}

Devices Preserved: {{num_devices}}

Total Data Preserved: {{data}}

Acquired Device Types

Breakdown of Device Type

Custodian Devices

Breakdown of Devices per Custodian

Preserved Data per Day

Acquired Data per Acquistion Date

""") TABLE = Template(""" Light Bootstrap Dashboard

Evidence Information

Preserved Data Details

{{ table_body }}
ID Description Type of Device Acquisition Date Size (GB)
""") DEMO = Template("""type = ['','info','success','warning','danger']; demo = { initPickColor: function(){ $('.pick-class-label').click(function(){ var new_class = $(this).attr('new-class'); var old_class = $('#display-buttons').attr('data-class'); var display_div = $('#display-buttons'); if(display_div.length) { var display_buttons = display_div.find('.btn'); display_buttons.removeClass(old_class); display_buttons.addClass(new_class); display_div.attr('data-class', new_class); } }); }, initChartist: function(){ var data = { labels: [{{bar_labels}}], series: [[{{bar_series}}]] }; var options = { seriesBarDistance: 10, axisX: { showGrid: false }, height: "245px" }; var responsiveOptions = [ ['screen and (max-width: 640px)', { seriesBarDistance: 5, axisX: { labelInterpolationFnc: function (value) { return value[0]; } } }] ]; Chartist.Bar('#chartActivity', data, options, responsiveOptions); var dataPreferences = { series: [ [25, 30, 20, 25] ] }; var optionsPreferences = { donut: true, donutWidth: 40, startAngle: 0, total: 100, showLabel: false, axisX: { showGrid: false } }; Chartist.Pie('#chartPreferences', dataPreferences, optionsPreferences); Chartist.Pie('#chartPreferences', { labels: [{{pi_labels}}], series: [{{pi_series}}] }); Chartist.Pie('#chartPreferences2', dataPreferences, optionsPreferences); Chartist.Pie('#chartPreferences2', { labels: [{{pi_2_labels}}], series: [{{pi_2_series}}] }); } } """) def main(output_dir): acquisition_data = [ ["001", "Debbie Downer", "Mobile", "08/05/2017 13:05:21", "32"], ["002", "Debbie Downer", "Mobile", "08/05/2017 13:11:24", "16"], ["003", "Debbie Downer", "External", "08/05/2017 13:34:16", "128"], ["004", "Debbie Downer", "Computer", "08/05/2017 14:23:43", "320"], ["005", "Debbie Downer", "Mobile", "08/05/2017 15:35:01", "16"], ["006", "Debbie Downer", "External", "08/05/2017 15:54:54", "8"], ["007", "Even Steven", "Computer", "08/07/2017 10:11:32", "256"], ["008", "Even Steven", "Mobile", "08/07/2017 10:40:32", "32"], ["009", "Debbie Downer", "External", "08/10/2017 12:03:42", "64"], ["010", "Debbie Downer", "External", "08/10/2017 12:43:27", "64"] ] print("[+] Processing acquisition data") process_data(acquisition_data, output_dir) def process_data(data, output_dir): html_table = "" for acq in data: html_table += "{}{}{}{}" \ "{}\n".format( acq[0], acq[1], acq[2], acq[3], acq[4]) device_types = Counter([x[2] for x in data]) custodian_devices = Counter([x[1] for x in data]) date_dict = {} for acq in data: date = acq[3].split(" ")[0] if date in date_dict: date_dict[date] += int(acq[4]) else: date_dict[date] = int(acq[4]) output_html(output_dir, len(data), html_table, device_types, custodian_devices, date_dict) def output_html(output, num_devices, table, devices, custodians, dates): print("[+] Rendering HTML and copy files to {}".format(output)) cwd = os.getcwd() bootstrap = os.path.join(cwd, "light-bootstrap-dashboard") shutil.copytree(bootstrap, output) dashboard_output = os.path.join(output, "dashboard.html") table_output = os.path.join(output, "table.html") demo_output = os.path.join(output, "assets", "js", "demo.js") with open(dashboard_output, "w") as outfile: outfile.write(DASH.render(num_custodians=len(custodians.keys()), num_devices=num_devices, data=calculate_size(dates))) with open(table_output, "w") as outfile: outfile.write(TABLE.render(table_body=table)) with open(demo_output, "w") as outfile: outfile.write( DEMO.render(bar_labels=return_labels(dates.keys()), bar_series=return_series(dates.values()), pi_labels=return_labels(devices.keys()), pi_series=return_series(devices.values()), pi_2_labels=return_labels(custodians.keys()), pi_2_series=return_series(custodians.values()))) def calculate_size(sizes): return sum(sizes.values()) def return_labels(list_object): return ", ".join("'{}'".format(x) for x in list_object) def return_series(list_object): return ", ".join(str(x) for x in list_object) if __name__ == "__main__": # Command-line Argument Parser parser = argparse.ArgumentParser( description=__description__, epilog="Developed by {} on {}".format( ", ".join(__authors__), __date__) ) parser.add_argument("OUTPUT_DIR", help="Desired Output Path") args = parser.parse_args() main(args.OUTPUT_DIR)