Ticket #99: snmptrapv1-scapy.diff
| File snmptrapv1-scapy.diff, 4.2 kB (added by Dirk Loss, 9 months ago) |
|---|
-
a/scapy.py
old new 1841 1841 UNIVERSAL_STRING = 28 1842 1842 CHAR_STRING = 29 1843 1843 BMP_STRING = 30 1844 IPADDRESS = 0x40 1844 1845 COUNTER32 = 0x41 1845 1846 TIME_TICKS = 0x43 1846 1847 … … 1921 1922 class ASN1_VIDEOTEX_STRING(ASN1_STRING): 1922 1923 tag = ASN1_Class_UNIVERSAL.VIDEOTEX_STRING 1923 1924 1925 class ASN1_IPADDRESS(ASN1_STRING): 1926 tag = ASN1_Class_UNIVERSAL.IPADDRESS 1927 1924 1928 class ASN1_UTC_TIME(ASN1_STRING): 1925 1929 tag = ASN1_Class_UNIVERSAL.UTC_TIME 1926 1930 … … 1968 1972 1969 1973 class BER_Exception(Exception): 1970 1974 pass 1975 1976 class BER_Encoding_Error(ASN1_Encoding_Error): 1977 def __init__(self, msg, encoded=None, remaining=None): 1978 Exception.__init__(self, msg) 1979 self.remaining = remaining 1980 self.encoded = encoded 1981 def __str__(self): 1982 s = Exception.__str__(self) 1983 if isinstance(self.encoded, BERcodec_Object): 1984 s+="\n### Already encoded ###\n%s" % self.encoded.strshow() 1985 else: 1986 s+="\n### Already encoded ###\n%r" % self.encoded 1987 s+="\n### Remaining ###\n%r" % self.remaining 1988 return s 1971 1989 1972 1990 class BER_Decoding_Error(ASN1_Decoding_Error): 1973 1991 def __init__(self, msg, decoded=None, remaining=None): … … 2189 2207 2190 2208 class BERcodec_IA5_STRING(BERcodec_STRING): 2191 2209 tag = ASN1_Class_UNIVERSAL.IA5_STRING 2210 2211 class BERcodec_IPADDRESS(BERcodec_STRING): 2212 tag = ASN1_Class_UNIVERSAL.IPADDRESS 2213 2214 @classmethod 2215 def enc(cls, ipaddr_ascii): 2216 try: 2217 s = inet_aton(ipaddr_ascii) 2218 except Exception: 2219 raise BER_Encoding_Error("IPv4 address could not be encoded") 2220 return chr(cls.tag)+BER_len_enc(len(s))+s 2221 2222 @classmethod 2223 def do_dec(cls, s, context=None, safe=False): 2224 l,s,t = cls.check_type_check_len(s) 2225 try: 2226 ipaddr_ascii = inet_ntoa(s) 2227 except Exception: 2228 raise BER_Decoding_Error("IP address could not be decoded", decoded=obj) 2229 return cls.asn1_object(ipaddr_ascii), t 2192 2230 2193 2231 class BERcodec_UTC_TIME(BERcodec_STRING): 2194 2232 tag = ASN1_Class_UNIVERSAL.UTC_TIME … … 4985 5023 4986 5024 class ASN1F_BIT_STRING(ASN1F_STRING): 4987 5025 ASN1_tag = ASN1_Class_UNIVERSAL.BIT_STRING 5026 5027 class ASN1F_IPADDRESS(ASN1F_STRING): 5028 ASN1_tag = ASN1_Class_UNIVERSAL.IPADDRESS 5029 5030 class ASN1F_TIME_TICKS(ASN1F_INTEGER): 5031 ASN1_tag = ASN1_Class_UNIVERSAL.TIME_TICKS 4988 5032 4989 5033 class ASN1F_UTC_TIME(ASN1F_STRING): 4990 5034 ASN1_tag = ASN1_Class_UNIVERSAL.UTC_TIME … … 9334 9378 9335 9379 class SNMPtrapv1(ASN1_Packet): 9336 9380 ASN1_codec = ASN1_Codecs.BER 9337 ASN1_root = ASN1F_SNMP_PDU_TRAPv1( ASN1F_INTEGER("id",0), 9338 ASN1F_OID("enterprise", "1.3"), 9339 ASN1F_STRING("agent_addr",""), 9381 ASN1_root = ASN1F_SNMP_PDU_TRAPv1( ASN1F_OID("enterprise", "1.3"), 9382 ASN1F_IPADDRESS("agent_addr",""), 9340 9383 ASN1F_enum_INTEGER("generic_trap", 0, SNMP_trap_types), 9341 9384 ASN1F_INTEGER("specific_trap", 0), 9342 ASN1F_ INTEGER("time_stamp", IntAutoTime()),9385 ASN1F_TIME_TICKS("time_stamp", IntAutoTime()), 9343 9386 ASN1F_SEQUENCE_OF("varbindlist", [], SNMPvarbind) 9344 9387 ) 9345 9388 … … 9591 9634 bind_layers( UDP, L2TP, sport=1701, dport=1701) 9592 9635 bind_layers( UDP, SNMP, sport=161) 9593 9636 bind_layers( UDP, SNMP, dport=161) 9637 bind_layers( UDP, SNMP, sport=162) 9638 bind_layers( UDP, SNMP, dport=162) 9594 9639 bind_layers( UDP, MGCP, dport=2727) 9595 9640 bind_layers( UDP, MGCP, sport=2727) 9596 9641 bind_layers( UDP, DNS, dport=53)