Skip to content

Commit a50ac40

Browse files
committed
Add support for PostgreSQL history
1 parent 4ebe0fc commit a50ac40

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

modules/post/linux/gather/enum_users_history.rb

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def run
4747
shells.each do |shell|
4848
get_shell_history(users, user, shell)
4949
end
50-
get_sql_history(users, user)
50+
get_mysql_history(users, user)
51+
get_psql_history(users, user)
5152
get_vim_history(users, user)
5253
last = execute("/usr/bin/last && /usr/bin/lastlog")
5354
sudoers = cat_file("/etc/sudoers")
@@ -109,25 +110,45 @@ def get_shell_history(users, user, shell)
109110
end
110111
end
111112

112-
def get_sql_history(users, user)
113+
def get_mysql_history(users, user)
113114
if user == "root" and users != nil
114115
users = users.chomp.split()
115116
users.each do |u|
116117
if u == "root"
117-
vprint_status("Extracting SQL history for #{u}")
118+
vprint_status("Extracting MySQL history for #{u}")
118119
sql_hist = cat_file("/root/.mysql_history")
119120
else
120-
vprint_status("Extracting SQL history for #{u}")
121+
vprint_status("Extracting MySQL history for #{u}")
121122
sql_hist = cat_file("/home/#{u}/.mysql_history")
122123
end
123-
124-
save("History for #{u}", sql_hist) unless sql_hist.nil? || sql_hist =~ /No such file or directory/
124+
save("MySQL History for #{u}", sql_hist) unless sql_hist.nil? || sql_hist =~ /No such file or directory/
125125
end
126126
else
127-
vprint_status("Extracting SQL history for #{user}")
127+
vprint_status("Extracting MySQL history for #{user}")
128128
sql_hist = cat_file("/home/#{user}/.mysql_history")
129129
vprint_status(sql_hist) if sql_hist
130-
save("SQL History for #{user}", sql_hist) unless sql_hist.nil? || sql_hist =~ /No such file or directory/
130+
save("MySQL History for #{user}", sql_hist) unless sql_hist.nil? || sql_hist =~ /No such file or directory/
131+
end
132+
end
133+
134+
def get_psql_history(users, user)
135+
if user == "root" and users != nil
136+
users = users.chomp.split()
137+
users.each do |u|
138+
if u == "root"
139+
vprint_status("Extracting PostgreSQL history for #{u}")
140+
sql_hist = cat_file("/root/.psql_history")
141+
else
142+
vprint_status("Extracting PostgreSQL history for #{u}")
143+
sql_hist = cat_file("/home/#{u}/.psql_history")
144+
end
145+
save("PostgreSQL History for #{u}", sql_hist) unless sql_hist.blank? || sql_hist =~ /No such file or directory/
146+
end
147+
else
148+
vprint_status("Extracting PostgreSQL history for #{user}")
149+
sql_hist = cat_file("/home/#{user}/.psql_history")
150+
vprint_status(sql_hist) if sql_hist
151+
save("PostgreSQL History for #{user}", sql_hist) unless sql_hist.blank? || sql_hist =~ /No such file or directory/
131152
end
132153
end
133154

0 commit comments

Comments
 (0)