本文整理汇总了Python中scapy.all.IP属性的典型用法代码示例。如果您正苦于以下问题:Python all.IP属性的具体用法?Python all.IP怎么用?Python all.IP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类scapy.all
的用法示例。
在下文中一共展示了all.IP属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rawhandle
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import IP [as 别名]
def rawhandle(pkt):
if sniff_pkts:
scapy.wrpcap(random_filename+"arpy.pcap",pkt)
counter = 0
while counter < 1:
counter += 1
layer = pkt.getlayer(counter)
if layer.haslayer(scapy.Raw) and layer.haslayer(scapy.IP):
print(bcolours.OKBLUE + '\n[Info] Found the following (' + layer.name + ' layer): ' + layer.src + " -> " + layer.dst + bcolours.ENDC)
tcpdata = layer.getlayer(scapy.Raw).load
if not opts.verbose:
print tcpdata
else:
print layer.show()
else:
break
示例2: pkt_callback
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import IP [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)
示例3: checkhost
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import IP [as 别名]
def checkhost(server, works, session, ipadd, natip):
"""
Check if host exist in Faraday
"""
resp = session.get(server + '/_api/v2/ws/' + works + '/hosts/')
if resp.status_code == 200:
hostdata = resp.json()
for hostrow in range(len(hostdata['rows'])):
if ipadd == hostdata['rows'][hostrow]['value']['ip']:
return int(hostdata['rows'][hostrow]['value']['id'])
HOST['ip'] = ipadd
HOST['description'] = 'NAT IP: ' + natip
resp = session.post(server + '/_api/v2/ws/' + works + '/hosts/', json=HOST)
if resp.status_code == 201:
hostdata = resp.json()
return hostdata['id']
else:
print('ERROR: API Host insert fail')
print(resp.text)
print(repr(HOST))
else:
print('ERROR: API Hosts call fail')
print(resp.text)
return None
示例4: callback
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import IP [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))
示例5: test_single_udp_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import IP [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"
示例6: test_single_tcp_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import IP [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"
示例7: test_single_dns_resp_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import IP [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"
示例8: test_single_dns_query_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import IP [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"
示例9: test_multiple_packets
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import IP [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"]
示例10: nfqueueHandler
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import IP [as 别名]
def nfqueueHandler(self, packet):
pkt = IP(packet.get_payload()) #Converts the raw packet to a scapy object
target = pkt.dst
victim = pkt.src
nc = Connection(pkt.src, pkt.dst, pkt[self.protocol].sport, pkt[self.protocol].dport, self.protocol, self.interface)
key = hash(str(nc.getMark()))
self.connectionManager[key] = nc
# Mark the packet so nfqueue won't touch it on the next iteration
packet.set_mark(self.nfqueueNum)
# Now that we've recoreded and marked the packet,
# let's have the kernel present the packet to us again as if it were new.
# This time NFqueue won't touch it, and it will be passed to the intercept servers
packet.repeat()
return
# This gets seperated off into a thread, it runs nfqueue
# which is the most critical part. Without it, the proxy
# cannot be transparent
示例11: _process_syn_scan
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import IP [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
))
示例12: get_server_hello
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import IP [as 别名]
def get_server_hello(pkt, layer, host_state):
if pkt[sc.IP].src in host_state.get_ip_mac_dict_copy():
device_ip = pkt[sc.IP].src
remote_ip = pkt[sc.IP].dst
device_port = pkt[sc.TCP].sport
remote_port = pkt[sc.TCP].dport
else:
device_ip = pkt[sc.IP].dst
remote_ip = pkt[sc.IP].src
device_port = pkt[sc.TCP].dport
remote_port = pkt[sc.TCP].sport
return {
'type': 'server_hello',
'version': getattr(layer, 'version', None),
'cipher_suite': getattr(layer, 'cipher_suite', None),
'device_ip': device_ip,
'device_port': device_port,
'remote_ip': remote_ip,
'remote_port': remote_port,
'client_ts': time.time()
}
示例13: spoof_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import IP [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()
示例14: inject_code
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import IP [as 别名]
def inject_code(packet):
http_packet = scapy.IP(packet.get_payload())
if http_packet.haslayer(scapy.Raw):
load = http_packet[scapy.Raw].load
if http_packet[scapy.TCP].dport == 10000:
load = re.sub("Accept-Encoding:.*?\\r\\n", "", load)
load = load.replace("HTTP/1.1", "HTTP/1.0")
elif http_packet[scapy.TCP].sport == 10000:
injection_code = """<script>alert('Hello from devopslife.xyz');
</script>"""
load = load.replace("</body>", injection_code + "</body>")
length_search = re.search("(?:Content-Length:\s)(\d*)", load)
if length_search and "text/html" in load:
length = length_search.group(1)
new_length = int(length) + len(injection_code)
load = load.replace(length, str(new_length))
if load != http_packet[scapy.Raw].load:
new_packet = change_payload(http_packet, load)
packet.set_payload(str(new_packet))
packet.accept()
示例15: build_dhcp
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import IP [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