Class: Rex::Proto::ACPP::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/proto/acpp/message.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMessage

Returns a new instance of Message.


84
85
86
87
88
89
90
91
92
93
# File 'lib/rex/proto/acpp/message.rb', line 84

def initialize
  @payload = ''
  @type = 0
  @status = 0
  @password = ''
  @unknown1 = 1
  @unknown2 = ''
  @unknown3 = ''
  @unknown4 = ''
end

Instance Attribute Details

#passwordString

Returns the password to attempt to authenticate with.

Returns:

  • (String)

    the password to attempt to authenticate with


78
79
80
# File 'lib/rex/proto/acpp/message.rb', line 78

def password
  @password
end

#payloadString

Returns the optional message payload.

Returns:

  • (String)

    the optional message payload


80
81
82
# File 'lib/rex/proto/acpp/message.rb', line 80

def payload
  @payload
end

#statusInteger

Returns the status of this message.

Returns:

  • (Integer)

    the status of this message


82
83
84
# File 'lib/rex/proto/acpp/message.rb', line 82

def status
  @status
end

#typeInteger

Returns the type of this message.

Returns:

  • (Integer)

    the type of this message


76
77
78
# File 'lib/rex/proto/acpp/message.rb', line 76

def type
  @type
end

Class Method Details

.decode(data, validate_checksum = true) ⇒ Message

Decodes the provided data into a Message

Parameters:

  • data (String)

    the data to parse as a Message

  • validate_checksum (Boolean) (defaults to: true)

    true to validate the message and payload checksums, false to not. Defaults to true.

Returns:

  • (Message)

    the decoded Message


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
# File 'lib/rex/proto/acpp/message.rb', line 126

def self.decode(data, validate_checksum = true)
  data = data.dup
  fail "Incorrect ACPP message size #{data.size} -- must be 128" unless data.size == 128
  fail 'Unexpected header' unless 'acpp' == data.slice!(0, 4)
  _unknown1 = data.slice!(0, 4)
  read_message_checksum = data.slice!(0, 4).unpack('N').first
  read_payload_checksum = data.slice!(0, 4).unpack('N').first
  _read_payload_size = data.slice!(0, 4).unpack('N').first
  _unknown2 = data.slice!(0, 8)
  type = data.slice!(0, 4).unpack('N').first
  status = data.slice!(0, 4).unpack('N').first
  _unknown3 = data.slice!(0, 12)
  password = Rex::Encoding::Xor::Generic.encode(data.slice!(0, 32), XOR_KEY).first.strip
  _unknown4 = data.slice!(0, 48)
  payload = data
  m = new
  m.type = type
  m.password = password
  m.status = status
  m.payload = payload

  # we can now validate the checksums if desired
  if validate_checksum
    actual_message_checksum = Zlib.adler32(m.with_checksum(0))
    if actual_message_checksum != read_message_checksum
      fail "Invalid message checksum (expected #{read_message_checksum}, calculated #{actual_message_checksum})"
    end
    # I'm not sure this can ever happen -- if the payload checksum is wrong, then the
    # message checksum will also be wrong.  So, either I misunderstand the protocol
    # or having two checksums is useless
    actual_payload_checksum = Zlib.adler32(payload)
    if actual_payload_checksum != read_payload_checksum
      fail "Invalid payload checksum (expected #{read_payload_checksum}, calculated #{actual_payload_checksum})"
    end
  end
  m
end

Instance Method Details

#==(other) ⇒ Boolean

Compares this Message and another Message for equality

Parameters:

  • other (Message)

    the Message to compare

Returns:

  • (Boolean)

    true iff the two messages are equal, false otherwise


113
114
115
116
117
118
# File 'lib/rex/proto/acpp/message.rb', line 113

def ==(other)
  other.type == @type &&
    other.status == @status &&
    other.password == @password &&
    other.payload == @payload
end

#successful?Boolean

Determines if this message has a successful status code

Returns:

  • (Boolean)

    true iff @status is 0, false otherwise


98
99
100
# File 'lib/rex/proto/acpp/message.rb', line 98

def successful?
  @status == 0
end

#to_sString

Get this Message as a String

Returns:

  • (String)

    the string representation of this Message


105
106
107
# File 'lib/rex/proto/acpp/message.rb', line 105

def to_s
  with_checksum(Zlib.adler32(with_checksum(0)))
end

#with_checksum(message_checksum) ⇒ Object


164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/rex/proto/acpp/message.rb', line 164

def with_checksum(message_checksum)
  [
    'acpp',
    @unknown1,
    message_checksum,
    Zlib.adler32(@payload),
    @payload.size,
    @unknown2,
    @type,
    @status,
    @unknown3,
    Rex::Encoding::Xor::Generic.encode([@password].pack('a32').slice(0, 32), XOR_KEY).first,
    @unknown4,
    payload
  ].pack('a4NNNNa8NNa12a32a48a*')
end