Skip to content

Commit 79603c9

Browse files
committed
Land rapid7#3505, a bunch o' Linux post module fixes
2 parents ced16ac + 42823fe commit 79603c9

File tree

10 files changed

+51
-52
lines changed

10 files changed

+51
-52
lines changed

lib/msf/core/post/common.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def cmd_exec(cmd, args=nil, time_out=15)
110110
break if d == ""
111111
o << d
112112
end
113+
o.chomp! if o
113114
process.channel.close
114115
process.close
115116
when /shell/

modules/post/linux/gather/enum_configs.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def initialize(info={})
2323
[
2424
'ohdae <bindshell[at]live.com>',
2525
],
26-
'Platform' => [ 'linux' ],
27-
'SessionTypes' => [ 'shell' ]
26+
'Platform' => ['linux'],
27+
'SessionTypes' => ['shell', 'meterpreter']
2828
))
2929
end
3030

@@ -74,7 +74,7 @@ def find_configs
7474

7575
configs.each do |f|
7676
output = read_file("#{f}")
77-
save(f, output) if output !~ /No such file or directory/
77+
save(f, output) if output && output !~ /No such file or directory/
7878
end
7979
end
8080
end

modules/post/linux/gather/enum_network.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def initialize(info={})
2626
'ohdae <bindshell[at]live.com>', # minor additions, modifications & testing
2727
'Stephen Haywood <averagesecurityguy[at]gmail.com>', # enum_linux
2828
],
29-
'Platform' => [ 'linux' ],
30-
'SessionTypes' => [ 'shell' ]
29+
'Platform' => ['linux'],
30+
'SessionTypes' => ['shell', 'meterpreter']
3131
))
3232
end
3333

modules/post/linux/gather/enum_protections.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def initialize(info={})
2828
[
2929
'ohdae <bindshell[at]live.com>'
3030
],
31-
'Platform' => [ 'linux' ],
32-
'SessionTypes' => [ 'shell' ]
31+
'Platform' => ['linux'],
32+
'SessionTypes' => ['shell', 'meterpreter']
3333
))
3434
end
3535

modules/post/linux/gather/enum_system.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def initialize(info={})
2929
'ohdae <bindshell[at]live.com>', # Combined separate mods, modifications and testing
3030
'Roberto Espreto <robertoespreto[at]gmail.com>', # log files and setuid/setgid
3131
],
32-
'Platform' => [ 'linux' ],
33-
'SessionTypes' => [ 'shell' ]
32+
'Platform' => ['linux'],
33+
'SessionTypes' => ['shell', 'meterpreter']
3434
))
3535

3636
end

modules/post/linux/gather/enum_users_history.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def initialize(info={})
2626
# based largely on get_bash_history function by Stephen Haywood
2727
'ohdae <bindshell[at]live.com>'
2828
],
29-
'Platform' => [ 'linux' ],
30-
'SessionTypes' => [ 'shell' ]
29+
'Platform' => ['linux'],
30+
'SessionTypes' => ['shell', 'meterpreter']
3131
))
3232

3333
end
@@ -49,8 +49,8 @@ def run
4949
last = execute("/usr/bin/last && /usr/bin/lastlog")
5050
sudoers = cat_file("/etc/sudoers")
5151

52-
save("Last logs", last)
53-
save("Sudoers", sudoers) unless sudoers =~ /Permission denied/
52+
save("Last logs", last) unless last.nil?
53+
save("Sudoers", sudoers) unless sudoers.nil? || sudoers =~ /Permission denied/
5454
end
5555

5656
def save(msg, data, ctype="text/plain")
@@ -96,13 +96,13 @@ def get_bash_history(users, user)
9696
hist = cat_file("/home/#{u}/.bash_history")
9797
end
9898

