本文整理汇总了Python中scapy.compat.orb函数的典型用法代码示例。如果您正苦于以下问题:Python orb函数的具体用法?Python orb怎么用?Python orb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了orb函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: OpenFlow
def OpenFlow(self, payload):
if self is None or self.dport == 6653 or self.dport == 6633 or self.sport == 6653 or self.sport == 6633: # noqa: E501
# port 6653 has been allocated by IANA, port 6633 should no longer be used # noqa: E501
# OpenFlow function may be called with None self in OFPPacketField
of_type = orb(payload[1])
if of_type == 1:
err_type = orb(payload[9])
# err_type is a short int, but last byte is enough
if err_type == 255:
err_type = 65535
return ofp_error_cls[err_type]
elif of_type == 16:
mp_type = orb(payload[9])
if mp_type == 255:
mp_type = 65535
return ofp_stats_request_cls[mp_type]
elif of_type == 17:
mp_type = orb(payload[9])
if mp_type == 255:
mp_type = 65535
return ofp_stats_reply_cls[mp_type]
else:
return ofpt_cls[of_type]
else:
return TCP_guess_payload_class_copy(self, payload)
开发者ID:plorinquer,项目名称:scapy,代码行数:25,代码来源:openflow.py
示例2: m2i
def m2i(self, pkt, s):
family = None
if pkt.type == 1: # A
family = socket.AF_INET
elif pkt.type in [2, 5, 12]: # NS, CNAME, PTR
if hasattr(pkt, "_orig_s") and pkt._orig_s:
if orb(s[0]) & 0xc0:
s = dns_get_str(s, 0, pkt)[0]
else:
s = dns_get_str(pkt._orig_s, pkt._orig_p, _internal=True)[0] # noqa: E501
else:
s = dns_get_str(s, 0)[0]
elif pkt.type == 16: # TXT
ret_s = list()
tmp_s = s
# RDATA contains a list of strings, each are prepended with
# a byte containing the size of the following string.
while tmp_s:
tmp_len = orb(tmp_s[0]) + 1
if tmp_len > len(tmp_s):
warning("DNS RR TXT prematured end of character-string (size=%i, remaining bytes=%i)" % (tmp_len, len(tmp_s))) # noqa: E501
ret_s.append(tmp_s[1:tmp_len])
tmp_s = tmp_s[tmp_len:]
s = ret_s
elif pkt.type == 28: # AAAA
family = socket.AF_INET6
if family is not None:
s = inet_ntop(family, s)
return s
开发者ID:netkey,项目名称:scapy,代码行数:29,代码来源:dns.py
示例3: dispatch_hook
def dispatch_hook(cls, _pkt=None, *args, **kargs):
"""
If the TLS class was called on raw SSLv2 data, we want to return an
SSLv2 record instance. We acknowledge the risk of SSLv2 packets with a
msglen of 0x1403, 0x1503, 0x1603 or 0x1703 which will never be casted
as SSLv2 records but TLS ones instead, but hey, we can't be held
responsible for low-minded extensibility choices.
"""
if _pkt and len(_pkt) >= 2:
byte0 = orb(_pkt[0])
byte1 = orb(_pkt[1])
if (byte0 not in _tls_type) or (byte1 != 3):
from scapy.layers.tls.record_sslv2 import SSLv2
return SSLv2
else:
s = kargs.get("tls_session", None)
if s and _tls_version_check(s.tls_version, 0x0304):
if s.rcs and not isinstance(s.rcs.cipher, Cipher_NULL):
from scapy.layers.tls.record_tls13 import TLS13
return TLS13
if _pkt and len(_pkt) < 5:
# Layer detected as TLS but too small to be a real packet (len<5). # noqa: E501
# Those packets appear when sessions are interrupted or to flush buffers. # noqa: E501
# Scapy should not try to decode them
return conf.raw_layer
return TLS
开发者ID:commial,项目名称:scapy,代码行数:26,代码来源:record.py
示例4: dispatch_hook
def dispatch_hook(cls, _pkt=None, *args, **kargs):
if _pkt and len(_pkt) >= 2:
version = orb(_pkt[0])
if version == 0x04: # OpenFlow 1.3
from scapy.contrib.openflow3 import OpenFlow3
return OpenFlow3.dispatch_hook(_pkt, *args, **kargs)
elif version == 0x01: # OpenFlow 1.0
# port 6653 has been allocated by IANA, port 6633 should no
# longer be used
# OpenFlow function may be called with a None
# self in OFPPacketField
of_type = orb(_pkt[1])
if of_type == 1:
err_type = orb(_pkt[9])
# err_type is a short int, but last byte is enough
if err_type == 255:
err_type = 65535
return ofp_error_cls[err_type]
elif of_type == 16:
mp_type = orb(_pkt[9])
if mp_type == 255:
mp_type = 65535
return ofp_stats_request_cls[mp_type]
elif of_type == 17:
mp_type = orb(_pkt[9])
if mp_type == 255:
mp_type = 65535
return ofp_stats_reply_cls[mp_type]
else:
return ofpt_cls[of_type]
else:
warning("Unknown OpenFlow packet")
return _UnknownOpenFlow
开发者ID:commial,项目名称:scapy,代码行数:33,代码来源:openflow.py
示例5: dispatch_hook
def dispatch_hook(cls, _pkt=None, *args, **kargs):
if _pkt and len(_pkt) >= 4:
if orb(_pkt[0]) in [0x12, 0x16, 0x17]:
return IGMP
elif orb(_pkt[0]) == 0x11 and len(_pkt) < 12:
return IGMP
return IGMPv3
开发者ID:commial,项目名称:scapy,代码行数:7,代码来源:igmpv3.py
示例6: obfuscate
def obfuscate(pay, secret, session_id, version, seq):
'''
Obfuscation methodology from section 3.7
https://tools.ietf.org/html/draft-ietf-opsawg-tacacs-06#section-3.7
'''
pad = b""
curr_pad = b""
# pad length must equal the payload to obfuscate.
# pad = {MD5_1 [,MD5_2 [ ... ,MD5_n]]}
while len(pad) < len(pay):
msg = hashlib.md5()
msg.update(struct.pack('!I', session_id))
msg.update(secret.encode())
msg.update(struct.pack('!BB', version, seq))
msg.update(curr_pad)
curr_pad = msg.digest()
pad += curr_pad
# Obf/Unobfuscation via XOR operation between plaintext and pad
return b"".join(chb(orb(pad[i]) ^ orb(pay[i])) for i in range(len(pay)))
开发者ID:plorinquer,项目名称:scapy,代码行数:27,代码来源:tacacs.py
示例7: in6_getAddrType
def in6_getAddrType(addr):
naddr = inet_pton(socket.AF_INET6, addr)
paddr = inet_ntop(socket.AF_INET6, naddr) # normalize
addrType = 0
# _Assignable_ Global Unicast Address space
# is defined in RFC 3513 as those in 2000::/3
if ((orb(naddr[0]) & 0xE0) == 0x20):
addrType = (IPV6_ADDR_UNICAST | IPV6_ADDR_GLOBAL)
if naddr[:2] == b' \x02': # Mark 6to4 @
addrType |= IPV6_ADDR_6TO4
elif orb(naddr[0]) == 0xff: # multicast
addrScope = paddr[3]
if addrScope == '2':
addrType = (IPV6_ADDR_LINKLOCAL | IPV6_ADDR_MULTICAST)
elif addrScope == 'e':
addrType = (IPV6_ADDR_GLOBAL | IPV6_ADDR_MULTICAST)
else:
addrType = (IPV6_ADDR_GLOBAL | IPV6_ADDR_MULTICAST)
elif ((orb(naddr[0]) == 0xfe) and ((int(paddr[2], 16) & 0xC) == 0x8)):
addrType = (IPV6_ADDR_UNICAST | IPV6_ADDR_LINKLOCAL)
elif paddr == "::1":
addrType = IPV6_ADDR_LOOPBACK
elif paddr == "::":
addrType = IPV6_ADDR_UNSPECIFIED
else:
# Everything else is global unicast (RFC 3513)
# Even old deprecated (RFC3879) Site-Local addresses
addrType = (IPV6_ADDR_GLOBAL | IPV6_ADDR_UNICAST)
return addrType
开发者ID:commial,项目名称:scapy,代码行数:30,代码来源:utils6.py
示例8: _tzsp_guess_next_tag
def _tzsp_guess_next_tag(payload):
"""
:return: class representing the next tag, Raw on error, None on missing payload # noqa: E501
"""
if not payload:
warning('missing payload')
return None
tag_type = orb(payload[0])
try:
tag_class_definition = _TZSP_TAG_CLASSES[tag_type]
except KeyError:
return _tzsp_handle_unknown_tag(payload, tag_type)
if type(tag_class_definition) is not dict:
return tag_class_definition
try:
length = orb(payload[1])
except IndexError:
length = None
if not length:
warning('no tag length given - packet to short')
return Raw
try:
return tag_class_definition[length]
except KeyError:
warning('invalid tag length {} for tag type {}'.format(length, tag_type)) # noqa: E501
return Raw
开发者ID:segment-routing,项目名称:scapy,代码行数:35,代码来源:tzsp.py
示例9: pre_dissect
def pre_dissect(self, s):
# Get the frame check sequence
sty = orb(s[0])
ty = orb(s[1]) >> 2
fc = struct.unpack("!H", s[2:4])[0]
length = 12 + 6 * ((ty != 1 or sty in [0x8, 0x9, 0xa, 0xb, 0xe, 0xf]) + (ty in [0, 2]) + (ty == 2 and fc & 3 == 3)) # noqa: E501
return s[:length] + s[-4:] + s[length:-4]
开发者ID:netkey,项目名称:scapy,代码行数:7,代码来源:dot11.py
示例10: dispatch_hook
def dispatch_hook(cls, _pkt=None, *args, **kargs):
if _pkt:
c = orb(_pkt[0])
if c in [1, 2] and len(_pkt) >= 5:
t = orb(_pkt[4])
return cls.registered_methods.get(t, cls)
return cls
开发者ID:plorinquer,项目名称:scapy,代码行数:7,代码来源:eap.py
示例11: dispatch_hook
def dispatch_hook(cls, _pkt=None, *args, **kargs):
if _pkt and len(_pkt) >= 4:
from scapy.contrib.igmpv3 import IGMPv3
if orb(_pkt[0]) in [0x22, 0x30, 0x31, 0x32]:
return IGMPv3
if orb(_pkt[0]) == 0x11 and len(_pkt) >= 12:
return IGMPv3
return IGMP
开发者ID:plorinquer,项目名称:scapy,代码行数:8,代码来源:igmp.py
示例12: dns_get_str
def dns_get_str(s, p, pkt=None, _internal=False):
"""This function decompresses a string s, from the character p.
params:
- s: the string to decompress
- p: start index of the string
- pkt: (optional) an InheritOriginDNSStrPacket packet
returns: (decoded_string, end_index, left_string)
"""
# The _internal parameter is reserved for scapy. It indicates
# that the string provided is the full dns packet, and thus
# will be the same than pkt._orig_str. The "Cannot decompress"
# error will not be prompted if True.
max_length = len(s)
name = b"" # The result = the extracted name
burned = 0 # The "burned" data, used to determine the remaining bytes
q = None # Will contain the index after the pointer, to be returned
processed_pointers = [p] # Used to check for decompression loops
while True:
if abs(p) >= max_length:
warning("DNS RR prematured end (ofs=%i, len=%i)" % (p, len(s)))
break
cur = orb(s[p]) # current value of the string at p
p += 1 # p is now pointing to the value of the pointer
burned += 1
if cur & 0xc0: # Label pointer
if q is None:
# p will follow the pointer, whereas q will not
q = p + 1
if p >= max_length:
warning("DNS incomplete jump token at (ofs=%i)" % p)
break
p = ((cur & ~0xc0) << 8) + orb(s[p]) - 12 # Follow the pointer
burned += 1
if pkt and hasattr(pkt, "_orig_s") and pkt._orig_s:
# There should not be a loop as pkt is None
name += dns_get_str(pkt._orig_s, p, None, _internal=True)[0]
if burned == max_length:
break
elif p in processed_pointers:
warning("DNS decompression loop detected")
break
elif not _internal:
raise Scapy_Exception("DNS message can't be compressed" +
"at this point!")
processed_pointers.append(p)
continue
elif cur > 0: # Label
name += s[p:p + cur] + b"."
p += cur
burned += cur
else:
break
if q is not None:
# Return the real end index (not the one we followed)
p = q
# name, end_index, remaining
return name, p, s[burned:]
开发者ID:netkey,项目名称:scapy,代码行数:58,代码来源:dns.py
示例13: dispatch_hook
def dispatch_hook(cls, _pkt=None, *args, **kargs):
if _pkt and len(_pkt) >= 1:
if (orb(_pkt[0]) >> 5) & 0x7 == 2:
from . import gtp_v2
return gtp_v2.GTPHeader
if _pkt and len(_pkt) >= 8:
_gtp_type = orb(_pkt[1:2])
return GTPforcedTypes.get(_gtp_type, GTPHeader)
return cls
开发者ID:plorinquer,项目名称:scapy,代码行数:9,代码来源:gtp.py
示例14: do_dec
def do_dec(cls, s, context=None, safe=False):
l, s, t = cls.check_type_check_len(s)
x = 0
if s:
if orb(s[0]) & 0x80: # negative int
x = -1
for c in s:
x <<= 8
x |= orb(c)
return cls.asn1_object(x), t
开发者ID:commial,项目名称:scapy,代码行数:10,代码来源:ber.py
示例15: decrypt
def decrypt(self, sa, esp, key, icv_size=None):
"""
Decrypt an ESP packet
@param sa: the SecurityAssociation associated with the ESP packet.
@param esp: an encrypted ESP packet
@param key: the secret key used for encryption
@param icv_size: the length of the icv used for integrity check
@return: a valid ESP packet encrypted with this algorithm
@raise IPSecIntegrityError: if the integrity check fails with an AEAD
algorithm
"""
if icv_size is None:
icv_size = self.icv_size if self.is_aead else 0
iv = esp.data[:self.iv_size]
data = esp.data[self.iv_size:len(esp.data) - icv_size]
icv = esp.data[len(esp.data) - icv_size:]
if self.cipher:
mode_iv = self._format_mode_iv(sa=sa, iv=iv)
cipher = self.new_cipher(key, mode_iv, icv)
decryptor = cipher.decryptor()
if self.is_aead:
# Tag value check is done during the finalize method
decryptor.authenticate_additional_data(
struct.pack('!LL', esp.spi, esp.seq)
)
try:
data = decryptor.update(data) + decryptor.finalize()
except InvalidTag as err:
raise IPSecIntegrityError(err)
# extract padlen and nh
padlen = orb(data[-2])
nh = orb(data[-1])
# then use padlen to determine data and padding
data = data[:len(data) - padlen - 2]
padding = data[len(data) - padlen - 2: len(data) - 2]
return _ESPPlain(spi=esp.spi,
seq=esp.seq,
iv=iv,
data=data,
padding=padding,
padlen=padlen,
nh=nh,
icv=icv)
开发者ID:6WIND,项目名称:scapy,代码行数:52,代码来源:ipsec.py
示例16: i2m
def i2m(self, pkt, x):
if any((orb(y) >= 0xc0) for y in x):
# The value has already been processed. Do not process it again
return x
if not x or x == b".":
return b"\x00"
# Truncate chunks that cannot be encoded (more than 63 bytes..)
x = b"".join(chb(len(y)) + y for y in (k[:63] for k in x.split(b".")))
if orb(x[-1]) != 0 and (orb(x[-2]) < 0xc0):
x += b"\x00"
return x
开发者ID:netkey,项目名称:scapy,代码行数:13,代码来源:dns.py
示例17: dispatch_hook
def dispatch_hook(cls, _pkt=None, *args, **kargs):
if len(_pkt) >= 2:
if (orb(_pkt[2]) & 0x80): # Response
return LLMNRResponse
else: # Query
return LLMNRQuery
return cls
开发者ID:segment-routing,项目名称:scapy,代码行数:7,代码来源:llmnr.py
示例18: post_build
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
开发者ID:plorinquer,项目名称:scapy,代码行数:7,代码来源:geneve.py
示例19: parse_data_pkt
def parse_data_pkt(pkt, tk):
"""Extract data from a WPA packet @pkt with temporal key @tk"""
TSC, TA, data = parse_TKIP_hdr(pkt)
TK = [orb(x) for x in tk]
rc4_key = gen_TKIP_RC4_key(TSC, TA, TK)
return ARC4_decrypt(rc4_key, data)
开发者ID:plorinquer,项目名称:scapy,代码行数:7,代码来源:crypto.py
示例20: getmacbyip
def getmacbyip(ip, chainCC=0):
"""Return MAC address corresponding to a given IP address"""
if isinstance(ip, Net):
ip = next(iter(ip))
ip = inet_ntoa(inet_aton(ip))
tmp = [orb(e) for e in inet_aton(ip)]
if (tmp[0] & 0xf0) == 0xe0: # mcast @
return "01:00:5e:%.2x:%.2x:%.2x" % (tmp[1] & 0x7f, tmp[2], tmp[3])
iff, _, gw = conf.route.route(ip)
if ((iff == consts.LOOPBACK_INTERFACE) or (ip == conf.route.get_if_bcast(iff))): # noqa: E501
return "ff:ff:ff:ff:ff:ff"
if gw != "0.0.0.0":
ip = gw
mac = conf.netcache.arp_cache.get(ip)
if mac:
return mac
res = srp1(Ether(dst=ETHER_BROADCAST) / ARP(op="who-has", pdst=ip),
type=ETH_P_ARP,
iface=iff,
timeout=2,
verbose=0,
chainCC=chainCC,
nofilter=1)
if res is not None:
mac = res.payload.hwsrc
conf.netcache.arp_cache[ip] = mac
return mac
return None
开发者ID:plorinquer,项目名称:scapy,代码行数:30,代码来源:l2.py
注:本文中的scapy.compat.orb函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论