1
2
3 """Network Basic Input/Output System."""
4 from __future__ import absolute_import
5
6 import struct
7
8 from . import dpkt
9 from . import dns
10
11
13 """Return the NetBIOS first-level encoded name."""
14 l = []
15 for c in struct.pack('16s', name):
16 c = ord(c)
17 l.append(chr((c >> 4) + 0x41))
18 l.append(chr((c & 0xf) + 0x41))
19 return ''.join(l)
20
21
23 """Return the NetBIOS first-level decoded nbname."""
24 if len(nbname) != 32:
25 return nbname
26 l = []
27 for i in range(0, 32, 2):
28 l.append(chr(((ord(nbname[i]) - 0x41) << 4) |
29 ((ord(nbname[i + 1]) - 0x41) & 0xf)))
30 return ''.join(l).split('\x00', 1)[0]
31
32
33 NS_A = 0x01
34 NS_NS = 0x02
35 NS_NULL = 0x0A
36 NS_NB = 0x20
37 NS_NBSTAT = 0x21
38
39
40 NS_IN = 1
41
42
43 NS_NAME_G = 0x8000
44 NS_NAME_DRG = 0x1000
45 NS_NAME_CNF = 0x0800
46 NS_NAME_ACT = 0x0400
47 NS_NAME_PRM = 0x0200
48
49
50 nbstat_svcs = {
51
52 (0x00, 0): [('', 'Domain Name')],
53 (0x00, 1): [('IS~', 'IIS'), ('', 'Workstation Service')],
54 (0x01, 0): [('__MSBROWSE__', 'Master Browser')],
55 (0x01, 1): [('', 'Messenger Service')],
56 (0x03, 1): [('', 'Messenger Service')],
57 (0x06, 1): [('', 'RAS Server Service')],
58 (0x1B, 1): [('', 'Domain Master Browser')],
59 (0x1C, 0): [('INet~Services', 'IIS'), ('', 'Domain Controllers')],
60 (0x1D, 1): [('', 'Master Browser')],
61 (0x1E, 0): [('', 'Browser Service Elections')],
62 (0x1F, 1): [('', 'NetDDE Service')],
63 (0x20, 1): [('Forte_$ND800ZA', 'DCA IrmaLan Gateway Server Service'),
64 ('', 'File Server Service')],
65 (0x21, 1): [('', 'RAS Client Service')],
66 (0x22, 1): [('', 'Microsoft Exchange Interchange(MSMail Connector)')],
67 (0x23, 1): [('', 'Microsoft Exchange Store')],
68 (0x24, 1): [('', 'Microsoft Exchange Directory')],
69 (0x2B, 1): [('', 'Lotus Notes Server Service')],
70 (0x2F, 0): [('IRISMULTICAST', 'Lotus Notes')],
71 (0x30, 1): [('', 'Modem Sharing Server Service')],
72 (0x31, 1): [('', 'Modem Sharing Client Service')],
73 (0x33, 0): [('IRISNAMESERVER', 'Lotus Notes')],
74 (0x43, 1): [('', 'SMS Clients Remote Control')],
75 (0x44, 1): [('', 'SMS Administrators Remote Control Tool')],
76 (0x45, 1): [('', 'SMS Clients Remote Chat')],
77 (0x46, 1): [('', 'SMS Clients Remote Transfer')],
78 (0x4C, 1): [('', 'DEC Pathworks TCPIP service on Windows NT')],
79 (0x52, 1): [('', 'DEC Pathworks TCPIP service on Windows NT')],
80 (0x87, 1): [('', 'Microsoft Exchange MTA')],
81 (0x6A, 1): [('', 'Microsoft Exchange IMC')],
82 (0xBE, 1): [('', 'Network Monitor Agent')],
83 (0xBF, 1): [('', 'Network Monitor Application')]
84 }
85
86
97
98
100 """NetBIOS Name Service."""
101
102 - class Q(dns.DNS.Q):
104
105 - class RR(dns.DNS.RR):
106 """NetBIOS resource record."""
107
123
124
127
131
132
134 """NetBIOS Session Service."""
135 __hdr__ = (
136 ('type', 'B', 0),
137 ('flags', 'B', 0),
138 ('len', 'H', 0)
139 )
140
141
142 SSN_MESSAGE = 0
143 SSN_REQUEST = 1
144 SSN_POSITIVE = 2
145 SSN_NEGATIVE = 3
146 SSN_RETARGET = 4
147 SSN_KEEPALIVE = 5
148
149
151 """NetBIOS Datagram Service."""
152 __hdr__ = (
153 ('type', 'B', 0),
154 ('flags', 'B', 0),
155 ('id', 'H', 0),
156 ('src', 'I', 0),
157 ('sport', 'H', 0),
158 ('len', 'H', 0),
159 ('off', 'H', 0)
160 )
161
162
163 DGRAM_UNIQUE = 0x10
164 DGRAM_GROUP = 0x11
165 DGRAM_BROADCAST = 0x12
166 DGRAM_ERROR = 0x13
167 DGRAM_QUERY = 0x14
168 DGRAM_POSITIVE = 0x15
169 DGRAM_NEGATIVE = 0x16
170