Commit Graph

1 Commits

Author SHA1 Message Date
Raz Kissos 20002f79e5 [SMB] Massive Fixes, Features and Refactoring (#1894)
* Add documentation in the comments for clearer use of NT_CREATE_ANDX flags.
Then sort out some mismatching flags.

* Change default shareAccessMode in the retr file methods to allow read, write and delete.
I found it out when capturing network traffic and seeing I can manage to read files with open handles.
This fixes SHARE_ACCESS_DENIED errors when trying to read files with handles on them.
This is the logical thing to do when we open files for reading.
We do not want to block other processes from interacting with the file.
This may raise problems when reading files that are being written into / being deleted.
I still think this is the right move since we usually want to read the files no matter what.

* Add ability to read files with open handles - this is related to my previous commits.

* Add ability to read files that have open handles to them.
This is related to my older commits on the subject.

* Update smbconnection.py

Add method parameters to `getFile` to easily communicate with the underlying SMB API.

* Fix `shareAccessMode` when opening files for writing.
We obviously do not want to allow others to write to the file while we are writing to it.

* Extend `SMBConnection`'s method parameters for `getFile` and `putFile` methods.

* Add comments for `DesiredAccess`, `ShareAccess` and `CreateDisposition` values in SMBv2.

* Update smb3structs.py

* Fix missing values.

* [SMB] Define CIFS SMB Date and SMB Time according to `2.2.1.4 Time`.
This is done to assist future development of SetInfo operations on files and directories.

```
Date Conversion Example - Year Component:
-----------------------------------------

    2009 - 1980 = 29

            | (convert to binary)
            V

    0001 1101

            | (position data correctly by shifting)
            V

                    0001 1101
    <<                     9
        ---------------------
    =  0 0011 1010 0000 0000

            | (trim to correct size with bitwise AND of correct mask)
            V

        0 0011 1010 0000 0000
    &   1111 1110 0000 0000
        ---------------------
    =   0011 1010 0000 0000
```

* [SMB] Added CIFS DateTime objects helper methods to convert values to classes.

* [SMB] Feature: added support for set_file_info method using trans2.
By doing so I also fixed a bad structure definition in the SMBSetFileBasicInfo structure.
Now we can modify file information remotely ;)

* [SMBServer] Moved FileTime Conversion methods to the base SMB library.
Also converted the SMB DATETIME methods to use my SMB_DATE and SMB_TIME implementations.

* [SMBConnection] Added type hinting for (almost) all methods.
Also implemented setInfo method to use for setting file information.

* [TEST_SMB] Add tests for new setInfo method.

* [TEST_SMB] This is causing errors so I will wait for now.

* [SMBConnection] add support for default info class type in queryInfo method.

* [SMBConnection] Fix queryInfo to allow retrieval of more
fileInformationClasses other than the default one.

* [attrib] Added attrib example to showcase file attribute modifications using SMB.
for now only implemented query.

* [smbserver] fix missing pack operation in getSMBTime method.

* [attrib] Finished set action, thus finishing the attrib example script.

* [attrib] Final touches, adding output to set action as well.

* [attrib] Add option to set connection timeout.

* [smbclient] Add reconnect command.

* [smb] Fix accidental SMB_TIME creation with removing `+ 1980` to hours.

* [examples] Implement filetime.py
An example script that allows querying and modifying file timestamps using SMB.

* After merge, fix some syntax issues.

* Actually show subparser's descriptions now.

* [SMB] Removed type annotations. Improved comments. Cleaned imports.

* [SMB] Removed type annotations, improved comments.

* [SMB] Comment changes.

* [examples] Add handling of empty action, even though argparse should catch it.

* refactor: Fix PR requests.
2025-08-07 15:01:58 -03:00