forked from chrisallenlane/watchtower
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
147 lines (122 loc) · 5.06 KB
/
Rakefile
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
require 'rubygems'
require 'csv'
require 'backports'
require 'fileutils'
require 'open-uri'
require 'rake/testtask'
require 'rdoc/task'
require 'uri'
namespace :docs do
RDoc::Task.new do |rdoc|
files = ['lib/models/vulnscanner.rb', 'lib/models/poi.rb', 'lib/models/signature.rb']
rdoc.rdoc_files.add(files)
rdoc.main = 'README.rdoc'
rdoc.title = 'WatchTower rdocs'
rdoc.rdoc_dir = 'doc'
rdoc.options << '--line-numbers'
end
desc "Builds the example reports"
task :examples do
puts 'Generating example reports...'
# mark the current directory
cwd = File.expand_path File.dirname(__FILE__)
# download and extract w3 total cache to build some sample reports
print 'Downloading W3 Total Cache plugin for scanning...'
`cd /tmp/; wget 'http://downloads.wordpress.org/plugin/w3-total-cache.zip'; unzip '/tmp/w3-total-cache.zip'`
puts 'Done.'
# build sample reports for all file types
## plain text ##
print 'Generating a plain-text report...'
`#{cwd}/watchtower -s /tmp/w3-total-cache/ -p 'W3 Total Cache Plugin' -C 7 -o txt > #{cwd}/examples/report.txt`
puts 'Done.'
## csv ##
print 'Generating a CSV report...'
`#{cwd}/watchtower -s /tmp/w3-total-cache/ -p 'W3 Total Cache Plugin' -C 7 -o csv > #{cwd}/examples/report.csv`
puts 'Done.'
## xml ##
print 'Generating an XML report...'
`#{cwd}/watchtower -s /tmp/w3-total-cache/ -p 'W3 Total Cache Plugin' -C 7 -o xml > #{cwd}/examples/report.xml`
puts 'Done.'
## xml ##
print 'Generating a Markdown report...'
`#{cwd}/watchtower -s /tmp/w3-total-cache/ -p 'W3 Total Cache Plugin' -C 7 -o markdown > #{cwd}/examples/report.markdown`
puts 'Done.'
## html ##
print 'Generating an HTML report...'
`#{cwd}/watchtower -s /tmp/w3-total-cache/ -p 'W3 Total Cache Plugin' -C 7 -o html > #{cwd}/examples/report.html`
puts 'Done.'
# clean up
puts 'Cleaning up...'
`rm '/tmp/w3-total-cache.zip'`
`rm -rf '/tmp/w3-total-cache/'`
puts 'The example reports have been generated.'
end
end
namespace :sigs do
desc "Generates signatures files based off of known malware domains and IP addresses"
task :generate_blocklists do
# download the entire Malware Domain List
puts 'Downloading updated blocklist from malwaredomainlist.com...'
csv = open('http://www.malwaredomainlist.com/mdlcsv.php').read
# generate the blocklists
puts 'Download complete. Generating blocklists...'
# track the ips and domains
ips = {}
domains = {}
# buffer the signatures produced
ip_signatures = ''
domain_signatures = '';
# iterate over the downloaded signatures file
CSV.parse(csv) do |row|
# parse out the domain and IP address
domain = row[3].chomp unless row[3].nil?
# this regex isn't quite correct, but it's good enough
# for our purposes here
ip = row[2].chomp.match(/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/) unless row[2].nil?
# process the domain
if !domain.nil? and !domain.eql? '-' and !domain.eql? '.' and !domains.has_key? domain.to_s
# buffer the signature
domain_signatures += "\tSignature.new({:literal => '#{domain}'}),\n"
# track that this domain exists
domains[domain.to_s] = true
end
# process the ip address
if !ip.nil? and !ip.eql? '-' and !ips.has_key? ip.to_s
# buffer the signature
ip_signatures += "\tSignature.new({:literal => '#{ip}'}),\n"
# track that this IP exists
ips[ip.to_s] = true
end
end
# strip the trailing whitespace from the buffers
domain_signatures.chomp!
ip_signatures.chomp!
# assemble the Ruby for the signatures file
ruby = <<-sigs
$signatures[:blocklists] ||= {}
$signatures[:blocklists][:malicious_domains] = [
#{domain_signatures}
]
$signatures[:blocklists][:malicious_ips] = [
#{ip_signatures}
]
sigs
# flush the buffers to a signatures file
puts 'Flushing buffers to file...'
File.open('./signatures/blocklist.rb', 'w') {|f| f.write(ruby) }
puts 'Complete.'
end
end
desc 'Builds the project'
task :build do
puts 'Building project...'
Rake::Task['sigs:generate_blocklists'].execute
Rake::Task['docs:examples'].execute
Rake::Task['docs:rerdoc'].execute
puts 'Build complete. Did you remember to update the version number if necessary?'
end
Rake::TestTask.new do |test|
test.libs << 'test'
test.test_files = ['test/test_poi.rb', 'test/test_vulnscanner.rb', 'test/test_signature.rb', 'test/test_reports.rb']
test.verbose = false
end