Commit 74a2bcd9 by lwilms

ips and uris

parent 9cb69d05
...@@ -91,48 +91,16 @@ ...@@ -91,48 +91,16 @@
\end{twentyshort} \end{twentyshort}
\BLOCK{endif} \BLOCK{endif}
% ---------------------------------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------------------------------
% ELF ANALYSIS
% ----------------------------------------------------------------------------------------------------------------------
%\BLOCK{if 'elf_analysis' in analysis }
% \section{ELF Analysis}
%
% \begin{twentyshort}
% \BLOCK{for ELF in analysis['elf_analysis']['summary'] | top_five(20)}
% \twentyitemshort{\VAR{analysis['elf_analysis']['summary'][ELF] | elements_count}}{\VAR{ELF | filter_chars}}
% \BLOCK{endfor}
% \end{twentyshort}
%\BLOCK{endif}
% ----------------------------------------------------------------------------------------------------------------------
% IP & URI % IP & URI
% ---------------------------------------------------------------------------------------------------------------------- % ----------------------------------------------------------------------------------------------------------------------
\BLOCK{if ('ips_v4' in analysis or 'ips_v6' in analysis or 'uris' in analysis)} \BLOCK{if 'ip_and_uri_finder' in analysis}
\section{IPs \& URIs} \section{IPs and URIs}
{\begin{longtable}{|p{3cm}|p{11.5cm}|}
\BLOCK{if 'ips_v4' in analysis}
\hline
IPs v4
\BLOCK{for ip in analysis['ips_v4'] | check_list | filter_list}
& \VAR{ip} \\
\BLOCK{endfor}
\BLOCK{elif 'ips_v6' in analysis}
\hline
IPs v6 \begin{twentyshort}
\BLOCK{for ip in analysis['ips_v6'] | check_list | filter_list} \BLOCK{for selected_analysis in analysis['ip_and_uri_finder']['summary'] | triplet}
& \VAR{ip} \\ \twentyitemshort{\VAR{selected_analysis}}
\BLOCK{endfor} \BLOCK{endfor}
\BLOCK{elif 'uris' in analysis} \end{twentyshort}
\hline
URIs
\BLOCK{for uri in analysis['uris'] | check_list | filter_list}
& \VAR{uri} \\
\BLOCK{endfor}
\BLOCK{endif}
\hline
\end{longtable}
}
\BLOCK{endif} \BLOCK{endif}
%---------------------------------------------------------------------------------------- %----------------------------------------------------------------------------------------
......
...@@ -5,6 +5,8 @@ from contextlib import suppress ...@@ -5,6 +5,8 @@ from contextlib import suppress
from pathlib import Path from pathlib import Path
from time import localtime, strftime from time import localtime, strftime
from random import choice
import socket
import jinja2 import jinja2
from common_helper_files import human_readable_file_size from common_helper_files import human_readable_file_size
...@@ -182,6 +184,8 @@ def count_this_mitigation(summary, mitigation): ...@@ -182,6 +184,8 @@ def count_this_mitigation(summary, mitigation):
def software_components(software_string): def software_components(software_string):
# analysis['software_components']['summary'] # analysis['software_components']['summary']
software = software_string
ver_number = ''
if ' ' in software_string: if ' ' in software_string:
if len(software_string.split(' ')) > 2: if len(software_string.split(' ')) > 2:
software = ''.join(software_string.split(' ')[:-1]) software = ''.join(software_string.split(' ')[:-1])
...@@ -196,13 +200,46 @@ def software_components(software_string): ...@@ -196,13 +200,46 @@ def software_components(software_string):
int(ver_number[0]) int(ver_number[0])
except ValueError: except ValueError:
ver_number, software = software, ver_number ver_number, software = software, ver_number
else:
software = software_string
ver_number = ''
return '{}{}{}{}'.format(ver_number, '}', '{', software) 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) > 40:
chosen_one = choice(desired_list)
return '{2}{1}{0}{3}{5} {4}'.format('{', '}', len(desired_list), which_desired,
replace_special_characters(chosen_one), '\quad' * 10)
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
# imported from ip & uri
def _validate_ip(ip, address_format):
try:
_ = socket.inet_pton(address_format, ip)
return True
except OSError:
return False
def _add_filters_to_jinja(environment): def _add_filters_to_jinja(environment):
environment.filters['number_format'] = render_number_as_size environment.filters['number_format'] = render_number_as_size
environment.filters['nice_unix_time'] = render_unix_time environment.filters['nice_unix_time'] = render_unix_time
...@@ -220,6 +257,7 @@ def _add_filters_to_jinja(environment): ...@@ -220,6 +257,7 @@ def _add_filters_to_jinja(environment):
environment.filters['sort'] = sorted environment.filters['sort'] = sorted
environment.filters['call_for_mitigations'] = exploit_mitigation environment.filters['call_for_mitigations'] = exploit_mitigation
environment.filters['split_space'] = software_components environment.filters['split_space'] = software_components
environment.filters['triplet'] = get_triples
class TemplateEngine: class TemplateEngine:
......
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