2020-02-08 15:59:32 -05:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
# -*- coding: binary -*-
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Check for data scripts to ensure they are up to date
|
|
|
|
|
#
|
|
|
|
|
# by h00die
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
require 'digest'
|
|
|
|
|
require 'open-uri'
|
|
|
|
|
require 'optparse'
|
|
|
|
|
|
|
|
|
|
options = {}
|
|
|
|
|
optparse = OptionParser.new do |opts|
|
|
|
|
|
opts.banner = 'Usage: chececk_external_scripts.rb [options]'
|
|
|
|
|
opts.on('-u', '--update', 'Overwrite old scripts with newer ones.') do
|
|
|
|
|
options[:update] = true
|
|
|
|
|
end
|
|
|
|
|
opts.on('-h', '--help', 'Display this screen.') do
|
|
|
|
|
puts opts
|
|
|
|
|
exit
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
optparse.parse!
|
|
|
|
|
|
|
|
|
|
# colors and puts templates from msftidy.rb
|
|
|
|
|
|
|
|
|
|
class String
|
|
|
|
|
def red
|
|
|
|
|
"\e[1;31;40m#{self}\e[0m"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def yellow
|
|
|
|
|
"\e[1;33;40m#{self}\e[0m"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def green
|
|
|
|
|
"\e[1;32;40m#{self}\e[0m"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def cyan
|
|
|
|
|
"\e[1;36;40m#{self}\e[0m"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Display an error message, given some text
|
|
|
|
|
#
|
|
|
|
|
def error(txt)
|
|
|
|
|
line_msg = ''
|
|
|
|
|
puts "[#{'ERROR'.red}] #{cleanup_text(txt)}"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Display a warning message, given some text
|
|
|
|
|
#
|
|
|
|
|
def warn(txt)
|
|
|
|
|
line_msg = ''
|
|
|
|
|
puts "[#{'WARNING'.yellow}] #{cleanup_text(txt)}"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Display a info message, given some text
|
|
|
|
|
#
|
|
|
|
|
def info(txt)
|
|
|
|
|
line_msg = ''
|
|
|
|
|
puts "[#{'INFO'.cyan}] #{cleanup_text(txt)}"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def cleanup_text(txt)
|
|
|
|
|
# remove line breaks
|
|
|
|
|
txt = txt.gsub(/[\r\n]/, ' ')
|
|
|
|
|
# replace multiple spaces by one space
|
|
|
|
|
txt.gsub(/\s{2,}/, ' ')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# Main
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
scripts = []
|
|
|
|
|
scripts << {
|
2020-04-02 21:32:10 -05:00
|
|
|
name: 'Sharphound (Bloodhound)',
|
|
|
|
|
addr: 'https://raw.githubusercontent.com/BloodHoundAD/BloodHound/master/Ingestors/SharpHound.ps1',
|
|
|
|
|
dest: '/data/post/powershell/SharpHound.ps1',
|
|
|
|
|
subs: [
|
|
|
|
|
["\t", " "], # tabs to spaces
|
|
|
|
|
[/\s+$/, ''] # trailing whitespace
|
|
|
|
|
]
|
|
|
|
|
}
|
2020-02-08 15:59:32 -05:00
|
|
|
|
|
|
|
|
path = File.expand_path('../../', File.dirname(__FILE__))
|
|
|
|
|
|
|
|
|
|
scripts.each do |script|
|
2020-04-02 21:32:10 -05:00
|
|
|
puts "Downloading: #{script[:name]}"
|
2020-02-08 15:59:32 -05:00
|
|
|
begin
|
2020-04-02 21:32:10 -05:00
|
|
|
old_content = File.binread(path + script[:dest])
|
|
|
|
|
old_hash = Digest::SHA1.hexdigest old_content
|
2020-02-08 15:59:32 -05:00
|
|
|
info "Old Hash: #{old_hash}"
|
2020-04-02 21:32:10 -05:00
|
|
|
|
|
|
|
|
new_content = open(script[:addr]).read
|
|
|
|
|
if script.key?(:subs) then
|
|
|
|
|
script[:subs].each do |sub|
|
|
|
|
|
new_content.gsub!(sub[0], sub[1])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
new_hash = Digest::SHA1.hexdigest new_content
|
2020-02-08 15:59:32 -05:00
|
|
|
info "New Hash: #{new_hash}"
|
2020-04-02 21:32:10 -05:00
|
|
|
|
2020-02-08 15:59:32 -05:00
|
|
|
unless old_hash == new_hash
|
|
|
|
|
warn " New version identified!"
|
|
|
|
|
if options[:update] == true
|
2020-04-02 21:32:10 -05:00
|
|
|
warn " Updating MSF copy of #{script[:dest]}"
|
|
|
|
|
File.binwrite(path + script[:dest], new_content)
|
2020-02-08 15:59:32 -05:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
rescue OpenURI::HTTPError
|
2020-04-02 21:32:10 -05:00
|
|
|
error "Unable to download, check URL: #{script[:addr]}"
|
2020-02-08 15:59:32 -05:00
|
|
|
rescue Errno::ENOENT
|
2020-04-02 21:32:10 -05:00
|
|
|
error "Destination not found, check path: #{path + script[:dest]}"
|
2020-02-08 15:59:32 -05:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|