Skip to content

Commit bc895ab

Browse files
author
Brent Cook
committed
Land rapid7#4582, jhart-r7's Apple Airport Authentication Avalanche
2 parents 47cd5a3 + b7eb4d2 commit bc895ab

File tree

7 files changed

+485
-0
lines changed

7 files changed

+485
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
require 'metasploit/framework/tcp/client'
2+
require 'rex/proto/acpp'
3+
require 'metasploit/framework/login_scanner/base'
4+
require 'metasploit/framework/login_scanner/rex_socket'
5+
6+
module Metasploit
7+
module Framework
8+
module LoginScanner
9+
# This is the LoginScanner class for dealing with the Apple Airport ACPP
10+
# protocol. It is responsible for taking a single target, and a list of
11+
# credentials and attempting them. It then saves the results.
12+
class ACPP
13+
include Metasploit::Framework::LoginScanner::Base
14+
include Metasploit::Framework::LoginScanner::RexSocket
15+
include Metasploit::Framework::Tcp::Client
16+
17+
#
18+
# CONSTANTS
19+
#
20+
DEFAULT_PORT = Rex::Proto::ACPP::DEFAULT_PORT
21+
LIKELY_PORTS = [ DEFAULT_PORT ]
22+
LIKELY_SERVICE_NAMES = [ 'acpp' ]
23+
PRIVATE_TYPES = [ :password ]
24+
REALM_KEY = nil
25+
26+
27+
# This method attempts a single login with a single credential against the target
28+
# @param credential [Credential] The credential object to attmpt to login with
29+
# @return [Metasploit::Framework::LoginScanner::Result] The LoginScanner Result object
30+
def attempt_login(credential)
31+
result_options = {
32+
credential: credential,
33+
host: host,
34+
port: port,
35+
protocol: 'tcp',
36+
service_name: 'acpp'
37+
}
38+
39+
begin
40+
# Make our initial socket to the target
41+
disconnect if self.sock
42+
connect
43+
44+
client = Rex::Proto::ACPP::Client.new(sock)
45+
46+
auth_response = client.authenticate(credential.private)
47+
if auth_response.successful?
48+
status = Metasploit::Model::Login::Status::SUCCESSFUL
49+
else
50+
status = Metasploit::Model::Login::Status::INCORRECT
51+
end
52+
result_options.merge!(
53+
proof: "Status code #{auth_response.status}",
54+
status: status
55+
)
56+
rescue ::EOFError, Errno::ENOTCONN, Rex::ConnectionError, ::Timeout::Error => e
57+
result_options.merge!(
58+
proof: e.message,
59+
status: Metasploit::Model::Login::Status::UNABLE_TO_CONNECT
60+
)
61+
ensure
62+
disconnect
63+
end
64+
65+
::Metasploit::Framework::LoginScanner::Result.new(result_options)
66+
end
67+
end
68+
end
69+
end
70+
end

lib/rex/proto/acpp.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: binary -*-
2+
#
3+
# Support for the protocol used by Apple Airport products, typically on
4+
# 5009/TCP. This protocol is not documented and doesn't appear to have a name,
5+
# so I'm calling it ACPP because that is the protocol header.
6+
#
7+
8+
require 'rex/proto/acpp/client'
9+
require 'rex/proto/acpp/message'
10+
11+
module Rex
12+
module Proto
13+
module ACPP
14+
DEFAULT_PORT = 5009
15+
end
16+
end
17+
end

lib/rex/proto/acpp/client.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: binary -*-
2+
3+
##
4+
# ACPP protocol support
5+
##
6+
7+
module Rex
8+
module Proto
9+
module ACPP
10+
11+
class Client
12+
13+
def initialize(sock, opts = {})
14+
@sock = sock
15+
@opts = opts
16+
end
17+
18+
def authenticate(password = 'public')
19+
login = Message.new
20+
login.password = password
21+
login.type = 20
22+
@sock.put(login.to_s)
23+
# TODO: the checksum never validates here
24+
Message.decode(@sock.get_once(128), false)
25+
end
26+
end
27+
end
28+
end
29+
end

