本文整理汇总了Python中scapy.all.DNS属性的典型用法代码示例。如果您正苦于以下问题:Python all.DNS属性的具体用法?Python all.DNS怎么用?Python all.DNS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类scapy.all
的用法示例。
在下文中一共展示了all.DNS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pkt_callback
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import DNS [as 别名]
def pkt_callback(self, pkt):
"""
Proccess DNS packets
"""
if self.ccname in pkt[DNS].qd.qname:
if pkt[DNS].qd.qname == '666.' + self.ccname + '.':
print(time.strftime("%Y-%m-%d %H:%M:%S ", time.gmtime())
+ 'DNS/PDNS:' + pkt[IP].src + ':ALARM Case Open!')
else:
text = decrypt(pkt[DNS].qd.qname.split('.')[0])
text = text.strip()
hexip = text.split(',')[-1]
text = text.replace(hexip, hextoip(hexip))
if pkt[DNS].qd.qtype == 2:
text = 'DNS:' + pkt[IP].src + ':' + text
else:
text = 'PDNS:' + pkt[IP].src + ':' + text
printer(self.filed, text)
示例2: __init__
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import DNS [as 别名]
def __init__(self, network_interface: str = 'eth0', quiet: bool = False) -> None:
"""
Init class DnsResolver
:param network_interface: Network interface (example: eth0)
:param quiet: Quiet mode on if True, quiet mode off if False (default: False)
"""
# Set network interface for sending DNS queries
self.network_interface: str = network_interface
# Set quiet mode
self.quiet: bool = quiet
# Get MAC, IPv4 and IPv6 addresses for network interface
self.your_mac_address: str = self.base.get_interface_mac_address(self.network_interface)
self.your_ipv4_address: str = self.base.get_interface_ip_address(self.network_interface)
self.your_ipv4_network: str = self.base.get_interface_network(self.network_interface)
self.your_ipv6_address: str = self.base.get_interface_ipv6_link_address(self.network_interface, False)
# endregion
# region Write resolve results to file
示例3: _save_result
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import DNS [as 别名]
def _save_result(self, result: Dict[str, str]) -> None:
try:
self.results.append(result)
if 'NS' in result.keys():
self.base.print_success('Domain: ', result['Domain'], ' NS: ', result['NS'])
else:
with open(RawDnsResolver.temporary_results_filename, 'a') as temporary_file:
temporary_file.write('Domain: ' + result['Domain'] +
' IPv4 address: ' + result['IPv4 address'] +
' IPv6 address: ' + result['IPv6 address'] + '\n')
if result['IPv6 address'] == '-':
print(self.base.cSUCCESS + '[' + str(len(self.uniq_hosts)) + '] ' + self.base.cEND +
result['Domain'] + ' - ' + result['IPv4 address'])
else:
print(self.base.cSUCCESS + '[' + str(len(self.uniq_hosts)) + '] ' + self.base.cEND +
result['Domain'] + ' - ' + result['IPv6 address'])
except AttributeError:
pass
except KeyError:
pass
# endregion
# region Parse DNS packet function
示例4: _parse_dns_request
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import DNS [as 别名]
def _parse_dns_request(self, dns_layer) -> dict:
from scapy.layers.dns import DNS, DNSRR
dns_layer = cast(DNS, dns_layer)
# Each DNS request has the basic qname/qtype
dns_data = {
"qname": dns_layer.qd.qname.decode(),
# Get 'A/MX/NS' as string rather than number.
"qtype": dns_layer.qd.get_field("qtype").i2repr(dns_layer.qd, dns_layer.qd.qtype),
}
if dns_layer.ancount > 0 and isinstance(dns_layer.an, DNSRR):
resp = dns_layer.an.rdata
if isinstance(resp, bytes):
resp = resp.decode()
dns_data["qanswer"] = resp
return dns_data
示例5: test_single_dns_resp_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import DNS [as 别名]
def test_single_dns_resp_packet():
packets = [
Ether(src="ab:ab:ab:ab:ab:ab", dst="12:12:12:12:12:12")
/ IP(src="127.0.0.1", dst="192.168.1.1")
/ UDP(sport=80, dport=53)
/ DNS(rd=1, qd=DNSQR(qtype="A", qname="google.com"), an=DNSRR(rdata="123.0.0.1"))
]
events = list(packets_to_datasource_events(packets).events())
assert len(events) == 1
assert events[0]["src_mac"] == "ab:ab:ab:ab:ab:ab"
assert events[0]["dst_mac"] == "12:12:12:12:12:12"
assert events[0]["src_ip"] == "127.0.0.1"
assert events[0]["dst_ip"] == "192.168.1.1"
assert events[0]["sport"] == 80
assert events[0]["dport"] == 53
assert events[0]["qname"] == "google.com."
assert events[0]["qanswer"] == "123.0.0.1"
assert events[0]["qtype"] == "A"
assert events[0]["event_type"] == "DNS"
示例6: test_single_dns_query_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import DNS [as 别名]
def test_single_dns_query_packet():
packets = [
Ether(src="ab:ab:ab:ab:ab:ab", dst="12:12:12:12:12:12")
/ IP(src="127.0.0.1", dst="192.168.1.1")
/ UDP(sport=80, dport=53)
/ DNS(rd=1, qd=DNSQR(qtype="A", qname="google.com"))
]
events = list(packets_to_datasource_events(packets).events())
assert len(events) == 1
assert events[0]["src_mac"] == "ab:ab:ab:ab:ab:ab"
assert events[0]["dst_mac"] == "12:12:12:12:12:12"
assert events[0]["src_ip"] == "127.0.0.1"
assert events[0]["dst_ip"] == "192.168.1.1"
assert events[0]["sport"] == 80
assert events[0]["dport"] == 53
assert events[0]["qname"] == "google.com."
assert events[0]["qtype"] == "A"
assert events[0]["event_type"] == "DNS"
示例7: test_multiple_packets
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import DNS [as 别名]
def test_multiple_packets():
packets = [
# HTTP Packet
Ether(src="ab:ab:ab:ab:ab:ab", dst="12:12:12:12:12:12")
/ IP(src="127.0.0.1", dst="192.168.1.1")
/ TCP(sport=12345, dport=80)
/ HTTP()
/ HTTPRequest(Method="GET", Path="/foo", Host="https://google.com"),
# DNS Packet
Ether(src="ab:ab:ab:ab:ab:ab", dst="12:12:12:12:12:12")
/ IP(src="127.0.0.1", dst="192.168.1.1")
/ UDP(sport=80, dport=53)
/ DNS(rd=1, qd=DNSQR(qtype="A", qname="google.com"), an=DNSRR(rdata="123.0.0.1")),
# TCP Packet
Ether(src="ab:ab:ab:ab:ab:ab", dst="12:12:12:12:12:12")
/ IP(src="127.0.0.1", dst="192.168.1.1")
/ TCP(sport=80, dport=5355),
]
events = list(packets_to_datasource_events(packets).events())
assert len(events) == 3
assert [e["event_type"] for e in events] == ["HTTPRequest", "DNS", "TCP"]
示例8: spoof_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import DNS [as 别名]
def spoof_packet(packet):
options = get_arguments()
dns_packet = scapy.IP(packet.get_payload())
if dns_packet.haslayer(scapy.DNSRR):
qname = dns_packet[scapy.DNSQR].qname
if options.website in qname:
dns_responce = scapy.DNSRR(rrname=qname, rdata=options.ip)
dns_packet[scapy.DNS].an = dns_responce
dns_packet[scapy.DNS].ancount = 1
del dns_packet[scapy.IP].len
del dns_packet[scapy.IP].chksum
del dns_packet[scapy.UDP].len
del dns_packet[scapy.UDP].chksum
packet.set_payload(str(dns_packet))
packet.accept()
示例9: proto_mapping_request
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import DNS [as 别名]
def proto_mapping_request(protocol):
"""Provide mapping of enum values to implementation classes."""
return {
Protocol.ALL: IP,
Protocol.UDP: UDP,
Protocol.TCP: TCP,
Protocol.CoAP: CoAP,
Protocol.mDNS: DNS,
Protocol.MQTT: MQTT,
Protocol.DTLS: DTLS,
Protocol.QUIC: UDP,
Protocol.RTSP: HTTPRequest,
Protocol.SSDP: HTTPRequest,
Protocol.HTCPCP: HTTPRequest,
Protocol.HTTP: HTTPRequest,
}[protocol]
示例10: mdns_send_query
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import DNS [as 别名]
def mdns_send_query(test_params, query, send_multicast=True):
"""Send mDNS query to normal and multicast address."""
dns_sd_query = str(DNS(rd=1, qd=DNSQR(qname=query, qtype="PTR")))
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
time.sleep(1)
udp_sr1(test_params, dns_sd_query)
if send_multicast:
multicast_test_params = copy.deepcopy(test_params)
if test_params.ip_version == 4:
multicast_test_params.dst_endpoint.ip_addr = DNS_SD_MULTICAST_IPV4
sock.sendto(
str(dns_sd_query),
(DNS_SD_MULTICAST_IPV4, multicast_test_params.dst_endpoint.port),
)
elif test_params.ip_version == 6:
multicast_test_params.dst_endpoint.ip_addr = DNS_SD_MULTICAST_IPV6
sock.sendto(
str(dns_sd_query),
(DNS_SD_MULTICAST_IPV6, multicast_test_params.dst_endpoint.port),
)
else:
return
示例11: run
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import DNS [as 别名]
def run(iface, local_ip, sniff_filter, spoof_domains):
print("#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#")
print("-#-#-#-#-#-RUNNING DNS SPOOFER-#-#-#-#-#-")
print("#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#")
print("Interface:\t\t\t%s" % iface)
print("Resolving to IP:\t\t%s" % local_ip)
print("Spoof domains:\t\t%s" % ', '.join(spoof_domains))
print("BPF sniff filter:\t\t%s" % sniff_filter)
print("")
print("Waiting for DNS requests...")
print("(Make sure the device you are targeting is set to use"\
"your local IP (%s) as its DNS server)" % local_ip)
scapy.sniff(iface=iface,
filter=sniff_filter,
prn=handle_packet_fn(iface, local_ip, spoof_domains))
示例12: parsepacket
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import DNS [as 别名]
def parsepacket(p):
if DHCP6_Solicit in p:
target = get_target(p)
if should_spoof_dhcpv6(target.host):
send_dhcp_advertise(p[DHCP6_Solicit], p, target)
if DHCP6_Request in p:
target = get_target(p)
if p[DHCP6OptServerId].duid == config.selfduid and should_spoof_dhcpv6(target.host):
send_dhcp_reply(p[DHCP6_Request], p)
print('IPv6 address %s is now assigned to %s' % (p[DHCP6OptIA_NA].ianaopts[0].addr, pcdict[p.src]))
if DHCP6_Renew in p:
target = get_target(p)
if p[DHCP6OptServerId].duid == config.selfduid and should_spoof_dhcpv6(target.host):
send_dhcp_reply(p[DHCP6_Renew],p)
print('Renew reply sent to %s' % p[DHCP6OptIA_NA].ianaopts[0].addr)
if ARP in p:
arpp = p[ARP]
if arpp.op is 2:
#Arp is-at package, update internal arp table
arptable[arpp.hwsrc] = arpp.psrc
if DNS in p:
if p.dst == config.selfmac:
send_dns_reply(p)
示例13: get_kube_dns_ip_mac
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import DNS [as 别名]
def get_kube_dns_ip_mac(self):
config = get_config()
kubedns_svc_ip = self.extract_nameserver_ip()
# getting actual pod ip of kube-dns service, by comparing the src mac of a dns response and arp scanning.
dns_info_res = srp1(
Ether() / IP(dst=kubedns_svc_ip) / UDP(dport=53) / DNS(rd=1, qd=DNSQR()),
verbose=0,
timeout=config.network_timeout,
)
kubedns_pod_mac = dns_info_res.src
self_ip = dns_info_res[IP].dst
arp_responses, _ = srp(
Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(op=1, pdst=f"{self_ip}/24"), timeout=config.network_timeout, verbose=0,
)
for _, response in arp_responses:
if response[Ether].src == kubedns_pod_mac:
return response[ARP].psrc, response.src
示例14: scapy_send_dns_requests
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import DNS [as 别名]
def scapy_send_dns_requests(number_of_packets):
for _ in range(number_of_packets):
dns_request = Ether(src=ethernet_src, dst=ethernet_dst) /\
IP(src=ip_src, dst=ip_dst) /\
UDP(dport=53, sport=randint(1024, 65535)) /\
DNS(id=randint(1, 1000), rd=1, qd=DNSQR(qname="www." + str(randint(1, 1000)) + ".com"))
sendp(dns_request, verbose=False)
# endregion
# region Main function
示例15: dnshandle
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import DNS [as 别名]
def dnshandle(pkt):
if dns_sniff_gource:
sys.stdout = open(random_filename+'parsed_nmap', 'a')
FQDN = pkt.getlayer(scapy.DNS).qd.qname
domain = FQDN.split('.')
print str(time.time())[:-3] + "|" + target + "|A|" + str(domain[1]) + '/' + str(FQDN)
else:
if pkt.haslayer(scapy.DNS):
print(bcolours.OKBLUE + pkt.getlayer(scapy.IP).src + '\t' + pkt.getlayer(scapy.IP).dst + '\t' + bcolours.WARNING + pkt.getlayer(scapy.DNS).qd.qname + bcolours.ENDC)