-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
Brief description
When making up SNMP packets using scapy and call packet.build(), an ValueError occurred.
In [1]: from scapy.all import *
In [2]: snmp_set_packet = SNMP(version=0, community='public', PDU=SNMPset(varbindlist=[SNMPvarbind(oid=ASN1_OID("1.3.6.1.2
...: .1.1.4.0"), value=RandBin())]))
In [3]: snmp_set_packet.build()
# ... something omitted
/usr/local/lib/python3.5/dist-packages/scapy/asn1/ber.py in enc(cls, s)
295 @classmethod
296 def enc(cls, s):
297 if isinstance(s, six.string_types):
298 return BERcodec_STRING.enc(s)
299 else:
--> 300 return BERcodec_INTEGER.enc(int(s))
301
302
ValueError: invalid literal for int() with base 10: b'(U\x1f\xe1t\xe7\xc0\xec\x8f9\x96<\xce~\r\xe8\x8eh\xb5\x1atq\x10}Q\x8a\x9d\x96\\\xeeq\xe7\xfb*\x8b\x98\xa1]\x06\xc1\x93\x9d\x06\x1d\x87\x83)\x88\xd8\x9eOxj\x19\xdd\xce\xd5\xa1\x03my\x81\xe9\xfa\x07\xthe string_types in six module is as follows. In py3 env, the type of data is bytes instead of str. So maybe use if isinstance(s, six.binary_type) instead, or add another condition?
if PY3:
string_types = str,
integer_types = int,
class_types = type,
text_type = str
binary_type = bytes
MAXSIZE = sys.maxsize
else:
string_types = basestring,
integer_types = (int, long)
class_types = (type, types.ClassType)
text_type = unicode
binary_type = strEnvironment
- Scapy version: 2.4.2
- Python version: 3.5
- Operating System: Ubuntu 16.04