Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fact_pdf_report
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-depend
fact_pdf_report
Commits
2bddb69a
Commit
2bddb69a
authored
Jul 13, 2020
by
lwilms
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apply suggestions & rename functions
parent
e1afb38c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
23 deletions
+23
-23
template_engine.py
pdf_generator/tex_generation/template_engine.py
+23
-23
No files found.
pdf_generator/tex_generation/template_engine.py
View file @
2bddb69a
...
...
@@ -84,7 +84,7 @@ def create_jinja_environment(templates_to_use='default'):
def
get_five_longest_entries
(
summary
,
top
=
5
):
sorted_summary
=
dict
()
if
len
(
summary
)
<
top
+
1
:
if
len
(
summary
)
<
top
+
1
:
return
summary
for
key
in
sorted
(
summary
,
key
=
lambda
key
:
len
(
summary
[
key
]),
reverse
=
True
):
sorted_summary
.
update
({
key
:
summary
[
key
]})
...
...
@@ -95,10 +95,10 @@ def get_five_longest_entries(summary, top=5):
def
exploit_mitigation
(
summary
):
summary
=
summary
[
'exploit_mitigations'
][
'summary'
]
max_count
=
count_mitigations
(
summary
)
max_count
=
_
count_mitigations
(
summary
)
numbers
=
dict
()
for
key
in
[
'PIE'
,
'RELRO'
,
'Canary'
,
'NX'
,
'FORTIFY'
]:
numbers
[
key
]
=
count_occurrences
(
key
,
summary
)
numbers
[
key
]
=
_
count_occurrences
(
key
,
summary
)
return
(
f
'{{CANARY/{numbers["Canary"] / max_count}}},{{PIE/{numbers["PIE"] / max_count}}},'
f
'{{RELRO/{numbers["RELRO"] / max_count}}},{{NX/{numbers["NX"] / max_count}}},'
...
...
@@ -106,7 +106,7 @@ def exploit_mitigation(summary):
)
def
count_occurrences
(
key
,
summary
):
def
_
count_occurrences
(
key
,
summary
):
return
sum
(
len
(
summary
[
entry
])
for
entry
in
summary
...
...
@@ -114,15 +114,15 @@ def count_occurrences(key, summary):
)
def
count_mitigations
(
summary
):
def
_
count_mitigations
(
summary
):
for
mitigation
in
[
'Canary'
,
'NX'
,
'RELRO'
,
'PIE'
,
'FORTIFY'
]:
count
=
count_this_mitigation
(
summary
,
mitigation
)
count
=
_
count_this_mitigation
(
summary
,
mitigation
)
if
count
!=
0
:
return
count
return
count
def
count_this_mitigation
(
summary
,
mitigation
):
def
_
count_this_mitigation
(
summary
,
mitigation
):
count
=
0
for
selected_summary
in
summary
:
if
mitigation
in
selected_summary
:
...
...
@@ -134,26 +134,26 @@ def software_components(software_string):
software
=
software_string
ver_number
=
''
if
' '
in
software_string
:
split
ted
_software_string
=
software_string
.
split
(
' '
)
if
len
(
split
ted
_software_string
)
>
2
:
software
,
ver_number
=
larger_two_components
(
splitted
_software_string
)
elif
len
(
split
ted
_software_string
[
1
])
>
0
:
software
,
ver_number
=
less_three_components
(
splitted
_software_string
)
split_software_string
=
software_string
.
split
(
' '
)
if
len
(
split_software_string
)
>
2
:
software
,
ver_number
=
_larger_two_components
(
split
_software_string
)
elif
len
(
split_software_string
[
1
])
>
0
:
software
,
ver_number
=
_less_three_components
(
split
_software_string
)
return
f
'{ver_number}}}{{{software}'
def
less_three_components
(
software_string
):
def
_
less_three_components
(
software_string
):
software
,
ver_number
=
software_string
try
:
int
(
ver_number
[
0
])
except
ValueError
:
return
ver_number
,
software
return
software
,
ver_number
return
_order_components
(
software
,
ver_number
)
def
larger_two_components
(
software_string
):
def
_
larger_two_components
(
software_string
):
software
=
''
.
join
(
software_string
[:
-
1
])
ver_number
=
software_string
[
-
1
]
return
_order_components
(
software
,
ver_number
)
def
_order_components
(
software
,
ver_number
):
try
:
int
(
ver_number
[
0
])
except
ValueError
:
...
...
@@ -164,19 +164,19 @@ def larger_two_components(software_string):
def
get_triples
(
analysis
):
combined_triples
=
[]
for
desired
in
[
'IPv4'
,
'IPv6'
,
'URI '
]:
combined_triples
.
append
(
get_desired_triple
(
analysis
,
desired
))
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
)
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
f
'{len(desired_list)}}}{{{which_desired}
\\
quad$
\\
>$ (incl. {replace_special_characters(chosen_one)})'
def
ip_or_uri
(
summary
,
which_select
):
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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment