Commit Graph

193 Commits

Author SHA1 Message Date
Kali c456746d7a tests: initialize DCOM connection for RemoteGetClassObject
Use DCOMConnection in test_RemoteGetClassObject instead of a raw
  DCE/RPC connection from self.connect(). RemoteGetClassObject returns an
  interface whose RemRelease path expects the DCOMConnection PORTMAPS cache
  to be initialized for the target; the raw connection path leaves that
  cache empty and can raise KeyError keyed by the target address.

  Wrap the interface use in a try/finally so the DCOM connection is always
  disconnected after the test.
2026-05-15 12:40:42 -03:00
Kali 9dcc815344 do not use hardcoded paths for tests.
do cleanup on finally block even in test fails
2026-05-15 11:27:47 -03:00
Herbenderbler 0be6514bdf BUG-2099: Fix Unhandled ValueError during authentication (#2151)
* Fix #2099: handle truncated SMB responses (SessionError + debug log)

- structure: asciiz without NUL raises clear ValueError with field name
- smb: catch ValueError at session/negotiate parse sites; log at debug, raise SessionError
- smbconnection: docstring notes invalid/truncated server response
- ci: fix flake8 F824 (goldenPac, ldapattack)
- tests: regression for asciiz NUL and session setup parsing; align with TESTING.md
- docs: ChangeLog

* Fix #2099 struct.error mapping.
2026-05-06 01:53:30 -03:00
alexisbalbachan 899ef248d8 ticketer.py: preserve KDC-issued lifetime for diamond tickets (issue #2058) (#2181)
* preserve request-based ticket lifetime and add regression test

* tests: expand coverage for request-based ticket lifetime preservation

* Updated tests to comply with the code review

* Update examples/ticketer.py

* update description of the -duration parameter

---------

Co-authored-by: Gabriel Gonzalez <gabriel.gonzalez@fortra.com>
2026-05-01 00:56:43 -03:00
alexisbalbachan 3236169747 Fix TS_ALL_PROCESSES_INFO parsing for RpcWinStationGetAllProcesses (#2155)
* Fixed TS_ALL_PROCESSES_INFO parsing for RpcWinStationGetAllProcesses

* Removed ldap3 dependency, fixed mismatched data type for rawsid, added missing test

* Removed unused imports, renamed imagenamesize -> imagename to match docs. Added missing test
2026-04-30 11:56:58 -03:00
alexisbalbachan 426f354767 Fix large-page ESE tag-state parsing for Windows Server 2025 NTDS.dit (issue #1924) (#2158)
* Fix issue #1924 large-page tag count parsing

* Applied code review changes, added unit test

* improved code
added testcase

* Fix USER_PROPERTIES parsing per MS-SAMR spec

---------

Co-authored-by: Kali <adrian.manrique@gmail.com>
2026-04-30 11:41:05 -03:00
Julien EGLOFF 3439d335a1 Modify ticketer and ccache logic (#2159)
* Modify ticketer and ccache logic

* ticketer now update existing ccache if KRB5CCNAME is specified
* ticketConverter now convert all TGS within the Kirbi or provided Ccache
* Fix a bug during the conversion from ccache to kirbi that does not correctly preserve ticket flags

* Update kirbi test cases. Improve Kirbi to Ccache conversion.
2026-04-29 17:13:05 -03:00
huh? 2f130643d4 raiseChild: fix PAC buffer preservation and add AES support for modern Windows (#2164)
* raiseChild: fix PAC buffer preservation and add AES support for modern Windows

Two bugs fixed:

1. makeGolden() hardcoded exactly 4 PAC buffers, discarding all others.
   Windows Server 2022 with CVE-2021-42287 patches requires PAC_REQUESTOR
   (type 18) to be present. Stripping it causes KDC_ERR_TGT_REVOKED.
   Fix: preserve all original PAC buffers, only update modified ones.

2. getKerberosTGT() called with aesKey=None hardcoded, ignoring -aesKey.
   Fix: pass aesKey, try AES first then fall back to RC4.

Additional improvements:
- Auto-retry golden ticket with AES if RC4 is rejected by KDC
- Fix signature zeroing to use actual length instead of hardcoded 12/16
- Updated help text with AES key usage examples

Tested against Windows Server 2022 Build 20348. Backward compatible.

* krb5: share PAC rebuild and signing helpers

* krb5: share AES ticket key selection helpers

* Fix password fallback suppression and TGT re-acquisition on golden ticket retry

* raiseChild: fix credential retry flow

* raiseChild: pass normalized AES key to target exec login

---------

Co-authored-by: plur1bu5 <plur1bu5@users.noreply.github.com>
Co-authored-by: Gabi Gonzalez <gabriel.gonzalez@fortra.com>
Co-authored-by: Your Name <you@example.com>
2026-04-24 10:30:19 -03:00
alexisbalbachan a4bdf59796 Fix SCMR failure actions marshaling and add regression test (Issue #2046) (#2160)
* Fix SCMR failure actions marshaling and add regression test

* Update tests/dcerpc/test_scmr.py

Applied Code review suggestions to the test

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Applied code review suggestion

* Update impacket/dcerpc/v5/scmr.py

set lpsaActions to NULL by default

Co-authored-by: Gabriel Gonzalez <gabriel.gonzalez@fortra.com>

* Update tests/dcerpc/test_scmr.py

Added regression test

Co-authored-by: Gabriel Gonzalez <gabriel.gonzalez@fortra.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Gabriel Gonzalez <gabriel.gonzalez@fortra.com>
2026-04-23 10:22:56 -03:00
Chris Thompson 43fe4ce7cb Add TDS 8.0 (Force Strict Encryption MSSQL Server setting) support to ntlmrelayx (#2122)
* Add support for TDS 8.0 when Force Strict Encryption = Yes

* Match log syntax

* Only use TDS 8.0 if Force Strict Encryption is set to Yes

* Add comments back and fix typos

* Use short timeout, remove excessive debug logs, add comments

* Testing changes to make TDS more broadly applicable by moving to tds.py

* Add TLS 1.2 cap and EPA channel binding for TDS 8.0

* Fix TDS 8.0 DONE parsing and TLS state handling

* Use negotiated TDS version for DONE rowcount parsing

* Align strict TDS login with modern LOGIN7 flow

* Keep relay TLS socket for strict TDS sessions

* Reassemble relay TDS packets over TLS

* tds: stop advertising UTF-8 support

* tds: fix relay login failure token packing

* mssqlrelay: fix PRELOGIN thread id encoding

* tds: preserve default LOGIN7 version in serializer

* tds: only retry strict fallback on connection close

* ntlmrelayx: support strict MSSQL SOCKS reuse

* Reassemble TDS frames on TLS-backed MSSQL reads

---------

Co-authored-by: Gabi Gonzalez <gabriel.gonzalez@fortra.com>
2026-04-21 09:33:52 -03:00
Alex d400a6aa6a Add RegisterRemoteSubscription and RemoteSubscriptionNext RPC calls (#2152)
* Add RegisterRemoteSubscription and RemoteSubscriptionNext RPC calls

* added testcases for EvtRpcRegisterRemoteSubscription and EvtRpcRemoteSubscriptionNext

* Remove redundant init definition

* Remove item definitions

* Use spec conform handle

---------

Co-authored-by: Kali <adrian.manrique@gmail.com>
2026-03-20 09:37:55 -03:00
alexisbalbachan dabf7fd2f2 Assorted fixes for NTLM AV_PAIRS container protocol and ImpactPacket LinuxSLL/IP (#2092, #2093, #2094) (#2137)
* Added fixes and tests for #2092, #2093, and #2094

* do not use interal __iter__ interface for av_pairs tests

---------

Co-authored-by: Kali <adrian.manrique@gmail.com>
2026-03-13 10:52:52 -03:00
Herbenderbler 256749185f BUG2095: Fixed fragment_by_list() crash when the child protocol is None (#2136)
* Fixed fragment_by_list() crash when child protocol is None

* removed the inline

* Added a regression test for IP.fragment_by_list() with Data payload

---------

Co-authored-by: herbenderbler <herbenderbler@users.noreply.github.com>
2026-03-12 11:30:26 -03:00
Gabriel Gonzalez 8c155a5b49 Add comprehensive unit tests for krb5.gssapi token parsing, factory selection, RC4/AES helpers, and wrap/MIC paths (#2138) 2026-03-06 16:53:46 -03:00
alexisbalbachan 9f2bf6b58c Ntfs read fixes (#2106)
* Fixed files not being listed when in INDEX_ROOT

* Added support for sparse files

* Fix double VNC shift, causing incorrect reads.
handle walk() returning None
null checks in do_cat
error handling in getINode
general refactor

* added tests for ntfs-read

---------

Co-authored-by: Kali <adrian.manrique@gmail.com>
2026-03-05 10:42:52 -03:00
Packet Phantom 8728bbcfee Implement PutClass and DeleteClass for WMI (#1803)
* add wmi ObjectFlags to improve human-readability

* Fix handling of empty buffer in CLASS_AND_METHODS_PART to prevent errors

* implement PutClass and DeleteClass functions in wmi

* bugfix: replace CIM_CLASS with CIM_INSTANCE

* unittest: add test cases for PutClass and DeleteClass

* improved wmi testcases

* Fix PutClass
  - Preserve existing class properties (ndTable, valueTable, name ref)
    when updating a class via PutClass
  - Use correct propIndex (existingCount + i) for DeclarationOrder
    and ndTable bit offsets on newly added properties

* uncommented failing case

---------

Co-authored-by: Kali <adrian.manrique@gmail.com>
2026-02-19 10:45:42 -03:00
Gaffner d029698149 smbclient ACL Support (#1240)
* Added smbcacls

* Changed example script

* improve ACL manage

* improve acl manage

* improved acl

* Closing all handles

* fixed directory and handle is open bug in acl.py

* Changed help a little bit

* Ignore from empty ACL

* fix indentation

* removee example to different PR

---------

Co-authored-by: john57 <your_email_address@example.com>
2026-02-18 00:42:34 -03:00
alexisbalbachan 101b62fda3 Structure.py: 'u' format calcUnpackSize fix for higher unicode codepoint values. (#1995)
* Fix calcUnpackSize for unicode format 'u' by searching for the real NULL-NULL terminator
Changed documentation about the 'u' format to clarify that it is UTF16-le

* Precompile regex and keep it cached.

* added test for #1992 , #1788

---------

Co-authored-by: Kali <adrian.manrique@gmail.com>
2025-11-25 12:38:36 -03:00
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