forked from noraj/OSCP-Exam-Report-Template-Markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.rb
executable file
·147 lines (137 loc) · 3.43 KB
/
generate.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env ruby
templates = [
{
exam: 'OSCP',
name: 'whoisflynn improved template v3.2',
path: 'src/OSCP-exam-report-template_whoisflynn_v3.2.md'
},
{
exam: 'OSCP',
name: 'official Offensive Security template v1',
path: 'src/OSCP-exam-report-template_OS_v1.md'
},
{
exam: 'OSCP',
name: 'official Offensive Security template v2',
path: 'src/OSCP-exam-report-template_OS_v2.md'
},
{
exam: 'OSWE',
name: 'official Offensive Security template v1',
path: 'src/OSWE-exam-report-template_OS_v1.md'
},
{
exam: 'OSWE',
name: 'noraj improved template v1',
path: 'src/OSWE-exam-report-template_noraj_v1.md'
},
{
exam: 'OSWE',
name: 'XL-SEC improved template v1',
path: 'src/OSWE-exam-report-template_xl-sec_v1.md'
},
{
exam: 'OSCE',
name: 'official Offensive Security template v1',
path: 'src/OSCE-exam-report-template_OS_v1.md'
},
{
exam: 'OSEE',
name: 'official Offensive Security template v1',
path: 'src/OSEE-exam-report-template_OS_v1.md'
},
{
exam: 'OSWP',
name: 'official Offensive Security template v1',
path: 'src/OSWP-exam-report-template_OS_v1.md'
},
{
exam: 'OSED',
name: 'official Offensive Security template v1',
path: 'src/OSED-exam-report-template_OS_v1.md'
},
{
exam: 'OSED',
name: 'epi improved template v1',
path: 'src/OSED-exam-report-template_epi_v1.md'
},
{
exam: 'OSEP',
name: 'official Offensive Security template v1',
path: 'src/OSEP-exam-report-template_OS_v1.md'
},
{
exam: 'OSEP',
name: 'ceso improved template v1',
path: 'src/OSEP-exam-report-template_ceso_v1.md'
}
]
# Choose template
puts '[+] Choose a template:'
templates.each_with_index do |t,i|
puts "#{i}. [#{t[:exam]}] #{t[:name]}"
end
print '> '
choice = gets.chomp
src = templates[choice.to_i][:path]
exam = templates[choice.to_i][:exam]
# Enter your OS id
puts "\n[+] Enter your OS id"
print '> OS-'
osid = 'OS-' + gets.chomp
# Choose syntax highlight style
style = 'breezedark'
puts "\n[+] Choose syntax highlight style [#{style}]"
print '> '
choice = gets.chomp
style = choice unless choice.empty?
puts style
# Generating report
puts "\n[+] Generating report..."
pdf = "output/#{exam}-#{osid}-Exam-Report.pdf"
%x(pandoc #{src} -o #{pdf} \
--from markdown+yaml_metadata_block+raw_html \
--template eisvogel \
--table-of-contents \
--toc-depth 6 \
--number-sections \
--top-level-division=chapter \
--highlight-style #{style} \
--resource-path=.:src
)
puts "\n[+] PDF generated at #{pdf}"
# Preview
puts "\n[+] Do you want to preview the report? [y/N]"
print '> '
choice = gets.chomp
if choice.downcase == 'y'
viewer = fork do
exec "xdg-open #{pdf}"
end
Process.detach(viewer)
end
# Generating archive
puts "\n[+] Generating archive..."
archive = "output/#{exam}-#{osid}-Exam-Report.7z"
%x(7z a #{archive} \
#{File.expand_path(pdf)}
)
# Optional lab report
puts "\n[+] Do you want to add an external lab report? [y/N]"
print '> '
choice = gets.chomp
if choice.downcase == 'y'
puts "\n[+] Write the path of your lab PDF"
print '> '
lab = gets.chomp
puts "\n[+] Updating archive..."
%x(7z a #{archive} \
#{File.expand_path(lab)}
)
end
puts "\n[+] Archive generated at #{archive}"
# Calculate MD5
puts "\n[+] Calculating MD5 of the archive..."
require 'digest'
md5 = Digest::MD5.hexdigest File.read(archive)
puts "\n[+] Archive MD5 (upload integrity check): #{md5}"