Changeset 876:d89fb130c10d

Show
Ignore:
Timestamp:
08/17/08 01:23:07 (3 months ago)
Author:
Phil <phil@secdev.org>
Message:

Fixed SNMPv1 traps (D. Loss, ticket #99)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • scapy/asn1/asn1.py

    r862 r876  
    160160    CHAR_STRING = 29 
    161161    BMP_STRING = 30 
     162    IPADDRESS = 0x40 
    162163    COUNTER32 = 0x41 
    163164    TIME_TICKS = 0x43 
     
    240241    tag = ASN1_Class_UNIVERSAL.VIDEOTEX_STRING 
    241242 
     243class ASN1_IPADDRESS(ASN1_STRING): 
     244    tag = ASN1_Class_UNIVERSAL.IPADDRESS 
     245 
    242246class ASN1_UTC_TIME(ASN1_STRING): 
    243247    tag = ASN1_Class_UNIVERSAL.UTC_TIME 
  • scapy/asn1/ber.py

    r862 r876  
    55 
    66from scapy.error import warning 
    7 from asn1 import ASN1_Decoding_Error,ASN1_BadTag_Decoding_Error,ASN1_Codecs,ASN1_Class_UNIVERSAL,ASN1_Error,ASN1_DECODING_ERROR,ASN1_BADTAG 
     7from asn1 import ASN1_Decoding_Error,ASN1_Encoding_Error,ASN1_BadTag_Decoding_Error,ASN1_Codecs,ASN1_Class_UNIVERSAL,ASN1_Error,ASN1_DECODING_ERROR,ASN1_BADTAG 
    88 
    99################## 
     
    1818class BER_Exception(Exception): 
    1919    pass 
     20 
     21class BER_Encoding_Error(ASN1_Encoding_Error): 
     22    def __init__(self, msg, encoded=None, remaining=None): 
     23        Exception.__init__(self, msg) 
     24        self.remaining = remaining 
     25        self.encoded = encoded 
     26    def __str__(self): 
     27        s = Exception.__str__(self) 
     28        if isinstance(self.encoded, BERcodec_Object): 
     29            s+="\n### Already encoded ###\n%s" % self.encoded.strshow() 
     30        else: 
     31            s+="\n### Already encoded ###\n%r" % self.encoded 
     32        s+="\n### Remaining ###\n%r" % self.remaining 
     33        return s 
    2034 
    2135class BER_Decoding_Error(ASN1_Decoding_Error): 
     
    240254    tag = ASN1_Class_UNIVERSAL.IA5_STRING 
    241255 
     256class BERcodec_IPADDRESS(BERcodec_STRING): 
     257    tag = ASN1_Class_UNIVERSAL.IPADDRESS 
     258     
     259    @classmethod 
     260    def enc(cls, ipaddr_ascii): 
     261        try: 
     262            s = inet_aton(ipaddr_ascii) 
     263        except Exception: 
     264            raise BER_Encoding_Error("IPv4 address could not be encoded")  
     265        return chr(cls.tag)+BER_len_enc(len(s))+s 
     266     
     267    @classmethod 
     268    def do_dec(cls, s, context=None, safe=False): 
     269        l,s,t = cls.check_type_check_len(s) 
     270        try: 
     271            ipaddr_ascii = inet_ntoa(s) 
     272        except Exception: 
     273            raise BER_Decoding_Error("IP address could not be decoded", decoded=obj) 
     274        return cls.asn1_object(ipaddr_ascii), t 
     275 
    242276class BERcodec_UTC_TIME(BERcodec_STRING): 
    243277    tag = ASN1_Class_UNIVERSAL.UTC_TIME 
  • scapy/asn1fields.py

    r862 r876  
    161161class ASN1F_BIT_STRING(ASN1F_STRING): 
    162162    ASN1_tag = ASN1_Class_UNIVERSAL.BIT_STRING 
     163     
     164class ASN1F_IPADDRESS(ASN1F_STRING): 
     165    ASN1_tag = ASN1_Class_UNIVERSAL.IPADDRESS     
     166 
     167class ASN1F_TIME_TICKS(ASN1F_INTEGER): 
     168    ASN1_tag = ASN1_Class_UNIVERSAL.TIME_TICKS 
    163169 
    164170class ASN1F_UTC_TIME(ASN1F_STRING): 
  • scapy/layers/snmp.py

    r862 r876  
    180180class SNMPtrapv1(ASN1_Packet): 
    181181    ASN1_codec = ASN1_Codecs.BER 
    182     ASN1_root = ASN1F_SNMP_PDU_TRAPv1( ASN1F_INTEGER("id",0), 
    183                                        ASN1F_OID("enterprise", "1.3"), 
    184                                        ASN1F_STRING("agent_addr",""), 
     182    ASN1_root = ASN1F_SNMP_PDU_TRAPv1( ASN1F_OID("enterprise", "1.3"), 
     183                                       ASN1F_IPADDRESS("agent_addr","0.0.0.0"), 
    185184                                       ASN1F_enum_INTEGER("generic_trap", 0, SNMP_trap_types), 
    186185                                       ASN1F_INTEGER("specific_trap", 0), 
    187                                        ASN1F_INTEGER("time_stamp", IntAutoTime()), 
     186                                       ASN1F_TIME_TICKS("time_stamp", IntAutoTime()), 
    188187                                       ASN1F_SEQUENCE_OF("varbindlist", [], SNMPvarbind) 
    189188                                       ) 
     
    232231bind_layers( UDP,           SNMP,          sport=161) 
    233232bind_layers( UDP,           SNMP,          dport=161) 
     233bind_layers( UDP,           SNMP,          sport=162)  
     234bind_layers( UDP,           SNMP,          dport=162)  
     235 
    234236def snmpwalk(dst, oid="1", community="public"): 
    235237    try: