#!/usr/bin/env ruby # Copyright (C) 2007 Sylvain SARMEJEANNE # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2. # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. module Scruby # Track dissectors @@dissectors = {} def Scruby.register_dissector(cls) @@dissectors[cls.to_s.split('::')[-1]] = cls end def Scruby.dissectors @@dissectors end def Scruby.get_dissector(d) if(@@dissectors[d]) return @@dissectors[d] end d = d.split('::')[-1] @@dissectors[d] end # Dissector for Ethernet class Ether1, "is-at"=>2, "RARP-req"=>3, "RARP-rep"=>4, "Dyn-RARP-req"=>5, "Dyn-RAR-rep"=>6, "Dyn-RARP-err"=>7, "InARP-req"=>8, "InARP-rep"=>9} def init @protocol = 'ARP' @fields_desc = [ XShortField("hwtype", 0x0001), XShortEnumField("ptype", ETHERTYPE_IPv4, ETHERTYPE_ALL), ByteField("hwlen", 6), ByteField("plen", 4), ShortField("op", @@request["who-has"]), MACField("hwsrc", '00:00:00:00:00:00'), IPField("psrc", '127.0.0.1'), MACField("hwdst", '00:00:00:00:00:00'), IPField("pdst", '127.0.0.1') ] end def pre_send(underlayer, payload) if underlayer.is_a?(Ether) underlayer.type = ETHERTYPE_ARP end end end # Dissector for IPv4 class IP -8 } ), FlagsField('present', 0, 32, RADIOTAP_PRESENT), StrLenField('radiotap', '', 'len') ] end end # Dot11 dissectors class Dot11 [ ['type', ETHERTYPE_IPv4, IP], ['type', ETHERTYPE_ARP, ARP] ], 'RadioTap' => [ [BIND_ALWAYS, BIND_ALWAYS, Dot11] ], 'Prism' => [ [BIND_ALWAYS, BIND_ALWAYS, Dot11] ], 'Dot11' => [ ['type', 2, LLC], ['subtype', 0, Dot11AssoReq], ['subtype', 1, Dot11AssoResp], ['subtype', 2, Dot11ReassoReq], ['subtype', 3, Dot11ReassoResp], ['subtype', 4, Dot11ProbeReq], ['subtype', 5, Dot11ProbeResp], ['subtype', 8, Dot11Beacon], ['subtype', 9, Dot11ATIM], ['subtype', 10, Dot11Disas], ['subtype', 11, Dot11Auth], ['subtype', 12, Dot11Deauth], ], 'Dot11QoS' => [ [BIND_ALWAYS, BIND_ALWAYS, LLC] ], 'Dot11Beacon' => [ [BIND_ALWAYS, BIND_ALWAYS, Dot11Elt] ], 'Dot11AssoReq' => [ [BIND_ALWAYS, BIND_ALWAYS, Dot11Elt] ], 'Dot11AssoResp' => [ [BIND_ALWAYS, BIND_ALWAYS, Dot11Elt] ], 'Dot11ReassoReq' => [ [BIND_ALWAYS, BIND_ALWAYS, Dot11Elt] ], 'Dot11ReassoResp' => [ [BIND_ALWAYS, BIND_ALWAYS, Dot11Elt] ], 'Dot11ProbeReq' => [ [BIND_ALWAYS, BIND_ALWAYS, Dot11Elt] ], 'Dot11ProbeResp' => [ [BIND_ALWAYS, BIND_ALWAYS, Dot11Elt] ], 'Dot11Auth' => [ [BIND_ALWAYS, BIND_ALWAYS, Dot11Elt] ], 'Dot11Elt' => [ [BIND_ALWAYS, BIND_ALWAYS, Dot11Elt] ], 'ClassicBSDLoopback' => [ ['header', BSDLOOPBACKTYPE_IPv4, IP] ], 'OpenBSDLoopback' => [ ['header', BSDLOOPBACKTYPE_IPv4, IP] ], 'IP' => [ ['proto', IPPROTO_ICMP, ICMP], ['proto', IPPROTO_TCP, TCP], ['proto', IPPROTO_UDP, UDP] ], } def self.layer_bounds @@layer_bounds end def Scruby.linklayer_dissector(datalink, pkt) case datalink when Pcap::DLT_EN10MB Ether(pkt) when Pcap::DLT_NULL ClassicBSDLoopback(pkt) when DLT_OPENBSD OpenBSDLoopback(pkt) when Pcap::DLT_PRISM_HEADER Prism(pkt) when Pcap::DLT_IEEE802 when Pcap::DLT_IEEE802_11 Dot11(pkt) when Pcap::DLT_IEEE802_11_RADIO RadioTap(pkt) when Pcap::DLT_IEEE802_11_RADIO_AVS RadioTap(pkt) when 101, IP(pkt) else nil end end end =begin Scruby packet dissectors/types: =============================== ANI ARP ClassicBSDLoopback Ether ICMP IP OpenBSDLoopback RIFF Raw TCP UDP LLC ARP Prism Dot11 Dot11Beacon Dot11Elt Dot11ATIM Dot11Disas Dot11AssoReq Dot11AssoResp Dot11ReassoReq Dot11ReassoResp Dot11ProbeReq Dot11ProbeResp Dot11Auth Dot11Deauth Dot11WEP Scapy (1.2.0.1) packet dissectors/types: ======================================== Raw Padding Ether PPPoE PPPoED Dot3 LLC CookedLinux SNAP Dot1Q RadioTap STP EAPOL EAP ARP IP TCP UDP ICMP IPerror TCPerror UDPerror ICMPerror IPv6 _IPv6OptionHeader PPP DNS DNSQR DNSRR BOOTP DHCPOptionsField DHCP Dot11 Dot11Beacon Dot11Elt Dot11ATIM Dot11Disas Dot11AssoReq Dot11AssoResp Dot11ReassoReq Dot11ReassoResp Dot11ProbeReq Dot11ProbeResp Dot11Auth Dot11Deauth Dot11WEP PrismHeader HSRP NTP GRE Radius RIP RIPEntry ISAKMP_class ISAKMP ISAKMP_payload_Transform ISAKMP_payload_Proposal ISAKMP_payload ISAKMP_payload_VendorID ISAKMP_payload_SA ISAKMP_payload_Nonce ISAKMP_payload_KE ISAKMP_payload_ID ISAKMP_payload_Hash Skinny RTP SebekHead SebekV1 SebekV3 SebekV2 SebekV3Sock SebekV2Sock MGCP GPRS HCI_Hdr HCI_ACL_Hdr L2CAP_Hdr L2CAP_CmdHdr L2CAP_ConnReq L2CAP_ConnResp L2CAP_CmdRej L2CAP_ConfReq L2CAP_ConfResp L2CAP_DisconnReq L2CAP_DisconnResp L2CAP_InfoReq L2CAP_InfoResp NetBIOS_DS IrLAPHead IrLAPCommand IrLMP NBNSQueryRequest NBNSRequest NBNSQueryResponse NBNSQueryResponseNegative NBNSNodeStatusResponse NBNSNodeStatusResponseService NBNSNodeStatusResponseEnd NBNSWackResponse NBTDatagram NBTSession SMBNetlogon_Protocol_Response_Header SMBMailSlot SMBNetlogon_Protocol_Response_Tail_SAM SMBNetlogon_Protocol_Response_Tail_LM20 SMBNegociate_Protocol_Request_Header SMBNegociate_Protocol_Request_Tail SMBNegociate_Protocol_Response_Advanced_Security SMBNegociate_Protocol_Response_No_Security SMBNegociate_Protocol_Response_No_Security_No_Key SMBSession_Setup_AndX_Request SMBSession_Setup_AndX_Response MobileIP MobileIPRRQ MobileIPRRP MobileIPTunnelData NetflowHeader NetflowHeaderV1 NetflowRecordV1 TFTP TFTP_RRQ TFTP_WRQ TFTP_DATA TFTP_Option TFTP_Options TFTP_ACK TFTP_ERROR TFTP_OACK ASN1_Class_SNMP ASN1_SNMP_PDU_GET ASN1_SNMP_PDU_NEXT ASN1_SNMP_PDU_RESPONSE ASN1_SNMP_PDU_SET ASN1_SNMP_PDU_TRAPv1 ASN1_SNMP_PDU_BULK ASN1_SNMP_PDU_INFORM ASN1_SNMP_PDU_TRAPv2 BERcodec_SNMP_PDU_GET BERcodec_SNMP_PDU_NEXT BERcodec_SNMP_PDU_RESPONSE BERcodec_SNMP_PDU_SET BERcodec_SNMP_PDU_TRAPv1 BERcodec_SNMP_PDU_BULK BERcodec_SNMP_PDU_INFORM BERcodec_SNMP_PDU_TRAPv2 ASN1F_SNMP_PDU_GET ASN1F_SNMP_PDU_NEXT ASN1F_SNMP_PDU_RESPONSE ASN1F_SNMP_PDU_SET ASN1F_SNMP_PDU_TRAPv1 ASN1F_SNMP_PDU_BULK ASN1F_SNMP_PDU_INFORM ASN1F_SNMP_PDU_TRAPv2 SNMPvarbind SNMPget SNMPnext SNMPresponse SNMPset SNMPtrapv1 SNMPbulk SNMPinform SNMPtrapv2 SNMP Scapy layer binding: ==================== bind_layers( Dot3, LLC, ) bind_layers( GPRS, IP, ) bind_layers( PrismHeader, Dot11, ) bind_layers( RadioTap, Dot11, ) bind_layers( Dot11, LLC, type=2) bind_layers( PPP, IP, proto=33) bind_layers( Ether, LLC, type=122) bind_layers( Ether, Dot1Q, type=33024) bind_layers( Ether, Ether, type=1) bind_layers( Ether, ARP, type=2054) bind_layers( Ether, IP, type=2048) bind_layers( Ether, EAPOL, type=34958) bind_layers( Ether, EAPOL, dst='01:80:c2:00:00:03', type=34958) bind_layers( Ether, PPPoED, type=34915) bind_layers( Ether, PPPoE, type=34916) bind_layers( CookedLinux, LLC, proto=122) bind_layers( CookedLinux, Dot1Q, proto=33024) bind_layers( CookedLinux, Ether, proto=1) bind_layers( CookedLinux, ARP, proto=2054) bind_layers( CookedLinux, IP, proto=2048) bind_layers( CookedLinux, EAPOL, proto=34958) bind_layers( CookedLinux, PPPoED, proto=34915) bind_layers( CookedLinux, PPPoE, proto=34916) bind_layers( GRE, LLC, proto=122) bind_layers( GRE, Dot1Q, proto=33024) bind_layers( GRE, Ether, proto=1) bind_layers( GRE, ARP, proto=2054) bind_layers( GRE, IP, proto=2048) bind_layers( GRE, EAPOL, proto=34958) bind_layers( PPPoE, PPP, code=0) bind_layers( EAPOL, EAP, type=0) bind_layers( LLC, STP, dsap=66, ssap=66, ctrl=3) bind_layers( LLC, SNAP, dsap=170, ssap=170, ctrl=3) bind_layers( SNAP, Dot1Q, code=33024) bind_layers( SNAP, Ether, code=1) bind_layers( SNAP, ARP, code=2054) bind_layers( SNAP, IP, code=2048) bind_layers( SNAP, EAPOL, code=34958) bind_layers( SNAP, STP, code=267) bind_layers( IPerror, IPerror, frag=0, proto=4) bind_layers( IPerror, ICMPerror, frag=0, proto=1) bind_layers( IPerror, TCPerror, frag=0, proto=6) bind_layers( IPerror, UDPerror, frag=0, proto=17) bind_layers( IP, IP, frag=0, proto=4) bind_layers( IP, ICMP, frag=0, proto=1) bind_layers( IP, TCP, frag=0, proto=6) bind_layers( IP, UDP, frag=0, proto=17) bind_layers( IP, GRE, frag=0, proto=47) bind_layers( UDP, SNMP, sport=161) bind_layers( UDP, SNMP, dport=161) bind_layers( UDP, MGCP, dport=2727) bind_layers( UDP, MGCP, sport=2727) bind_layers( UDP, DNS, dport=53) bind_layers( UDP, DNS, sport=53) bind_layers( UDP, ISAKMP, dport=500, sport=500) bind_layers( UDP, HSRP, dport=1985, sport=1985) bind_layers( UDP, NTP, dport=123, sport=123) bind_layers( UDP, BOOTP, dport=67, sport=68) bind_layers( UDP, BOOTP, dport=68, sport=67) bind_layers( BOOTP, DHCP, options='c\x82Sc') bind_layers( UDP, RIP, sport=520) bind_layers( UDP, RIP, dport=520) bind_layers( RIP, RIPEntry, ) bind_layers( RIPEntry, RIPEntry, ) bind_layers( Dot11, Dot11AssoReq, subtype=0, type=0) bind_layers( Dot11, Dot11AssoResp, subtype=1, type=0) bind_layers( Dot11, Dot11ReassoReq, subtype=2, type=0) bind_layers( Dot11, Dot11ReassoResp, subtype=3, type=0) bind_layers( Dot11, Dot11ProbeReq, subtype=4, type=0) bind_layers( Dot11, Dot11ProbeResp, subtype=5, type=0) bind_layers( Dot11, Dot11Beacon, subtype=8, type=0) bind_layers( Dot11, Dot11ATIM, subtype=9, type=0) bind_layers( Dot11, Dot11Disas, subtype=10, type=0) bind_layers( Dot11, Dot11Auth, subtype=11, type=0) bind_layers( Dot11, Dot11Deauth, subtype=12, type=0) bind_layers( Dot11Beacon, Dot11Elt, ) bind_layers( Dot11AssoReq, Dot11Elt, ) bind_layers( Dot11AssoResp, Dot11Elt, ) bind_layers( Dot11ReassoReq, Dot11Elt, ) bind_layers( Dot11ReassoResp, Dot11Elt, ) bind_layers( Dot11ProbeReq, Dot11Elt, ) bind_layers( Dot11ProbeResp, Dot11Elt, ) bind_layers( Dot11Auth, Dot11Elt, ) bind_layers( Dot11Elt, Dot11Elt, ) bind_layers( TCP, Skinny, dport=2000) bind_layers( TCP, Skinny, sport=2000) bind_layers( UDP, SebekHead, sport=1101) bind_layers( UDP, SebekHead, dport=1101) bind_layers( UDP, SebekHead, dport=1101, sport=1101) bind_layers( SebekHead, SebekV1, version=1) bind_layers( SebekHead, SebekV2Sock, version=2, type=2) bind_layers( SebekHead, SebekV2, version=2) bind_layers( SebekHead, SebekV3Sock, version=3, type=2) bind_layers( SebekHead, SebekV3, version=3) bind_layers( CookedLinux, IrLAPHead, proto=23) bind_layers( IrLAPHead, IrLAPCommand, Type=1) bind_layers( IrLAPCommand, IrLMP, ) bind_layers( UDP, NBNSQueryRequest, dport=137) bind_layers( UDP, NBNSRequest, dport=137) bind_layers( UDP, NBNSQueryResponse, sport=137) bind_layers( UDP, NBNSQueryResponseNegative, sport=137) bind_layers( UDP, NBNSNodeStatusResponse, sport=137) bind_layers( NBNSNodeStatusResponse, NBNSNodeStatusResponseService, ) bind_layers( NBNSNodeStatusResponse, NBNSNodeStatusResponseService, ) bind_layers( NBNSNodeStatusResponseService, NBNSNodeStatusResponseService, ) bind_layers( NBNSNodeStatusResponseService, NBNSNodeStatusResponseEnd, ) bind_layers( UDP, NBNSWackResponse, sport=137) bind_layers( UDP, NBTDatagram, dport=138) bind_layers( TCP, NBTSession, dport=139) bind_layers( NBTSession, SMBNegociate_Protocol_Request_Header, ) bind_layers( SMBNegociate_Protocol_Request_Header, SMBNegociate_Protocol_Request_Tail, ) bind_layers( SMBNegociate_Protocol_Request_Tail, SMBNegociate_Protocol_Request_Tail, ) bind_layers( NBTSession, SMBNegociate_Protocol_Response_Advanced_Security, ExtendedSecurity=1) bind_layers( NBTSession, SMBNegociate_Protocol_Response_No_Security, ExtendedSecurity=0, EncryptionKeyLength=8) bind_layers( NBTSession, SMBNegociate_Protocol_Response_No_Security_No_Key, ExtendedSecurity=0, EncryptionKeyLength=0) bind_layers( NBTSession, SMBSession_Setup_AndX_Request, ) bind_layers( NBTSession, SMBSession_Setup_AndX_Response, ) bind_layers( HCI_Hdr, HCI_ACL_Hdr, type=2) bind_layers( HCI_Hdr, Raw, ) bind_layers( HCI_ACL_Hdr, L2CAP_Hdr, ) bind_layers( L2CAP_Hdr, L2CAP_CmdHdr, cid=1) bind_layers( L2CAP_CmdHdr, L2CAP_CmdRej, code=1) bind_layers( L2CAP_CmdHdr, L2CAP_ConnReq, code=2) bind_layers( L2CAP_CmdHdr, L2CAP_ConnResp, code=3) bind_layers( L2CAP_CmdHdr, L2CAP_ConfReq, code=4) bind_layers( L2CAP_CmdHdr, L2CAP_ConfResp, code=5) bind_layers( L2CAP_CmdHdr, L2CAP_DisconnReq, code=6) bind_layers( L2CAP_CmdHdr, L2CAP_DisconnResp, code=7) bind_layers( L2CAP_CmdHdr, L2CAP_InfoReq, code=10) bind_layers( L2CAP_CmdHdr, L2CAP_InfoResp, code=11) bind_layers( UDP, MobileIP, sport=434) bind_layers( UDP, MobileIP, dport=434) bind_layers( MobileIP, MobileIPRRQ, type=1) bind_layers( MobileIP, MobileIPRRP, type=3) bind_layers( MobileIP, MobileIPTunnelData, type=4) bind_layers( MobileIPTunnelData, IP, nexthdr=4) bind_layers( NetflowHeader, NetflowHeaderV1, version=1) bind_layers( NetflowHeaderV1, NetflowRecordV1, ) bind_layers(UDP, TFTP, dport=69) bind_layers(TFTP, TFTP_RRQ, op=1) bind_layers(TFTP, TFTP_WRQ, op=2) bind_layers(TFTP, TFTP_DATA, op=3) bind_layers(TFTP, TFTP_ACK, op=4) bind_layers(TFTP, TFTP_ERROR, op=5) bind_layers(TFTP, TFTP_OACK, op=6) bind_layers(TFTP_RRQ, TFTP_Options) bind_layers(TFTP_WRQ, TFTP_Options) bind_layers(TFTP_OACK, TFTP_Options) =end