Commit Graph

175 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
Packet Phantom bb69bf3dec Fixes for NMB Protocol (#1970)
* bugfix in NBNodeStatusResponse() marshalling

* fix unused parameter 'servport' in NetBIOS constructor

* remove unused parameter 'timeout' in _setup_connection() of NetBIOS class

* unittest: add local test cases for nmb
2025-07-14 10:09:06 -03:00
adrian manrique f2f2b367f5 Update build_and_test.yml (#1965)
* Update build_and_test.yml

added python 3.13
removed python 3.8

* workaround delying thread initialization to avoid python3.13 bug

* workaround delaying thread initialization to avoid python3.13 bug

* avoid running Process instances beacuse of a bug in python3.13 https://github.com/python/cpython/issues/134381

* removed hack

* make helper servers run as daemon in order to make testecases not to get stuck
2025-05-23 18:48:29 -03:00
zblurx 75707eaeb7 fix checkMIC function (#1960)
* fix checkMIC function

* update test_ntlm.py
2025-05-15 11:41:21 -03:00
alexisbalbachan 828fc7ae97 Fixes unicode exceptions when changing passwords containing encoded characters longer than 2 bytes (#1955) 2025-05-08 10:07:45 -03:00
zblurx c384b5fb11 Support channel binding and ldap signing for ntlm and kerberos auth (#1919)
* support channel binding and ldap signing for ntlm and kerberos auth

* fix test_ntlm.py

* implement gssapi_aes

* refacto channel binding

* remove exceptions

* refacto encrypt and decrypt functions

* restore gssapi.py file

* fix gss_unwrap_ldap function

* revert useless changes on kerberostype3

* remove unused channel_binding variable and last changes to kerberosv5
2025-04-15 19:56:18 -03:00
Alex Romero ea242af1c7 add more requests to even6 protocol (#1798)
* add EvtRpcRegisterControllableOperation and EvtRpcClearLog to even6 protocol

* add EvtRpcExportLog request to even6

* add tests for even6 EvtRpcClearLog and EvtRpcExportLog requests

* minor changes in even6
2025-01-23 09:33:25 -03:00
Alex ea27e8b2df LDAP Channel binding implementation from #1697 (#1844)
* Implemented LDAP channel binding as cleanly as I could, based on https://github.com/ly4k/ldap3.

* Set channel binding to bytes value as requested in the review

* Fix test sessionBaseKey

* Fix test ntResponse

* Fix test encryptedSessionKey

* Fix test ntlmChallengeResponse

* Fix test ntlmChallengeResponse

* Removing leftover print statement

* Remove unnecessary AV_EOL, this is done by impackets struct anyway

---------

Co-authored-by: frank <frank.spierings@warpnet.nl>
2024-11-25 16:29:52 -03:00
gabrielg5 c21ad14910 Fixed copyright notice in some tests scripts. 2024-09-02 11:05:17 -03:00
gabrielg5 27e7e7478d Updating copyright banner... 2024-08-28 17:52:57 -03:00
Alex Romero 3c15e009af Add new test cases for test_smb.py (#1760)
* remove spaces

* add remained functions to test_getData() in test_smb.py

* add new test case test_queryInfo() in test_smb.py
2024-07-10 19:51:03 -03:00
Gabriel Gonzalez 9b4a139405 Updated Copyright to 2023 2023-07-31 11:48:28 -03:00
leandro b5dab2df5e Merge pull request #1526 from NtAlexio2/ldap-sasl
support sasl authentication in ldap protocol
2023-06-29 12:11:15 -03:00
Alex Romero 44b5e00264 change test_comev() status to remote test 2023-05-09 11:40:34 -04:00
Alex Romero fbd3a8c579 add test case for ldap sasl authentication 2023-04-15 15:58:47 -04:00
Gabriel Gonzalez 8799a1a2c4 Update file banners to reflect Fortra ownership 2022-12-14 17:28:23 -03:00
0xdeaddood 7a18ef5c8b About to tag a release 2022-05-04 11:33:16 -03:00
Martin Gallo bffca7ec5b Tests: Fixing more tests on Windows Server 2016 onwards
EVEN, PAR, TSCH and some RPCRT unit tests moved to using PKT_PRIVACY.
2022-05-03 13:29:08 -07:00
Martin Gallo 46c5439a63 Tests: Fixing SAMR tests for Windows Server 2016 onwards
Windows Server 2016 and up requires PKT_PRIVACY on remote SAM RPC calls.
2022-05-03 10:58:34 -07:00
Martin Gallo e868dba5bc DPAPI: Added some simple tests to blob decryption with and without entropy 2022-04-06 13:52:38 -07:00
0xdeaddood 6e288da406 CCache: Fixed unit tests on 2.7 so no errrors are thrown
Co-authored-by: Martin Gallo <mgallo@secureauth.com>
2022-03-10 11:51:47 -03:00
Martin Gallo 1c9624c0ff CCache: Added some unit tests
- Parsing v3 and v4 ccache files to check #1106 (and not support for v1 and v2)
- Parsing creds from kirbi to check #1254
- Checking #1166 parseFile function
2022-02-09 11:10:30 -08:00
0xdeaddood 2abda3c8b3 Tests: Added new test cases in MS-PAR and MS-RPRN. 2022-02-03 15:57:57 -03:00
0xdeaddood ecc3008d3b Tests: some fixes to NRPC tests
- Updated the Netlogon Authenticator computation.
- Modified the authenticate function. Now, the user's machine connects to the server.
- Marked some tests as Xfail due to the Zerologon patch.
2022-01-28 17:17:59 -03:00
Martin Gallo 84d254d935 Tests: Make SCMR tests more idempotent (#1238)
- If a previous test run broke, the services was left on the target and thus create calls will fail. Implemented an open or create helper function to solve that.
2022-01-19 14:47:52 -03:00
Martin Gallo 35700a999a Tests: Added some basic test cases for [MS-PAR] (#1237)
- Testing `RpcAsyncEnumPrinters` and `RpcAsyncEnumPrinterDrivers` calls
2022-01-18 18:29:25 -03:00
Martin Gallo 7722d094a3 Tests: arranging DHCPM test cases 2022-01-18 05:00:27 -08:00
Martin Gallo 3b2c07b162 Tests: Fixed broken SRVS test case
Using a more generic exception catch for when we're closing ourselvex
2022-01-17 13:21:22 -08:00
Martin Gallo e6b2f207fc Tests: some fixes to NRPC tests to get back to previous pass rate 2022-01-17 12:38:27 -08:00
Martin Gallo ee3d988b06 Merge branch 'master' into test-refactor-catchup 2021-12-03 06:05:46 -08:00
Martin Gallo f057477633 Removed some deprecation warnings (#1157)
* Fixed warnings related to threading, that will start to appear in Pyhton 3.10, see https://docs.python.org/3.10/whatsnew/3.10.html#deprecated
* Fixed warnings related to unrecognized escape sequences, see https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals
2021-09-21 15:11:27 -03:00
Martin Gallo 1893ce7f96 Merge branch 'test-refactor' of https://github.com/SecureAuthCorp/impacket into test-refactor 2021-09-03 11:19:27 -07:00
Martin Gallo fac172018f Merge branch 'master' into test-refactor 2021-09-03 11:17:17 -07:00
Martin Gallo c348d94b0f Tests: Refactor DCE/RPC endpoints test cases (#1151)
Main changes are:
* Moved DCE/RPC endpoints test cases to a separate folder to better match code layout
* Using a base class for test cases to abstract code and reduce reuse
* Improved some of the tests cases to avoid code duplication
* Marking and skipping tests cases known to be failing
2021-09-03 15:15:31 -03:00
Martin Gallo 7bf33024bb SMBServer: Various fixes and improvements
* Harness unit and functional tests, covering more operations
* Added test for unicode filenames #878
* Added test for unicode username #700
* Added TID checks
* Hardened path checks:
  * Added a normalize_path function
  * Using isInFileJail across operations
* Added close method to avoid address reuse in tests
2021-08-19 06:55:52 -07:00
Martin Gallo c39fc6e48c Tests: Simplify remote configuration (#1131)
* Merged TCP and SMB transport configuration into only one.
* Abstracted remote configuration parsing routines into functions.
* Remote config file can now be specified as pytest option.
* Added some notes on testing guide.
2021-07-29 12:37:30 -03:00
Martin Gallo 0b4a759fb8 Tests: Refactors to some tests
* Moved binary hashes to base class
* Using assertEqual instead of assertTrue when possible
* Fixed a couple of bad assertions
2021-07-21 16:02:07 -07:00
Martin Gallo 51b66c71b3 Merge branch 'master' into test-refactor-catchup 2021-07-20 06:57:48 -07:00
Martin Gallo cd4fe47cfc Arrange tagline, copyright and license notes across all source files
This was a pending change to:
- Use the same tagline, copyright and license notice across files.
- Remove authors' contacts that are no longer valid (due to affiliation changes).
- Update repository location.
- Update license file with missing licenses (althought those were already in source files).

This doesn't include any change on the source code, nor any change on current copyright or licenses. Just formatting and phrasing to make our and distro's maintainers life easier.
2021-07-20 10:04:27 -03:00
Martin Gallo 2d32383811 Tests: Refactored configuration of remote test cases (#1122)
Refactored configuration to avoid duplicated code.

Main changes are:
* Moved AES keys config to base class
* Moved hash split to base class
* Made machine hashes parameters optional
* Made AES keys parameters optional
* Updated testing guide
2021-07-16 10:44:12 -03:00
Martin Gallo b3a608eb35 Tests: Removed test files PEP8 warnings 2021-07-07 18:26:09 -07:00
Martin Gallo d479c1c9da Merge branch 'master' into test-refactor-catchup 2021-07-07 16:42:29 -07:00
Martin Gallo 6bb5ea427b Tests: Continue refactor of test cases (#1112)
Continue refactor some of our test cases structure.

Main changes introduced are:
* Moved testing guide as a separate file and added some of the steps to configure the test environment.
* Leveraging unittest.main to catch command-line args and build the default suite.
* Only running GitHub actions workflow once for our own branches/PRs.
* Remote test config file can be specified via an env var now.
* Moved remote test config to a template and ignored config file.
2021-07-02 12:22:14 -03:00
0xdeaddood 142cacb649 Merge pull request #1074 from franferrax/master
WMI objects minor refactors, fixes, and offline parsing tests
2021-06-29 12:35:13 -03:00
Martin Gallo 658e0ab8e1 Tests: First batch of changes on refactoring test cases (#1102)
Tests: First batch of changes on refactoring test cases

This is the first part of a larger effort to refactor some of our test cases structure.

Main changes introduced are:
- Using pytest as the testing framework to organize and mark test cases.
- Replacing custom bash scripts with test cases discovery.
- Integrating pytest-cov plugin to easier coverage collection and reporting.
- Marking remote test cases to being able to pick those during run.
- Abstracted remote test cases configuration in a base class.
- Consolidating pytest, coverage and tox configuration in a single tox.ini file.
- Removed some Python 2.5 support and replaced custom compat checks with six.
- Replace unittest.TextTestRunner.run by unittest.main (cherry-picked from f5dab5ca76, thanks @franferrax !)
2021-06-25 11:19:52 -03:00
Martin Gallo 11f430437d Tests: PEP8 format on misc tests
Made some PEP8 arrangements on misc unit tests modules
2021-06-18 05:48:10 -07:00
Martin Gallo d659b7898b Tests: Adding coverage on passwords with @
We were missing the case when passwords had one or more '@' characters.
2021-06-18 05:36:34 -07:00
Francisco Ferrari Bihurriet f9514ee36d Create offline test parsing wmipersist.py objects
Create self.createIWbemClassObject() helper to avoid duplicating logic. It also uses wmi.INTERFACE as a wmi.IWbemServices mock (this is enough for our testing purposes).

This test also shows that #1069 fix is no longer necessary, since `DeliveryQoS` is zero after b1499ae822 & bc57bf7404 changes.

It should fail due to splash damage of the aforementioned changes. Upcoming fix...
2021-06-09 12:54:16 -03:00
Francisco Ferrari Bihurriet 8849e5ad17 Minor adjustments in test_win32_current_time_class_parsing
Invert expected and actual values order in assertEqual(), according with PyCharm's unittest runner interpretation of failures.

Avoid sample patching code to be considered by PyCharm's unittest runner as an example to be run.
2021-06-08 13:44:28 -03:00
Francisco Ferrari Bihurriet f5dab5ca76 Replace unittest.TextTestRunner.run by unittest.main
In this way, tests return the execution status to the OS shell, making the tox run fail and report failures in GitHub (hopefully)
2021-06-08 02:43:53 -03:00