本文整理汇总了Python中scapy.packet.bind_layers函数的典型用法代码示例。如果您正苦于以下问题:Python bind_layers函数的具体用法?Python bind_layers怎么用?Python bind_layers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bind_layers函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TEXT_MESSAGE_TRANSFER
#!/usr/bin/env python
# Text message transfer SDU
from scapy.packet import Packet, bind_layers
from scapy.fields import BitField, ConditionalField
from .sdstl import SDS_TRANSFER
# Table 446: Text message transfer SDU contents
class TEXT_MESSAGE_TRANSFER(Packet):
name = 'Text Message Transfer SDU'
fields_desc = [
BitField('tstp_used', 0, 1),
BitField('text_coding', 0, 7),
ConditionalField(BitField('timestamp', 0, 24), lambda pkt: pkt.tstp_used == 1),
]
# FIXME : this is just wrong. We should rely on the value of D_SDS_DATA.proto
# but Scapy does not allow us to use the fields of an "ancestor" layer.
bind_layers(SDS_TRANSFER, TEXT_MESSAGE_TRANSFER)
示例2: ShortField
ShortField('reserved', None),
XIntField('spi', 0x0),
IntField('seq', 0),
StrField('icv', None),
StrField('padding', None),
]
overload_fields = {
IP: {'proto': socket.IPPROTO_AH},
IPv6: {'nh': socket.IPPROTO_AH},
IPv6ExtHdrHopByHop: {'nh': socket.IPPROTO_AH},
IPv6ExtHdrDestOpt: {'nh': socket.IPPROTO_AH},
IPv6ExtHdrRouting: {'nh': socket.IPPROTO_AH},
}
bind_layers(IP, AH, proto=socket.IPPROTO_AH)
bind_layers(IPv6, AH, nh=socket.IPPROTO_AH)
#------------------------------------------------------------------------------
class ESP(Packet):
"""
Encapsulated Security Payload
See https://tools.ietf.org/rfc/rfc4303.txt
"""
name = 'ESP'
fields_desc = [
XIntField('spi', 0x0),
IntField('seq', 0),
StrField('data', None),
示例3: EtherIP
# This file is part of Scapy
# Scapy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# any later version.
#
# Scapy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Scapy. If not, see <http://www.gnu.org/licenses/>.
# scapy.contrib.description = EtherIP
# scapy.contrib.status = loads
from scapy.fields import BitField
from scapy.packet import Packet, bind_layers
from scapy.layers.inet import IP
from scapy.layers.l2 import Ether
class EtherIP(Packet):
name = "EtherIP / RFC 3378"
fields_desc = [ BitField("version", 3, 4),
BitField("reserved", 0, 12)]
bind_layers( IP, EtherIP, frag=0, proto=0x61)
bind_layers( EtherIP, Ether)
示例4: warning
if self.has_ifindex and self.ifindex is None:
warning('has_ifindex set but ifindex is not set.')
if self.has_ipaddr and self.afi is None:
warning('has_ipaddr set but afi is not set.')
if self.has_ipaddr and self.ip4 is None and self.ip6 is None:
warning('has_ipaddr set but ip4 or ip6 is not set.')
if self.has_ifname and self.ifname is None:
warning('has_ifname set but ifname is not set.')
if self.has_mtu and self.mtu is None:
warning('has_mtu set but mtu is not set.')
return ICMPExtensionObject.self_build(self, field_pos_list=field_pos_list)
# Add the post_dissection() method to the existing ICMPv4 and
# ICMPv6 error messages
scapy.layers.inet.ICMPerror.post_dissection = ICMPExtension_post_dissection
scapy.layers.inet.TCPerror.post_dissection = ICMPExtension_post_dissection
scapy.layers.inet.UDPerror.post_dissection = ICMPExtension_post_dissection
scapy.layers.inet6.ICMPv6DestUnreach.post_dissection = ICMPExtension_post_dissection
scapy.layers.inet6.ICMPv6TimeExceeded.post_dissection = ICMPExtension_post_dissection
# ICMPExtensionHeader looks at fields from the upper layer object when
# determining which upper layer to use.
bind_layers(ICMPExtensionHeader, ICMPExtensionMPLS,
classnum=1, classtype=1)
bind_layers(ICMPExtensionHeader, ICMPExtensionInterfaceInformation, classnum=2)
示例5: range
g_log_loading.info(_crypto_loading_failure_message)
return None
packed_hdr = struct.pack("!B", self.code)
packed_hdr += struct.pack("!B", self.id)
packed_hdr += struct.pack("!H", self.len)
packed_attrs = ''
for index in range(0, len(self.attributes)):
packed_attrs = packed_attrs + str(self.attributes[index])
packed_data = packed_hdr + packed_request_auth + packed_attrs +\
shared_secret
digest = hashes.Hash(hashes.MD5(), backend=default_backend())
digest.update(packed_data)
return digest.finalize()
def post_build(self, p, pay):
p += pay
length = self.len
if length is None:
length = len(p)
p = p[:2] + struct.pack("!H", length) + p[4:]
return p
bind_layers(UDP, Radius, sport=1812)
bind_layers(UDP, Radius, dport=1812)
bind_layers(UDP, Radius, sport=1813)
bind_layers(UDP, Radius, dport=1813)
示例6: X3BytesField
X3BytesField("vni", 0),
XByteField("reserved2", 0x00),
GENEVEOptionsField("options", "")]
def post_build(self, p, pay):
p += pay
optionlen = self.optionlen
if optionlen is None:
optionlen = (len(self.options) + 3) // 4
p = chb(optionlen & 0x2f | orb(p[0]) & 0xc0) + p[1:]
return p
def answers(self, other):
if isinstance(other, GENEVE):
if ((self.proto == other.proto) and (self.vni == other.vni)):
return self.payload.answers(other.payload)
else:
return self.payload.answers(other)
return 0
def mysummary(self):
return self.sprintf("GENEVE (vni=%GENEVE.vni%,"
"optionlen=%GENEVE.optionlen%,"
"proto=%GENEVE.proto%)")
bind_layers(UDP, GENEVE, dport=6081)
bind_layers(GENEVE, Ether, proto=0x6558)
bind_layers(GENEVE, IP, proto=0x0800)
bind_layers(GENEVE, IPv6, proto=0x86dd)
示例7: guess_payload_class
def guess_payload_class(self, payload):
''' Decides if the payload is an HTTP Request or Response, or
something else '''
try:
prog = re.compile(
r"^(?:OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT) "
r"(?:.+?) "
r"HTTP/\d\.\d$"
)
crlfIndex = payload.index("\r\n".encode())
req = payload[:crlfIndex].decode("utf-8")
result = prog.match(req)
if result:
return HTTPRequest
else:
prog = re.compile(r"^HTTP/\d\.\d \d\d\d .*$")
result = prog.match(req)
if result:
return HTTPResponse
except:
pass
return Packet.guess_payload_class(self, payload)
bind_layers(TCP, HTTP, dport=80)
bind_layers(TCP, HTTP, sport=80)
#For Proxy
bind_layers(TCP, HTTP, sport=8080)
bind_layers(TCP, HTTP, dport=8080)
示例8: default_payload_class
def default_payload_class(self, payload):
return conf.padding_layer
class IGMPv3mr(Packet):
"""IGMP Membership Report extension for IGMPv3.
Payload of IGMPv3 when type=0x22"""
name = "IGMPv3mr"
fields_desc = [XShortField("res2", 0),
FieldLenField("numgrp", None, count_of="records"),
PacketListField("records", [], IGMPv3gr, count_from=lambda x: x.numgrp)] # noqa: E501
class IGMPv3mra(Packet):
"""IGMP Multicas Router Advertisement extension for IGMPv3.
Payload of IGMPv3 when type=0x30"""
name = "IGMPv3mra"
fields_desc = [ShortField("qryIntvl", 0),
ShortField("robust", 0)]
bind_layers(IP, IGMPv3, frag=0,
proto=2,
ttl=1,
tos=0xc0,
dst='224.0.0.22')
bind_layers(IGMPv3, IGMPv3mq, type=0x11)
bind_layers(IGMPv3, IGMPv3mr, type=0x22, mrcode=0x0)
bind_layers(IGMPv3, IGMPv3mra, type=0x30)
示例9: Read10
class Read10(Packet):
name = "Read(10) "
fields_desc = [ XByteField("Reserved1", 0),
XIntField("LogicalBlockAddr", 0),
XByteField("Reserved2", 0),
ShortField("TransferLength", 1), # Number of blocks
XByteField("Control", 0) ]
class ReadTOC(Packet):
name = "ReadTOC "
fields_desc = [ ByteEnumField("MSF", 0, {0:"", 2:""}),
XByteField("Format-A", 0),
XByteField("Reserved1", 0),
XByteField("Reserved2", 0),
XByteField("Reserved3", 0),
XByteField("Reserved4", 0),
ShortField("AllocationLength", 12),
XByteField("Format-B", 0x40)]
bind_layers(SCSICmd, RequestSense, {"OperationCode":0x03})
bind_layers(SCSICmd, FormatUnit, {"OperationCode":0x04})
bind_layers(SCSICmd, Read6, {"OperationCode":0x0A})
bind_layers(SCSICmd, Inquiry, {"OperationCode":0x12})
bind_layers(SCSICmd, ReadCapacity10, {"OperationCode":0x25})
bind_layers(SCSICmd, Read10, {"OperationCode":0x28})
bind_layers(SCSICmd, ReadTOC, {"OperationCode":0x43})
示例10: isinstance
isinstance(other, TFTP_WRQ) or
isinstance(other, TFTP_ACK))
def mysummary(self):
return self.sprintf("ERROR %errorcode%: %errormsg%"), [UDP]
class TFTP_OACK(Packet):
name = "TFTP Option Ack"
fields_desc = []
def answers(self, other):
return isinstance(other, TFTP_WRQ) or isinstance(other, TFTP_RRQ)
bind_layers(UDP, TFTP, dport=69)
bind_layers(TFTP, TFTP_RRQ, op=1)
bind_layers(TFTP, TFTP_WRQ, op=2)
bind_layers(TFTP, TFTP_DATA, op=3)
bind_layers(TFTP, TFTP_ACK, op=4)
bind_layers(TFTP, TFTP_ERROR, op=5)
bind_layers(TFTP, TFTP_OACK, op=6)
bind_layers(TFTP_RRQ, TFTP_Options)
bind_layers(TFTP_WRQ, TFTP_Options)
bind_layers(TFTP_OACK, TFTP_Options)
class TFTP_read(Automaton):
def parse_args(self, filename, server, sport=None, port=69, **kargs):
Automaton.parse_args(self, **kargs)
self.filename = filename
示例11: len
# Setting length of packet to obfuscate if not filled by user
if self.length is None and pay:
p = p[:-4] + struct.pack('!I', len(pay))
if self.flags == 0:
pay = obfuscate(pay, SECRET, self.session_id, self.version, self.seq) # noqa: E501
return p + pay
return p
def hashret(self):
return struct.pack('I', self.session_id)
def answers(self, other):
return (isinstance(other, TacacsHeader) and
self.seq == other.seq + 1 and
self.type == other.type and
self.session_id == other.session_id)
bind_layers(TCP, TacacsHeader, dport=49)
bind_layers(TCP, TacacsHeader, sport=49)
bind_layers(TacacsHeader, TacacsAuthenticationStart, type=1, dport=49)
bind_layers(TacacsHeader, TacacsAuthenticationReply, type=1, sport=49)
if __name__ == '__main__':
from scapy.main import interact
interact(mydict=globals(), mybanner='tacacs+')
示例12: ByteEnumField
ByteEnumField("descr", None, _tls_alert_description)]
def post_dissection_tls_session_update(self, msg_str):
pass
def post_build_tls_session_update(self, msg_str):
pass
###############################################################################
# TLS Application Data #
###############################################################################
class TLSApplicationData(_GenericTLSSessionInheritance):
name = "TLS Application Data"
fields_desc = [StrField("data", "")]
def post_dissection_tls_session_update(self, msg_str):
pass
def post_build_tls_session_update(self, msg_str):
pass
###############################################################################
# Bindings #
###############################################################################
bind_layers(TCP, TLS, sport=443)
bind_layers(TCP, TLS, dport=443)
示例13: MPLS
# Imported from scapy at revision 1270:113ef25f9583
# This file is not included in the Ubuntu packages of scapy, so it is checked
# in to our repo to simplify installation. This file is under the GPLv2.
# http://trac.secdev.org/scapy/ticket/31
# scapy.contrib.description = MPLS
# scapy.contrib.status = loads
from scapy.packet import Packet,bind_layers
from scapy.fields import BitField,ByteField
from scapy.layers.l2 import Ether
class MPLS(Packet):
name = "MPLS"
fields_desc = [ BitField("label", 3, 20),
BitField("cos", 0, 3),
BitField("s", 1, 1),
ByteField("ttl", 0) ]
bind_layers(Ether, MPLS, type=0x8847)
# Not in upstream scapy
bind_layers(MPLS, MPLS, s=0)
示例14: GTPSupportedExtensionHeadersNotification
class GTPSupportedExtensionHeadersNotification(Packet):
name = "GTP Supported Extension Headers Notification"
fields_desc = [PacketListField("IE_list", [IE_ExtensionHeaderList(),
], IE_Dispatcher)]
class GTPmorethan1500(Packet):
# 3GPP TS 29.060 V9.1.0 (2009-12)
name = "GTP More than 1500"
fields_desc = [ByteEnumField("IE_Cause", "Cause", IEType),
BitField("IE", 1, 12000), ]
# Bind GTP-C
bind_layers(UDP, GTPHeader, dport=2123)
bind_layers(UDP, GTPHeader, sport=2123)
bind_layers(GTPHeader, GTPEchoRequest, gtp_type=1, S=1)
bind_layers(GTPHeader, GTPEchoResponse, gtp_type=2, S=1)
bind_layers(GTPHeader, GTPCreatePDPContextRequest, gtp_type=16)
bind_layers(GTPHeader, GTPCreatePDPContextResponse, gtp_type=17)
bind_layers(GTPHeader, GTPUpdatePDPContextRequest, gtp_type=18)
bind_layers(GTPHeader, GTPUpdatePDPContextResponse, gtp_type=19)
bind_layers(GTPHeader, GTPDeletePDPContextRequest, gtp_type=20)
bind_layers(GTPHeader, GTPDeletePDPContextResponse, gtp_type=21)
bind_layers(GTPHeader, GTPPDUNotificationRequest, gtp_type=27)
bind_layers(GTPHeader, GTPSupportedExtensionHeadersNotification, gtp_type=31, S=1) # noqa: E501
bind_layers(GTPHeader, GTP_UDPPort_ExtensionHeader, next_ex=64, E=1)
bind_layers(GTPHeader, GTP_PDCP_PDU_ExtensionHeader, next_ex=192, E=1)
# Bind GTP-U
示例15: _ISIS_PSNP_Base
class _ISIS_PSNP_Base(_ISIS_PduBase):
fields_desc = [
_ISIS_PduLengthField(),
ISIS_NodeIdField("sourceid", "0102.0304.0506.00"),
_ISIS_TlvListField()
]
class ISIS_L1_PSNP(_ISIS_PSNP_Base):
name = "ISIS L1 Partial Sequence Number Packet"
def answers(self, other):
return _snp_answers(self, other, "ISIS_L1_LSP")
class ISIS_L2_PSNP(_ISIS_PSNP_Base):
name = "ISIS L2 Partial Sequence Number Packet"
def answers(self, other):
return _snp_answers(self, other, "ISIS_L2_LSP")
register_cln_protocol(0x83, ISIS_CommonHdr)
bind_layers(ISIS_CommonHdr, ISIS_L1_LAN_Hello, hdrlen=27, pdutype=15)
bind_layers(ISIS_CommonHdr, ISIS_L2_LAN_Hello, hdrlen=27, pdutype=16)
bind_layers(ISIS_CommonHdr, ISIS_P2P_Hello, hdrlen=20, pdutype=17)
bind_layers(ISIS_CommonHdr, ISIS_L1_LSP, hdrlen=27, pdutype=18)
bind_layers(ISIS_CommonHdr, ISIS_L2_LSP, hdrlen=27, pdutype=20)
bind_layers(ISIS_CommonHdr, ISIS_L1_CSNP, hdrlen=33, pdutype=24)
bind_layers(ISIS_CommonHdr, ISIS_L2_CSNP, hdrlen=33, pdutype=25)
bind_layers(ISIS_CommonHdr, ISIS_L1_PSNP, hdrlen=17, pdutype=26)
bind_layers(ISIS_CommonHdr, ISIS_L2_PSNP, hdrlen=17, pdutype=27)