Commit 4dcde063 by lwilms

Merge remote-tracking branch 'new_shiny_report/nice_view_latex' into new_shiny_report

parents 71f48ffa 336a80f1
......@@ -4,7 +4,7 @@ WORKDIR /opt/app
COPY . /opt/app
RUN install_clean git python3 python3-pip python3-wheel python3-setuptools texlive-latex-base texlive-latex-extra lmodern
RUN install_clean git python3 python3-pip python3-wheel python3-setuptools texlive-latex-base texlive-latex-extra texlive-fonts-extra texlive-fonts-recommended lmodern
RUN pip3 install -r requirements.txt
......
......@@ -21,23 +21,24 @@ 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
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):
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()
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)
move_pdf_report(target_path)
......@@ -45,4 +46,4 @@ def main():
if __name__ == '__main__':
exit(main())
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, TemplateEngine
LOGO_FILE, MAIN_TEMPLATE, META_TEMPLATE, CUSTOM_TEMPLATE_CLASS, TemplateEngine
)
PDF_NAME = Path(MAIN_TEMPLATE).with_suffix('.pdf').name
......@@ -13,6 +13,8 @@ PDF_NAME = Path(MAIN_TEMPLATE).with_suffix('.pdf').name
def execute_latex(tmp_dir):
current_dir = os.getcwd()
os.chdir(tmp_dir)
print(current_dir)
print(tmp_dir)
execute_shell_command('env buf_size=1000000 pdflatex {}'.format(MAIN_TEMPLATE))
os.chdir(current_dir)
......@@ -21,12 +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('/', '__')
......@@ -41,11 +37,10 @@ def compile_pdf(meta_data, tmp_dir):
return target_path
def create_templates(analysis, meta_data, tmp_dir):
engine = TemplateEngine(tmp_dir=tmp_dir)
Path(tmp_dir, MAIN_TEMPLATE).write_text(engine.render_main_template(analysis=analysis, meta_data=meta_data))
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))
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):
Path(tmp_dir, filename).write_text(rendered_template)
if template_style == 'default':
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}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage[a4paper, total={6in, 8in}]{geometry}
\usepackage{longtable}
\usepackage{sectsty}
%----------------------------------------------------------------------------------------
% PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------
\allsectionsfont{\sffamily}
\documentclass[letterpaper, icon]{twentysecondcv}
\profilepic{fact.png}
\input{meta.tex}
\begin{document}
\begin{titlepage}
\aboutme{
\BLOCK{if 'crypto_material' in analysis}
\BLOCK{for selected_summary in analysis['crypto_material']['summary']}
\VAR{selected_summary | filter_chars} \\
\BLOCK{endfor}
\BLOCK{endif}
}
\skills{\VAR{ analysis | call_for_mitigations}}
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\makeprofile
% ----------------------------------------------------------------------------------------------------------------------
% Binwalk & Entropy Graph
% ----------------------------------------------------------------------------------------------------------------------
\BLOCK{if 'binwalk' in analysis}
%\section{Entropy Graph}
\center
\includegraphics[width = \textwidth]{\VAR{analysis['binwalk']['entropy_analysis_graph'] | base64_to_png('entropy_analysis_graph', tmp_dir)}}
\BLOCK{endif}
% ----------------------------------------------------------------------------------------------------------------------
% Software Components
% ----------------------------------------------------------------------------------------------------------------------
\BLOCK{if 'software_components' in analysis}
\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}\\
% ----------------------------------------------------------------------------------------------------------------------
% Known Vulnerabilities
% ----------------------------------------------------------------------------------------------------------------------
\BLOCK{if 'known_vulnerabilities' in analysis}
\section{Known Vulnerabilities}
\HRule \\[0.4cm]
{\fontfamily{lmss}\selectfont
{\Large \bfseries Firmware Analysis of \VAR{meta_data['hid'] | filter_chars }}\\[0.4cm]
}
\HRule \\[1.5cm]
\begin{twentyshort}
\BLOCK{for known_vullies in analysis['known_vulnerabilities']['summary']}
\twentyitemshort{\VAR{known_vullies | filter_chars}}{}
\BLOCK{endfor}
\end{twentyshort}
\BLOCK{endif}\\
% ----------------------------------------------------------------------------------------------------------------------
% Top 5 File Types
% ----------------------------------------------------------------------------------------------------------------------
\section{Top five occuring file types}
\vspace{3.0cm}
\begin{twentyshort}
\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}\\
% ----------------------------------------------------------------------------------------------------------------------
% IP & URI
% ----------------------------------------------------------------------------------------------------------------------
\BLOCK{if 'ip_and_uri_finder' in analysis}
\section{IPs and URIs}
{\fontfamily{lmss}\selectfont
\input{meta.tex}
}
\begin{twentyshort}
\BLOCK{for selected_analysis in analysis['ip_and_uri_finder']['summary'] | triplet}
\twentyitemshort{\VAR{selected_analysis}}
\BLOCK{endfor}
\end{twentyshort}
\BLOCK{endif}
% ----------------------------------------------------------------------------------------------------------------------
% Executables
% ----------------------------------------------------------------------------------------------------------------------
\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}\\
%----------------------------------------------------------------------------------------
% 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
\end{titlepage}
% 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.
\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}|}
\hline
HID & \VAR{meta_data['hid'] | filter_chars}\\
\hline
\cvname{\VAR{meta_data['device_name'] | filter_chars }} % Your name
\cvjobtitle{\VAR{meta_data['device_class'] | filter_chars }} % Job title/career
Device Name & \VAR{meta_data['device_name'] | filter_chars}\\
\hline
\cvdate{\VAR{meta_data['vendor'] | filter_chars }} % Date of birth
\cvaddress{\VAR{meta_data['size'] | number_format}} % Short address/location, use \newline if more than 1 line is required
\cvnumberphone{\VAR{meta_data['version'] | filter_chars}} % Phone number
\cvsite{\VAR{meta_data['release_date']}} % Personal website
\cvmail{} % Email address
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
% to change the icons: line 142 in twentysecondcv.cls
% 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,\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
import logging
from base64 import decodebytes
from collections import OrderedDict
from contextlib import suppress
from pathlib import Path
from time import localtime, strftime
from random import choice
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'
PLUGIN_TEMPLATE_BLUEPRINT = '{}.tex'
LOGO_FILE = 'fact_logo.png'
CUSTOM_TEMPLATE_CLASS = 'twentysecondcv.cls'
LOGO_FILE = 'fact.png'
def render_number_as_size(number, verbose=True):
......@@ -44,6 +44,7 @@ def replace_special_characters(data):
latex_character_escapes = OrderedDict()
latex_character_escapes['\\'] = ''
latex_character_escapes['\''] = ''
latex_character_escapes['/'] = '/' # no need to replace?
latex_character_escapes['$'] = '\\$'
latex_character_escapes['('] = '$($'
latex_character_escapes[')'] = '$)$'
......@@ -100,6 +101,7 @@ def item_contains_string(item, string):
return string in item
# X-Executable in summary
def create_jinja_environment(templates_to_use='default'):
template_directory = Path(Path(__file__).parent.parent, 'templates', templates_to_use)
environment = jinja2.Environment(
......@@ -123,6 +125,124 @@ def plugin_name(name):
return ' '.join((part.title() for part in name.split('_')))
def get_five_longest_entries(summary, top=5):
sorted_summary = dict()
if len(summary) < 6:
return summary
for key in sorted(summary, key=lambda key: len(summary[key]), reverse=True):
sorted_summary.update({key: summary[key]})
if len(sorted_summary) == top:
return sorted_summary
return sorted_summary
def exploit_mitigation(summary):
summary = summary['exploit_mitigations']['summary']
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:
pie_num += len(summary[selected_summary])
if 'RELRO' in selected_summary and 'enabled' in selected_summary:
relro_num += len(summary[selected_summary])
if 'Canary' in selected_summary and 'enabled' in selected_summary:
canary_num += len(summary[selected_summary])
if 'NX' in selected_summary and 'enabled' in selected_summary:
nx_num += len(summary[selected_summary])
if 'FORTIFY' in selected_summary and 'enabled' in selected_summary:
fortify_num += len(summary[selected_summary])
return '{0}{2}/{3}{1},' \
'{0}{4}/{5}{1},' \
'{0}{6}/{7}{1},' \
'{0}{8}/{9}{1},' \
'{0}{10}/{11}{1}'.format('{', '}',
'CANARY', canary_num * 6 / max_count,
'PIE', pie_num * 6 / max_count,
'RELRO', relro_num * 6 / max_count,
'NX', nx_num * 6 / max_count,
'FORTIFY\_SOURCE', fortify_num * 6 / max_count)
def count_mitigations(summary):
for mitigation in ['Canary', 'NX', 'RELRO', 'PIE', 'FORTIFY']:
count = count_this_mitigation(summary, mitigation)
if count != 0:
return count
return count
def count_this_mitigation(summary, mitigation):
count = 0
for selected_summary in summary:
if mitigation in selected_summary:
count += len(summary[selected_summary])
return count
def software_components(software_string):
software = software_string
ver_number = ''
if ' ' in software_string:
if len(software_string.split(' ')) > 2:
software = ''.join(software_string.split(' ')[:-1])
ver_number = software_string.split(' ')[-1]
try:
int(ver_number[0])
except ValueError:
ver_number, software = software, ver_number
elif isinstance(software_string.split(' '), list) and len(software_string.split(' ')[1]) > 0:
software, ver_number = software_string.split(' ')
try:
int(ver_number[0])
except ValueError:
ver_number, software = software, ver_number
return '{}{}{}{}'.format(ver_number, '}', '{', software)
def get_triples(analysis):
combined_triples = []
for desired in ['IPv4', 'IPv6', 'URI ']:
combined_triples.append(get_desired_triple(analysis, desired))
return combined_triples
def get_desired_triple(seleced_summary, which_desired):
desired_list = ip_or_uri(seleced_summary, which_desired)
chosen_one = 'x x' * 60
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))
def ip_or_uri(summary, which_select):
new_list = []
for data in summary:
if ('URI ' in which_select and not _validate_ip(data, socket.AF_INET) and not _validate_ip(data,
socket.AF_INET6)):
new_list.append(data)
elif 'IPv4' in which_select and _validate_ip(data, socket.AF_INET):
new_list.append(data)
elif 'IPv6' in which_select and _validate_ip(data, socket.AF_INET6):
new_list.append(data)
return new_list
def _validate_ip(ip, address_format):
try:
_ = socket.inet_pton(address_format, ip)
return True
except OSError:
return False
def get_x_entries(summary, how_many=10):
if len(summary) <= how_many:
return summary
else:
return summary[:how_many]
def _add_filters_to_jinja(environment):
environment.filters['number_format'] = render_number_as_size
environment.filters['nice_unix_time'] = render_unix_time
......@@ -136,6 +256,12 @@ def _add_filters_to_jinja(environment):
environment.filters['split_hash'] = split_hash_string
environment.filters['split_output_lines'] = split_long_lines
environment.filters['contains'] = item_contains_string
environment.filters['top_five'] = get_five_longest_entries
environment.filters['sort'] = sorted
environment.filters['call_for_mitigations'] = exploit_mitigation
environment.filters['split_space'] = software_components
environment.filters['triplet'] = get_triples
environment.filters['x_entires'] = get_x_entries
class TemplateEngine:
......@@ -143,18 +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)
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