-
-
Save marchon/adaf973c0ced3a8098577aa0d7ba6fc5 to your computer and use it in GitHub Desktop.
playing around with a DNS packet definition for libpnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! DNS packet abstraction | |
use packet::Packet; | |
use pnet_macros::types::*; | |
/// Represents an UDP Packet | |
#[packet] | |
pub struct Dns { | |
id: u16be, | |
qr: u1, | |
op: u4, | |
aa: u1, | |
tc: u1, | |
rd: u1, | |
ra: u1, | |
z: u1, | |
ad: u1, | |
cd: u1, | |
rcode: u4, | |
qd_count: u16be, | |
an_count: u16be, | |
ns_count: u16be, | |
ar_count: u16be, | |
length: u32, | |
#[length = "length"] | |
len_datas: Vec<LenData>, | |
#[payload] | |
payload: Vec<u8> | |
} | |
/// Represents the query in a DNS packet | |
#[packet] | |
pub struct LenData { | |
length: u8, | |
#[length = "length"] | |
data: Vec<u8>, | |
#[payload] | |
payload: Vec<u8> | |
} | |
/* | |
payload here might be tricky. for future reference I am adding a simple DNS packet(as hex) and description of each part. | |
DNS portion of packet: | |
ca 76 01 00 00 01 00 00 00 00 00 00 04 74 65 73 74 03 63 6f 6d 00 01 00 01 | |
breakdown: | |
QID ca 76 | |
FLAGS 01 00 | |
breakdown of flags by bit: | |
0(QR) 0000(opcode) 0(AA) 0(TC) 1(RD) 0(RA) 0(Z) 0(AD) 0(CD) 0000(RCODE) | |
Questions 00 01 | |
Answer RRs 00 00 | |
Authority RRs 00 00 | |
Additional RRs 00 00 | |
this is the end of the header. now we have the query itself (for the A record of test.com) | |
04 74 65 73 74 read as 4 characters, 't', 'e', 's', 't' | |
03 63 6f 6d read as 3 characters, 'c', 'o', 'm' | |
00 end of qname | |
00 01 Type: A record | |
00 01 Class: IN (internet. this is most queries) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment