Class: Rex::Proto::ACPP::Message
- Inherits:
-
Object
- Object
- Rex::Proto::ACPP::Message
- Defined in:
- lib/rex/proto/acpp/message.rb
Instance Attribute Summary collapse
-
#password ⇒ String
The password to attempt to authenticate with.
-
#payload ⇒ String
The optional message payload.
-
#status ⇒ Integer
The status of this message.
-
#type ⇒ Integer
The type of this message.
Class Method Summary collapse
-
.decode(data, validate_checksum = true) ⇒ Message
Decodes the provided data into a Message.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares this Message and another Message for equality.
-
#initialize ⇒ Message
constructor
A new instance of Message.
-
#successful? ⇒ Boolean
Determines if this message has a successful status code.
-
#to_s ⇒ String
Get this Message as a String.
- #with_checksum(message_checksum) ⇒ Object
Constructor Details
#initialize ⇒ Message
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
#password ⇒ String
Returns the password to attempt to authenticate with.
78 79 80 |
# File 'lib/rex/proto/acpp/message.rb', line 78 def password @password end |
#payload ⇒ String
Returns the optional message payload.
80 81 82 |
# File 'lib/rex/proto/acpp/message.rb', line 80 def payload @payload end |
#status ⇒ Integer
Returns the status of this message.
82 83 84 |
# File 'lib/rex/proto/acpp/message.rb', line 82 def status @status end |
#type ⇒ Integer
Returns 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
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) = 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 = Zlib.adler32(m.with_checksum(0)) if != fail "Invalid message checksum (expected #{}, calculated #{})" 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
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
98 99 100 |
# File 'lib/rex/proto/acpp/message.rb', line 98 def successful? @status == 0 end |
#to_s ⇒ String
Get this Message as a String
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() [ 'acpp', @unknown1, , 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 |