U v`M' @sdZddlmZddlZddlmZddlmZddlmZdd Z d d Z dZ d Z d Z dZdZdZdZdZdZdZdZdgddgdgdgdgdgdgddgdgdgd gd!d"gd#gd$gd%gd&gd'gd(gd)gd*gd+gd,gd-gd.gd/gd0gd0gd1gd2gd3gd4gd5Zd6d7ZGd8d9d9ejZGd:d;d;ejZdZdZd ZdZ!Gd?d@d@ejZ"dAZ#dBZ$dCZ%dDZ&dEZ'dFZ(dGZ)dHdIZ*dJdKZ+dLdMZ,dNdOZ-dPdQZ.dRdSZ/dTdUZ0dS)Vz"Network Basic Input/Output System.)absolute_importN)dpkt)dns) compat_ordcCsXg}td|D]8}t|}|t|d?d|t|d@dqd|S)a Return the NetBIOS first-level encoded name. 14.1. FIRST LEVEL ENCODING The first level representation consists of two parts: - NetBIOS name - NetBIOS scope identifier The 16 byte NetBIOS name is mapped into a 32 byte wide field using a reversible, half-ASCII, biased encoding. Each half-octet of the NetBIOS name is encoded into one byte of the 32 byte field. The first half octet is encoded into the first byte, the second half- octet into the second byte, etc. Each 4-bit, half-octet of the NetBIOS name is treated as an 8-bit, right-adjusted, zero-filled binary number. This number is added to value of the ASCII character 'A' (hexidecimal 41). The resulting 8- bit number is stored in the appropriate byte. The following diagram demonstrates this procedure: 0 1 2 3 4 5 6 7 +-+-+-+-+-+-+-+-+ |a b c d|w x y z| ORIGINAL BYTE +-+-+-+-+-+-+-+-+ | | +--------+ +--------+ | | SPLIT THE NIBBLES v v 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ |0 0 0 0 a b c d| |0 0 0 0 w x y z| +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ | | + + ADD 'A' | | 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ |0 1 0 0 0 0 0 1| |0 1 0 0 0 0 0 1| +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ This encoding results in a NetBIOS name being represented as a sequence of 32 ASCII, upper-case characters from the set {A,B,C...N,O,P}. The NetBIOS scope identifier is a valid domain name (without a leading dot). An ASCII dot (2E hexidecimal) and the scope identifier are appended to the encoded form of the NetBIOS name, the result forming a valid domain name. Z16sA)structpackencoderappendchrjoin)namel_crd/private/var/folders/0j/yyfkg7712236ncpm167bvylc27vst9/T/pip-unpacked-wheel-y9gppv54/dpkt/netbios.py encode_name s 7rc Csrt|dkr|Sg}tdddD]:}|tt||dd>t||ddd@Bq d|d ddS) z9 Return the NetBIOS first-level decoded nbname. rrrrr r )lenrangerrordrsplit)Znbnamerirrr decode_nameLs rr r!iiii)r z Domain Name)zIS~IIS)r Workstation Service)Z __MSBROWSE__Master Browser)r zMessenger Service)r zRAS Server Service)r zDomain Master Browser)z INet~Servicesr#)r zDomain Controllers)r r%)r zBrowser Service Elections)r zNetDDE Service)zForte_$ND800ZAz"DCA IrmaLan Gateway Server Service)r zFile Server Service)r zRAS Client Service)r z0Microsoft Exchange Interchange(MSMail Connector))r zMicrosoft Exchange Store)r zMicrosoft Exchange Directory)r zLotus Notes Server Service)Z IRISMULTICAST Lotus Notes)r zModem Sharing Server Service)r zModem Sharing Client Service)ZIRISNAMESERVERr&)r zSMS Clients Remote Control)r z&SMS Administrators Remote Control Tool)r zSMS Clients Remote Chat)r zSMS Clients Remote Transfer)r z)DEC Pathworks TCPIP service on Windows NT)r zMicrosoft Exchange MTA)r zMicrosoft Exchange IMC)r zNetwork Monitor Agent)r zNetwork Monitor Application))rr)rr)rr)rr)r)r)r)r)r)r)r)rr)r!r)"r)#r)$r)+r)/r)0r)1r)3r)Cr)Dr)Er)Fr)Lr)Rr)r)jr)r)rcCsb|\}}}z>t|t@dk}t||fD]\}}||r(|WSq(Wntk r\YnXdS)Nrr )int NS_NAME_G nbstat_svcs startswithKeyError)Zname_service_flagsrserviceflagsuniqueZnamepfxsvcnamerrrnode_to_service_names  rIc@s8eZdZdZGdddejjZGdddejjZdS)NSzQ NetBIOS Name Service. RFC1002: https://tools.ietf.org/html/rfc1002 c@s eZdZdS)zNS.QN)__name__ __module__ __qualname__rrrrQsrNc@s(eZdZdZedZejZddZ dS)zNS.RRaNetBIOS resource record. RFC1001: 14. REPRESENTATION OF NETBIOS NAMES NetBIOS names as seen across the client interface to NetBIOS are exactly 16 bytes long. Within the NetBIOS-over-TCP protocols, a longer representation is used. There are two levels of encoding. The first level maps a NetBIOS name into a domain system name. The second level maps the domain system name into the "compressed" representation required for interaction with the domain name system. Except in one packet, the second level representation is the only NetBIOS name representation used in NetBIOS-over-TCP packet formats. The exception is the RDATA field of a NODE STATUS RESPONSE packet. z>15s B HcsHjtkrj_n0jtkrDtjd}fddt|D_dS)Nrcs&g|]}jjd|jqS)r)_node_name_struct unpack_fromrdata_node_name_len).0idxselfrr s  z&NS.RR.unpack_rdata..)typeNS_ArQip NS_NBSTATrr nodenames)rVbufoffZ num_namesrrUr unpack_rdatas    zNS.RR.unpack_rdataN) rKrLrM__doc__r StructrOsizerRr_rrrrRRs rcN)rKrLrMr`rDNSrNrcrrrrrJsrJc@seZdZdZdZdS)SessionzNetBIOS Session Service.)rXBrrFrgrrHrNrKrLrMr`Z__hdr__rrrrresrer'rc@seZdZdZdZdS)DatagramzNetBIOS Datagram Service.)rfrh)idrjr)srcIr)Zsportrjrri)r^rjrNrkrrrrrmsrmcCs4tddksttddks ttddks0tdS)NThe NetBIOS name FEGIGFCAEOGFHEECEJEPFDCAGOGBGNGFzFRED Z EGFCEFEECACACACACACACACACACACACA* CKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)rAssertionErrorrrrrtest_encode_namesr}cCsDtddksttddks ttddks0ttddks@tdS)NryrxZ FEGHGFCAEOGFHEECEJEPFDCAHEGBGNGFzTge NetBIOS tamer{rzZ"CKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABB)rr|rrrrtest_decode_namesr~cCstd}|dkstdS)N)ISSrr"r$rIr|rHrrrtest_node_to_service_name srcCstd}|dkstdS)N)rr"r rrrrr"test_node_to_service_name_keyerrorsrc Cspddl}ddlm}t}|tt|W5QRX|dddddg}| |d|j |j kslt dS)Nr unhexlifyr Z01000100000000Z0000) pytestbinasciirrJrcZraisesNotImplementedErrorrrr_rZrQr|)rrrrr]rrrtest_rrs   rcCsfddlm}|ddddddg}d }tjt|d }|jtksDt||d|j d d gksbtdS) Nrrr A4141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141Z0033rrZ0004s%ABCDEFGHIJKLMNO/PQRSTUVWXYZABCDC)rXrQ)sABCDEFGHIJKLMNOr2i)sPQRSTUVWXYZABCDr6i) rrrrJrcr[rXr|r_r\)rr]rQrrrrtest_rr_nbstat%s(  rcCs.ddlm}t}|d}t||ks*tdS)NrrZ000001000000000000000000)rrrJbytesr|)rnscorrectrrrtest_ns@s  r)1r` __future__rr r rrcompatrrrrYZNS_NSZNS_NULLZNS_NBr[ZNS_INrAZ NS_NAME_DRGZ NS_NAME_CNFZ NS_NAME_ACTZ NS_NAME_PRMrBrIrdrJZPacketreZ SSN_MESSAGEZ SSN_REQUESTZ SSN_POSITIVEZ SSN_NEGATIVEZ SSN_RETARGETZ SSN_KEEPALIVErmZ DGRAM_UNIQUEZ DGRAM_GROUPZDGRAM_BROADCASTZ DGRAM_ERRORZ DGRAM_QUERYZDGRAM_POSITIVEZDGRAM_NEGATIVEr}r~rrrrrrrrrs    ?% .