@@ -11,28 +11,26 @@ class Metasploit3 < Msf::Post
11
11
include Msf ::Post ::File
12
12
include Msf ::Post ::Linux ::System
13
13
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
+ ) )
36
34
end
37
35
38
36
def run
@@ -53,13 +51,15 @@ def run
53
51
users = execute ( "/bin/cat /etc/passwd | cut -d : -f 1" )
54
52
user = execute ( "/usr/bin/whoami" )
55
53
54
+ print_good ( "\t Module running as \" #{ user } \" user" )
55
+
56
56
installed_pkg = get_packages ( distro [ :distro ] )
57
57
installed_svc = get_services ( distro [ :distro ] )
58
58
59
59
mount = execute ( "/bin/mount -l" )
60
60
crons = get_crons ( users , user )
61
61
diskspace = execute ( "/bin/df -ahT" )
62
- disks = ( mount +"\n \/ " + diskspace )
62
+ disks = ( mount + "\n \n " + diskspace )
63
63
logfiles = execute ( "find /var/log -type f -perm -4 2> /dev/null" )
64
64
uidgid = execute ( "find / -xdev -type f -perm +6000 -perm -1 2> /dev/null" )
65
65
@@ -71,14 +71,12 @@ def run
71
71
save ( "Disk info" , disks )
72
72
save ( "Logfiles" , logfiles )
73
73
save ( "Setuid/setgid files" , uidgid )
74
-
75
74
end
76
75
77
-
78
- def save ( msg , data , ctype = "text/plain" )
76
+ def save ( msg , data , ctype = 'text/plain' )
79
77
ltype = "linux.enum.system"
80
78
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 } " )
82
80
end
83
81
84
82
def get_host
@@ -91,81 +89,82 @@ def get_host
91
89
92
90
print_status ( "Running module against #{ host } " )
93
91
94
- return host
92
+ host
95
93
end
96
94
97
95
def execute ( cmd )
98
96
vprint_status ( "Execute: #{ cmd } " )
99
97
output = cmd_exec ( cmd )
100
- return output
98
+ output
101
99
end
102
100
103
101
def cat_file ( filename )
104
102
vprint_status ( "Download: #{ filename } " )
105
103
output = read_file ( filename )
106
- return output
104
+ output
107
105
end
108
106
109
107
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/
112
111
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/
118
117
packages_installed = execute ( "equery list" )
119
- elsif distro =~ /arch/
118
+ when /arch/
120
119
packages_installed = execute ( "/usr/bin/pacman -Q" )
121
120
else
122
121
print_error ( "Could not determine package manager to get list of installed packages" )
123
122
end
124
- return packages_installed
123
+ packages_installed
125
124
end
126
125
127
126
def get_services ( distro )
128
127
services_installed = ""
129
- if distro =~ /fedora|redhat|suse|mandrake|oracle|amazon/
128
+ case distro
129
+ when /fedora|redhat|suse|mandrake|oracle|amazon/
130
130
services_installed = execute ( "/sbin/chkconfig --list" )
131
- elsif distro =~ /slackware/
131
+ when /slackware/
132
132
services_installed << "\n Enabled:\n *************************\n "
133
133
services_installed << execute ( "ls -F /etc/rc.d | /bin/grep \' *$\' " )
134
134
services_installed << "\n \n Disabled:\n *************************\n "
135
135
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/
139
139
services_installed = execute ( "/bin/rc-status --all" )
140
- elsif distro =~ /arch/
140
+ when /arch/
141
141
services_installed = execute ( "/bin/egrep '^DAEMONS' /etc/rc.conf" )
142
142
else
143
143
print_error ( "Could not determine the Linux Distribution to get list of configured services" )
144
144
end
145
- return services_installed
145
+ services_installed
146
146
end
147
147
148
148
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
151
151
users . each do |u |
152
152
if u == "root"
153
153
vprint_status ( "Enumerating as root" )
154
154
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 "
158
158
end
159
159
end
160
160
end
161
161
else
162
162
vprint_status ( "Enumerating as #{ user } " )
163
163
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" )
169
165
166
+ # Save cron data to loot
167
+ cron_data
168
+ end
170
169
end
171
170
end
0 commit comments