Skip to content

Commit 86c5e96

Browse files
committed
Land rapid7#5146, enum_system cleanup
2 parents 0a4ab99 + 001253a commit 86c5e96

File tree

1 file changed

+55
-56
lines changed

1 file changed

+55
-56
lines changed

modules/post/linux/gather/enum_system.rb

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,26 @@ class Metasploit3 < Msf::Post
1111
include Msf::Post::File
1212
include Msf::Post::Linux::System
1313

14-
15-
def initialize(info={})
16-
super( update_info( info,
17-
'Name' => 'Linux Gather System and User Information',
18-
'Description' => %q{
19-
This module gathers system information. We collect
20-
installed packages, installed services, mount information,
21-
user list, user bash history and cron jobs
22-
},
23-
'License' => MSF_LICENSE,
24-
'Author' =>
25-
[
26-
'Carlos Perez <carlos_perez[at]darkoperator.com>', # get_packages and get_services
27-
'Stephen Haywood <averagesecurityguy[at]gmail.com>', # get_cron and original enum_linux
28-
'sinn3r', # Testing and modification of original enum_linux
29-
'ohdae <bindshell[at]live.com>', # Combined separate mods, modifications and testing
30-
'Roberto Espreto <robertoespreto[at]gmail.com>', # log files and setuid/setgid
31-
],
32-
'Platform' => ['linux'],
33-
'SessionTypes' => ['shell', 'meterpreter']
34-
))
35-
14+
def initialize(info = {})
15+
super(update_info(info,
16+
'Name' => 'Linux Gather System and User Information',
17+
'Description' => %q{
18+
This module gathers system information. We collect
19+
installed packages, installed services, mount information,
20+
user list, user bash history and cron jobs
21+
},
22+
'License' => MSF_LICENSE,
23+
'Author' =>
24+
[
25+
'Carlos Perez <carlos_perez[at]darkoperator.com>', # get_packages and get_services
26+
'Stephen Haywood <averagesecurityguy[at]gmail.com>', # get_cron and original enum_linux
27+
'sinn3r', # Testing and modification of original enum_linux
28+
'ohdae <bindshell[at]live.com>', # Combined separate mods, modifications and testing
29+
'Roberto Espreto <robertoespreto[at]gmail.com>', # log files and setuid/setgid
30+
],
31+
'Platform' => ['linux'],
32+
'SessionTypes' => ['shell', 'meterpreter']
33+
))
3634
end
3735

3836
def run
@@ -53,13 +51,15 @@ def run
5351
users = execute("/bin/cat /etc/passwd | cut -d : -f 1")
5452
user = execute("/usr/bin/whoami")
5553

54+
print_good("\tModule running as \"#{user}\" user")
55+
5656
installed_pkg = get_packages(distro[:distro])
5757
installed_svc = get_services(distro[:distro])
5858

5959
mount = execute("/bin/mount -l")
6060
crons = get_crons(users, user)
6161
diskspace = execute("/bin/df -ahT")
62-
disks = (mount +"\n\/"+ diskspace)
62+
disks = (mount + "\n\n" + diskspace)
6363
logfiles = execute("find /var/log -type f -perm -4 2> /dev/null")
6464
uidgid = execute("find / -xdev -type f -perm +6000 -perm -1 2> /dev/null")
6565

@@ -71,14 +71,12 @@ def run
7171
save("Disk info", disks)
7272
save("Logfiles", logfiles)
7373
save("Setuid/setgid files", uidgid)
74-
7574
end
7675

77-
78-
def save(msg, data, ctype="text/plain")
76+
def save(msg, data, ctype = 'text/plain')
7977
ltype = "linux.enum.system"
8078
loot = store_loot(ltype, ctype, session, data, nil, msg)
81-
print_status("#{msg} stored in #{loot.to_s}")
79+
print_status("#{msg} stored in #{loot}")
8280
end
8381

8482
def get_host
@@ -91,81 +89,82 @@ def get_host
9189

9290
print_status("Running module against #{host}")
9391

94-
return host
92+
host
9593
end
9694

