本文整理汇总了Python中scapy.packet.Raw方法的典型用法代码示例。如果您正苦于以下问题:Python packet.Raw方法的具体用法?Python packet.Raw怎么用?Python packet.Raw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scapy.packet
的用法示例。
在下文中一共展示了packet.Raw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_tcp_packet
# 需要导入模块: from scapy import packet [as 别名]
# 或者: from scapy.packet import Raw [as 别名]
def generate_tcp_packet(ip_src: str = "192.168.64.32", ip_dst: str = "192.168.64.48",
mac_src: str = "56:6D:D9:BC:70:1C", ttl: int = 64,
mac_dst: str = "F4:2B:95:B3:0E:1A", port_src: int = 1337, port_dst: int = 6442,
tcpflags: str = "S", payload: str = ""):
"""
Builds a TCP packet with the values specified by the caller.
:param ip_src: the source IP address of the IP header
:param ip_dst the destination IP address of the IP header
:param mac_src: the source MAC address of the MAC header
:param ttl: the ttl value of the packet
:param mac_dst: the destination MAC address of the MAC header
:param port_src: the source port of the TCP header
:param port_dst: the destination port of the TCP header
:param tcpflags: the TCP flags of the TCP header
:param payload: the payload of the packet
:return: the corresponding TCP packet
"""
ether = Ether(src=mac_src, dst=mac_dst)
ip = IP(src=ip_src, dst=ip_dst, ttl=ttl)
tcp = TCP(sport=port_src, dport=port_dst, flags=tcpflags)
packet = ether / ip / tcp / Raw(load=payload)
return packet
示例2: voip_play1
# 需要导入模块: from scapy import packet [as 别名]
# 或者: from scapy.packet import Raw [as 别名]
def voip_play1(s1,list=None,**kargs):
dsp,rd = os.popen2("sox -t .ul - -t ossdsp /dev/dsp")
def play(pkt):
if not pkt:
return
if not pkt.haslayer(UDP):
return
ip=pkt.getlayer(IP)
if s1 in [ip.src, ip.dst]:
dsp.write(pkt.getlayer(Raw).load[12:])
try:
if list is None:
sniff(store=0, prn=play, **kargs)
else:
for p in list:
play(p)
finally:
dsp.close()
rd.close()
示例3: voip_play3
# 需要导入模块: from scapy import packet [as 别名]
# 或者: from scapy.packet import Raw [as 别名]
def voip_play3(lst=None,**kargs):
dsp,rd = os.popen2("sox -t .ul - -t ossdsp /dev/dsp")
try:
def play(pkt, dsp=dsp):
if pkt and pkt.haslayer(UDP) and pkt.haslayer(Raw):
dsp.write(pkt.getlayer(RTP).load)
if lst is None:
sniff(store=0, prn=play, **kargs)
else:
for p in lst:
play(p)
finally:
try:
dsp.close()
rd.close()
except:
pass
示例4: add_padding
# 需要导入模块: from scapy import packet [as 别名]
# 或者: from scapy.packet import Raw [as 别名]
def add_padding(packet, bytes_padding:int = 0, user_padding:bool=True, rnd:bool = False):
"""
Adds padding to a packet with the given amount of bytes, but a maximum of 100 bytes, if called by the user.
:param packet: the packet that will be extended with the additional payload
:param bytes_padding: the amount of bytes that will be appended to the packet. Capped to 100,
if called by the user.
:param user_padding: true, if the function add_padding by the user and not within the code
:param rnd: adds a random padding between 0 and bytes_padding, if true
:return: the initial packet, extended with the wanted amount of bytes of padding
"""
if user_padding == True and bytes_padding > 100:
bytes_padding = 100
if rnd is True:
r = int(round(bytes_padding / 4)) # sets bytes_padding to any number between 0 and
bytes_padding = random2.random_integers(0, r) * 4 # bytes_padding, that's dividable by 4
payload = generate_payload(bytes_padding)
packet[Raw].load += Raw(load=payload).load
return packet
示例5: get_data
# 需要导入模块: from scapy import packet [as 别名]
# 或者: from scapy.packet import Raw [as 别名]
def get_data(self, pkt):
# Avoid packet from other interfaces
if RadioTap not in pkt:
return
# Skip retries
if pkt[Dot11].FCfield.retry:
return
# Skip unencrypted frames (TKIP rely on encrypted packets)
if not pkt[Dot11].FCfield.protected:
return
# Dot11.type 2: Data
if pkt.type == 2 and Raw in pkt and pkt.addr1 == self.mac:
# Do not check pkt.addr3, frame can be broadcast
raise self.KRACK_DISPATCHER().action_parameters(pkt)
示例6: get_arp
# 需要导入模块: from scapy import packet [as 别名]
# 或者: from scapy.packet import Raw [as 别名]
def get_arp(self, pkt):
# Avoid packet from other interfaces
if RadioTap not in pkt:
return
# Skip retries
if pkt[Dot11].FCfield.retry:
return
# Skip unencrypted frames (TKIP rely on encrypted packets)
if not pkt[Dot11].FCfield.protected:
return
# Dot11.type 2: Data
if pkt.type == 2 and Raw in pkt and pkt.addr1 == self.mac:
# Do not check pkt.addr3, frame can be broadcast
raise self.WAIT_ARP_REPLIES().action_parameters(pkt)
示例7: m2i
# 需要导入模块: from scapy import packet [as 别名]
# 或者: from scapy.packet import Raw [as 别名]
def m2i(self, pkt, m):
"""
The client_kx_msg may be either None, EncryptedPreMasterSecret
(for RSA encryption key exchange), ClientDiffieHellmanPublic,
or ClientECDiffieHellmanPublic. When either one of them gets
dissected, the session context is updated accordingly.
"""
tmp_len = self.length_from(pkt)
tbd, rem = m[:tmp_len], m[tmp_len:]
s = pkt.tls_session
cls = None
if s.prcs and s.prcs.key_exchange:
cls = s.prcs.key_exchange.client_kx_msg_cls
if cls is None:
return Raw(tbd) / Padding(rem)
return cls(tbd, tls_session=s) / Padding(rem)
示例8: build
# 需要导入模块: from scapy import packet [as 别名]
# 或者: from scapy.packet import Raw [as 别名]
def build(self, *args, **kargs):
fval = self.getfieldval("exchkeys")
if fval is None:
s = self.tls_session
if s.prcs:
cls = s.prcs.key_exchange.client_kx_msg_cls
cls = cls(tls_session=s)
else:
cls = Raw()
self.exchkeys = cls
return _TLSHandshake.build(self, *args, **kargs)
###############################################################################
# Finished #
###############################################################################
示例9: getfield
# 需要导入模块: from scapy import packet [as 别名]
# 或者: from scapy.packet import Raw [as 别名]
def getfield(self, pkt, s):
i = self.m2i(pkt, s)
# i can be <OFPMatch> or <OFPMatch <Padding>>
# or <OFPMatch <Raw>> or <OFPMatch <Raw <Padding>>>
# and we want to return "", <OFPMatch> or "", <OFPMatch <Padding>>
# or raw(<Raw>), <OFPMatch> or raw(<Raw>), <OFPMatch <Padding>>
if Raw in i:
r = i[Raw]
if Padding in r:
p = r[Padding]
i.payload = p
del(r.payload)
return r.load, i
else:
return b"", i
# Actions #
示例10: _tzsp_handle_unknown_tag
# 需要导入模块: from scapy import packet [as 别名]
# 或者: from scapy.packet import Raw [as 别名]
def _tzsp_handle_unknown_tag(payload, tag_type):
payload_len = len(payload)
if payload_len < 2:
warning('invalid or unknown tag type (%i) and too short packet - treat remaining data as Raw' % tag_type) # noqa: E501
return Raw
tag_data_length = orb(payload[1])
tag_data_fits_in_payload = (tag_data_length + 2) <= payload_len
if not tag_data_fits_in_payload:
warning('invalid or unknown tag type (%i) and too short packet - treat remaining data as Raw' % tag_type) # noqa: E501
return Raw
warning('invalid or unknown tag type (%i)' % tag_type)
return TZSPTagUnknown
示例11: parse_options
# 需要导入模块: from scapy import packet [as 别名]
# 或者: from scapy.packet import Raw [as 别名]
def parse_options(self, supported_responses=None,
main_socket=None, broadcast_socket=None, basecls=Raw,
timeout=None):
self.main_socket = main_socket
self.sockets = [self.main_socket]
if broadcast_socket is not None:
self.sockets.append(broadcast_socket)
self.ecu_state = ECU(logging=False, verbose=False,
store_supported_responses=False)
self.basecls = basecls
self.supported_responses = supported_responses
self.sniff_options["timeout"] = timeout
self.sniff_options["opened_socket"] = self.sockets
示例12: _sdoption_class
# 需要导入模块: from scapy import packet [as 别名]
# 或者: from scapy.packet import Raw [as 别名]
def _sdoption_class(payload, **kargs):
pl_type = orb(payload[2])
cls = {
SDOPTION_CFG_TYPE: SDOption_Config,
SDOPTION_LOADBALANCE_TYPE: SDOption_LoadBalance,
SDOPTION_IP4_ENDPOINT_TYPE: SDOption_IP4_EndPoint,
SDOPTION_IP4_MCAST_TYPE: SDOption_IP4_Multicast,
SDOPTION_IP4_SDENDPOINT_TYPE: SDOption_IP4_SD_EndPoint,
SDOPTION_IP6_ENDPOINT_TYPE: SDOption_IP6_EndPoint,
SDOPTION_IP6_MCAST_TYPE: SDOption_IP6_Multicast,
SDOPTION_IP6_SDENDPOINT_TYPE: SDOption_IP6_SD_EndPoint
}.get(pl_type, Raw)
return cls(payload, **kargs)
# SD Option
示例13: generate_udp_packet
# 需要导入模块: from scapy import packet [as 别名]
# 或者: from scapy.packet import Raw [as 别名]
def generate_udp_packet(ip_src: str = "192.168.64.32", ip_dst: str = "192.168.64.48",
mac_src: str = "56:6D:D9:BC:70:1C", ttl: int = 64,
mac_dst: str = "F4:2B:95:B3:0E:1A", port_src: int = 1337, port_dst: int = 6442,
payload: str = ""):
"""
Builds an UDP packet with the values specified by the caller.
:param ip_src: the source IP address of the IP header
:param ip_dst the destination IP address of the IP header
:param mac_src: the source MAC address of the MAC header
:param ttl: the ttl value of the packet
:param mac_dst: the destination MAC address of the MAC header
:param port_src: the source port of the UDP header
:param port_dst: the destination port of the UDP header
:param payload: the payload of the packet
:return: the corresponding UDP packet
"""
ether = Ether(src=mac_src, dst=mac_dst)
ip = IP(src=ip_src, dst=ip_dst, ttl=ttl)
udp = UDP(sport=port_src, dport=port_dst)
packet = ether / ip / udp / Raw(load=payload)
return packet
#################################################
######## IP address generation ########
#################################################
示例14: guess_payload_class
# 需要导入模块: from scapy import packet [as 别名]
# 或者: from scapy.packet import Raw [as 别名]
def guess_payload_class(self, payload):
""" Sense for ciphertext
"""
cls = StackedLenPacket.guess_payload_class(self, payload)
p = cls(payload, _internal=1, _underlayer=self)
if p.haslayer(TLSHandshakes) and len(p[TLSHandshakes].handshakes) > 0:
p = p[TLSHandshakes].handshakes[0]
try:
if cls == Raw().__class__ or p.length > len(payload):
# length does not fit len raw_bytes, assume its corrupt or encrypted
cls = TLSCiphertext
except AttributeError:
# e.g. TLSChangeCipherSpec might land here
pass
return cls
示例15: send_wpa_enc
# 需要导入模块: from scapy import packet [as 别名]
# 或者: from scapy.packet import Raw [as 别名]
def send_wpa_enc(self, data, iv, seqnum, dest, mic_key,
key_idx=0, additionnal_flag=["from-DS"],
encrypt_key=None):
"""Send an encrypted packet with content @data, using IV @iv,
sequence number @seqnum, MIC key @mic_key
"""
if encrypt_key is None:
encrypt_key = self.tk
rep = RadioTap()
rep /= Dot11(
addr1=dest,
addr2=self.mac,
addr3=self.mac,
FCfield="+".join(['protected'] + additionnal_flag),
SC=(next(self.seq_num) << 4),
subtype=0,
type="Data",
)
# Assume packet is send by our AP -> use self.mac as source
# Encapsule in TKIP with MIC Michael and ICV
data_to_enc = build_MIC_ICV(raw(data), mic_key, self.mac, dest)
# Header TKIP + payload
rep /= Raw(build_TKIP_payload(data_to_enc, iv, self.mac, encrypt_key))
self.send(rep)
return rep