99-
save("History for #{u}", hist) unless hist =~ /No such file or directory/
99+
save("History for #{u}", hist) unless hist.nil? || hist =~ /No such file or directory/
100100
end
101101
else
102102
vprint_status("Extracting history for #{user}")
103103
hist = cat_file("/home/#{user}/.bash_history")
104104
vprint_status(hist)
105-
save("History for #{user}", hist) unless hist =~ /No such file or directory/
105+
save("History for #{user}", hist) unless hist.nil? || hist =~ /No such file or directory/
106106
end
107107
end
108108

@@ -118,19 +118,19 @@ def get_sql_history(users, user)
118118
sql_hist = cat_file("/home/#{u}/.mysql_history")
119119
end
120120

121-
save("History for #{u}", sql_hist) unless sql_hist =~ /No such file or directory/
121+
save("History for #{u}", sql_hist) unless sql_hist.nil? || sql_hist =~ /No such file or directory/
122122
end
123123
else
124124
vprint_status("Extracting SQL history for #{user}")
125125
sql_hist = cat_file("/home/#{user}/.mysql_history")
126-
vprint_status(sql_hist)
127-
save("SQL History for #{user}", sql_hist) unless sql_hist =~ /No such file or directory/
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/
128128
end
129129
end
130130

131131
def get_vim_history(users, user)
132132
if user == "root" and users != nil
133-
users = users.chomp.split()
133+
users = users.chomp.split
134134
users.each do |u|
135135
if u == "root"
136136
vprint_status("Extracting VIM history for #{u}")
@@ -140,13 +140,13 @@ def get_vim_history(users, user)
140140
vim_hist = cat_file("/home/#{u}/.viminfo")
141141
end
142142

143-
save("VIM History for #{u}", vim_hist) unless vim_hist =~ /No such file or directory/
143+
save("VIM History for #{u}", vim_hist) unless vim_hist.nil? || vim_hist =~ /No such file or directory/
144144
end
145145
else
146146
vprint_status("Extracting history for #{user}")
147147
vim_hist = cat_file("/home/#{user}/.viminfo")
148148
vprint_status(vim_hist)
149-
save("VIM History for #{user}", vim_hist) unless vim_hist =~ /No such file or directory/
149+
save("VIM History for #{user}", vim_hist) unless vim_hist.nil? || vim_hist =~ /No such file or directory/
150150
end
151151
end
152152
end

modules/post/linux/gather/enum_xchat.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ def initialize(info={})
2020
.log files.
2121
},
2222
'License' => MSF_LICENSE,
23-
'Author' => [ 'sinn3r'],
24-
'Platform' => [ 'linux' ],
23+
'Author' => ['sinn3r'],
24+
'Platform' => ['linux'],
2525
# linux meterpreter is too busted to support right now,
2626
# will come back and add support once it's more usable.
27-
'SessionTypes' => [ 'shell' ],
27+
'SessionTypes' => ['shell', 'meterpreter'],
2828
'Actions' =>
2929
[
3030
['CONFIGS', { 'Description' => 'Collect XCHAT\'s config files' } ],
@@ -62,7 +62,7 @@ def get_file(file)
6262
end
6363

6464
def whoami
65-
user = cmd_exec("whoami").chomp
65+
user = cmd_exec("/usr/bin/whoami").chomp
6666
return user
6767
end
6868

@@ -120,7 +120,7 @@ def get_configs(base)
120120
files.each do |f|
121121
vprint_status("#{@peer} - Downloading: #{base + f}")
122122
buf = read_file(base + f)
123-
next if buf.empty?
123+
next if buf.blank?
124124
config << {
125125
:filename => f,
126126
:data => buf
@@ -139,7 +139,7 @@ def run
139139
@peer = "#{session.session_host}:#{session.session_port}"
140140

141141
user = whoami
142-
if user.nil?
142+
if user.blank?
143143
print_error("#{@peer} - Unable to get username, abort.")
144144
return
145145
end
@@ -149,8 +149,8 @@ def run
149149
configs = get_configs(base) if action.name =~ /ALL|CONFIGS/i
150150
chatlogs = get_chatlogs(base) if action.name =~ /ALL|CHATS/i
151151

152-
save(:configs, configs) if not configs.empty?
153-
save(:chatlogs, chatlogs) if not chatlogs.empty?
152+
save(:configs, configs) unless configs.empty?
153+
save(:chatlogs, chatlogs) unless chatlogs.empty?
154154
end
155155

156156
end

modules/post/linux/gather/hashdump.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ def initialize(info={})
1616
'Name' => 'Linux Gather Dump Password Hashes for Linux Systems',
1717
'Description' => %q{ Post Module to dump the password hashes for all users on a Linux System},
1818
'License' => MSF_LICENSE,
19-
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
20-
'Platform' => [ 'linux' ],
21-
'SessionTypes' => [ 'shell' ]
19+
'Author' => ['Carlos Perez <carlos_perez[at]darkoperator.com>'],
20+
'Platform' => ['linux'],
21+
'SessionTypes' => ['shell', 'meterpreter']
2222
))
23-
2423
end
2524