9795
def execute(cmd)
9896
vprint_status("Execute: #{cmd}")
9997
output = cmd_exec(cmd)
100-
return output
98+
output
10199
end
102100

103101
def cat_file(filename)
104102
vprint_status("Download: #{filename}")
105103
output = read_file(filename)
106-
return output
104+
output
107105
end
108106

109107
def get_packages(distro)
110-
packages_installed = nil
111-
if distro =~ /fedora|redhat|suse|mandrake|oracle|amazon/
108+
packages_installed = ""
109+
case distro
110+
when /fedora|redhat|suse|mandrake|oracle|amazon/
112111
packages_installed = execute("rpm -qa")
113-
elsif distro =~ /slackware/
114-
packages_installed = execute("ls /var/log/packages")
115-
elsif distro =~ /ubuntu|debian/
116-
packages_installed = execute("dpkg -l")
117-
elsif distro =~ /gentoo/
112+
when /slackware/
113+
packages_installed = execute("/bin/ls /var/log/packages")
114+
when /ubuntu|debian/
115+
packages_installed = execute("/usr/bin/dpkg -l")
116+
when /gentoo/
118117
packages_installed = execute("equery list")
119-
elsif distro =~ /arch/
118+
when /arch/
120119
packages_installed = execute("/usr/bin/pacman -Q")
121120
else
122121
print_error("Could not determine package manager to get list of installed packages")
123122
end
124-
return packages_installed
123+
packages_installed
125124
end
126125

127126
def get_services(distro)
128127
services_installed = ""
129-
if distro =~ /fedora|redhat|suse|mandrake|oracle|amazon/
128+
case distro
129+
when /fedora|redhat|suse|mandrake|oracle|amazon/
130130
services_installed = execute("/sbin/chkconfig --list")
131-
elsif distro =~ /slackware/
131+
when /slackware/
132132
services_installed << "\nEnabled:\n*************************\n"
133133
services_installed << execute("ls -F /etc/rc.d | /bin/grep \'*$\'")
134134
services_installed << "\n\nDisabled:\n*************************\n"
135135
services_installed << execute("ls -F /etc/rc.d | /bin/grep \'[a-z0-9A-z]$\'")
136-
elsif distro =~ /ubuntu|debian/
137-
services_installed = execute("/usr/bin/service --status-all")
138-
elsif distro =~ /gentoo/
136+
when /ubuntu|debian/
137+
services_installed = execute("/usr/sbin/service --status-all")
138+
when /gentoo/
139139
services_installed = execute("/bin/rc-status --all")
140-
elsif distro =~ /arch/
140+
when /arch/
141141
services_installed = execute("/bin/egrep '^DAEMONS' /etc/rc.conf")
142142
else
143143
print_error("Could not determine the Linux Distribution to get list of configured services")
144144
end
145-
return services_installed
145+
services_installed
146146
end
147147

148148
def get_crons(users, user)
149-
if user == "root" and users != nil
150-
users = users.chomp.split()
149+
if user == "root" && users
150+
users = users.chomp.split
151151
users.each do |u|
152152
if u == "root"
153153
vprint_status("Enumerating as root")
154154
cron_data = ""
155-
users.each do |u|
156-
cron_data += "*****Listing cron jobs for #{u}*****\n"
157-
cron_data += execute("crontab -u #{u} -l") + "\n\n"
155+
users.each do |usr|
156+
cron_data << "*****Listing cron jobs for #{usr}*****\n"
157+
cron_data << execute("crontab -u #{usr} -l") + "\n\n"
158158
end
159159
end
160160
end
161161
else
162162
vprint_status("Enumerating as #{user}")
163163
cron_data = "***** Listing cron jobs for #{user} *****\n\n"
164-
cron_data += execute("crontab -l")
165-
end
166-
167-
# Save cron data to loot
168-
return cron_data
164+
cron_data << execute("crontab -l")
169165

166+
# Save cron data to loot
167+
cron_data
168+
end
170169
end
171170
end

0 commit comments

Comments
 (0)