This repository has been archived by the owner on Nov 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrone_burp.rb
executable file
·179 lines (146 loc) · 5.67 KB
/
drone_burp.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/ruby
require 'rubygems'
require 'yaml'
require 'fileutils'
require 'zip/zip'
PATH = File.dirname(__FILE__)
LIB_PATH = File.join(File.dirname(__FILE__), 'lib')
DEBUG = false
CONFIG_FILE = File.join(PATH, 'config.yml')
require File.join(LIB_PATH, 'parse/dom/burp')
require File.join(LIB_PATH, 'parse/writer/conviso')
require File.join(LIB_PATH, 'communication/xmpp')
require File.join(LIB_PATH, 'output/debug')
# PARSING CONFIGURATION FILE
if !File.exists?(CONFIG_FILE)
puts('Configuration file is missing.')
exit
end
configuration = YAML.load_file(CONFIG_FILE)
# SETUPING LOG FILE
debug = Output::Debug.new(configuration)
Output::Debug::level = configuration['debug_level'].to_i || 0
# LOADING ANALYSIS MODULES
analysis_modules = []
Dir.glob(File.join(LIB_PATH, 'analysis/*_analysis.rb')).each do |a|
debug.info("Loading analysis module: [#{a}]")
begin
require a
a =~ /analysis\/(\w+)_analysis.rb/
am = eval("Analysis::#{$1.capitalize}.new()")
am.config = configuration['analysis'][$1.downcase]
am.debug = debug
analysis_modules << am
rescue Exception => e
debug.error("Error loading analysis module: [#{a}]")
end
end
module Drone
class Burp
def initialize(config = '', debug = nil, analyses = [])
@config, @debug, @analyses = config, debug, analyses
# INITIALIZING A NEW XMPP COMMUNICATION CHANNEL
@comm = Communication::XMPP.new(@config, @debug)
# PERFORMING MINNOR CHECKS BEFORE STARTS OPPERATING
__validate_configuration
end
def run
# VERIFY IF THE CONNECTION IS STILL ACTIVE
if @comm.active?
# SCAN ALL SOURCES SPECIFIED IN THE CONFIGURATION FILE
@config['sources'].each do |s|
# SETUP A COLLECTION OF ALL XMLs FOUND INSIDE THE CURRENT SOURCE INPUT DIRECTORY
xml_files = __scan_input_directory(s)
# FOR EACH XML
xml_files.each do |xml_file|
begin
# PARSING THE CURRENT XML USING THE SPECIFIC PARSER FOR THE TOOL OUTPUT FORMAT
structure = __parse_file(xml_file)
rescue Exception => e
@debug.error("Error parsing XML file: [#{xml_file}]")
next
end
# Try to send all vulnerabilities then, if had success, compress and
# archive the XML file otherwise does not touch the original file
if __sent_structure(structure, s)
compressed_file = __compress_file(xml_file)
__archive_file(compressed_file) unless @config['archive_directory'].to_s.empty?
end
end
end
end
end
private
def __sent_structure(tool_structure, source)
# EXECUTES ALL BULK ANALYSES
@analyses.select {|a| a.class.superclass == Analysis::Interface::Bulk}.each {|a| tool_structure[:issues] = a._analyse(tool_structure[:issues])}
# SEND EACH ISSUE INDIVIDUALLY TO THE SERVER
# THE "source" STRUCTURE CONTAINS A TUPLE WITH (CLIENT_ID, PROJECT_ID)
response = tool_structure[:issues].collect do |issue|
# EXECUTES ALL INDIVIDUAL ANALYSES
@analyses.select {|a| !a.class.superclass == Analysis::Interface::Individual}.each {|a| issue = a._analyse(issue)}
# SEND THE MSG WITH THE ISSUE
source['tool_name'] = @config['tool_name']
ret = @comm.send_msg(Parse::Writer::Conviso.build_xml(issue, source))
if @config['xmpp']['importer_address'] =~ /validator/
msg = @comm.receive_msg
ret = false
if msg =~ /[OK]/
@debug.info('VALIDATOR - THIS MESSAGE IS VALID')
else
@debug.info('VALIDATOR - THIS MESSAGE IS INVALID')
end
end
ret
end
# JUST IN CASE THE RESPONSE ARRAY COMES EMPTY
response = response + [true]
# IF ALL ISSUES WERE SUCCESSFULLY SENT TO THE SERVER RETURN TRUE
response.inject{|a,b| a & b}
end
#TODO: Criar classes de excecões para todos esses erros
def __validate_configuration
# VALIDATES IF INPUT DIRECTORIES FOR ALL SOURCES
@config['sources'].each do |s|
if !Dir.exists?(s['input_directory'].to_s)
@debug.error("Input directory #{s['input_directory']}does not exist.")
exit
end
end
# VALIDATES THE ARCHIVE DIRECTORY
if !@config['archive_directory'].nil? && !Dir.exists?(@config['archive_directory'].to_s)
@debug.error('Archive directory does not exist.')
exit
end
end
def __scan_input_directory(source)
@debug.info("Pooling input directory ...")
files = Dir.glob(File.join(source['input_directory'], '*.xml'))
@debug.info("##{files.size} files were found.")
return files
end
def __parse_file (xml_file = '')
@debug.info("Parsing xml file [#{xml_file}].")
parse = Parse::DOM::Burp.new() # = Parse::DOM::Tool.new()
parse.parse_file(xml_file)
end
def __archive_file (zip_file = '')
@debug.info("Archiving xml file [#{zip_file}].")
FileUtils.mv(zip_file, @config['archive_directory'])
end
def __compress_file (xml_file = '')
@debug.info("Compressing xml file [#{xml_file}].")
zip_file_name = xml_file + ".zip"
File.unlink(zip_file_name) if File.exists?(zip_file_name)
zip = Zip::ZipFile.new(zip_file_name, true)
zip.add(File.basename(xml_file), xml_file)
zip.close
File.unlink(xml_file)
return zip_file_name
end
end
end
# Creating an instance of Drone::NewTool Object
drone = Drone::Burp.new(configuration, debug, analysis_modules)
debug.info("Starting #{configuration['plugin_name']} Drone ...")
drone.run