lib/rex/proto/acpp/message.rb

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# -*- coding: binary -*-
2+
3+
module Rex
4+
module Proto
5+
module ACPP
6+
# From what I've been able to gather from the very limited findings on the
7+
# web about this protocol, playing with it against a real Airport device and
8+
# referencing the airport-utils package in Debian/Ubuntu, the format of (at
9+
# least) the login message is:
10+
#
11+
# acpp # the header tag, always exactly acpp (4 bytes)
12+
# unknown1 # unknown 4-byte field. Almost always 0x00000001
13+
# messageChecksum # checksum of the message, 4 bytes
14+
# payloadChecksum # checksum of the payload, 4 bytes
15+
# payloadSize # size of the payload, 4 bytes
16+
# unknown2 # unknown 8-byte field. probably some sort of
17+
# request/response identifier. generally 0 for requests, 1 for replies
18+
# messageType # the type of message, 4 bytes. see below.
19+
# status # the status of this message, 4 bytes.
20+
# generally 0 for success and !0 for failure.
21+
# unknown3 # unknown 12-byte field, seemingly always 0. Probably 'reserved'
22+
# password # 32-byte password, 'encrypted' by XOR'ing it with a 256-byte static key (see XOR_KEY)
23+
# unknown4 # unknown 48-byte field, always 0.
24+
#
25+
# There are several possible message types:
26+
#
27+
# * 20 -- retrieve settings (payload is some list of settings to obtain)
28+
# * 21 -- update setttings (and if the 'acRB' setting is set, it reboots)
29+
# * 3 -- Upload firmware
30+
#
31+
# TODO: if you find more, add them above.
32+
#
33+
# When the message type is anything other than 20 or 3, payloadSize is set to -1 and
34+
# payloadChecksum is set to 1. It may be a bug that 21 doesn't look at the
35+
# checksum. Adler32 is used to compute the checksum.
36+
#
37+
# The message payload is a bit of an unknown right now, as it *seems* like
38+
# the payload always comes in a subsequent request. Simply appending
39+
# a payload to the existing message does not appear to work (but this needs
40+
# more testing)
41+
42+
# This was taken from airport-util's AirportInforRecord for ease of copying, but can
43+
# also be obtained by XOR'ing the null-padded known plain text with the appropriate 32-byte
44+
# ciphertext from an airport-util request
45+
XOR_KEY = [
46+
14, 57, -8, 5, -60, 1, 85, 79, 12, -84,
47+
-123, 125, -122, -118, -75, 23, 62, 9, -56, 53,
48+
-12, 49, 101, 127, 60, -100, -75, 109, -106, -102,
49+
-91, 7, 46, 25, -40, 37, -28, 33, 117, 111,
50+
44, -116, -91, -99, 102, 106, 85, -9, -34, -23,
51+
40, -43, 20, -47, -123, -97, -36, 124, 85, -115,
52+
118, 122, 69, -25, -50, -7, 56, -59, 4, -63,
53+
-107, -113, -52, 108, 69, -67, 70, 74, 117, -41,
54+
-2, -55, 8, -11, 52, -15, -91, -65, -4, 92,
55+
117, -83, 86, 90, 101, -57, -18, -39, 24, -27,
56+
36, -31, -75, -81, -20, 76, 101, -35, 38, 42,
57+
21, -73, -98, -87, 104, -107, 84, -111, -59, -33,
58+
-100, 60, 21, -51, 54, 58, 5, -89, -114, -71,
59+
120, -123, 68, -127, -43, -49, -116, 44, 5, -3,
60+
6, 10, 53, -105, -66, -119, 72, -75, 116, -79,
61+
-27, -1, -68, 28, 53, -19, 22, 26, 37, -121,
62+
-82, -103, 88, -91, 100, -95, -11, -17, -84, 12,
63+
37, 29, -26, -22, -43, 119, 94, 105, -88, 85,
64+
-108, 81, 5, 31, 92, -4, -43, 13, -10, -6,
65+
-59, 103, 78, 121, -72, 69, -124, 65, 21, 15,
66+
76, -20, -59, 61, -58, -54, -11, 87, 126, 73,
67+
-120, 117, -76, 113, 37, 63, 124, -36, -11, 45,
68+
-42, -38, -27, 71, 110, 89, -104, 101, -92, 97,
69+
53, 47, 108, -52, -27, 93, -90, -86, -107, 55,
70+
30, 41, -24, 21, -44, 17, 69, 95, 28, -68,
71+
-107, 77, -74, -70, -123, 39
72+
].pack("C*")
73+
74+
class Message
75+
# @return [Integer] the type of this message
76+
attr_accessor :type
77+
# @return [String] the password to attempt to authenticate with
78+
attr_accessor :password
79+
# @return [String] the optional message payload
80+
attr_accessor :payload
81+
# @return [Integer] the status of this message
82+
attr_accessor :status
83+
84+
def initialize
85+
@payload = ''
86+
@type = 0
87+
@status = 0
88+
@password = ''
89+
@unknown1 = 1
90+
@unknown2 = ''
91+
@unknown3 = ''
92+
@unknown4 = ''
93+
end
94+
95+
# Determines if this message has a successful status code
96+
#
97+
# @return [Boolean] true iff @status is 0, false otherwise
98+
def successful?
99+
@status == 0
100+
end
101+
102+
# Get this Message as a String
103+
#
104+
# @return [String] the string representation of this Message
105+
def to_s
106+
with_checksum(Zlib.adler32(with_checksum(0)))
107+
end
108+
109+
# Compares this Message and another Message for equality
110+
#
111+
# @param other [Message] the Message to compare
112+
# @return [Boolean] true iff the two messages are equal, false otherwise
113+
def ==(other)
114+
other.type == @type &&
115+
other.status == @status &&
116+
other.password == @password &&
117+
other.payload == @payload
118+
end
119+
120+
# Decodes the provided data into a Message
121+
#
122+
# @param data [String] the data to parse as a Message
123+
# @param validate_checksum [Boolean] true to validate the message and
124+
# payload checksums, false to not. Defaults to true.
125+
# @return [Message] the decoded Message
126+
def self.decode(data, validate_checksum = true)
127+
data = data.dup
128+
fail "Incorrect ACPP message size #{data.size} -- must be 128" unless data.size == 128
129+
fail 'Unexpected header' unless 'acpp' == data.slice!(0, 4)
130+
_unknown1 = data.slice!(0, 4)
131+
read_message_checksum = data.slice!(0, 4).unpack('N').first
132+
read_payload_checksum = data.slice!(0, 4).unpack('N').first
133+
_read_payload_size = data.slice!(0, 4).unpack('N').first
134+
_unknown2 = data.slice!(0, 8)
135+
type = data.slice!(0, 4).unpack('N').first
136+
status = data.slice!(0, 4).unpack('N').first
137+
_unknown3 = data.slice!(0, 12)
138+
password = Rex::Encoding::Xor::Generic.encode(data.slice!(0, 32), XOR_KEY).first.strip
139+
_unknown4 = data.slice!(0, 48)
140+
payload = data
141+
m = new
142+
m.type = type
143+
m.password = password
144+
m.status = status
145+
m.payload = payload
146+
147+
# we can now validate the checksums if desired
148+
if validate_checksum
149+
actual_message_checksum = Zlib.adler32(m.with_checksum(0))
150+
if actual_message_checksum != read_message_checksum
151+
fail "Invalid message checksum (expected #{read_message_checksum}, calculated #{actual_message_checksum})"
152+
end
153+
# I'm not sure this can ever happen -- if the payload checksum is wrong, then the
154+
# message checksum will also be wrong. So, either I misunderstand the protocol
155+
# or having two checksums is useless
156+
actual_payload_checksum = Zlib.adler32(payload)
157+
if actual_payload_checksum != read_payload_checksum
158+
fail "Invalid payload checksum (expected #{read_payload_checksum}, calculated #{actual_payload_checksum})"
159+
end
160+
end
161+
m
162+
end
163+
164+
def with_checksum(message_checksum)
165+
[
166+
'acpp',
167+
@unknown1,
168+
message_checksum,
169+
Zlib.adler32(@payload),
170+
@payload.size,
171+
@unknown2,
172+
@type,
173+
@status,
174+
@unknown3,
175+
Rex::Encoding::Xor::Generic.encode([@password].pack('a32').slice(0, 32), XOR_KEY).first,
176+
@unknown4,
177+
payload
178+
].pack('a4NNNNa8NNa12a32a48a*')
179+
end
180+
end
181+
end
182+
end
183+
end

0 commit comments

Comments
 (0)