mirror of https://github.com/secdev/scapy.git
Python 3: various fixes
This commit is contained in:
parent
e9d17e356b
commit
8e939eee9b
|
@ -94,8 +94,8 @@ def _exec_query_ps(cmd, fields):
|
|||
def _vbs_exec_code(code, split_tag="@"):
|
||||
if not conf.prog.cscript:
|
||||
raise OSError("Scapy could not detect cscript !")
|
||||
tmpfile = tempfile.NamedTemporaryFile(suffix=".vbs", delete=False)
|
||||
tmpfile.write(code)
|
||||
tmpfile = tempfile.NamedTemporaryFile(mode="wb", suffix=".vbs", delete=False)
|
||||
tmpfile.write(raw(code))
|
||||
tmpfile.close()
|
||||
ps = sp.Popen([conf.prog.cscript, tmpfile.name],
|
||||
stdout=sp.PIPE, stderr=open(os.devnull),
|
||||
|
@ -112,10 +112,10 @@ def _vbs_exec_code(code, split_tag="@"):
|
|||
def _vbs_get_hardware_iface_guid(devid):
|
||||
try:
|
||||
devid = str(int(devid) + 1)
|
||||
guid = iter(_vbs_exec_code("""WScript.Echo CreateObject("WScript.Shell").RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\\%s\\ServiceName")
|
||||
""" % devid)).next()
|
||||
guid = guid[:-1] if guid.endswith(b'}\n') else guid
|
||||
if guid.startswith(b'{') and guid.endswith(b'}'):
|
||||
guid = next(iter(_vbs_exec_code("""WScript.Echo CreateObject("WScript.Shell").RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\\%s\\ServiceName")
|
||||
""" % devid)))
|
||||
guid = guid[:-1] if guid.endswith('}\n') else guid
|
||||
if guid.startswith('{') and guid.endswith('}'):
|
||||
return guid
|
||||
except StopIteration:
|
||||
return None
|
||||
|
@ -180,7 +180,7 @@ Set line = wmi.Get("Win32_Service.Name='" & serviceName & "'")
|
|||
while True:
|
||||
yield [None if fld is None else
|
||||
_VBS_WMI_OUTPUT.get(cmd[1], {}).get(fld, lambda x: x)(
|
||||
values.next().strip()
|
||||
next(values).strip()
|
||||
)
|
||||
for fld in fields]
|
||||
|
||||
|
@ -393,7 +393,7 @@ class NetworkInterface(object):
|
|||
if not conf.use_npcap:
|
||||
raise OSError("This operation requires Npcap.")
|
||||
if self.raw80211 is None:
|
||||
dot11adapters = iter(_vbs_exec_code("""WScript.Echo CreateObject("WScript.Shell").RegRead("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\npcap\\Parameters\\Dot11Adapters")""")).next()
|
||||
dot11adapters = next(iter(_vbs_exec_code("""WScript.Echo CreateObject("WScript.Shell").RegRead("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\npcap\\Parameters\\Dot11Adapters")""")))
|
||||
self.raw80211 = ("\\Device\\" + self.guid).lower() in dot11adapters.lower()
|
||||
if not self.raw80211:
|
||||
raise Scapy_Exception("This interface does not support raw 802.11")
|
||||
|
@ -905,7 +905,7 @@ def _get_valid_guid():
|
|||
if scapy.consts.LOOPBACK_INTERFACE:
|
||||
return scapy.consts.LOOPBACK_INTERFACE.guid
|
||||
else:
|
||||
for i in IFACES:
|
||||
for i in six.itervalues(IFACES):
|
||||
if not i.is_invalid():
|
||||
return i.guid
|
||||
|
||||
|
|
|
@ -348,6 +348,7 @@ class SSLv2ClientMasterKey(_SSLv2Handshake):
|
|||
cs_val = self.cipher
|
||||
if cs_val not in _tls_cipher_suites_cls:
|
||||
warning("Unknown cipher suite %d from ClientMasterKey" % cs_val)
|
||||
cs_cls = None
|
||||
else:
|
||||
cs_cls = _tls_cipher_suites_cls[cs_val]
|
||||
|
||||
|
|
|
@ -36,6 +36,12 @@ from scapy.layers.tls.crypto.cipher_stream import Cipher_NULL
|
|||
from scapy.layers.tls.crypto.ciphers import CipherError
|
||||
from scapy.layers.tls.crypto.h_mac import HMACError
|
||||
|
||||
# Util
|
||||
def _tls_version_check(version, min):
|
||||
"""Returns if version >= min, or False if version == None"""
|
||||
if version == None:
|
||||
return False
|
||||
return version >= min
|
||||
|
||||
###############################################################################
|
||||
### TLS Record Protocol ###
|
||||
|
@ -119,7 +125,7 @@ class _TLSMsgListField(PacketListField):
|
|||
remain, ret = s[:l], s[l:]
|
||||
|
||||
if remain == b"":
|
||||
if ((pkt.tls_session.tls_version or 0x0303 > 0x0200) and
|
||||
if (((pkt.tls_session.tls_version or 0x0303) > 0x0200) and
|
||||
hasattr(pkt, "type") and pkt.type == 23):
|
||||
return ret, [TLSApplicationData(data=b"")]
|
||||
else:
|
||||
|
@ -183,7 +189,7 @@ class _TLSMsgListField(PacketListField):
|
|||
for p in val:
|
||||
res += self.i2m(pkt, p)
|
||||
if (isinstance(pkt, _GenericTLSSessionInheritance) and
|
||||
(pkt.tls_session.tls_version or 0x0303 >= 0x0304) and
|
||||
_tls_version_check(pkt.tls_session.tls_version, 0x0304) and
|
||||
not isinstance(pkt, TLS13ServerHello)):
|
||||
return s + res
|
||||
if not pkt.type:
|
||||
|
@ -278,7 +284,7 @@ class TLS(_GenericTLSSessionInheritance):
|
|||
return SSLv2
|
||||
else:
|
||||
s = kargs.get("tls_session", None)
|
||||
if s and s.tls_version >= 0x0304:
|
||||
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
|
||||
|
|
|
@ -74,7 +74,7 @@ a.show()
|
|||
= Complex HCI - L2CAP dissect
|
||||
a = HCI_Hdr(b'\x02\x00\x00\x11\x00\r\x00\x05\x00\x0b\x00\t\x00\x01\x00\x00\x00debug')
|
||||
assert a[L2CAP_InfoResp].result == 0
|
||||
assert a[L2CAP_InfoResp].data == "debug"
|
||||
assert a[L2CAP_InfoResp].data == b"debug"
|
||||
|
||||
= Answers
|
||||
a = HCI_Hdr(b'\x02\x00\x00\x0c\x00\x08\x00\x05\x00\x02\x00\x04\x00\x00\x00\x9a;')
|
||||
|
@ -91,7 +91,7 @@ assert not a.answers(b)
|
|||
a = HCI_Hdr()/HCI_Event_Hdr()/HCI_Event_LE_Meta()/HCI_LE_Meta_Advertising_Report(addr = "a1:b2:c3:d4:e5:f6", data=EIR_Hdr()/EIR_CompleteLocalName(local_name="scapy"))
|
||||
assert raw(a) == b'\x04>\x00\x02\x00\x00\x00\xf6\xe5\xd4\xc3\xb2\xa1\x07\x06\tscapy\x00'
|
||||
b = HCI_Hdr(raw(a))
|
||||
assert b.data[0][EIR_CompleteLocalName].local_name == "scapy"
|
||||
assert b.data[0][EIR_CompleteLocalName].local_name == b"scapy"
|
||||
assert b[HCI_LE_Meta_Advertising_Report].addr == "a1:b2:c3:d4:e5:f6"
|
||||
|
||||
assert a.summary() == "HCI Event / HCI_Event_Hdr / HCI_Event_LE_Meta / HCI_LE_Meta_Advertising_Report"
|
||||
|
|
|
@ -150,7 +150,7 @@ InterfaceMetric : 256
|
|||
# Test the function
|
||||
routes = _read_routes6_post2008()
|
||||
for r in routes:
|
||||
print r
|
||||
print(r)
|
||||
print(len(routes))
|
||||
assert(len(routes) == 9)
|
||||
assert(check_mandatory_ipv6_routes(routes))
|
||||
|
|
Loading…
Reference in New Issue