Package dpkt :: Module smb
[hide private]
[frames] | no frames]

Source Code for Module dpkt.smb

  1  # $Id: smb.py 23 2006-11-08 15:45:33Z dugsong $ 
  2  # -*- coding: utf-8 -*- 
  3  """Server Message Block.""" 
  4  from __future__ import print_function 
  5  from __future__ import absolute_import 
  6   
  7  from . import dpkt 
  8   
  9   
 10  # https://msdn.microsoft.com/en-us/library/ee441774.aspx 
 11   
 12  SMB_FLAGS_LOCK_AND_READ_OK = 0x01 
 13  SMB_FLAGS_BUF_AVAIL = 0x02 
 14  SMB_FLAGS_CASE_INSENSITIVE = 0x08 
 15  SMB_FLAGS_CANONICALIZED_PATHS = 0x10 
 16  SMB_FLAGS_OPLOCK = 0x20 
 17  SMB_FLAGS_OPBATCH = 0x40 
 18  SMB_FLAGS_REPLY = 0x80 
 19   
 20  SMB_FLAGS2_LONG_NAMES = 0x0001 
 21  SMB_FLAGS2_EXTENDED_ATTRIBUTES = 0x0002 
 22  SMB_FLAGS2_SECURITY_SIGNATURES = 0x0004 
 23  SMB_FLAGS2_COMPRESSED = 0x0008 
 24  SMB_FLAGS2_SECURITY_SIGNATURES_REQUIRED = 0x0010 
 25  SMB_FLAGS2_IS_LONG_NAME = 0x0040 
 26  SMB_FLAGS2_REVERSE_PATH = 0x0400 
 27  SMB_FLAGS2_EXTENDED_SECURITY = 0x0800 
 28  SMB_FLAGS2_DFS = 0x1000 
 29  SMB_FLAGS2_PAGING_IO = 0x2000 
 30  SMB_FLAGS2_NT_STATUS = 0x4000 
 31  SMB_FLAGS2_UNICODE = 0x8000 
 32   
 33  SMB_STATUS_SUCCESS = 0x00000000 
34 35 36 -class SMB(dpkt.Packet):
37 """Server Message Block. 38 39 TODO: Longer class information.... 40 41 Attributes: 42 __hdr__ = [ 43 ('proto', '4s', b'\xffSMB'), 44 ('cmd', 'B', 0), 45 ('status', 'I', SMB_STATUS_SUCCESS), 46 ('flags', 'B', 0), 47 ('flags2', 'H', 0), 48 ('_pidhi', 'H', 0), 49 ('security', '8s', b''), 50 ('rsvd', 'H', 0), 51 ('tid', 'H', 0), 52 ('_pidlo', 'H', 0), 53 ('uid', 'H', 0), 54 ('mid', 'H', 0) 55 ] 56 """ 57 58 __byte_order__ = '<' 59 __hdr__ = [ 60 ('proto', '4s', b'\xffSMB'), 61 ('cmd', 'B', 0), 62 ('status', 'I', SMB_STATUS_SUCCESS), 63 ('flags', 'B', 0), 64 ('flags2', 'H', 0), 65 ('_pidhi', 'H', 0), 66 ('security', '8s', b''), 67 ('rsvd', 'H', 0), 68 ('tid', 'H', 0), 69 ('_pidlo', 'H', 0), 70 ('uid', 'H', 0), 71 ('mid', 'H', 0) 72 ] 73 74 @property
75 - def pid(self):
76 return (self._pidhi << 16) | self._pidlo
77 78 @pid.setter
79 - def pid(self, v):
80 self._pidhi = v >> 16 81 self._pidlo = v & 0xffff
82
83 84 -def test_smb():
85 buf = b'\xffSMB\xa0\x00\x00\x00\x00\x08\x03\xc8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\xfa\x7a\x00\x08\x53\x02' 86 smb = SMB(buf) 87 88 assert smb.flags == SMB_FLAGS_CASE_INSENSITIVE 89 assert smb.flags2 == SMB_FLAGS2_UNICODE | SMB_FLAGS2_NT_STATUS | SMB_FLAGS2_EXTENDED_SECURITY | SMB_FLAGS2_EXTENDED_ATTRIBUTES | SMB_FLAGS2_LONG_NAMES 90 assert smb.pid == 31482 91 assert smb.uid == 2048 92 assert smb.mid == 595 93 print(repr(smb)) 94 95 smb = SMB() 96 smb.pid = 0x00081020 97 smb.uid = 0x800 98 assert str(smb) == str(b'\xffSMB\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x10\x00\x08\x00\x00')
99 100 101 if __name__ == '__main__': 102 test_smb() 103 print('Tests Successful...') 104