Thanks Narendran.

It's another contribution from a USoC students. That's awesome!

---------- Forwarded message ----------
From: Narendran Thangarajan <[email protected]>
Date: 2011/7/4
Subject: Re: Executing the test suite
To: "Luís A. Bastião Silva" <[email protected]>


Hi Luis,
I have completed the SMB Header part. Working on the other section,
the SMB Message, now..


Code:
#!/usr/bin/env python


from umit.umpa.protocols import _consts
from umit.umpa.protocols import _fields
from umit.umpa.protocols import _protocols


__all__ = ["SMB",]

#Fields
class SMB_protocol(_fields.IntField):
       """
       Always set to constant value
       """
       bits = 32
       auto = True

       def _generate_value(self):
               """
               Set the default value to SMB --> 0xff534d42
               """
               return 0xff534d42

class SMB_command(_fields.EnumField):
       """
       One Byte code indicating the type of SMB command
       """
       bits = 8
       auto = False
       enumerable = {
               "SMB_COM_CREATE_DIRECTORY" : 0x00,
               "SMB_COM_DELETE_DIRECTORY" : 0x01,
               "SMB_COM_OPEN" : 0x02,
               "SMB_COM_CREATE" : 0x03,
               "SMB_COM_CLOSE" : 0x04,
               "SMB_COM_FLUSH" : 0x05,
               "SMB_COM_DELETE" : 0x06,
               "SMB_COM_RENAME" : 0x07,
               "SMB_COM_QUERY_INFORMATION" : 0x08,
               "SMB_COM_SET_INFORMATION" : 0x09,
               "SMB_COM_READ" : 0x0A,
               "SMB_COM_WRITE" : 0x0B,
               "SMB_COM_LOCK_BYTE_RANGE" : 0x0C,
               "SMB_COM_UNLOCK_BYTE_RANGE" : 0x0D,
               "SMB_COM_CREATE_TEMPORARY" : 0x0E,
               "SMB_COM_CREATE_NEW" : 0x0F,
               "SMB_COM_CHECK_DIRECTORY" : 0x10,
               "SMB_COM_PROCESS_EXIT" : 0x011,
               "SMB_COM_SEEK" : 0x12,
               "SMB_COM_LOCK_AND_READ" : 0x13,
               "SMB_COM_WRITE_AND_UNLOCK" : 0x14,
               "SMB_COM_READ_RAW" : 0x1A,
               "SMB_COM_READ_MPX" : 0x1B,
               "SMB_COM_READ_MPX_SECONDARY" : 0x1C,
               "SMB_COM_WRITE_RAW" : 0x1D,
               "SMB_COM_WRITE_MPX" : 0x1E,
               "SMB_COM_WRITE_MPX_SECONDARY" : 0x1F,
               "SMB_COM_WRITE_COMPLETE" : 0x20,
               "SMB_COM_QUERY_SERVER" : 0x21,
               "SMB_COM_SET_INFORMATION2" : 0x22,
               "SMB_COM_QUERY_INFORMATION2" : 0x23,
               "SMB_COM_LOCKING_ANDX" : 0x24,
               "SMB_COM_TRANSACTION" : 0x25,
               "SMB_COM_TRANSACTION_SECONDARY" : 0x26,
               "SMB_COM_IOCTL" : 0x27,
               "SMB_COM_IOCTL_SECONDARY" : 0x28,
               "SMB_COM_COPY" : 0x29,
               "SMB_COM_MOVE" : 0x2A,
               "SMB_COM_ECHO" : 0x2B,
               "SMB_COM_WRITE_AND_CLOSE" : 0x2C,
               "SMB_COM_OPEN_ANDX" : 0x2D,
               "SMB_COM_READ_ANDX" : 0x2E,
               "SMB_COM_WRITE_ANDX" : 0x2F,
               "SMB_COM_NEW_FILE_SIZE" : 0x30,
               "SMB_COM_CLOSE_AND_TREE_DISC" : 0x31,
               "SMB_COM_TRANSACTION2" : 0x32,
               "SMB_COM_TRANSACTION2_SECONDARY" : 0x33,
               "SMB_COM_FIND_CLOSE2" : 0x34,
               "SMB_COM_FIND_NOTIFY_CLOSE" : 0x35,
               "SMB_COM_TREE_CONNECT" : 0x70,
               "SMB_COM_TREE_DISCONNECT" : 0x71,
               "SMB_COM_NEGOTIATE" : 0x72,
               "SMB_COM_SESSION_SETUP_ANDX" : 0x73,
               "SMB_COM_LOGOFF_ANDX" : 0x74,
               "SMB_COM_TREE_CONNECT_ANDX" : 0x75,
               "SMB_COM_SECURITY_PACKAGE_ANDX" : 0x7E,
               "SMB_COM_QUERY_INFORMATION_DISK" : 0x80,
               "SMB_COM_SEARCH" : 0x81,
               "SMB_COM_FIND" : 0x82,
               "SMB_COM_FIND_UNIQUE" : 0x83,
               "SMB_COM_FIND_CLOSE" : 0x84,
               "SMB_COM_NT_TRANSACT" : 0xA0,
               "SMB_COM_NT_TRANSACT_SECONDARY" : 0xA1,
               "SMB_COM_NT_CREATE_ANDX" : 0xA2,
               "SMB_COM_NT_CANCEL" : 0xA4,
               "SMB_COM_NT_RENAME" : 0xA5,
               "SMB_COM_OPEN_PRINT_FILE" : 0xC0,
               "SMB_COM_WRITE_PRINT_FILE" : 0xC1,
               "SMB_COM_CLOSE_PRINT_FILE" : 0xC2,
               "SMB_COM_GET_PRINT_QUEUE" : 0xC3,
               "SMB_COM_READ_BULK" : 0xD8,
               "SMB_COM_WRITE_BULK" : 0xD9,
               "SMB_COM_WRITE_BULK_DATA" : 0xDA,
               "SMB_COM_INVALID" : 0xFE,
               "SMB_COM_NO_ANDX_COMMAND" : 0xFF,
       }

class SMB_status(_fields.IntField):
       """
       32 bit field used to communicate error messages from server to client
       """
       bits = 32
       auto = True

       def _generate_value(self):
               """
               Generate the value of the predefined field
               0x00 defines SUCCESS
               0x02 defines FAILURE
               """
               return 0x00

#Field and Field2 are directly included into the SMB Class

class SMB_signature(_fields.IntField):
       """
       Signature is a security feature for the SMB protocol.
       If the security signatures are negotiated, ie. if SMB_Command is
SMB_COM_NEGOTIATE,
               then the Signature field should contain an 8-byte
cryptographic message
       """
       bits = 64
       auto = True

       def _generate_value(self):
               """
               Generate value for the undefined field
               """

               return 0x0000000000000000

class SMB_reserved(_fields.IntField):
       """
       Reserved for future use
       """
       bits = 16
       auto = True

       def _generate_value(self):
               """
               Generate value for the undefined field
               """
               return 0x0000

class SMB_treeid(_fields.IntField):
       """
       Reserved for future use
       """
       bits = 16
       auto = True

       def _generate_value(self):
               """
               Generate value for the undefined field
               """
               return 0x0000

class SMB_processid(_fields.IntField):
       """
       Reserved for future use
       """
       bits = 16
       auto = True

       #ProcessID has to input through the constructor
       def __init__(self,pid):
               if pid:
                       self.value=pid
               else:
                       _generate_value()


       def _generate_value(self):
               """
               Generate value for the undefined field
               """
               return 0x0000

class SMB_userid(_fields.IntField):
       """
       Reserved for future use
       """
       bits = 16
       auto = True

       def __init__(self,uid):
               if pid:
                       self.value=uid
               else:
                       _generate_value()

       def _generate_value(self):
               """
               Generate value for the undefined field
               """
               return 0x0000

class SMB_multiplexid(_fields.IntField):
       """
       Reserved for future use
       """
       bits = 16
       auto = True

       def __init__(self,mid):
               if pid:
                       self.value=mid
               else:
                       _generate_value()


       def _generate_value(self):
               """
               Generate value for the undefined field
               """
               return 0x0000


#Section 1 --> SMBHeader
class SMBHeader(_protocols.Protocol):
       """
       Denotes the SMB Header part
       Collection of fields
       """
       name="SMB Header"
       def __init__(self,**kwargs):
               """
               Create a new SMBHeader()
               Enter the names in the correct order.
               """

               flags_bits =
('req','not','op','can','case','res','rec','lock')
               flags_predefined = dict.fromkeys(flags_bits, 0)

               flags2_bits =
('uni','error','exe','dfs','ext','res1','res2','res3','res4','islong','res5','res6','res7','sec','attr','long')
               flags2_bits = dict.fromkeys(flags2_bits,0)

               fields_list = [ SMB_protocol("Protocol",0),
                                        SMB_command("Command",0),
                                        SMB_status("Status",0),
                                        _fields.Flags("Flags",flags_bits)
                                        _fields.Flags("Flags2",flags2_bits)
                                        SMB_processid("ProcessID High",0)
                                        SMB_signature("Signature",0)
                                        SMB_reserved("Reserved",0)
                                        SMB_treeid("TreeID",0)
                                        SMB_processid("ProcessID",0)
                                        SMB_userid("UserID",0)
                                        SMB_multiplexid("MultiplexID",0)
                                        ]
               super(SMB,self).__init__(fields_list,**kwargs)

               #set_doc yet to be added

       def _pre_raw(self, raw_value, bit, protocol_container,
protocol_bits):
               """
               Handles the fields before the fillout function is called
               """
               return raw_value,bit

       def _post_raw(self,raw_value, bit, protocol_container,
protocol_bits):
               """
               Handles the fields after the fillout function is called
               """
               return raw_value, bit



protocols = [SMB,]

On 6/22/11, Luís A. Bastião Silva <[email protected]> wrote:
> That's nice! Let me know if you tackle some difficult issue handling the
> SMB.
>
> 2011/6/22 Narendran Thangarajan <[email protected]>
>
>> Luis I got the test suite working.. After including NetBiOS and the
>> corresponding test code.. this is the output of run_tests.sh
>>
>> /home/sunshadow/Documents/git-repos/pygit/umpa/umit/umpa/protocols/ARP
>>                 68     54    79%
>>
/home/sunshadow/Documents/git-repos/pygit/umpa/umit/umpa/protocols/Ethernet
>>                37     37   100%
>> /home/sunshadow/Documents/git-repos/pygit/umpa/umit/umpa/protocols/IP
>>                  137    103    75%
>>
*/home/sunshadow/Documents/git-repos/pygit/umpa/umit/umpa/protocols/NetBIOS
>>      33     25    75%*
>>
/home/sunshadow/Documents/git-repos/pygit/umpa/umit/umpa/protocols/Payload
>>                 42     41    97%
>> /home/sunshadow/Documents/git-repos/pygit/umpa/umit/umpa/protocols/SLL
>>                   60     59    98%
>> /home/sunshadow/Documents/git-repos/pygit/umpa/umit/umpa/protocols/TCP
>>                 108     98    90%
>> /home/sunshadow/Documents/git-repos/pygit/umpa/umit/umpa/protocols/UDP
>>                   57     57   100%
>>
>> I dint get any specific errors on NetBIOS before the summary.
>> And there was no Assertion error when i tested the protocol
>> independently..
>> I've done a local commit..
>> Working on SMB now..
>>
>
>
>
> --
> Luís A. Bastião Silva
> Umit Project Developer
> Skype: koplabs
> http://www.umitproject.org
> http://www.bastiao.org
>



-- 
Luís A. Bastião Silva
Umit Project Developer
Skype: koplabs
http://www.umitproject.org
http://www.bastiao.org
------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Umit-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/umit-devel

Reply via email to