CRITICAL: Fixed malformed packet error which is caused by not correctly parsing TXT record length in construct() and unwrap() of DNS module.

This commit is contained in:
abbie 2022-04-13 11:32:55 +01:00
parent 51c5444917
commit 922c1f1fb3
No known key found for this signature in database
GPG key ID: 04DDE463F9200F87
2 changed files with 12 additions and 2 deletions

View file

@ -1,7 +1,7 @@
[package]
name = "packeteer"
description = "An attempt at a Rust library that can be used to assist in programmatically analysing, serving and handling received protocol packets."
version = "0.4.1"
version = "0.4.2"
edition = "2021"
authors = ["Celeste <colean@colean.cc>"]
license = "MPL-2.0"

View file

@ -163,6 +163,9 @@ pub fn construct(packet: Vec<u8>) -> DnsPacket {
i = i + 1;
v = v - 1;
}
if zrtype == RecordType::TXT {
data.remove(0 as usize);
}
let ans = DnsAnswer { name: 0xc00c, rtype: zrtype, class: class, ttl: ttl, data: data };
answerz.push(ans);
}
@ -217,9 +220,16 @@ pub fn unpack_answer(answer: DnsAnswer) -> Vec<u8> {
raw.push((low_ttl >> 8) as u8);
raw.push((low_ttl & 0xff) as u8);
let datums = answer.data;
let len = datums.len() as u16;
let mut len = datums.len() as u16;
if rtype == 16 {
len = len + 1;
}
raw.push((len >> 8) as u8);
raw.push((len & 0xff) as u8);
if rtype == 16 {
len = len - 1;
raw.push((len & 0xff) as u8);
}
for byte in datums {
raw.push(byte);
}