Commit 336a80f1 by lwilms

delete old template

parent 72ca17d4
......@@ -21,7 +21,7 @@ import json
import shutil
from pathlib import Path
from tempfile import TemporaryDirectory
from sys import exit as sys_exit
from pdf_generator.generator import compile_pdf, create_templates
......@@ -36,8 +36,6 @@ def move_pdf_report(pdf_path):
def main(template_style='default'):
analysis, meta_data = get_data()
# if 'exploit_mitigations' in analysis:
# analysis['exploit_mitigations']['count'] = count_mitigations(analysis['exploit_mitigations']['summary'])
with TemporaryDirectory() as tmp_dir:
create_templates(analysis, meta_data, tmp_dir, template_style)
......@@ -48,7 +46,4 @@ def main(template_style='default'):
if __name__ == '__main__':
exit(main())
# TODO
# order of sections
\ No newline at end of file
sys_exit(main())
......@@ -4,7 +4,7 @@ from pathlib import Path
from common_helper_process import execute_shell_command
from pdf_generator.tex_generation.template_engine import (
LOGO_FILE, MAIN_TEMPLATE, META_TEMPLATE, PLUGIN_TEMPLATE_BLUEPRINT, CUSTOM_TEMPLATE_CLASS, TemplateEngine
LOGO_FILE, MAIN_TEMPLATE, META_TEMPLATE, CUSTOM_TEMPLATE_CLASS, TemplateEngine
)
PDF_NAME = Path(MAIN_TEMPLATE).with_suffix('.pdf').name
......@@ -23,13 +23,6 @@ def copy_fact_image(target):
shutil.copy(str(Path(__file__).parent / 'templates' / LOGO_FILE), str(Path(target) / LOGO_FILE))
def render_analysis_templates(engine, analysis):
return [
(PLUGIN_TEMPLATE_BLUEPRINT.format(analysis_plugin),
engine.render_analysis_template(analysis_plugin, analysis[analysis_plugin])) for analysis_plugin in analysis
]
def create_report_filename(meta_data):
unsafe_name = '{}_analysis_report.pdf'.format(meta_data['device_name'])
safer_name = unsafe_name.replace(' ', '_').replace('/', '__')
......@@ -46,11 +39,8 @@ def compile_pdf(meta_data, tmp_dir):
def create_templates(analysis, meta_data, tmp_dir, template_style='default'):
engine = TemplateEngine(template_folder=template_style, tmp_dir=tmp_dir)
Path(tmp_dir, MAIN_TEMPLATE).write_text(engine.render_main_template(analysis=analysis, meta_data=meta_data))
Path(tmp_dir, MAIN_TEMPLATE).write_text(engine.render_main_template(analysis=analysis))
Path(tmp_dir, META_TEMPLATE).write_text(engine.render_meta_template(meta_data))
if template_style == 'default':
Path(tmp_dir, CUSTOM_TEMPLATE_CLASS).write_text(engine.render_template_class())
else:
for filename, rendered_template in render_analysis_templates(engine=engine, analysis=analysis):
Path(tmp_dir, filename).write_text(rendered_template)
\subsection*{Binwalk (v. \VAR{selected_analysis['plugin_version']})}
{\fontfamily{lmss}\selectfont
\begin{longtable}{|p{3cm}|p{11.5cm}|}
\hline
\multicolumn{2}{|p{14.5cm}|}{Signature Analysis:} \\
\multicolumn{2}{|p{14.5cm}|}{} \\
\multicolumn{2}{|p{14.5cm}|}{\VAR{selected_analysis['signature_analysis'] | filter_chars}} \\
\hline
Entropy Graph & \includegraphics[scale = 0.7]{\VAR{selected_analysis['entropy_analysis_graph'] | base64_to_png('entropy_analysis_graph', tmp_dir)}} \\
\hline
\BLOCK{if selected_analysis['summary']}
\multicolumn{2}{|p{14.5cm}|}{Summary:} \\
\multicolumn{2}{|p{14.5cm}|}{} \\
\BLOCK{for data in selected_analysis['summary']}
\multicolumn{2}{|p{14.5cm}|}{\VAR{data | filter_chars}} \\
\BLOCK{endfor}
\hline
\BLOCK{endif}
\end{longtable}
}
\ No newline at end of file
\subsection*{Exploit Mitigation (v. \VAR{selected_analysis['plugin_version']})}
{\fontfamily{lmss}\selectfont
\begin{longtable}{|p{3cm}|p{11.5cm}|}
\hline
\BLOCK{if selected_analysis['summary']}
NX
&
\BLOCK{for selected_summary in selected_analysis['summary']}
\BLOCK{if selected_summary | contains('NX')}
\VAR{selected_summary | filter_chars} (\VAR{ selected_analysis['summary'][selected_summary] | elements_count })
\BLOCK{endif}
\BLOCK{endfor} \\
\hline
Canary
&
\BLOCK{for selected_summary in selected_analysis['summary']}
\BLOCK{if selected_summary | contains('Canary')}
\VAR{selected_summary | filter_chars} (\VAR{ selected_analysis['summary'][selected_summary] | elements_count })
\BLOCK{endif}
\BLOCK{endfor} \\
\hline
PIE
&
\BLOCK{for selected_summary in selected_analysis['summary']}
\BLOCK{if selected_summary | contains('PIE')}
\VAR{selected_summary | filter_chars} (\VAR{ selected_analysis['summary'][selected_summary] | elements_count })
\BLOCK{endif}
\BLOCK{endfor} \\
\hline
RELRO
&
\BLOCK{for selected_summary in selected_analysis['summary']}
\BLOCK{if selected_summary | contains('RELRO')}
\VAR{selected_summary | filter_chars} (\VAR{ selected_analysis['summary'][selected_summary] | elements_count })
\BLOCK{endif}
\BLOCK{endfor} \\
\hline
\BLOCK{endif}
\end{longtable}
}
\ No newline at end of file
\subsection*{Hashes (v. \VAR{selected_analysis['plugin_version']})}
{\fontfamily{lmss}\selectfont
\begin{tabular}{|p{3cm}|p{11.5cm}|}
\hline
md5 & \VAR{selected_analysis['md5']}\\
\hline
ripemd160 & \VAR{selected_analysis['ripemd160']}\\
\hline
sha1 & \VAR{selected_analysis['sha1']}\\
\hline
sha256 & \VAR{selected_analysis['sha256']}\\
\hline
sha512 & \VAR{selected_analysis['sha512'] | split_hash}\\
\hline
\end{tabular}
}
\ No newline at end of file
\subsection*{File Type (v. \VAR{selected_analysis['plugin_version']})}
{\fontfamily{lmss}\selectfont
\begin{longtable}{|p{3cm}|p{11.5cm}|}
\hline
File Type & \VAR{selected_analysis['full'] | filter_chars} \\
\hline
MIME & \VAR{selected_analysis['mime'] | filter_chars} \\
\hline
\BLOCK{if selected_analysis['summary']}
Containing Files
\BLOCK{for selected_summary in selected_analysis['summary']}
& \VAR{ selected_summary | filter_chars } (\VAR{ selected_analysis['summary'][selected_summary] | elements_count }) \\
\BLOCK{endfor}
\hline
\BLOCK{endif}
\end{longtable}
}
\ No newline at end of file
\subsection*{\VAR{plugin_name | plugin_name | filter_chars} (v. \VAR{selected_analysis['plugin_version'] | filter_chars})}
{\fontfamily{lmss}\selectfont
\begin{longtable}{|p{3cm}|p{11.5cm}|}
\hline
Time of Analysis & \VAR{selected_analysis['analysis_date'] | nice_unix_time} \\
\hline
Plugin Version & \VAR{selected_analysis['plugin_version']} \\
\hline
\BLOCK{if selected_analysis['summary']}
Summary
\BLOCK{for selected_summary in selected_analysis['summary']}
& \VAR{selected_summary | filter_chars} \\
\BLOCK{endfor}
\hline
\BLOCK{endif}
\end{longtable}
}
\ No newline at end of file
\subsection*{IPs and URIs (v. \VAR{selected_analysis['plugin_version']})}
{\fontfamily{lmss}\selectfont
\begin{longtable}{|p{3cm}|p{11.5cm}|}
\hline
IPs v4
\BLOCK{for ip in selected_analysis['ips_v4'] | check_list | filter_list}
& \VAR{ip} \\
\BLOCK{endfor}
\hline
IPs v6
\BLOCK{for ip in selected_analysis['ips_v6'] | check_list | filter_list}
& \VAR{ip} \\
\BLOCK{endfor}
\hline
URIs
\BLOCK{for uri in selected_analysis['uris'] | check_list | filter_list}
& \VAR{uri} \\
\BLOCK{endfor}
\hline
\BLOCK{if selected_analysis['summary']}
\multicolumn{2}{|p{14.5cm}|}{Summary:} \\
\multicolumn{2}{|p{14.5cm}|}{} \\
\BLOCK{for data in selected_analysis['summary']}
\multicolumn{2}{|p{14.5cm}|}{\VAR{data | filter_chars}} \\
\BLOCK{endfor}
\hline
\BLOCK{endif}
\end{longtable}
}
\ No newline at end of file
\documentclass{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{longtable}
\usepackage{sectsty}
\allsectionsfont{\sffamily}
\begin{document}
\begin{titlepage}
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\center
\includegraphics[width = 13cm]{fact_logo.png}\\[3cm]
\HRule \\[0.4cm]
{\fontfamily{lmss}\selectfont
{\Large \bfseries Firmware Analysis of \VAR{meta_data['hid'] | filter_chars }}\\[0.4cm]
}
\HRule \\[1.5cm]
\vspace{3.0cm}
{\fontfamily{lmss}\selectfont
\input{meta.tex}
}
\vfill
\end{titlepage}
\BLOCK{for current_analysis in analysis}
\input{\VAR{current_analysis}.tex}
\newpage
\BLOCK{endfor}
\end{document}
\subsection*{Malware (v. \VAR{selected_analysis['plugin_version']})}
{\fontfamily{lmss}\selectfont
\begin{longtable}{|p{3cm}|p{11.5cm}|}
\hline
MD5 & \VAR{selected_analysis['md5']} \\
\hline
System Version & \VAR{selected_analysis['system_version']} \\
\hline
Scanners Number & \VAR{selected_analysis['number_of_scanners']} \\
\hline
Positives & \VAR{selected_analysis['positives']} \\
\hline
Scanners
\BLOCK{for scanner in selected_analysis['scanners']}
& \VAR{scanner} \\
\BLOCK{endfor}
\hline
Scanns
\BLOCK{for scan in selected_analysis['scans']}
\BLOCK{for value in selected_analysis['scans'][scan]}
& \VAR{scan} :: \VAR{value}:\VAR{selected_analysis['scans'][scan][value]} \\
\BLOCK{endfor}
\BLOCK{endfor}
\hline
\BLOCK{if selected_analysis['summary']}
Summary
\BLOCK{for selected_summary in selected_analysis['summary']}
& \VAR{selected_summary | filter_chars} \\
\BLOCK{endfor}
\hline
\BLOCK{endif}
\end{longtable}
}
\ No newline at end of file
\begin{tabular}{|p{3cm}|p{11.5cm}|}
\hline
HID & \VAR{meta_data['hid'] | filter_chars}\\
\hline
Device Name & \VAR{meta_data['device_name'] | filter_chars}\\
\hline
Vendor & \VAR{meta_data['vendor'] | filter_chars}\\
\hline
Device Class & \VAR{meta_data['device_class'] | filter_chars}\\
\hline
Version & \VAR{meta_data['version'] | filter_chars}\\
\hline
Release Date & \VAR{meta_data['release_date']}\\
\hline
Size & \VAR{meta_data['size'] | number_format}\\
\hline
\end{tabular}
\ No newline at end of file
\subsection*{String Stats (v. \VAR{selected_analysis['plugin_version']})}
{\fontfamily{lmss}\selectfont
\begin{tabular}{|p{3cm}|p{11.5cm}|}
\hline
String Count & \VAR{selected_analysis['strings'] | elements_count}\\
\hline
\end{tabular}
}
\ No newline at end of file
\subsection*{String Eval Stats (v. \VAR{selected_analysis['plugin_version']})}
{\fontfamily{lmss}\selectfont
\begin{tabular}{|p{3cm}|p{11.5cm}|}
\hline
String Count & \VAR{selected_analysis['string_eval'] | elements_count}\\
\hline
\end{tabular}
}
\ No newline at end of file
\subsection*{Unpacker (v. \VAR{selected_analysis['plugin_version']})}
{\fontfamily{lmss}\selectfont
\begin{longtable}{|p{3cm}|p{11.5cm}|}
\hline
Plugin & \VAR{selected_analysis['plugin_used'] | filter_chars} \\
\hline
Extracted & \VAR{selected_analysis['number_of_unpacked_files']} \\
\hline
\BLOCK{if selected_analysis['output']}
\multicolumn{2}{|p{14.5cm}|}{Output:}\\
\multicolumn{2}{|p{14.5cm}|}{}\\
\multicolumn{2}{|p{14.5cm}|}{\VAR{selected_analysis['output'] | split_output_lines | filter_chars }} \\
\hline
\BLOCK{endif}
Entropy & \VAR{selected_analysis['entropy'] | nice_number} \\
\hline
\end{longtable}
}
\ No newline at end of file
import logging
from base64 import decodebytes
from collections import OrderedDict
from contextlib import suppress
......@@ -10,11 +9,9 @@ import socket
import jinja2
from common_helper_files import human_readable_file_size
GENERIC_TEMPLATE = 'generic.tex'
MAIN_TEMPLATE = 'main.tex'
META_TEMPLATE = 'meta.tex'
CUSTOM_TEMPLATE_CLASS = 'twentysecondcv.cls'
PLUGIN_TEMPLATE_BLUEPRINT = '{}.tex'
LOGO_FILE = 'fact.png'
......@@ -47,7 +44,7 @@ def replace_special_characters(data):
latex_character_escapes = OrderedDict()
latex_character_escapes['\\'] = ''
latex_character_escapes['\''] = ''
latex_character_escapes['/'] = '/'
latex_character_escapes['/'] = '/' # no need to replace?
latex_character_escapes['$'] = '\\$'
latex_character_escapes['('] = '$($'
latex_character_escapes[')'] = '$)$'
......@@ -141,7 +138,7 @@ def get_five_longest_entries(summary, top=5):
def exploit_mitigation(summary):
summary = summary['exploit_mitigations']['summary']
max_count = count_mitigations(summary) # skillsbar is maxed out at 6
max_count = count_mitigations(summary) # skillsbar is maxed at 6
pie_num, canary_num, relro_num, nx_num, fortify_num = 0, 0, 0, 0, 0
for selected_summary in summary:
if 'PIE' in selected_summary and 'present' in selected_summary:
......@@ -183,7 +180,6 @@ def count_this_mitigation(summary, mitigation):
def software_components(software_string):
# analysis['software_components']['summary']
software = software_string
ver_number = ''
if ' ' in software_string:
......@@ -216,7 +212,7 @@ def get_desired_triple(seleced_summary, which_desired):
while len(chosen_one) > 50:
chosen_one = choice(desired_list)
return '{2}{1}{0}{3}{4}$\>$ (incl. {5})'.format('{', '}', len(desired_list), which_desired, '\quad',
replace_special_characters(chosen_one))
replace_special_characters(chosen_one))
def ip_or_uri(summary, which_select):
......@@ -273,22 +269,14 @@ class TemplateEngine:
self._environment = create_jinja_environment(template_folder if template_folder else 'default')
self._tmp_dir = tmp_dir
def render_main_template(self, analysis, meta_data):
def render_main_template(self, analysis):
template = self._environment.get_template(MAIN_TEMPLATE)
return template.render(analysis=analysis, meta_data=meta_data, tmp_dir=self._tmp_dir)
return template.render(analysis=analysis, tmp_dir=self._tmp_dir)
def render_meta_template(self, meta_data):
template = self._environment.get_template(META_TEMPLATE)
return template.render(meta_data=meta_data)
def render_analysis_template(self, plugin, analysis):
try:
template = self._environment.get_template(PLUGIN_TEMPLATE_BLUEPRINT.format(plugin))
except jinja2.TemplateNotFound:
logging.warning('Falling back on generic template for {}'.format(plugin))
template = self._environment.get_template(GENERIC_TEMPLATE)
return template.render(plugin_name=plugin, selected_analysis=analysis, tmp_dir=self._tmp_dir)
def render_template_class(self):
template = self._environment.get_template(CUSTOM_TEMPLATE_CLASS)
return template.render(tmp_dir=self._tmp_dir)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment