-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathreporter.rb
More file actions
77 lines (67 loc) · 2.3 KB
/
reporter.rb
File metadata and controls
77 lines (67 loc) · 2.3 KB
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
# frozen_string_literal: true
require_relative 'printer'
require_relative 'graphql_build'
require 'json'
require 'jsonl'
require 'yaml'
module Reporter
include Printer
include GraphqlBuild
def process_json
full_path = File.join('/workspace', @opts.nuclei_output)
output_parsed = JSONL.parse(File.read(full_path))
output_parsed.each do |json_line|
report = prepare_report(json_line)
unless report.nil?
response = submit_report(report)
if response[:sent] == true
print_success(response[:message])
else
print_error(response[:message])
save_unsent_report(json_line)
end
else
save_unsent_report(json_line)
end
end
print_warning("The unregistered findings are in the file '#{File.join(@opts.unregistered_dir, @opts.file_name)}'") if @opts.verify
end
def prepare_report(json_line)
template = find_template(json_line)
unless template.nil?
{
matcher_name: json_line["matcher-name"],
vid: template['report']['vid'],
description: prepare_description(json_line, template),
evidence_temp: create_evidence(json_line)
}
end
end
def find_template(json_line)
if File.exists?("#{@opts.dirname}/templates/#{@opts.env}/#{json_line["template-id"]}.yaml")
template = YAML::load_file("#{@opts.dirname}/templates/#{@opts.env}/#{json_line["template-id"]}.yaml")
unless template['nuclei-matcher-name'][json_line["matcher-name"]].nil?
template['nuclei-matcher-name'][json_line["matcher-name"]]
else
print_error("The template '#{json_line["matcher-name"]}' not found")
nil
end
else
print_error("The template '#{json_line["matcher-name"]}' not found")
nil
end
end
def prepare_description(json_line, template)
template['report']['description'].gsub('{{host}}', json_line["host"])
end
def create_evidence(raw_scanner_info)
tempfile = Tempfile.new(['evidence_', '.txt'])
tempfile.write(raw_scanner_info['response'])
tempfile
end
def save_unsent_report(json_line)
Dir.mkdir(@opts.unregistered_dir) unless Dir.exist?(@opts.unregistered_dir)
File.write(File.join(@opts.unregistered_dir, @opts.file_name), "#{json_line.to_json}#{$/}", mode: 'a')
@opts.verify = true
end
end