Commit Graph

544 Commits

Author SHA1 Message Date
adrian manrique 417c237da5 Shadow credentials update2 (#2031)
* removed PyOpenSSL dependency

* - fixed bug exporting to PEM files
- fixed bug computing KeyHash
- removed OpenSSL dependency
- fixed bug computing in getTicksNow() function
- certificate validity time expanded to 10 years

* removed print

* updated name certificate
2025-09-03 16:10:39 -03:00
Gabriel Gonzalez 576933651d NTLMRelayX: Show client IP when realying successful (#2012)
* ntlmrelayx: showing client ip when relay successful. standardized relay server prefixes (protocol). showin an incremental id for session relayed.

* reverting 'client_id' additions as are not important/valid in the context of this pr
2025-08-28 03:14:28 -03:00
Otavio Brito f66f82b8db [samedit.py] Added example script to edit local SAM hashes (#1761)
* Added example script samedit.py

* Rebased with latest version

* Replaced instances of "options.hash" with "options.hashes"

---------

Co-authored-by: alexisbalbachan <alexisbalbachan@gmail.com>
2025-08-20 17:46:53 -03:00
Alex 578733af71 Fix 2 critical bugs in ntlmrelayx (#2019)
* Fix getFileTime missing import

* Fix SSL settings
2025-08-10 22:14:44 -03:00
h3-josh-the-engineer 33a8dc554f Close issue #1436. Prevent secretsdump crashing win2k19 by adding DRS_EXT_NONDOMAIN_NCS flag to DRSBind call (#2017) 2025-08-08 16:08:28 -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
Gabriel Gonzalez 849c74b7b9 Monkeypatches (#2003)
* Added monkeypatches.py; contains a couple of functions to modify for specific usecases/issues: monkeypatch_ssl_create_default_context and monkeypatch_readline_backend

* Revert "Added monkeypatches.py; contains a couple of functions to modify for specific usecases/issues: monkeypatch_ssl_create_default_context and monkeypatch_readline_backend"

This reverts commit 7049ded298.

* defining and running monkeypatch functions from the init of impacket.examples

* leveraging 'init_ldap_session' from addcomputer.py

* leveraging ssl monkeypatch in 'init_ldap_session'
2025-08-01 11:39:18 -03:00
Roman Karwacik b5302a84ed [MSSQL] Fix regression: Connection establishment (#2005)
* Fix mssql connection establishment

* Fix mssql connection establishment in mssqlrelayclient.py as well

* Apply suggestions from code review

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

---------

Co-authored-by: Gabriel Gonzalez <gabriel.gonzalez@fortra.com>
2025-07-28 09:39:25 -03:00
Deft_ 7561038277 [MSSQL] Fix file exist error (#2002)
* [MSSQL] Improves version display

* [MSSQL] Patch file exists if language is not english

* Add impacket.mssql to setup.py

* Pass on KeyError exception

---------

Co-authored-by: Aurélien CHALOT <aurelien.chalot@orangecyberdefense.com>
2025-07-21 10:52:11 -03:00
Daniel b6ff7ac61c target arbitrary objects with ldapshell grant_control (#1927) 2025-07-14 13:01:02 -03:00
Fabrizzio53 171a324d3a Update utils.py to fix -dc-host when ntlm is disabled (#1997) 2025-07-08 15:58:31 -03:00
Markb1337 337569b260 Added user-status functionality to the SAMHashes Class of the secrestdump.py (#1847)
* Added functionality to the SAMHashes Class of the secrestdump.py library to be able to print the user status for SAM dumps. There was already a user-status flag for the NTDS dumps, but not for the SAM dumps. Now, when directly calling secretsdump.py to make a SAM dump, the user can specify the -user-status flag, just like with the NTDS dump. Alternatively, when other tools are using the Secretsdump library, they can simply initiate the SAMHashes class with the printUserStatus flag set to True. The default is False, so if you don't specify anything when calling the Secretsdump Library it will do exactly as it did before. This should not break any existing tools.

* Added some extra checks to make sure the account is no longer marked as "locked" when the lockout duration has passed. In the previous interation, the "locked" mark was only removed after the locked account was used at least once after being unlocked.

---------

Co-authored-by: Mark Bregman <mark.bregman@fox-it.com>
2025-07-08 15:02:44 -03:00
Deft_ a60a1f17be [MSSQL] Implements Channel Binding Token (#1986)
* Update mssqlrelay.py as in tds.py

* Manual fix for tds.py after dropping bad commit

* Reverted minor changes doublequote by singlequote for the sake of clarity in the review

* Reverted minor changes doublequote by singlequote for the sake of clarity in the review

* Reverted minor changes doublequote by singlequote for the sake of clarity in the review

* [TEST Commit] Adding debug log lines in tds.py to validate a scenario

* Fix issue receiving long messages from server. Reverted last [TEST Commit]

---------

Co-authored-by: Aurélien CHALOT <aurelien.chalot@orangecyberdefense.com>
Co-authored-by: gabrielg5 <gabriel.gonzalez@fortra.com>
2025-07-07 15:26:59 -03:00
Gabriel Gonzalez 6b8f62317b Connection discarded processing last target (#1983)
* SMBRelayServer: Fixing target processing when reaching end of target list; reload targets and then gather a new target to try to relay to

* HTTPRelayServer: Fixing target processing when reaching end of target list; reload targets and then gather a new target to try to relay to
2025-06-26 06:36:31 -03:00
Roman Karwacik b6b0daecb4 ntlmrelayx.py: RPC server and EPM (#1974)
* RPC Relay server

* Adds https://github.com/fortra/impacket/pull/1442

* Add EPM so e.g. printspooler can be relayed

* Fix log creation

* Fix copyright header

* RPCAttack: Save certificate to file instead of printing to console by default

* Removed unused RPC attack mode

* RPC relay server: keep relaying

* RPC relay server: Fix forgotten variable

* rpcrelayserver.py: Fixing client_address property

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

* rpcrelayserver.py: replace constant by reference

* rpcrelayserver.py: keep relaying 2

* rpcrelayserver.py: disable multirelay

* rpcrelayserver.py: outsource target setting to negotiate_ntlm_session

* RPCRelayServer: Consuming targets only on NTLMSSP_AUTH_NEGOTIATE

* Opportunistic enhancement: consider finishedAttack target's scheme to retrieve target candidate

---------

Co-authored-by: Sylvain Heiniger <sploutchy@gmail.com>
Co-authored-by: S3cur3Th1sSh1t <27858067+S3cur3Th1sSh1t@users.noreply.github.com>
Co-authored-by: Gabriel Gonzalez <gabriel.gonzalez@fortra.com>
2025-06-23 12:46:06 -03:00
Gabriel Gonzalez fde4265abd Adding "-dc-host" parameter to dacledit.py, owneredit.py, rbcd.py. Reintroduced SessionError:"STATUS_NOT_SUPPORTED" in function _get_machine_name now that all these examples have "-dc-host" parameter. (#1940) 2025-05-08 10:48:19 -03:00
Muhammad Ibrahim 756ca96e4a Added Support for LDAPS When Retrieving LAPS Password from Windows Server 2025 (#1942)
* Added Support for LDAPS When Using Windows Server 2025

* set ldaps_flag as optional in ldap_login()

---------

Co-authored-by: Gabriel Gonzalez <gabriel.gonzalez@fortra.com>
2025-04-30 17:49:57 -03:00
Julien decf5b3f1b PR: ntlmrelayx.py ignores URL parameters provided in targets #1910 (#1911)
* Added 'query' to the HTTP(s)RelayClient class and condition for sendNegotiate and sendAuth

* remove tab

* added conition (if query) for registerTarget

* forgot line 82

* Added condition for target.scheme contain http
2025-04-30 00:37:12 -03:00
Signum21 00ced47f3e mssqlshell.py new Download function and fix Upload function for linked servers (#1915)
* mssqlshell.py new Download function and fix Upload function for linked servers

* Changed file exists function and check for permission
2025-04-04 13:32:23 -03:00
Gabriel Gonzalez 352695f18b Techdebt examples bootstrapping target domain fixes (#1937)
* Fixing ldap login logic - affecting findDelegation and GetUserSPNs

* Fixing ldap login logic - considering those examples that do not have "target_domain" parameter.

* Fixing SMBConnection initialization in _get_machine_name
2025-04-01 17:27:59 -03:00
Leron Gray 675ace8111 Update smbclient.py (#1933)
Fix error in self.outputfile access
2025-03-28 15:08:38 -03:00
Gabriel Gonzalez 7078e935f1 Update utils.py
Removed some exception handling in _get_machine_name to make it valid for all examples using it

(From #1918 and https://github.com/fortra/impacket/issues/1923#issuecomment-2759487006)
2025-03-27 18:15:49 -03:00
Gabriel Gonzalez 9f61287dc4 Update utils.py
Removed extra parameter in _init_ldap_connection()

(From #1918)
2025-03-27 17:58:54 -03:00
Gabriel Gonzalez ae0ec300f8 Techdebt examples bootstrapping v2 (#1928)
* Standardized examples logger init method

* Fixing missing import

* Standardized examples init_ldap_session function #1

* Calling new shared function _ldap3_kerberos_login from example addcomputer

* Removed considering -debug in each example. Now it's handled in utils.

* Standardized EMPTY_LM_HASH in impacket.examples.utils

* Unify parse_identity function (phase 1)

* Standardized parse_identity

* Renamed "_ldap3_kerberos_login" to "ldap3_kerberos_login" (as it is called from outside)

* Standardize "logger" init in regsecrets.py

* Standardized LDAP login into a single function in utils.py:ldap_login
2025-03-26 22:58:39 -03:00
SAERXCIT 5a402fcb90 [secretsdump] Filter foreign users when parsing NTDS.dit (#1759) 2025-03-20 09:44:48 -03:00
PF d842c24dde Add autocomplete to "cat" command in smbclient.py (#1862)
A small contribution to add autocomplete functionality to the `cat command, similar to `cd`.
2025-03-20 07:58:43 -03:00
Alex e61ff5d7a5 Fix invalid escape sequence warnings (#1921) 2025-03-20 01:26:16 -03:00
Julien Egloff 8b4566b12f Adding regsecrets to impacket (#1898)
Co-authored-by: laxa <laxa@ddracepro.net>
2025-03-14 17:20:46 -03:00
p0rtL6 678cd0abbe Add the Option to Dump Ntlm Hashes in Ntlmrelayx (#1904)
* Add option to dump relayed hashes to console (ntlmrelayx)

* Add Documentation

* Simplify print statements

* Update README.md

Reverted changes in the README.md file in preparation for merge.

---------

Co-authored-by: p0rtL6 <p0rtl.pue@gmail.com>
Co-authored-by: Gabriel Gonzalez <gabriel.gonzalez@fortra.com>
2025-03-11 09:09:21 -03:00
gjhami 0f4b866641 Fix SOCKS Target Parsing (#1843)
* Update socksserver.py

Fixes https://github.com/fortra/impacket/issues/1575 by parsing the target hostname correctly from commands run through ntlmrelayx's socks5 proxy.

* Update socksserver.py

Fix hostname parsing
2025-01-30 10:43:06 -03:00
Alexander Neumann ff8d248c90 ntlmrelayx: support upn format + oem encoding (#1833)
Co-authored-by: Lucas Vater <lucas.vater@redteam-pentesting.de>
2025-01-21 13:47:00 -03:00
Pierre Milioni 9c8e4083e8 Add support for LDAP and LDAPS protocols in ntlmrelayx SOCKS (#1825)
* Add support for LDAP and LDAPS in ntlmrelayx SOCKS

Should fix #514

* Use real NTLM Challenge message during LDAP socks relay

* Reply to generic LDAP messages that comes before authentication and drop unbind LDAP messages

* Fix missing imports

* LDAP socks code cleaning

* Better handling of initial LDAP bind request in ntlmrelayx LDAP socks

* Better handling of clients' closing connections in ntlmrelayx LDAP socks
2024-12-20 18:24:33 -03:00
Gabriel Gonzalez 0fd9f288cd secretsdump - changing log level for message displayed when account does not have sam hash information (#1860) 2024-12-09 09:17:17 -03:00
kiriknik 9ef36ac811 Update mssqlclient.py (#1381)
* Update mssqlclient.py

Add functionality to upload files

* mssqlshell - refactor 'do_upload' command implementing code review changes

* mssqlshell - 'do_upload' command showing unhandled exceptions

---------

Co-authored-by: Gabriel Gonzalez <gabriel.gonzalez@fortra.com>
2024-12-05 18:25:03 -03:00
Erik Geiser bc934b0467 ntlmrelayx.py: Set log level for 'Unsupported MechType' to DEBUG (#1647) 2024-12-05 11:38:41 -03:00
q-roland 463693ea04 SCCM Management Point and Distribution Point relay attacks implementation (#1832)
* Adding SCCM Policies attack and SCCM Distribution Point attack

* Fixing typo in error log message

* Handle packages one at a time for DP attack ; uniformise coding style ; update requirements.txt
2024-11-25 09:26:39 -03:00
Jannik Vieten 835e17550b Fixed warnings with Python 3.12 (#1695)
* fixed SyntaxWarnings due to invalid escape sequence

* fixed DeprecationWarning since datetime.datetime.utcnow() is deprecated in Python 3.12+

* fixed DeprecationWarning since datetime.datetime.utcfromtimestamp() is deprecated in Python 3.12+
2024-10-24 09:00:11 -03:00
gabrielg5 27e7e7478d Updating copyright banner... 2024-08-28 17:52:57 -03:00
Gabriel Gonzalez 0656b487e8 Allowing to configure "logger" in tds::printReplies function; both for error and info. (#1795)
Change mssqlattack.py and mssqlshell.py to align with changes
2024-08-27 17:17:06 -03:00
adrian manrique 0630989669 removed pyreadline dependency (#1800)
* removed pyreadline dependency

* replaced pyreadline by pyreadline3

* Update setup.py
2024-08-27 14:02:40 -03:00
SAERXCIT b6713d20df [ntlmrelayx] Dump ADCS: bug fixes (#1318)
* [ntlmrelayx] Dump ADCS: fix case when ACE has neither "ObjectType" nor "InheritedObjectType"

* [ntlmrelayx] Dump ADCS: fix issue when SID cannot be translated
2024-08-21 23:34:53 -03:00
Gabriel Gonzalez f70e3626fa Print message when connections are received in relay servers (#1792)
* Printing a message when a WebDav request was received in HTTPRelayServer at NTLMRelayX (PROPFIND method)

* Opportunistic enhancement: showing listening ports for SMBRelayServer and WCFRelayServer
2024-08-16 16:10:21 -03:00
Gabriel Gonzalez e52791288d smbserver examples log to console (#1791)
* Setting "log_file" property to "None" for smbserver configuration file ~ will print to console

* Setting "log_file" property to "None" for smbrelayx.py
2024-08-12 20:54:08 -03:00
adrian manrique d458fce704 Shadow credentials update (#1780)
* refactored shadow creds functionality

* bugfixes

* bug fixes. added references
2024-08-07 02:09:11 -03:00
Pedro Gabaldon f93bf78ccd Remove unused code (#1769)
Co-authored-by: Peter Gabaldon <peter@pgj11.com>
2024-07-11 10:07:37 -03:00
nurfed1 452ca845f3 Add ldapshell dirsync/whoami (#1424) 2024-05-23 02:06:19 -03:00
adrian manrique f9d1d74763 Update shadow_credentials.py added pydsinternals project reference 2024-05-22 10:22:49 -03:00
Pedro Gabaldon e692d9052f [SECRETSDUMP] New Dump Method - Shadow Snapshot Method via WMI (#1719)
* Starting remote 'Shadow Snapshot Method'

* Continue :)

* Added options

* Logic error hehe :)

* Ups :S

* Remote Shadow Snapshot Working. Path calculated well. Need to fix download

* Download not working. SMB access is protected. Run copy command remotely? Too much noise I think :S

* Could not find a way to copy using WMI using GLOBALROOT path. Failing back to RCE; noisy :(

* Working

* Working

* Working

* Added debug log

* Working without RCE, download from ShadowCopy using SMB

* Removed commented code and unused methods

* Delete ShadowCopy after downlodaing SAM/SYSTEM/SECURITY

---------

Co-authored-by: Pedro Gabaldon <peter@pgj11.com>
2024-05-13 10:37:52 -03:00
adrian manrique 2a65d8d9f4 Update adcsattack.py
PKCS#12 clarification and formatting
closes #1692
2024-05-09 09:54:04 -03:00
alexisbalbachan 8856defa66 NTLMRelayX Multirelay fixes and behavioral changes (#1741)
* * Record failed targets
* [MULTIRELAY][Default Behavior] The relay will cycle over its target list only once, this matches the behavior of the single relay mode
* [MULTIRELAY] Added a flag to cycle over the target list any time a new connection is established, essentially relaying against each target in the list for every incoming connection
* [MULTIRELAY] HTTP server will stop consuming targets after the first failed attempt, this matches the behavior of SMB server
* Fixed issue in HTTP server when an unhandled exception occurs while trying to establish a connection with the target. Now it is recorded as a failed attempt.

* * When a connection attempt fails (such as connection refused) the target is now (internally) marked as "failed"
* Bugfix: initclient-> unhandled return status of client.initconnection, now properly raises an exception when that call fails
* Bugfix: enable-retries now works with smbserver

* [REFACTOR] Renamed logTarget -> registerTarget

* Modified flag help text

* * Record failed targets
* [MULTIRELAY][Default Behavior] The relay will cycle over its target list only once, this matches the behavior of the single relay mode
* [MULTIRELAY] Added a flag to cycle over the target list any time a new connection is established, essentially relaying against each target in the list for every incoming connection
* [MULTIRELAY] HTTP server will stop consuming targets after the first failed attempt, this matches the behavior of SMB server
* Fixed issue in HTTP server when an unhandled exception occurs while trying to establish a connection with the target. Now it is recorded as a failed attempt.

* * When a connection attempt fails (such as connection refused) the target is now (internally) marked as "failed"
* Bugfix: initclient-> unhandled return status of client.initconnection, now properly raises an exception when that call fails
* Bugfix: enable-retries now works with smbserver

* [REFACTOR] Renamed logTarget -> registerTarget

* Modified flag help text

* * Renamed enable-retries flag to keep-relaying
* Set default value of keep-relaying flag to False
2024-05-06 19:37:29 -03:00