Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/tools/dev/check_external_scripts.rb
Views: 11768
#!/usr/bin/env ruby1# -*- coding: binary -*-23#4# Check for data scripts to ensure they are up to date5#6# by h00die7#89require 'digest'10require 'open-uri'11require 'optparse'12require 'tempfile'1314options = {}15optparse = OptionParser.new do |opts|16opts.banner = 'Usage: check_external_scripts.rb [options]'17opts.on('-u', '--update', 'Overwrite old scripts with newer ones.') do18options[:update] = true19end20opts.on('-h', '--help', 'Display this screen.') do21puts opts22exit23end24end25optparse.parse!2627# colors and puts templates from msftidy.rb2829class String30def red31"\e[1;31;40m#{self}\e[0m"32end3334def yellow35"\e[1;33;40m#{self}\e[0m"36end3738def green39"\e[1;32;40m#{self}\e[0m"40end4142def cyan43"\e[1;36;40m#{self}\e[0m"44end45end4647#48# Display an error message, given some text49#50def error(txt)51puts "[#{'ERROR'.red}] #{cleanup_text(txt)}"52end5354#55# Display a warning message, given some text56#57def warning(txt)58puts "[#{'WARNING'.yellow}] #{cleanup_text(txt)}"59end6061#62# Display a info message, given some text63#64def info(txt)65puts "[#{'INFO'.cyan}] #{cleanup_text(txt)}"66end6768def cleanup_text(txt)69# remove line breaks70txt = txt.gsub(/[\r\n]/, ' ')71# replace multiple spaces by one space72txt.gsub(/\s{2,}/, ' ')73end7475def cleanup_sqlmap_decloak_dir76unless system('rm -rf /tmp/sqlmap_decloak')77error 'Could not remove existing /tmp/sqlmap_decloak directory'78end79end8081def clone_sqlmap_decloak82cleanup_sqlmap_decloak_dir83unless system('git clone -q --depth=1 https://github.com/sqlmapproject/sqlmap.git /tmp/sqlmap_decloak')84error "Either 'git' is not installed, your internet is not connected, or /tmp/sqlmap_decloak could not be removed."85end86end8788# https://github.com/rapid7/metasploit-framework/pull/13191#issuecomment-62658468989def decloak(file)90unless system("python /tmp/sqlmap_decloak/extra/cloak/cloak.py -d -i #{file.path} -o #{file.path}_decloak")91unless system("python3 /tmp/sqlmap_decloak/extra/cloak/cloak.py -d -i #{file.path} -o #{file.path}_decloak")92error "Either python is not installed, or the file at #{file.path} could not be found! Please double check your computer's setup and check that the #{file.path} file exists!"93end94end95File.binread("#{file.path}_decloak")96end9798#99#100# Main101#102#103104scripts = []105106###107# Bloodhound/Sharphound files108###109110# https://github.com/BloodHoundAD/BloodHound/commit/b6ab5cd369c70219c6376d9f5c4fcd63f34fb4a0111scripts << {112name: 'Sharphound (Bloodhound) ps1',113addr: 'https://raw.githubusercontent.com/BloodHoundAD/BloodHound/master/Collectors/SharpHound.ps1',114dest: '/data/post/powershell/SharpHound.ps1',115subs: [116["\t", ' '], # tabs to spaces117[/\s+$/, ''] # trailing whitespace118]119}120scripts << {121name: 'Sharphound (Bloodhound) exe',122addr: 'https://raw.githubusercontent.com/BloodHoundAD/BloodHound/master/Collectors/SharpHound.exe',123dest: '/data/post/SharpHound.exe',124subs: []125}126###127# JTR files128###129scripts << {130name: 'JTR - dumb16.conf',131addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/dumb16.conf',132dest: '/data/jtr/dumb16.conf',133subs: []134}135scripts << {136name: 'JTR - alnumspace.chr',137addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/alnumspace.chr',138dest: '/data/jtr/alnumspace.chr',139subs: []140}141scripts << {142name: 'JTR - regex_alphabets.conf',143addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/regex_alphabets.conf',144dest: '/data/jtr/regex_alphabets.conf',145subs: []146}147scripts << {148name: 'JTR - latin1.chr',149addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/latin1.chr',150dest: '/data/jtr/latin1.chr',151subs: []152}153scripts << {154name: 'JTR - lowerspace.chr',155addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/lowerspace.chr',156dest: '/data/jtr/lowerspace.chr',157subs: []158}159scripts << {160name: 'JTR - utf8.chr',161addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/utf8.chr',162dest: '/data/jtr/utf8.chr',163subs: []164}165scripts << {166name: 'JTR - john.conf',167addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/john.conf',168dest: '/data/jtr/john.conf',169subs: []170}171scripts << {172name: 'JTR - dumb32.conf',173addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/dumb32.conf',174dest: '/data/jtr/dumb32.conf',175subs: []176}177scripts << {178name: 'JTR - alpha.chr',179addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/alpha.chr',180dest: '/data/jtr/alpha.chr',181subs: []182}183scripts << {184name: 'JTR - dynamic.conf',185addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/dynamic.conf',186dest: '/data/jtr/dynamic.conf',187subs: []188}189scripts << {190name: 'JTR - repeats32.conf',191addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/repeats32.conf',192dest: '/data/jtr/repeats32.conf',193subs: []194}195scripts << {196name: 'JTR - lm_ascii.chr',197addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/lm_ascii.chr',198dest: '/data/jtr/lm_ascii.chr',199subs: []200}201scripts << {202name: 'JTR - upper.chr',203addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/upper.chr',204dest: '/data/jtr/upper.chr',205subs: []206}207scripts << {208name: 'JTR - lowernum.chr',209addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/lowernum.chr',210dest: '/data/jtr/lowernum.chr',211subs: []212}213scripts << {214name: 'JTR - ascii.chr',215addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/ascii.chr',216dest: '/data/jtr/ascii.chr',217subs: []218}219scripts << {220name: 'JTR - dynamic_disabled.conf',221addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/dynamic_disabled.conf',222dest: '/data/jtr/dynamic_disabled.conf',223subs: []224}225scripts << {226name: 'JTR - hybrid.conf',227addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/hybrid.conf',228dest: '/data/jtr/hybrid.conf',229subs: []230}231scripts << {232name: 'JTR - repeats16.conf',233addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/repeats16.conf',234dest: '/data/jtr/repeats16.conf',235subs: []236}237scripts << {238name: 'JTR - digits.chr',239addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/digits.chr',240dest: '/data/jtr/digits.chr',241subs: []242}243scripts << {244name: 'JTR - uppernum.chr',245addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/uppernum.chr',246dest: '/data/jtr/uppernum.chr',247subs: []248}249scripts << {250name: 'JTR - lanman.chr',251addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/lanman.chr',252dest: '/data/jtr/lanman.chr',253subs: []254}255scripts << {256name: 'JTR - dynamic_flat_sse_formats.conf',257addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/dynamic_flat_sse_formats.conf',258dest: '/data/jtr/dynamic_flat_sse_formats.conf',259subs: []260}261scripts << {262name: 'JTR - alnum.chr',263addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/alnum.chr',264dest: '/data/jtr/alnum.chr',265subs: []266}267scripts << {268name: 'JTR - lower.chr',269addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/lower.chr',270dest: '/data/jtr/lower.chr',271subs: []272}273scripts << {274name: 'JTR - korelogic.conf',275addr: 'https://raw.githubusercontent.com/magnumripper/JohnTheRipper/bleeding-jumbo/run/korelogic.conf',276dest: '/data/jtr/korelogic.conf',277subs: []278}279280###281# SQLMap UDF files282###283scripts << {284name: 'SQLMap UDF - lib_mysqludf_sys_32.so',285addr: 'https://github.com/sqlmapproject/sqlmap/blob/master/data/udf/mysql/linux/32/lib_mysqludf_sys.so_?raw=true',286dest: '/data/exploits/mysql/lib_mysqludf_sys_32.so',287subs: []288}289scripts << {290name: 'SQLMap UDF - lib_mysqludf_sys_64.so',291addr: 'https://github.com/sqlmapproject/sqlmap/blob/master/data/udf/mysql/linux/64/lib_mysqludf_sys.so_?raw=true',292dest: '/data/exploits/mysql/lib_mysqludf_sys_64.so',293subs: []294}295scripts << {296name: 'SQLMap UDF - lib_mysqludf_sys_32.dll',297addr: 'https://github.com/sqlmapproject/sqlmap/blob/master/data/udf/mysql/windows/32/lib_mysqludf_sys.dll_?raw=true',298dest: '/data/exploits/mysql/lib_mysqludf_sys_32.dll',299subs: []300}301scripts << {302name: 'SQLMap UDF - lib_mysqludf_sys_64.dll',303addr: 'https://github.com/sqlmapproject/sqlmap/blob/master/data/udf/mysql/windows/64/lib_mysqludf_sys.dll_?raw=true',304dest: '/data/exploits/mysql/lib_mysqludf_sys_64.dll',305subs: []306}307308###309# CMS Files310###311312# https://github.com/rapid7/metasploit-framework/pull/11862#issuecomment-496578367313scripts << {314name: 'WordPress - Plugins List',315addr: 'https://plugins.svn.wordpress.org',316dest: '/data/wordlists/wp-plugins.txt',317subs: [318[/^((?! <li>).)*/, ''], # remove all non-plugin lines319[/ <li><a href="[^"]+">/, ''], # remove beginning320[/\/<\/a><\/li>/,''], # remove end321[/^\s*/,''] # remove empty lines322]323}324325scripts << {326name: 'WordPress - Themes List',327addr: 'https://themes.svn.wordpress.org',328dest: '/data/wordlists/wp-themes.txt',329subs: [330[/^((?! <li>).)*/, ''], # remove all non-plugin lines331[/ <li><a href="[^"]+">/, ''], # remove beginning332[/\/<\/a><\/li>/,''], # remove end333[/^\s*/,''] # remove empty lines334]335}336337# Joomla's is more complicated. It looks for more than338# just components. Because of that, if you want the339# file updated, see:340# https://github.com/rapid7/metasploit-framework/pull/11199#issue-242415518341# python3 tools/dev/update_joomla_components.py342343path = File.expand_path('../../', File.dirname(__FILE__))344345clone_sqlmap_decloak346347scripts.each do |script|348puts "Downloading: #{script[:name]}"349begin350old_content = File.binread(path + script[:dest])351old_hash = Digest::SHA1.hexdigest old_content352info "Old Hash: #{old_hash}"353354new_content = URI.open(script[:addr]).read355if script.key?(:subs)356script[:subs].each do |sub|357new_content.gsub!(sub[0], sub[1])358end359end360361if script[:name].start_with?('SQLMap UDF')362info('Performing decloaking')363f = Tempfile.new('sqlmap_udf')364f.write(new_content)365f.close366new_content = decloak(f)367end368369new_hash = Digest::SHA1.hexdigest new_content370info "New Hash: #{new_hash}"371372unless old_hash == new_hash373warning ' New version identified!'374if options[:update] == true375warning " Updating MSF copy of #{script[:dest]}"376File.binwrite(path + script[:dest], new_content)377end378end379rescue OpenURI::HTTPError380error "Unable to download, check URL: #{script[:addr]}"381rescue Errno::ENOENT382error "Destination not found, check path: #{path + script[:dest]}"383end384end385386cleanup_sqlmap_decloak_dir387388389