message
import "github.com/TheManticoreProject/Manticore/network/llmnr/message"
Index
- type Message
- func CreateResponseFromMessage(msg *Message) *Message
- func NewMessage() *Message
- func (m *Message) AddAnswer(rr resourcerecord.ResourceRecord) error
- func (m *Message) AddAnswerClassINTypeA(name, ip string) error
- func (m *Message) AddAnswerClassINTypeAAAA(name, ip string) error
- func (m *Message) AddQuestion(name string, qtype llmnr_type.Type, qclass class.Class) error
- func (m *Message) Describe(indent int)
- func (m *Message) IsQuery() bool
- func (m *Message) IsResponse() bool
- func (m *Message) Marshal() ([]byte, error)
- func (m *Message) SetQuery()
- func (m *Message) SetResponse()
- func (m *Message) Unmarshal(data []byte) (int, error)
- func (m *Message) Validate() error
type Message
Message represents an LLMNR message.
An LLMNR (Link-Local Multicast Name Resolution) message consists of a header and four sections: Questions, Answers, Authority, and Additional. The header contains metadata about the message, such as the transaction ID and various flags. The Questions section contains the questions being asked in the message, while the Answers, Authority, and Additional sections contain resource records that provide answers, authority information, and additional information, respectively.
Fields: - Header: The header of the LLMNR message, containing metadata such as the transaction ID and flags. - Questions: A slice of Question structs representing the questions in the message. - Answers: A slice of ResourceRecord structs representing the answers in the message. - Authority: A slice of ResourceRecord structs representing the authority records in the message. - Additional: A slice of ResourceRecord structs representing the additional records in the message.
type Message struct {
// The header of the LLMNR message, containing metadata such as the transaction ID and flags.
Header header.Header
// A slice of Question structs representing the questions in the message.
Questions []question.Question `json:"questions"`
// A slice of ResourceRecord structs representing the answers in the message.
Answers []resourcerecord.ResourceRecord `json:"answers"`
// A slice of ResourceRecord structs representing the authority records in the message.
Authority []resourcerecord.ResourceRecord `json:"authority"`
// A slice of ResourceRecord structs representing the additional records in the message.
Additional []resourcerecord.ResourceRecord `json:"additional"`
}
func CreateResponseFromMessage
func CreateResponseFromMessage(msg *Message) *Message
CreateResponseFromMessage creates a new LLMNR message that is a response to the given message.
Parameters: - msg: The message to create a response for.
Returns: - A pointer to the newly created Message instance.
func NewMessage
func NewMessage() *Message
NewMessage creates a new LLMNR message with a randomly generated transaction ID and initializes the Questions, Answers, Authority, and Additional sections as empty slices. The Header of the message is also initialized with the generated transaction ID.
Returns: - A pointer to the newly created Message instance.
func (*Message) AddAnswer
func (m *Message) AddAnswer(rr resourcerecord.ResourceRecord) error
AddAnswer adds a resource record to the Answers section of the LLMNR message and updates the answer count in the header. It validates the domain name of the resource record before adding it.
Parameters: - rr: The resource record to be added to the Answers section.
Returns: - An error if the domain name of the resource record is invalid. - nil if the resource record is successfully added.
func (*Message) AddAnswerClassINTypeA
func (m *Message) AddAnswerClassINTypeA(name, ip string) error
AddAnswerClassINTypeA adds a resource record with Class IN and Type A to the Answers section of the LLMNR message and updates the answer count in the header. It validates the domain name of the resource record before adding it.
Parameters: - name: The domain name for the resource record. - rdata: The resource data for the Type A record (e.g., an IPv4 address).
Returns: - An error if the domain name of the resource record is invalid. - nil if the resource record is successfully added.
func (*Message) AddAnswerClassINTypeAAAA
func (m *Message) AddAnswerClassINTypeAAAA(name, ip string) error
AddAnswerClassINTypeAAAA adds a resource record with Class IN and Type AAAA to the Answers section of the LLMNR message and updates the answer count in the header. It validates the domain name of the resource record before adding it.
Parameters: - name: The domain name for the resource record. - rdata: The resource data for the Type AAAA record (e.g., an IPv6 address).
Returns: - An error if the domain name of the resource record is invalid. - nil if the resource record is successfully added.
func (*Message) AddQuestion
func (m *Message) AddQuestion(name string, qtype llmnr_type.Type, qclass class.Class) error
AddQuestion adds a question to the Questions section of the LLMNR message and updates the question count in the header. It validates the domain name of the question before adding it.
Parameters: - name: The domain name for the question. - qtype: The type of the question (e.g., TypeA, TypeAAAA). - qclass: The class of the question (e.g., ClassIN).
Returns: - An error if the domain name is invalid. - nil if the question is successfully added.
func (*Message) Describe
func (m *Message) Describe(indent int)
Describe prints a detailed description of the Message structure.
Parameters: - indent: An integer value specifying the indentation level for the output.
func (*Message) IsQuery
func (m *Message) IsQuery() bool
IsQuery returns true if the message is a query.
This function checks the QR (Query/Response) flag in the message’s Flags field. If the QR flag is not set, the message is considered a query and the function returns true. If the QR flag is set, the message is considered a response and the function returns false.
Returns:
- A boolean value indicating whether the message is a query (true) or not (false).
func (*Message) IsResponse
func (m *Message) IsResponse() bool
IsResponse returns true if the message is a response.
This function checks the QR (Query/Response) flag in the message’s Flags field. If the QR flag is set, the message is considered a response and the function returns true. If the QR flag is not set, the message is considered a query and the function returns false.
Returns:
- A boolean value indicating whether the message is a response (true) or not (false).
func (*Message) Marshal
func (m *Message) Marshal() ([]byte, error)
Marshal serializes the Message struct into a byte slice according to the LLMNR wire format. It encodes the header, questions, and answers sections of the message.
Returns: - A byte slice containing the encoded message. - An error if encoding fails at any point, such as if there is an error encoding the questions or answers.
func (*Message) SetQuery
func (m *Message) SetQuery()
SetQuery marks the message as a query.
This function clears the QR (Query/Response) flag in the message’s Flags field. By clearing the QR flag, the message is considered a query.
Usage:
msg.SetQuery()
After calling this function, the message will be marked as a query.
Returns:
- Nothing. This function modifies the message in place.
func (*Message) SetResponse
func (m *Message) SetResponse()
SetResponse marks the message as a response.
This function sets the QR (Query/Response) flag in the message’s Flags field. By setting the QR flag, the message is considered a response.
Usage:
msg.SetResponse()
After calling this function, the message will be marked as a response.
Returns:
- Nothing. This function modifies the message in place.
func (*Message) Unmarshal
func (m *Message) Unmarshal(data []byte) (int, error)
Unmarshal decodes a byte slice into the Message receiver. It expects the byte slice to be in the wire format as specified by the LLMNR protocol. The function first checks if the provided data is at least as long as the LLMNR header. It then proceeds to decode the header fields, followed by the question and answer sections.
Parameters: - data: A byte slice containing the LLMNR message in wire format.
Returns:
- The number of bytes read from data.
- An error if the decoding fails at any point, such as if the data is too short or if there is an error decoding the question or answer sections.
func (*Message) Validate
func (m *Message) Validate() error
Validate checks the integrity of the LLMNR message by ensuring that the counts in the header match the actual number of questions, answers, authority, and additional records. It also validates the domain names in the questions and answers sections.
Returns: - An error if any of the counts do not match or if any domain name is invalid. - nil if the message is valid.