本文整理汇总了Python中scapy.all.Ether方法的典型用法代码示例。如果您正苦于以下问题:Python all.Ether方法的具体用法?Python all.Ether怎么用?Python all.Ether使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scapy.all
的用法示例。
在下文中一共展示了all.Ether方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: callback
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Ether [as 别名]
def callback(self, packet):
flags = packet.sprintf("%TCP.flags%")
proto = IP
if IPv6 in packet:
proto = IPv6
if flags == "A" and not self.ignore_packet(packet, proto):
src_mac = packet[Ether].src
dst_mac = packet[Ether].dst
src_ip = packet[proto].src
dst_ip = packet[proto].dst
src_port = packet[TCP].sport
dst_port = packet[TCP].dport
seq = packet[TCP].seq
ack = packet[TCP].ack
if self.verbose:
print("RST from %s:%s (%s) --> %s:%s (%s) w/ %s" % (src_ip, src_port, src_mac, dst_ip, dst_port, dst_mac, ack))
if self.noisy:
self.send(self.build_packet(src_mac, dst_mac, src_ip, dst_ip, src_port, dst_port, seq, proto))
self.send(self.build_packet(dst_mac, src_mac, dst_ip, src_ip, dst_port, src_port, ack, proto))
示例2: test_single_udp_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Ether [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"
示例3: test_single_tcp_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Ether [as 别名]
def test_single_tcp_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")
/ TCP(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"] == "TCP"
示例4: test_single_dns_resp_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Ether [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"
示例5: test_single_http_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Ether [as 别名]
def test_single_http_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")
/ TCP(sport=12345, dport=80)
/ HTTP()
/ HTTPRequest(Method="GET", Path="/foo", Host="https://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"] == 12345
assert events[0]["dport"] == 80
assert events[0]["http_method"] == "GET"
assert events[0]["uri"] == "/foo"
assert events[0]["http_dest"] == "https://google.com"
assert events[0]["event_type"] == "HTTPRequest"
示例6: test_multiple_packets
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Ether [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"]
示例7: _process_syn_scan
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Ether [as 别名]
def _process_syn_scan(self, pkt):
"""
Receives SYN scan response from devices.
"""
src_mac = pkt[sc.Ether].src
device_id = utils.get_device_id(src_mac, self._host_state)
device_port = pkt[sc.TCP].sport
with self._host_state.lock:
port_list = self._host_state.pending_syn_scan_dict.setdefault(device_id, [])
if device_port not in port_list:
port_list.append(device_port)
utils.log('[SYN Scan Debug] Device {} ({}): Port {}'.format(
pkt[sc.IP].src, device_id, device_port
))
示例8: build_dhcp
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Ether [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
示例9: run
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Ether [as 别名]
def run(self):
"""Starts the thread, which is sniffing incoming ARP packets and sends out packets to spoof
all clients on the network and the gateway. This packets are sent every __SLEEP seconds.
Note:
First, a ARP request packet is generated for every possible client of the network.
This packets are directed at the gateway and update existing entries of the gateway's ARP table.
So the gateway is not flooded with entries for non-existing clients.
Second, a GARP broadcast request packet is generated to spoof every client on the network.
"""
# start sniffing thread
self.sniffthread.start()
# generates a packet for each possible client of the network
# these packets update existing entries in the arp table of the gateway
# packets = [Ether(dst=self.gate_mac) / ARP(op=1, psrc=str(x), pdst=str(x)) for x in self.ip_range]
# gratuitous arp to clients
# updates the gateway entry of the clients arp table
packets = [Ether(dst=ETHER_BROADCAST) / ARP(op=1, psrc=self.ipv4.gateway, pdst=self.ipv4.gateway, hwdst=ETHER_BROADCAST)]
while True:
sendp(packets)
time.sleep(self.__SLEEP)
示例10: run
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Ether [as 别名]
def run(self):
"""Sends IGMP general query packets using the multicast address 224.0.0.1.
Received replies are processed by a SniffThread.
"""
# create IGMP general query packet
ether_part = Ether(src=self.mac)
ip_part = IP(ttl=self._TTL, src=self.ip, dst=self._IGMP_MULTICAST)
igmp_part = IGMP(type=self._IGMP_GENERAL_QUERY)
# Called to explicitely fixup associated IP and Ethernet headers
igmp_part.igmpize(ether=ether_part, ip=ip_part)
while True:
sendp(ether_part / ip_part / igmp_part)
time.sleep(self._SLEEP)
示例11: scan_ips
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Ether [as 别名]
def scan_ips(interface='wlan0', ips='192.168.1.0/24'):
"""a simple ARP scan with Scapy"""
try:
print('[*] Start to scan')
conf.verb = 0 # hide all verbose of scapy
ether = Ether(dst="ff:ff:ff:ff:ff:ff")
arp = ARP(pdst = ips)
answer, unanswered = srp(ether/arp, timeout = 2, iface = interface, inter = 0.1)
for sent, received in answer:
print(received.summary())
except KeyboardInterrupt:
print('[*] User requested Shutdown')
print('[*] Quitting...')
sys.exit(1)
示例12: send_dhcp_advertise
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Ether [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)
示例13: send_dhcp_reply
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Ether [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)
示例14: get_kube_dns_ip_mac
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Ether [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
示例15: build_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Ether [as 别名]
def build_packet(self, src_mac, dst_mac, src_ip, dst_ip, src_port, dst_port, seq, proto):
eth = Ether(src=src_mac, dst=dst_mac, type=0x800)
if proto == IP:
ip = IP(src=src_ip, dst=dst_ip)
elif proto == IPv6:
ip = IPv6(src=src_ip, dst=dst_ip)
else:
return str(eth) #if unknown L2 protocol, send back dud ether packet
tcp = TCP(sport=src_port, dport=dst_port, seq=seq, flags="R")
return str(eth/ip/tcp)