Unverified Commit 180c71ea by Johannes vom Dorp Committed by GitHub

Merge pull request #4 from fkie-cad/new_shiny_report

New shiny report
parents 71f48ffa e96b6f8c
FROM phusion/baseimage:0.11 FROM phusion/baseimage:0.11
RUN install_clean git python3 python3-pip python3-wheel python3-setuptools texlive-latex-base texlive-latex-extra texlive-fonts-extra texlive-fonts-recommended lmodern
WORKDIR /opt/app WORKDIR /opt/app
COPY . /opt/app COPY . /opt/app
RUN install_clean git python3 python3-pip python3-wheel python3-setuptools texlive-latex-base texlive-latex-extra lmodern
RUN pip3 install -r requirements.txt RUN pip3 install -r requirements.txt
RUN apt-get remove -y python3-pip RUN apt-get remove -y python3-pip
......
...@@ -20,29 +20,34 @@ ...@@ -20,29 +20,34 @@
import json import json
import shutil import shutil
from pathlib import Path from pathlib import Path
from sys import exit as sys_exit
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
from pdf_generator.generator import compile_pdf, create_templates from pdf_generator.generator import compile_pdf, create_templates
def get_data(): def get_data():
return json.loads(Path('/tmp', 'interface', 'data', 'analysis.json').read_text()), json.loads(Path('/tmp', 'interface', 'data', 'meta.json').read_text()) return json.loads(Path('/tmp', 'interface', 'data', 'analysis.json').read_text()), json.loads(
Path('/tmp', 'interface', 'data', 'meta.json').read_text())
def move_pdf_report(pdf_path): def move_pdf_report(pdf_path):
shutil.move(str(pdf_path.absolute()), str(Path('/tmp', 'interface', 'pdf', pdf_path.name))) shutil.move(str(pdf_path.absolute()), str(Path('/tmp', 'interface', 'pdf', pdf_path.name)))
def main(): def main(template_style='default'):
analysis, meta_data = get_data() analysis, meta_data = get_data()
with TemporaryDirectory() as tmp_dir: with TemporaryDirectory() as tmp_dir:
create_templates(analysis, meta_data, tmp_dir) create_templates(analysis, meta_data, tmp_dir, template_style)
target_path = compile_pdf(meta_data, tmp_dir) try:
move_pdf_report(target_path) target_path = compile_pdf(meta_data, tmp_dir)
move_pdf_report(target_path)
except RuntimeError:
pass
return 0 return 0
if __name__ == '__main__': if __name__ == '__main__':
exit(main()) sys_exit(main())
...@@ -2,9 +2,10 @@ import os ...@@ -2,9 +2,10 @@ import os
import shutil import shutil
from pathlib import Path from pathlib import Path
from common_helper_process import execute_shell_command from common_helper_process import execute_shell_command_get_return_code
from pdf_generator.tex_generation.template_engine import ( from pdf_generator.tex_generation.template_engine import (
LOGO_FILE, MAIN_TEMPLATE, META_TEMPLATE, PLUGIN_TEMPLATE_BLUEPRINT, TemplateEngine CUSTOM_TEMPLATE_CLASS, LOGO_FILE, MAIN_TEMPLATE, META_TEMPLATE, TemplateEngine
) )
PDF_NAME = Path(MAIN_TEMPLATE).with_suffix('.pdf').name PDF_NAME = Path(MAIN_TEMPLATE).with_suffix('.pdf').name
...@@ -13,7 +14,11 @@ PDF_NAME = Path(MAIN_TEMPLATE).with_suffix('.pdf').name ...@@ -13,7 +14,11 @@ PDF_NAME = Path(MAIN_TEMPLATE).with_suffix('.pdf').name
def execute_latex(tmp_dir): def execute_latex(tmp_dir):
current_dir = os.getcwd() current_dir = os.getcwd()
os.chdir(tmp_dir) os.chdir(tmp_dir)
execute_shell_command('env buf_size=1000000 pdflatex {}'.format(MAIN_TEMPLATE)) output, return_code = execute_shell_command_get_return_code('env buf_size=1000000 pdflatex {}'.format(MAIN_TEMPLATE))
if return_code != 0:
print(f'Warnings / Errors when trying to build PDF:\n{output}')
if not Path('main.pdf').exists():
raise RuntimeError('No pdf output generated. Aborting.')
os.chdir(current_dir) os.chdir(current_dir)
...@@ -21,12 +26,6 @@ def copy_fact_image(target): ...@@ -21,12 +26,6 @@ def copy_fact_image(target):
shutil.copy(str(Path(__file__).parent / 'templates' / LOGO_FILE), str(Path(target) / LOGO_FILE)) 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): def create_report_filename(meta_data):
unsafe_name = '{}_analysis_report.pdf'.format(meta_data['device_name']) unsafe_name = '{}_analysis_report.pdf'.format(meta_data['device_name'])
safer_name = unsafe_name.replace(' ', '_').replace('/', '__') safer_name = unsafe_name.replace(' ', '_').replace('/', '__')
...@@ -41,11 +40,10 @@ def compile_pdf(meta_data, tmp_dir): ...@@ -41,11 +40,10 @@ def compile_pdf(meta_data, tmp_dir):
return target_path return target_path
def create_templates(analysis, meta_data, tmp_dir): def create_templates(analysis, meta_data, tmp_dir, template_style='default'):
engine = TemplateEngine(tmp_dir=tmp_dir) engine = TemplateEngine(template_folder=template_style, tmp_dir=tmp_dir)
Path(tmp_dir, MAIN_TEMPLATE).write_text(engine.render_main_template(analysis=analysis))
Path(tmp_dir, MAIN_TEMPLATE).write_text(engine.render_main_template(analysis=analysis, meta_data=meta_data))
Path(tmp_dir, META_TEMPLATE).write_text(engine.render_meta_template(meta_data)) Path(tmp_dir, META_TEMPLATE).write_text(engine.render_meta_template(meta_data))
for filename, rendered_template in render_analysis_templates(engine=engine, analysis=analysis): if template_style == 'default':
Path(tmp_dir, filename).write_text(rendered_template) Path(tmp_dir, CUSTOM_TEMPLATE_CLASS).write_text(engine.render_template_class())
The MIT License (MIT)
Copyright (c) 2016 Carmine Spagnuolo
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.
delim_0 "\\dotfill\ "
delim_1 "\\dotfill\ "
headings_flag 1
heading_prefix "\\nopagebreak\n\\tikz\\node at (0pt,0pt) [draw=none,fill=ocre!50,line width=1pt,inner sep=5pt]{\\parbox{\\linewidth-2\\fboxsep-2\\fboxrule-2pt}{\\centering\\large\\sffamily\\bfseries\\textcolor{white}{" heading_suffix "}}};\\vspace*{0.2cm}\\nopagebreak\n"
\ No newline at end of file
\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} % % % % % % % %
% Twenty Seconds Resume/CV
% LaTeX Template
% Version 1.1 (8/1/17)
%
% This template has been downloaded from:
% http://www.LaTeXTemplates.com
%
% Original author:
% Carmine Spagnuolo (cspagnuolo@unisa.it) with major modifications by
% Vel (vel@LaTeXTemplates.com)
%
% License:
% The MIT License (see included LICENSE file)
%
% % % % % % % %
\usepackage[english]{babel} %----------------------------------------------------------------------------------------
\usepackage[utf8]{inputenc} % PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
\usepackage{amsmath} %----------------------------------------------------------------------------------------
\usepackage{graphicx} \batchmode
\usepackage{lmodern} \documentclass[letterpaper, icon]{twentysecondcv}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{longtable}
\usepackage{sectsty}
\allsectionsfont{\sffamily} %----------------------------------------------------------------------------------------
% SIDE BAR
%----------------------------------------------------------------------------------------
\profilepic{fact.png}
\input{meta.tex}
\begin{document} \begin{document}
%----------------------------------------------------------------------------------------
% CRYPTOGRAPHY
%----------------------------------------------------------------------------------------
\aboutme{
\BLOCK{if 'crypto_material' in analysis}
\BLOCK{if analysis['crypto_material']['summary'] | length}
\BLOCK{for selected_summary in analysis['crypto_material']['summary']}
\VAR{selected_summary | filter_chars} \\
\BLOCK{endfor}
\BLOCK{endif}
\BLOCK{else}
Analysis not present
\BLOCK{endif}
}
%----------------------------------------------------------------------------------------
% EXPLOIT MITIGATION
%----------------------------------------------------------------------------------------
\BLOCK{if 'exploit_mitigations' in analysis}
\BLOCK{if analysis['exploit_mitigations']['summary'] | length}
\begin{titlepage} \skills{\VAR{ analysis | call_for_mitigations}}
\BLOCK{endif}
\BLOCK{else}
\skills{Analysis not present/1}
\BLOCK{endif}
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}} \makeprofile
% ----------------------------------------------------------------------------------------------------------------------
% Binwalk & Entropy Graph
% ----------------------------------------------------------------------------------------------------------------------
\BLOCK{if 'binwalk' in analysis}
\BLOCK{if 'entropy_analysis_graph' in analysis['binwalk']}
\BLOCK{if analysis['binwalk']['entropy_analysis_graph'] | length}
\center \includegraphics[width = \textwidth]{\VAR{analysis['binwalk']['entropy_analysis_graph'] | base64_to_png('entropy_analysis_graph', tmp_dir)}}
\BLOCK{endif}
\BLOCK{endif}
\BLOCK{endif}
% ----------------------------------------------------------------------------------------------------------------------
% Software Components
% ----------------------------------------------------------------------------------------------------------------------
\BLOCK{if 'software_components' in analysis}
\BLOCK{if analysis['software_components']['summary'] | length}
\section{Software}
\includegraphics[width = 13cm]{fact_logo.png}\\[3cm] \begin{twentyshort}
\BLOCK{for summary in analysis['software_components']['summary'] | sort | x_entires}
\twentyitemshort{\VAR{summary | split_space}}
\BLOCK{endfor}
\BLOCK{if analysis['software_components']['summary'] | elements_count > 10}
\twentyitemshort{}{and \VAR{analysis['software_components']['summary'] | elements_count - 10} others}
\BLOCK{endif}
\end{twentyshort}
\BLOCK{endif}
\BLOCK{endif}\\
% ----------------------------------------------------------------------------------------------------------------------
% Known Vulnerabilities
% ----------------------------------------------------------------------------------------------------------------------
\BLOCK{if 'known_vulnerabilities' in analysis}
\BLOCK{if analysis['known_vulnerabilities']['summary'] | length}
\section{Known Vulnerabilities}
\HRule \\[0.4cm] \begin{twentyshort}
{\fontfamily{lmss}\selectfont \BLOCK{for known_vullies in analysis['known_vulnerabilities']['summary']}
{\Large \bfseries Firmware Analysis of \VAR{meta_data['hid'] | filter_chars }}\\[0.4cm] \twentyitemshort{\VAR{known_vullies | filter_chars}}{}
} \BLOCK{endfor}
\HRule \\[1.5cm] \end{twentyshort}
\BLOCK{endif}
\BLOCK{endif}\\
% ----------------------------------------------------------------------------------------------------------------------
% CVE Lookup
% ----------------------------------------------------------------------------------------------------------------------
\BLOCK{if 'cve_lookup' in analysis}
\BLOCK{if analysis['cve_lookup']['summary'] | length}
\section{CVE Lookup}
\vspace{3.0cm} \begin{twentyshort}
\BLOCK{for cve in analysis['cve_lookup']['summary'] | cve_crits}
\twentyitemshort{\VAR{cve | filter_chars}}{}
\BLOCK{endfor}
\end{twentyshort}
\BLOCK{endif}
\BLOCK{endif}\\
% ----------------------------------------------------------------------------------------------------------------------
% Top 5 File Types
% ----------------------------------------------------------------------------------------------------------------------
\BLOCK{if 'file_type' in analysis}
\BLOCK{if analysis['file_type']['summary'] | length}
\section{Top five occuring file types}
{\fontfamily{lmss}\selectfont \begin{twentyshort}
\input{meta.tex} \BLOCK{for selected_summary in analysis['file_type']['summary'] | top_five}
} \twentyitemshort{\VAR{analysis['file_type']['summary'][selected_summary] | elements_count}}{\VAR{selected_summary | filter_chars}}
\BLOCK{endfor}
\end{twentyshort}
\BLOCK{endif}
\BLOCK{endif}\\
% ----------------------------------------------------------------------------------------------------------------------
% IP & URI
% ----------------------------------------------------------------------------------------------------------------------
\BLOCK{if 'ip_and_uri_finder' in analysis}
\BLOCK{if analysis['ip_and_uri_finder']['summary'] | length}
\section{IPs and URIs}
\begin{twentyshort}
\BLOCK{for selected_analysis in analysis['ip_and_uri_finder']['summary'] | triplet}
\twentyitemshort{\VAR{selected_analysis}}
\BLOCK{endfor}
\end{twentyshort}
\BLOCK{endif}
\BLOCK{endif}
% ----------------------------------------------------------------------------------------------------------------------
% Executables
% ----------------------------------------------------------------------------------------------------------------------
\BLOCK{if 'cpu_architecture' in analysis}
\BLOCK{if analysis['cpu_architecture']['summary'] | length}
\section{Executables}
\begin{twentyshort}
\BLOCK{for selected_summary in analysis['cpu_architecture']['summary']}
\twentyitemshort{\VAR{analysis['cpu_architecture']['summary'][selected_summary] | elements_count}}{\VAR{selected_summary | filter_chars}}
\BLOCK{endfor}
\end{twentyshort}\\
\BLOCK{endif}
\BLOCK{endif}
%----------------------------------------------------------------------------------------
% SECOND PAGE EXAMPLE
%----------------------------------------------------------------------------------------
%\newpage % Start a new page
%\makeprofile % Print the sidebar
% \section{Other information}
% \subsection{Review}
% Alice approaches Wonderland as an anthropologist, but maintains a strong sense of noblesse oblige that comes with her class status. She has confidence in her social position, education, and the Victorian virtue of good manners. Alice has a feeling of entitlement, particularly when comparing herself to Mabel, whom she declares has a ``poky little house," and no toys. Additionally, she flaunts her limited information base with anyone who will listen and becomes increasingly obsessed with the importance of good manners as she deals with the rude creatures of Wonderland. Alice maintains a superior attitude and behaves with solicitous indulgence toward those she believes are less privileged.
% \section{Other information}
% \subsection{Review}
\vfill % Alice approaches Wonderland as an anthropologist, but maintains a strong sense of noblesse oblige that comes with her class status. She has confidence in her social position, education, and the Victorian virtue of good manners. Alice has a feeling of entitlement, particularly when comparing herself to Mabel, whom she declares has a ``poky little house," and no toys. Additionally, she flaunts her limited information base with anyone who will listen and becomes increasingly obsessed with the importance of good manners as she deals with the rude creatures of Wonderland. Alice maintains a superior attitude and behaves with solicitous indulgence toward those she believes are less privileged.
\end{titlepage}
\BLOCK{for current_analysis in analysis} %----------------------------------------------------------------------------------------
\input{\VAR{current_analysis}.tex}
\newpage
\BLOCK{endfor}
\end{document} \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}|} \BLOCK{if 'device_name' in meta_data}
\hline \cvname{\VAR{meta_data['device_name'] | filter_chars }}
HID & \VAR{meta_data['hid'] | filter_chars}\\ \BLOCK{else}
\hline \cvname{No Name}
\BLOCK{endif}
Device Name & \VAR{meta_data['device_name'] | filter_chars}\\ \BLOCK{if 'device_class' in meta_data}
\hline \cvjobtitle{\VAR{meta_data['device_class'] | filter_chars }}
\BLOCK{else}
\cvjobtitle{No Class}
\BLOCK{endif}
Vendor & \VAR{meta_data['vendor'] | filter_chars}\\ \BLOCK{if 'vendor' in meta_data}
\hline \cvdate{\VAR{meta_data['vendor'] | filter_chars }}
\BLOCK{else}
\cvdate{No Vendor}
\BLOCK{endif}
Device Class & \VAR{meta_data['device_class'] | filter_chars}\\ \BLOCK{if 'size' in meta_data}
\hline \cvaddress{\VAR{meta_data['size'] | number_format}}
\BLOCK{else}
\cvaddress{No Size}
\BLOCK{endif}
Version & \VAR{meta_data['version'] | filter_chars}\\ \BLOCK{if 'version' in meta_data}
\hline \cvnumberphone{\VAR{meta_data['version'] | filter_chars}}
\BLOCK{else}
\cvnumberphone{No Version}
\BLOCK{endif}
Release Date & \VAR{meta_data['release_date']}\\ \BLOCK{if 'release_date' in meta_data}
\hline \cvsite{\VAR{meta_data['release_date']}}
\BLOCK{else}
\cvsite{No Release Date}
\BLOCK{endif}
Size & \VAR{meta_data['size'] | number_format}\\ \cvmail{}
\hline
\end{tabular} % to change the icons: line 142 in twentysecondcv.cls
\ No newline at end of file % all icons possible from: https://github.com/spagnuolocarmine/TwentySecondsCurriculumVitae-LaTex/raw/master/fontawesome.pdf
\ 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
\ProvidesClass{twentysecondcv}[2017/01/08 CV class]
\LoadClass{article}
\NeedsTeXFormat{LaTeX2e}
%----------------------------------------------------------------------------------------
% REQUIRED PACKAGES
%----------------------------------------------------------------------------------------
\RequirePackage[sfdefault]{ClearSans}
\RequirePackage[T1]{fontenc}
\RequirePackage{tikz}
\RequirePackage{xcolor}
\RequirePackage[absolute,overlay]{textpos}
\RequirePackage{ragged2e}
\RequirePackage{etoolbox}
\RequirePackage{ifmtarg}
\RequirePackage{ifthen}
\RequirePackage{pgffor}
\RequirePackage{marvosym}
\RequirePackage{parskip}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\newbool{icon}
\DeclareOption{icon}{%
\booltrue{icon}
}
\DeclareOption{print}{\def\@cv@print{}}
\DeclareOption*{
\PassOptionsToClass{\CurrentOption}{article}
}
\ProcessOptions\relax
\ifbool{icon}{\RequirePackage{fontawesome}}{}
\usetikzlibrary{calc}
%----------------------------------------------------------------------------------------
% COLOURS
%----------------------------------------------------------------------------------------
\definecolor{white}{RGB}{255,255,255}
\definecolor{gray}{HTML}{4D4D4D}
\definecolor{sidecolor}{HTML}{E7E7E7}
\definecolor{mainblue_place_holder}{HTML}{0E5484}
\definecolor{maingray_place_holder}{HTML}{B9B9B9}
\definecolor{fraunhofer_dark_green}{HTML}{009879}% fraunhofer dark green
\definecolor{fraunhofer_light_green}{HTML}{69C0AC}% fraunhofer light green
\definecolor{mainblue}{HTML}{0E5484}
\definecolor{maingray}{HTML}{69C0AC}
%----------------------------------------------------------------------------------------
% MISC CONFIGURATIONS
%----------------------------------------------------------------------------------------
\renewcommand{\bfseries}{\color{gray}} % Make \textbf produce coloured text instead
\pagestyle{empty} % Disable headers and footers
\setlength{\parindent}{0pt} % Disable paragraph indentation
%----------------------------------------------------------------------------------------
% SIDEBAR DEFINITIONS
%----------------------------------------------------------------------------------------
\setlength{\TPHorizModule}{1cm} % Left margin
\setlength{\TPVertModule}{1cm} % Top margin
\newlength\imagewidth
\newlength\imagescale
\pgfmathsetlength{\imagewidth}{5cm}
\pgfmathsetlength{\imagescale}{\imagewidth/600}
\newlength{\TotalSectionLength} % Define a new length to hold the remaining line width after the section title is printed
\newlength{\SectionTitleLength} % Define a new length to hold the width of the section title
\newcommand{\profilesection}[1]{%
\setlength\TotalSectionLength{\linewidth}% Set the total line width
\settowidth{\SectionTitleLength}{\huge #1 }% Calculate the width of the section title
\addtolength\TotalSectionLength{-\SectionTitleLength}% Subtract the section title width from the total width
\addtolength\TotalSectionLength{-2.22221pt}% Modifier to remove overfull box warning
\vspace{8pt}% Whitespace before the section title
{\color{black!80} \huge #1 \rule[0.15\baselineskip]{\TotalSectionLength}{1pt}}% Print the title and auto-width rule
}
% Define custom commands for CV info
\newcommand{\cvdate}[1]{\renewcommand{\cvdate}{#1}}
\newcommand{\cvmail}[1]{\renewcommand{\cvmail}{#1}}
\newcommand{\cvnumberphone}[1]{\renewcommand{\cvnumberphone}{#1}}
\newcommand{\cvaddress}[1]{\renewcommand{\cvaddress}{#1}}
\newcommand{\cvsite}[1]{\renewcommand{\cvsite}{#1}}
\newcommand{\aboutme}[1]{\renewcommand{\aboutme}{#1}}
\newcommand{\profilepic}[1]{\renewcommand{\profilepic}{#1}}
\newcommand{\cvname}[1]{\renewcommand{\cvname}{#1}}
\newcommand{\cvjobtitle}[1]{\renewcommand{\cvjobtitle}{#1}}
% Command for printing the contact information icons
\newcommand*\icon[1]{\tikz[baseline=(char.base)]{\node[shape=circle,draw,inner sep=1pt, fill=mainblue,mainblue,text=white] (char) {#1};}}
% Command for printing skill progress bars
\newcommand\skills[1]{
\renewcommand{\skills}{
\begin{tikzpicture}
\foreach [count=\i] \x/\y in {#1}{
\draw[fill=maingray,maingray] (0,\i) rectangle (6,\i+0.4);
\draw[fill=white,mainblue](0,\i) rectangle (\y*6,\i+0.4);
\node [above right] at (0,\i+0.4) {\x};
}
\end{tikzpicture}
}
}
% Command for printing skills text
\newcommand\skillstext[1]{
\renewcommand{\skillstext}{
\begin{flushleft}
\foreach [count=\i] \x/\y in {#1}{
\x$ \star $\y
}
\end{flushleft}
}
}
%----------------------------------------------------------------------------------------
% SIDEBAR LAYOUT
%----------------------------------------------------------------------------------------
\newcommand{\makeprofile}{
\begin{tikzpicture}[remember picture,overlay]
\node [rectangle, fill=sidecolor, anchor=north, minimum width=9cm, minimum height=\paperheight+1cm] (box) at (-5cm,0.5cm){};
\end{tikzpicture}
%------------------------------------------------
\begin{textblock}{6}(0.5, 0.2)
%------------------------------------------------
\ifthenelse{\equal{\profilepic}{}}{}{
\begin{center}
\begin{tikzpicture}[x=\imagescale,y=-\imagescale]
%\clip (600/2, 567/2) circle (567/2);
\node[anchor=north west, inner sep=0pt, outer sep=0pt] at (0,0) {\includegraphics[width=\imagewidth]{\profilepic}};
\end{tikzpicture}
\end{center}
}
%------------------------------------------------
{\Huge\color{mainblue}\cvname}
%------------------------------------------------
{\Large\color{black!80}\cvjobtitle}
%------------------------------------------------
\renewcommand{\arraystretch}{1.6}
\begin{tabular}{p{0.5cm} @{\hskip 0.5cm}p{5cm}}
\ifthenelse{\equal{\cvdate}{}}{}{\textsc{\large\icon{\faIndustry}} & \cvdate\\}
\ifthenelse{\equal{\cvaddress}{}}{}{\textsc{\Large\icon{\faArrowsH}} & \cvaddress\\}
\ifthenelse{\equal{\cvnumberphone}{}}{}{\textsc{\Large\icon{\faCodeFork}} & \cvnumberphone\\}
\ifthenelse{\equal{\cvsite}{}}{}{\textsc{\large\icon{\faCalendar}} & \cvsite\\}
\ifthenelse{\equal{\cvmail}{}}{}{\textsc{\large\icon{@}} & \href{mailto:\cvmail}{\cvmail}}
\end{tabular}
%------------------------------------------------
\ifthenelse{\equal{\aboutme}{}}{}{
\profilesection{Crypto}
\begin{flushleft}
\aboutme
\end{flushleft}
}
%------------------------------------------------
\profilesection{Exp. Mitigation}
\skills
\skillstext
\scriptsize
%------------------------------------------------
\end{textblock}
}
%----------------------------------------------------------------------------------------
% COLOURED SECTION TITLE BOX
%----------------------------------------------------------------------------------------
% Command to create the rounded boxes around the first three letters of section titles
\newcommand*\round[2]{%
\tikz[baseline=(char.base)]\node[anchor=north west, draw,rectangle, rounded corners, inner sep=1.6pt, minimum size=5.5mm, text height=3.6mm, fill=#2,#2,text=white](char){#1};%
}
\newcounter{colorCounter}
\newcommand{\sectioncolor}[1]{%
{%
\round{#1}{
\ifcase\value{colorCounter}%
maingray\or%
mainblue\or%
maingray\or%
mainblue\or%
maingray\or%
mainblue\or%
maingray\or%
mainblue\or%
maingray\or%
mainblue\else%
maingray\fi%
}%
}%
\stepcounter{colorCounter}%
}
\renewcommand{\section}[1]{
{%
\color{gray}%
\Large\sectioncolor{#1}%
}
}
\renewcommand{\subsection}[1]{
\par\vspace{.5\parskip}{%
\large\color{gray} #1%
}
\par\vspace{.25\parskip}%
}
%----------------------------------------------------------------------------------------
% LONG LIST ENVIRONMENT
%----------------------------------------------------------------------------------------
\setlength{\tabcolsep}{0pt}
% New environment for the long list
\newenvironment{twenty}{%
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}ll}
}{%
\end{tabular*}
}
\newcommand{\twentyitem}[4]{%
#1&\parbox[t]{0.83\textwidth}{%
\textbf{#2}%
\hfill%
{\footnotesize#3}\\%
#4\vspace{\parsep}%
}\\
}
%----------------------------------------------------------------------------------------
% SMALL LIST ENVIRONMENT
%----------------------------------------------------------------------------------------
\setlength{\tabcolsep}{0pt}
% New environment for the small list
\newenvironment{twentyshort}{%
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}ll}
}{%
\end{tabular*}
}
\newcommand{\twentyitemshort}[2]{%
#1&\parbox[t]{0.83\textwidth}{%
\textbf{#2}%
}\\
}
%----------------------------------------------------------------------------------------
% MARGINS AND LINKS
%----------------------------------------------------------------------------------------
\RequirePackage[left=7.6cm,top=0.1cm,right=1cm,bottom=0.2cm,nohead,nofoot]{geometry}
\RequirePackage{hyperref}
\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
{"device_name": "A devices name", "device_class": "Router", "device_part": "", "vendor": "a vendor", "version": "version 42.13", "release_date": "1970-01-01", "hid": "some specs", "size": 2315412323, "number_of_included_files": 21, "included_files": [1,2,3,4,5,6,7], "total_files_in_firmware": 12}
\ No newline at end of file
import pytest import pytest
from pdf_generator.tex_generation.template_engine import TemplateEngine from pdf_generator.tex_generation.template_engine import TemplateEngine
from test.data.test_dict import TEST_DICT from test.data.test_dict import TEST_DICT, META_DICT
# pylint: disable=redefined-outer-name
TEST_DATA = { # pylint: disable=redefined-outer-name
'analysis': {'file_hashes': {'ssdeep': 'bla', 'sha1': 'blah'}},
'meta_data': {'device_name': 'test_device'}
}
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
...@@ -16,13 +12,10 @@ def stub_engine(): ...@@ -16,13 +12,10 @@ def stub_engine():
def test_latex_code_generation(stub_engine: TemplateEngine): def test_latex_code_generation(stub_engine: TemplateEngine):
result = stub_engine.render_meta_template(TEST_DICT) result = stub_engine.render_meta_template(META_DICT)
assert result assert result
def test_render_template(tmpdir): def test_render_template(stub_engine, tmpdir):
engine = TemplateEngine(template_folder='test', tmp_dir=tmpdir) output = stub_engine.render_main_template(analysis=[TEST_DICT, META_DICT])
test_data = {'meta_data': '123', 'analysis': '456'} assert output
output = engine.render_analysis_template(plugin='render_test', analysis=test_data)
assert output == 'Test - '
from pathlib import Path
import shutil
import PyPDF2
from docker_entry import main as main_docker_entry
# pylint: disable=redefined-outer-name
INTERFACE_DIR = Path('/tmp/interface')
OUTPUT_FILE = INTERFACE_DIR / 'pdf' / 'A_devices_name_analysis_report.pdf'
TEST_META_DATA = Path(__file__).parent / 'data' / 'meta.json'
TEST_ANALYSIS_DATA = Path(__file__).parent / 'data' / 'analysis.json'
def test_docker_entry():
(INTERFACE_DIR / 'data').mkdir(parents=True, exist_ok=True)
(INTERFACE_DIR / 'pdf').mkdir(parents=True, exist_ok=True)
shutil.copyfile(TEST_ANALYSIS_DATA, INTERFACE_DIR / 'data' / 'analysis.json')
shutil.copyfile(TEST_META_DATA, INTERFACE_DIR / 'data' / 'meta.json')
output = main_docker_entry()
assert output == 0, 'LaTeX PDF build unsuccessful'
assert OUTPUT_FILE.is_file()
try:
PyPDF2.PdfFileReader(open(str(OUTPUT_FILE), 'rb'))
except PyPDF2.utils.PdfReadError:
assert False, 'PDF could not be read'
...@@ -2,10 +2,11 @@ import json ...@@ -2,10 +2,11 @@ import json
from pathlib import Path from pathlib import Path
import pytest import pytest
from pdf_generator.generator import ( from pdf_generator.generator import (
LOGO_FILE, MAIN_TEMPLATE, META_TEMPLATE, PLUGIN_TEMPLATE_BLUEPRINT, copy_fact_image, create_report_filename, copy_fact_image, create_report_filename, create_templates, execute_latex, LOGO_FILE, MAIN_TEMPLATE, META_TEMPLATE
create_templates, execute_latex, render_analysis_templates
) )
from test.data.test_dict import META_DICT, TEST_DICT
class MockEngine: class MockEngine:
...@@ -13,8 +14,8 @@ class MockEngine: ...@@ -13,8 +14,8 @@ class MockEngine:
pass pass
@staticmethod @staticmethod
def render_main_template(analysis, meta_data): def render_main_template(analysis):
return '{}\n{}'.format(json.dumps(analysis), json.dumps(meta_data)) return json.dumps(analysis)
@staticmethod @staticmethod
def render_meta_template(meta_data): def render_meta_template(meta_data):
...@@ -24,13 +25,18 @@ class MockEngine: ...@@ -24,13 +25,18 @@ class MockEngine:
def render_analysis_template(_, analysis): def render_analysis_template(_, analysis):
return json.dumps(analysis) return json.dumps(analysis)
@staticmethod
def render_template_class():
return json.dumps('template_class.cls')
def exec_mock(*_, **__): def exec_mock(*_, **__):
Path('test').write_text('works') Path('test').write_text('works')
return '', 0
def test_execute_latex(monkeypatch, tmpdir): def test_execute_latex(monkeypatch, tmpdir):
monkeypatch.setattr('pdf_generator.generator.execute_shell_command', exec_mock) monkeypatch.setattr('pdf_generator.generator.execute_shell_command_get_return_code', exec_mock)
execute_latex(str(tmpdir)) execute_latex(str(tmpdir))
assert Path(str(tmpdir), 'test').exists() assert Path(str(tmpdir), 'test').exists()
...@@ -51,22 +57,9 @@ def test_create_report_filename(device_name, pdf_name): ...@@ -51,22 +57,9 @@ def test_create_report_filename(device_name, pdf_name):
assert create_report_filename({'device_name': device_name}) == pdf_name assert create_report_filename({'device_name': device_name}) == pdf_name
def test_create_analysis_templates():
templates = render_analysis_templates(engine=MockEngine(), analysis={'test': {'result': 'data'}})
assert len(templates) == 1
filename, result_code = templates[0]
assert filename == PLUGIN_TEMPLATE_BLUEPRINT.format('test')
assert result_code == '{"result": "data"}'
def test_create_templates(monkeypatch, tmpdir): def test_create_templates(monkeypatch, tmpdir):
monkeypatch.setattr('pdf_generator.generator.TemplateEngine', MockEngine) monkeypatch.setattr('pdf_generator.generator.TemplateEngine', MockEngine)
create_templates(analysis={'test': {'result': 'data'}}, meta_data={}, tmp_dir=str(tmpdir)) create_templates(analysis=TEST_DICT, meta_data=META_DICT, tmp_dir=str(tmpdir))
assert Path(str(tmpdir), MAIN_TEMPLATE).exists() assert Path(str(tmpdir), MAIN_TEMPLATE).exists()
assert Path(str(tmpdir), META_TEMPLATE).exists() assert Path(str(tmpdir), META_TEMPLATE).exists()
assert Path(str(tmpdir), PLUGIN_TEMPLATE_BLUEPRINT.format('test')).exists()
assert Path(str(tmpdir), PLUGIN_TEMPLATE_BLUEPRINT.format('test')).read_text() == '{"result": "data"}'
...@@ -2,10 +2,12 @@ from pathlib import Path ...@@ -2,10 +2,12 @@ from pathlib import Path
import pytest import pytest
from pdf_generator.tex_generation.template_engine import ( from pdf_generator.tex_generation.template_engine import (
TemplateEngine, decode_base64_to_file, render_number_as_size, render_number_as_string, render_unix_time, software_components, TemplateEngine, decode_base64_to_file, render_number_as_size, render_unix_time,
replace_characters_in_list, replace_special_characters, split_hash_string, split_long_lines replace_special_characters, get_five_longest_entries
) )
from test.data.test_dict import TEST_DICT
# pylint: disable=redefined-outer-name # pylint: disable=redefined-outer-name
...@@ -22,17 +24,6 @@ def test_byte_number_filter(): ...@@ -22,17 +24,6 @@ def test_byte_number_filter():
assert render_number_as_size(128000, verbose=False) == '125.00 KiB' assert render_number_as_size(128000, verbose=False) == '125.00 KiB'
def test_nice_number_filter():
assert render_number_as_string(None) == 'not available'
assert render_number_as_string('no int') == 'not available'
assert render_number_as_string(12) == '12'
assert render_number_as_string(12.1) == '12.10'
assert render_number_as_string(12.101) == '12.10'
assert render_number_as_string(12.109) == '12.11'
assert render_number_as_string('12') == '12'
@pytest.mark.skip(reason='Since local time used, result is not stable') @pytest.mark.skip(reason='Since local time used, result is not stable')
def test_nice_unix_time(): def test_nice_unix_time():
assert render_unix_time(None) == 'not available' assert render_unix_time(None) == 'not available'
...@@ -40,16 +31,6 @@ def test_nice_unix_time(): ...@@ -40,16 +31,6 @@ def test_nice_unix_time():
assert render_unix_time(10) == '1970-01-01 01:00:10' assert render_unix_time(10) == '1970-01-01 01:00:10'
def test_split_hash():
assert split_hash_string('X' * 62) == '{}\nX'.format('X' * 61)
assert split_hash_string('X' * 61) == 'X' * 61
def test_split_output_lines():
assert split_long_lines('X\nX') == 'X\nX'
assert split_long_lines('{}\nX'.format('X' * 93)) == '{}\nX\nX'.format('X' * 92)
def test_convert_base64_to_png_filter(tmpdir): def test_convert_base64_to_png_filter(tmpdir):
decode_base64_to_file('0000', 'testfile', str(tmpdir)) decode_base64_to_file('0000', 'testfile', str(tmpdir))
assert Path(str(tmpdir), 'testfile.png').read_bytes() == b'\xd3\x4d\x34' assert Path(str(tmpdir), 'testfile.png').read_bytes() == b'\xd3\x4d\x34'
...@@ -62,19 +43,28 @@ def test_filter_latex_special_chars(): ...@@ -62,19 +43,28 @@ def test_filter_latex_special_chars():
assert replace_special_characters(r'100 $') == r'100 \$' assert replace_special_characters(r'100 $') == r'100 \$'
def test_filter_chars_in_list():
assert replace_characters_in_list([]) == []
assert replace_characters_in_list([r'safe', r'un\safe']) == ['safe', 'unsafe']
def test_render_meta_template(stub_engine): def test_render_meta_template(stub_engine):
assert stub_engine.render_meta_template(meta_data='anything') == 'Test anything - ' assert stub_engine.render_meta_template(meta_data='anything') == 'Test anything - '
def test_render_main_template(stub_engine): def test_render_main_template(stub_engine):
assert stub_engine.render_main_template(meta_data='anything', analysis='else') == 'Test anything - else' assert stub_engine.render_main_template(analysis='else') == 'Test - else'
def test_render_analysis_template(stub_engine): def test_get_five_longest_entries():
assert stub_engine.render_analysis_template(plugin='non_existing', analysis='result') == 'Presenting: result' assert len(get_five_longest_entries(TEST_DICT['file_type']['summary'], top=3)) <= 3
longest_dict = get_five_longest_entries(TEST_DICT['file_type']['summary'], top=1)
assert len(longest_dict) == 1
assert 'compression/zlib' in longest_dict.keys()
@pytest.mark.parametrize('test_input, expected_output', [
('FOO 1.0', '1.0}{FOO'),
('1.0 FOO', '1.0}{FOO'),
('FOO BAR 1.0', '1.0}{FOOBAR'),
('FOO', '}{FOO'),
(' FOO ', '}{FOO'),
(' FOO BAR 1.0 ', '1.0}{FOOBAR'),
])
def test_software_components(test_input, expected_output):
assert software_components(test_input) == expected_output
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