本文整理汇总了Python中scapy.all.UDP属性的典型用法代码示例。如果您正苦于以下问题:Python all.UDP属性的具体用法?Python all.UDP怎么用?Python all.UDP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类scapy.all
的用法示例。
在下文中一共展示了all.UDP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_single_udp_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import UDP [as 别名]
def test_single_udp_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=5355)
]
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"] == 5355
assert events[0]["event_type"] == "UDP"
示例2: test_single_dns_resp_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import UDP [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"
示例3: test_single_dns_query_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import UDP [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"
示例4: test_multiple_packets
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import UDP [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"]
示例5: __init__
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import UDP [as 别名]
def __init__(self, client_ip = "", server_ip = "", client_port = 0, server_port = 0, protocol = "TCP", interface = ""):
self.client_ip = client_ip
self.server_ip = server_ip
self.client_port = client_port
self.server_port = server_port
self.protocol = protocol.lower()
self.interface = interface
# This returns just the source address & port in a string format
# so that it can be hashed and tied back to the connectionManager.
# The protocol, source address, and port are the only shared pieces of information
# that both the MiTMModule socket and nfqueue intercept have access to, so
# nfqueue hashes this info together and uses that hash as the key in the
# connectionMnaager. Once the MiTMModule recieves the intercepted connection,
# it will hash the proto/source ip/port to pull back the whole Connection
# object from the connectionManager - and thus - have the destination ip and port
# to then behave like a fully transparent TCP/UDP MiTM server.
示例6: spoof_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import UDP [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()
示例7: build_dhcp
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import UDP [as 别名]
def build_dhcp(pdiscover):
req_addr = None
server_id = None
vendor_class = None
try:
for m in pdiscover[DHCP].options:
n, v = m
if n == "requested_addr":
req_addr = v
elif n == "server_id":
server_id = v
elif n == "vendor_class_id":
vendor_class = v
except:
pass
print "[i] --> received vendor_class = %s" % vendor_class
e_dst = pdiscover[Ether].src
p = Ether(dst=e_dst) / IP(src=server_id, dst=req_addr or "0.0.0.0") / UDP(sport=67, dport=68, len=9000)
p[UDP].chksum = get_udp_checksum(p)
return p
示例8: test_reflector_sniffer_pos
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import UDP [as 别名]
def test_reflector_sniffer_pos(self):
args = ["8.8.8.8", "-I", "0"]
options = amplifier_parse_args(args)
sniffer = ReflectorSniffer(options)
packet = IP() / UDP()
result = sniffer.filter_action(packet)
self.assertMultiLineEqual(
result,
"TARGET: 8.8.8.8 | TO TARGET packets: 0, bytes: 0 | FROM "
"TARGET packets: 0, bytes: 0 | AMPLIF FACTOR: 0.00%",
)
packet = IP(src="1.1.1.1", dst="8.8.8.8") / UDP(dport=1000, sport=2000)
result = sniffer.filter_action(packet)
self.assertIn("-100.00%", result)
self.assertIn(" 28 ", result)
packet = IP(src="8.8.8.8", dst="1.1.1.1") / UDP(dport=1000, sport=2000)
result = sniffer.filter_action(packet)
self.assertIn(" 28 ", result)
self.assertIn(" 0.00%", result)
示例9: sr1_file
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import UDP [as 别名]
def sr1_file(test_params, test_filename, display_packet=False):
"""Read test message from given file, sends this message to server and parses response."""
with open(test_filename, "rb") as file_handle:
test_packet = file_handle.read()
if display_packet:
# print("Protocol: {}".format(proto_mapping(test_params.protocol)))
try:
if test_params.protocol in PROTOCOL_TESTERS:
out_packet = PROTOCOL_TESTERS[test_params.protocol].request_parser(
test_packet
)
out_packet.show()
print_verbose(test_params, 60 * "-")
except (TypeError, struct.error, RuntimeError, ValueError, Scapy_Exception):
pass
test_result = None
if test_params.protocol in [Protocol.SSDP]:
test_result = ssdp_send_query(test_params, test_packet)
elif test_params.protocol in protocols_using(UDP):
test_result = udp_sr1(test_params, test_packet)
elif test_params.protocol in protocols_using(TCP):
test_result = tcp_sr1(test_params, test_packet)
return test_result
示例10: proto_mapping_request
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import UDP [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]
示例11: send_dhcp_advertise
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import UDP [as 别名]
def send_dhcp_advertise(p, basep, target):
global ipv6noaddrc
resp = Ether(dst=basep.src)/IPv6(src=config.selfaddr, dst=basep[IPv6].src)/UDP(sport=547, dport=546) #base packet
resp /= DHCP6_Advertise(trid=p.trid)
#resp /= DHCP6OptPref(prefval = 255)
resp /= DHCP6OptClientId(duid=p[DHCP6OptClientId].duid)
resp /= DHCP6OptServerId(duid=config.selfduid)
resp /= DHCP6OptDNSServers(dnsservers=[config.selfaddr])
if config.localdomain:
resp /= DHCP6OptDNSDomains(dnsdomains=[config.localdomain])
if target.ipv4 != '':
addr = config.ipv6prefix + target.ipv4.replace('.', ':')
else:
addr = config.ipv6prefix + '%d:%d' % (config.ipv6noaddr, config.ipv6noaddrc)
config.ipv6noaddrc += 1
opt = DHCP6OptIAAddress(preflft=300, validlft=300, addr=addr)
resp /= DHCP6OptIA_NA(ianaopts=[opt], T1=200, T2=250, iaid=p[DHCP6OptIA_NA].iaid)
sendp(resp, iface=config.default_if, verbose=False)
示例12: send_dhcp_reply
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import UDP [as 别名]
def send_dhcp_reply(p, basep):
resp = Ether(dst=basep.src)/IPv6(src=config.selfaddr, dst=basep[IPv6].src)/UDP(sport=547, dport=546) #base packet
resp /= DHCP6_Reply(trid=p.trid)
#resp /= DHCP6OptPref(prefval = 255)
resp /= DHCP6OptClientId(duid=p[DHCP6OptClientId].duid)
resp /= DHCP6OptServerId(duid=config.selfduid)
resp /= DHCP6OptDNSServers(dnsservers=[config.selfaddr])
if config.localdomain:
resp /= DHCP6OptDNSDomains(dnsdomains=[config.localdomain])
try:
opt = p[DHCP6OptIAAddress]
resp /= DHCP6OptIA_NA(ianaopts=[opt], T1=200, T2=250, iaid=p[DHCP6OptIA_NA].iaid)
sendp(resp, iface=config.default_if, verbose=False)
except IndexError:
# Some hosts don't send back this layer for some reason, ignore those
if config.debug or config.verbose:
print('Ignoring DHCPv6 packet from %s: Missing DHCP6OptIAAddress layer' % basep.src)
示例13: get_kube_dns_ip_mac
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import UDP [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: find_imsi_from_pkt
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import UDP [as 别名]
def find_imsi_from_pkt(p):
udpdata = bytes(p[UDP].payload)
find_imsi(udpdata)
示例15: __init__
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import UDP [as 别名]
def __init__(self, dns_captured_cb):
self.name = "UDP traffic"
self.dns_captured_cb = dns_captured_cb