2625
# Run Method for when run command is issued
@@ -43,11 +42,9 @@ def run
4342
# Save pwd file
4443
upassf = store_loot("linux.hashes", "text/plain", session, john_file, "unshadowed_passwd.pwd", "Linux Unshadowed Password File")
4544
print_good("Unshadowed Password File: #{upassf}")
46-
4745
else
4846
print_error("You must run this module as root!")
4947
end
50-
5148
end
5249

5350
def unshadow(pf,sf)
@@ -63,6 +60,8 @@ def unshadow(pf,sf)
6360
end
6461
end
6562
end
66-
return unshadowed
63+
64+
unshadowed
6765
end
66+
6867
end

modules/post/linux/gather/mount_cifs_creds.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ class Metasploit3 < Msf::Post
1111

1212
def initialize(info={})
1313
super( update_info( info,
14-
'Name' => 'Linux Gather Saved mount.cifs/mount.smbfs Credentials',
15-
'Description' => %q{
16-
Post Module to obtain credentials saved for mount.cifs/mount.smbfs in
17-
/etc/fstab on a Linux system.
18-
},
19-
'License' => MSF_LICENSE,
20-
'Author' => [ 'Jon Hart <jhart[at]spoofed.org>'],
21-
'Platform' => [ 'linux' ],
22-
'SessionTypes' => [ 'shell' ]
23-
))
14+
'Name' => 'Linux Gather Saved mount.cifs/mount.smbfs Credentials',
15+
'Description' => %q{
16+
Post Module to obtain credentials saved for mount.cifs/mount.smbfs in
17+
/etc/fstab on a Linux system.
18+
},
19+
'License' => MSF_LICENSE,
20+
'Author' => ['Jon Hart <jhart[at]spoofed.org>'],
21+
'Platform' => ['linux'],
22+
'SessionTypes' => ['shell', 'meterpreter']
23+
))
2424
end
2525

2626
def run

modules/post/linux/manage/download_exec.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,23 @@ def initialize(info={})
1515
super( update_info( info,
1616
'Name' => 'Linux Manage Download and Execute',
1717
'Description' => %q{
18-
This module downloads and runs a file with bash. It first tries to uses curl as
19-
its HTTP client and then wget if it's not found. Bash found in the PATH is used to
20-
execute the file.
18+
This module downloads and runs a file with bash. It first tries to uses curl as
19+
its HTTP client and then wget if it's not found. Bash found in the PATH is used
20+
to execute the file.
2121
},
2222
'License' => MSF_LICENSE,
2323
'Author' =>
2424
[
2525
'Joshua D. Abraham <jabra[at]praetorian.com>',
2626
],
27-
'Platform' => [ 'linux' ],
28-
'SessionTypes' => [ 'shell' ]
27+
'Platform' => ['linux'],
28+
'SessionTypes' => ['shell', 'meterpreter']
2929
))
3030

3131
register_options(
3232
[
3333
OptString.new('URL', [true, 'Full URL of file to download.'])
3434
], self.class)
35-
3635
end
3736

3837
def cmd_exec_vprint(cmd)

0 commit comments

Comments
 (0)