scapy.layers.dns

DNS:域名系统.

class scapy.layers.dns.DNS

Bases: scapy.packet.Packet

aliastypes
answers(other)
compress()

返回压缩的DNS数据包(使用dns_compress()

fields_desc
DNS字段

length

ShortField (Cond)

None

id

ShortField

0

qr

BitField (1位)

0

opcode

BitEnumField (4位)

0

aa

BitField (1位)

0

tc

BitField (1位)

0

rd

BitField (1位)

1

ra

BitField (1位)

0

z

BitField (1 bit)

0

ad

BitField (1位)

0

cd

BitField (1位)

0

rcode

BitEnumField (4位)

0

qdcount

DNSRRCountField

None

ancount

DNSRRCountField

None

nscount

DNSRRCountField

None

arcount

DNSRRCountField

None

qd

DNSQRField

None

an

DNSRRField

None

ns

DNSRRField

None

ar

DNSRRField

None

mysummary()
post_build(pkt, pay)
pre_dissect(s)

检查是否可以解码有效的TCP over DNS消息

class scapy.layers.dns.DNSQR(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns.InheritOriginDNSStrPacket

aliastypes
fields_desc
DNSQR字段

qname

DNSStrField

b'www.example.com'

qtype

ShortEnumField

1

qclass

ShortEnumField

1

show_indent = 0
class scapy.layers.dns.DNSQRField(name, countfld, passon=1)

Bases: scapy.layers.dns.DNSRRField

decodeRR(name, s, p)
class scapy.layers.dns.DNSRR(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns.InheritOriginDNSStrPacket

aliastypes
fields_desc
DNSRR字段

rrname

DNSStrField

b'.'

type

ShortEnumField

1

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

FieldLenField

None

rdata

MultipleTypeField

b''

show_indent = 0
class scapy.layers.dns.DNSRRCountField(name, default, rr)

Bases: scapy.fields.ShortField

i2h(pkt, x)
i2m(pkt, x)
rr
class scapy.layers.dns.DNSRRDLV(*args, **kargs)

Bases: scapy.layers.dns.DNSRRDS

aliastypes
fields_desc
DNSRRDLV字段

rrname

DNSStrField

b'.'

type

ShortEnumField

43

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

keytag

ShortField

0

algorithm

ByteEnumField

5

digesttype

ByteEnumField

5

digest

StrField

b''

class scapy.layers.dns.DNSRRDNSKEY(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRDNSKEY字段

rrname

DNSStrField

b'.'

type

ShortEnumField

48

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

flags

FlagsField (16位)

<Flag 256 (Z)>

protocol

ByteField

3

algorithm

ByteEnumField

5

publickey

StrField

b''

class scapy.layers.dns.DNSRRDS(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRDS字段

rrname

DNSStrField

b'.'

type

ShortEnumField

43

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

keytag

ShortField

0

algorithm

ByteEnumField

5

digesttype

ByteEnumField

5

digest

StrField

b''

class scapy.layers.dns.DNSRRField(name, countfld, passon=1)

Bases: scapy.fields.StrField

countfld
decodeRR(name, s, p)
getfield(pkt, s)
holds_packets = 1
i2m(pkt, x)
passon
class scapy.layers.dns.DNSRRMX(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRMX字段

rrname

DNSStrField

b'.'

type

ShortEnumField

6

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

preference

ShortField

0

exchange

DNSStrField

b'.'

class scapy.layers.dns.DNSRRNSEC(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRNSEC字段

rrname

DNSStrField

b'.'

type

ShortEnumField

47

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

nextname

DNSStrField

b'.'

typebitmaps

RRlistField

b''

class scapy.layers.dns.DNSRRNSEC3(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRNSEC3字段

rrname

DNSStrField

b'.'

type

ShortEnumField

50

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

hashalg

ByteField

0

flags

BitEnumField (8位)

0

iterations

ShortField

0

saltlength

FieldLenField

0

salt

StrLenField

b''

hashlength

FieldLenField

0

nexthashedownername

StrLenField

b''

typebitmaps

RRlistField

b''

class scapy.layers.dns.DNSRRNSEC3PARAM(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRNSEC3PARAM字段

rrname

DNSStrField

b'.'

type

ShortEnumField

51

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

hashalg

ByteField

0

flags

ByteField

0

iterations

ShortField

0

saltlength

FieldLenField

0

salt

StrLenField

b''

class scapy.layers.dns.DNSRROPT(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns.InheritOriginDNSStrPacket

aliastypes
fields_desc
DNSRROPT字段

rrname

DNSStrField

b'.'

type

ShortEnumField

41

rclass

ShortField

4096

extrcode

ByteField

0

version

ByteField

0

z

BitEnumField (16位)

32768

rdlen

FieldLenField

None

rdata

PacketListField

[]

class scapy.layers.dns.DNSRRRSIG(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRRSIG字段

rrname

DNSStrField

b'.'

type

ShortEnumField

46

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

typecovered

ShortEnumField

1

algorithm

ByteEnumField

5

labels

ByteField

0

originalttl

IntField

0

expiration

UTCTimeField

0

inception

UTCTimeField

0

keytag

ShortField

0

signersname

DNSStrField

b'.'

signature

StrField

b''

class scapy.layers.dns.DNSRRSOA(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRSOA字段

rrname

DNSStrField

b'.'

type

ShortEnumField

6

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

mname

DNSStrField

b'.'

rname

DNSStrField

b'.'

serial

IntField

0

refresh

IntField

0

retry

IntField

0

expire

IntField

0

minimum

IntField

0

class scapy.layers.dns.DNSRRSRV(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRSRV字段

rrname

DNSStrField

b'.'

type

ShortEnumField

33

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

priority

ShortField

0

weight

ShortField

0

port

ShortField

0

target

DNSStrField

b'.'

class scapy.layers.dns.DNSRRTSIG(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.layers.dns._DNSRRdummy

aliastypes
fields_desc
DNSRRTSIG字段

rrname

DNSStrField

b'.'

type

ShortEnumField

250

rclass

ShortEnumField

1

ttl

IntField

0

rdlen

ShortField

None

algo_name

DNSStrField

b'hmac-sha1'

time_signed

TimeSignedField

b'\x00\x00\x00\x00\x00\x00'

fudge

ShortField

0

mac_len

FieldLenField

20

mac_data

StrLenField

b''

original_id

ShortField

0

error

ShortField

0

other_len

FieldLenField

0

other_data

StrLenField

b''

class scapy.layers.dns.DNSStrField(name, default, fld=None, length_from=None, max_length=None)

Bases: scapy.fields.StrLenField

处理DNS编码/解码的特殊StrField. 它还将处理DNS解压缩. (如果传递了length_from,则可能是StrLenField),

getfield(pkt, s)
h2i(pkt, x)
i2len(pkt, x)
i2m(pkt, x)
class scapy.layers.dns.DNSTextField(name, default, fld=None, length_from=None, max_length=None)

Bases: scapy.fields.StrLenField

特殊的StrLenField处理DNS TEXT数据(16)

any2i(pkt, x)
i2len(pkt, x)
i2m(pkt, s)
islist = 1
m2i(pkt, s)
class scapy.layers.dns.DNS_am(**kargs)

Bases: scapy.ansmachine.AnsweringMachine

filter = 'udp port 53'
function_name = 'dns_spoof'
is_request(req)
make_reply(req)
parse_options(joker='192.168.1.1', match=None)
scapy.layers.dns.DNSgetstr(*args, **kwargs)

旧版功能. 不推荐使用

class scapy.layers.dns.EDNS0TLV

Bases: scapy.packet.Packet

aliastypes
extract_padding(p)
fields_desc
EDNS0TLV字段

optcode

ShortEnumField

0

optlen

FieldLenField

None

optdata

StrLenField

b''

class scapy.layers.dns.InheritOriginDNSStrPacket(_pkt=None, _orig_s=None, _orig_p=None, *args, **kwargs)

Bases: scapy.packet.Packet

aliastypes
default_fields
direction
explicit
fields
fieldtype
name
original
overload_fields
overloaded_fields
packetfields
payload
post_transforms
raw_packet_cache
raw_packet_cache_fields
sent_time
sniffed_on
time
underlayer
wirelen
scapy.layers.dns.RRlist2bitmap(lst)

将代表资源记录的整数列表编码为NSEC资源记录中使用的位图字段.

class scapy.layers.dns.RRlistField(name, default, fmt='H', remain=0)

Bases: scapy.fields.StrField

h2i(pkt, x)
i2repr(pkt, x)
class scapy.layers.dns.TimeSignedField(name, default)

Bases: scapy.fields.StrFixedLenField

h2i(pkt, seconds)

将自70年1月1日UTC以来的秒数转换为打包的表示形式.

i2h(pkt, packed_seconds)

将内部表示形式转换为自70年1月1日UTC以来的秒数.

i2repr(pkt, packed_seconds)

使用RFC格式将内部表示转换为漂亮的表示.

scapy.layers.dns.bitmap2RRlist(bitmap)

将NSEC资源记录的"类型位图"字段解码为整数列表.

scapy.layers.dns.dns_compress(pkt)

此功能根据压缩规则压缩DNS数据包.

scapy.layers.dns.dns_encode(x, check_built=False)

将字节字符串编码为DNS格式

Parameters
  • x –字符串

  • check_built –检测已构建的字符串并忽略它们

Returns

编码的字节字符串

scapy.layers.dns.dns_get_str(s, pointer=0, pkt=None, _fullpacket=False)

此函数从给定的指针开始解压缩字符串s.

Parameters
  • s –要解压缩的字符串

  • 指针 –字符串的第一个指针(默认值:0)

  • pkt –(可选)InheritOriginDNSStrPacket数据包

Returns

(解码字符串,结尾索引,左字符串)

scapy.layers.dns.dyndns_add(nameserver, name, rdata, type='A', ttl=10)

将DNS添加消息发送到名称服务器以获取"名称",以拥有新的" rdata" dyndns_add(名称服务器,名称,rdata,类型=" A",ttl = 10)->结果代码(0 =确定)

例如:dyndns_add(" ns1.toto.com"," dyn.toto.com"," 127.0.0.1")RFC2136

scapy.layers.dns.dyndns_del(nameserver, name, type='ALL', ttl=10)

将DNS删除消息发送到名称服务器,用于"名称" dyndns_del(名称服务器,名称,类型=" ANY",ttl = 10)->结果代码(0 = ok)

例如:dyndns_del(" ns1.toto.com"," dyn.toto.com")RFC2136

scapy.layers.dns.isdnssecRR(obj)