Skip to content

Commit 4ebe0fc

Browse files
committed
Add support for different shells
1 parent f9b141c commit 4ebe0fc

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

modules/post/linux/gather/enum_users_history.rb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ def run
4343
user = execute("/usr/bin/whoami")
4444

4545
mount = execute("/bin/mount -l")
46-
get_bash_history(users, user)
46+
shells = ['ash', 'bash', 'csh', 'ksh', 'sh', 'tcsh', 'zsh']
47+
shells.each do |shell|
48+
get_shell_history(users, user, shell)
49+
end
4750
get_sql_history(users, user)
4851
get_vim_history(users, user)
4952
last = execute("/usr/bin/last && /usr/bin/lastlog")
@@ -84,25 +87,25 @@ def cat_file(filename)
8487
return output
8588
end
8689

87-
def get_bash_history(users, user)
90+
def get_shell_history(users, user, shell)
91+
return if shell.nil?
8892
if user == "root" and users != nil
8993
users = users.chomp.split()
9094
users.each do |u|
9195
if u == "root"
92-
vprint_status("Extracting history for #{u}")
93-
hist = cat_file("/root/.bash_history")
96+
vprint_status("Extracting #{shell} history for #{u}")
97+
hist = cat_file("/root/.#{shell}_history")
9498
else
95-
vprint_status("Extracting history for #{u}")
96-
hist = cat_file("/home/#{u}/.bash_history")
99+
vprint_status("Extracting #{shell} history for #{u}")
100+
hist = cat_file("/home/#{u}/.#{shell}_history")
97101
end
98-
99-
save("History for #{u}", hist) unless hist.nil? || hist =~ /No such file or directory/
102+
save("#{shell} History for #{u}", hist) unless hist.blank? || hist =~ /No such file or directory/
100103
end
101104
else
102-
vprint_status("Extracting history for #{user}")
103-
hist = cat_file("/home/#{user}/.bash_history")
105+
vprint_status("Extracting #{shell} history for #{user}")
106+
hist = cat_file("/home/#{user}/.#{shell}_history")
104107
vprint_status(hist)
105-
save("History for #{user}", hist) unless hist.nil? || hist =~ /No such file or directory/
108+
save("#{shell} History for #{user}", hist) unless hist.blank? || hist =~ /No such file or directory/
106109
end
107110
end
108111

0 commit comments

Comments
 (0)