Commit Graph

63 Commits

Author SHA1 Message Date
Vincent Yang 80c4dba1c9 Fix smbexec getting stuck (#1963) 2025-05-29 02:51:23 -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
Fluffy_Kaiju 3ce41be452 docs(smbexec): update doc dead link (#1850)
* Update the blog link to web.archive.org
2024-11-20 17:32:16 -03:00
gabrielg5 27e7e7478d Updating copyright banner... 2024-08-28 17:52:57 -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
Gabriel Gonzalez 9b4a139405 Updated Copyright to 2023 2023-07-31 11:48:28 -03:00
Santiago Moliner 8b3f9eff06 Merge pull request #1555 from Sanmopre/smbexec-service-name
* Deleted 'BTOBTO' hardcoded service name

* Deleted output file if still in share

* Fixed deleting output file

* Moved random string generation

* Deleted extra lines
2023-05-24 18:09:21 -03:00
alexisbalbachan f5cd886415 Apply suggestions from code review 2023-04-13 04:46:46 -03:00
Janis König 8247f3471a examples/smbexec.py: Use %COMPUTERNAME% in UNC path
Using the RFC1060 localhost IP doesn't resolve successfully on
all machines:

	C:\>echo foo > \\127.0.0.1\C$\bar
	echo foo > \\127.0.0.1\C$\bar
	The specified user does not exist.

	C:\>echo foo > \\localhost\C$\bam
	echo foo > \\localhost\C$\bam
	You were not connected because a duplicate name exists on the network. Go to System in Control Panel to change the computer name and try again.

	C:\>echo fo > \\localhost.localdomain\C$\bam
	echo fo > \\localhost.localdomain\C$\bam

	The network path was not found.

However, UNC paths work well and are documented to use the computer's
name for addressing.  Hence, switch to %COMPUTERNAME% for more reliable
execution.

Otherwise we may have errors such as:

	impacket.dcerpc.v5.scmr.DCERPCSessionError: SCMR SessionError: code: 0x41d - ERROR_SERVICE_REQUEST_TIMEOUT - The service did not respond to the start or control request in a timely fashion.
	Traceback (most recent call last):
	  File "/usr/lib/python3/dist-packages/impacket/smbconnection.py", line 769, in getFile
	    return self._SMBConnection.retr_file(shareName, pathName, callback)
	           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	  File "/usr/lib/python3/dist-packages/impacket/smb.py", line 4009, in retr_file
	    fid = self.nt_create_andx(tid, filename, shareAccessMode = shareAccessMode, accessMask = 0x20089)
	          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	  File "/home/jkoenig/MS17-010/examples/smbexec.py", line 206, in nt_create_andx
	    self._last_fid = smb.SMB.nt_create_andx(self, tid, filename, smb_packet, cmd, shareAccessMode, disposition, accessMask)
	                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	  File "/usr/lib/python3/dist-packages/impacket/smb.py", line 3896, in nt_create_andx
	    if smb.isValidAnswer(SMB.SMB_COM_NT_CREATE_ANDX):
	       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	  File "/usr/lib/python3/dist-packages/impacket/smb.py", line 778, in isValidAnswer
	    raise SessionError("SMB Library Error", self['ErrorClass'] + (self['_reserved'] << 8), self['ErrorCode'], self['Flags2'] & SMB.FLAGS2_NT_STATUS, self)
	impacket.smb.SessionError: SMB SessionError: STATUS_OBJECT_NAME_NOT_FOUND(The object name is not found.)

	CRITICAL:root:SMB SessionError: STATUS_OBJECT_NAME_NOT_FOUND(The object name is not found.)
2023-03-03 17:40:20 +01:00
Janis König 26f6319831 examples/smbexec.py: Python 3 compat
* Cannot concatenate string to bytes
 * configparser now(?) requires the values to be String
2023-03-03 17:35:48 +01:00
Jonas Vestberg 97d67a85d5 Add missing imports 2023-02-16 20:53:26 +01:00
Jonas Vestberg 35cbac53c7 Replace static path to BAT file with random name 2023-02-16 20:51:52 +01:00
Gabriel Gonzalez 8799a1a2c4 Update file banners to reflect Fortra ownership 2022-12-14 17:28:23 -03: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 adb230256d Refactored the target parsing functions (#1053)
In reviewing #1051 (and related #347) we found out that there's some ugly duplicated code that's better suited for an utils function.

The expected target format is:
`<DOMAIN></USERNAME><:PASSWORD>@HOSTNAME`

This PR:
- Moved target parsing routine to an utils module.
- Added unit tests for the new function.
- Using the new function across example scripts that accept a target.
2021-04-22 09:11:33 -03:00
Sam Free5ide 8b0293e174 Add PowerShell option for semi-interactive shells 2021-03-11 20:31:54 +03:00
Roman Maksimov 896f78df18 convert UTF-8 to lowercase 2020-03-08 02:11:41 +03:00
asolino afe746d2e2 Adding keytab support to secretsdump and remote exec scripts
- Added a loadKeysFromKeytab() class method into keytab.py for easier usage from the scripts.
2020-02-25 15:37:00 -03:00
asolino 8d4c91481b Print Library's installation path by default when -debug is specified 2020-02-05 19:52:39 -03:00
asolino 4661adb094 Removed commented lines 2020-01-27 15:21:18 -03:00
Roman Maksimov d49cc05d45 fix connection issue in smbexec.py and samrdump.py 2020-01-16 23:59:40 +03:00
Alberto Solino fb723db3c0 Merge pull request #728 from GoSecure/more_flags
Added flags to SMBExec and PSExec to bypass badly made detection use cases
2020-01-07 16:47:48 -03:00
Maxime Nadeau e2fe6938dc Possibility to rename the PSExec uploaded binary name to avoid entropy-based detection use cases 2019-12-19 13:16:09 -05:00
Maxime Nadeau 906724ae56 Added the -service-name flag to SMBExec to avoid BTOBTO-based detection use cases 2019-12-19 13:01:25 -05:00
0xdeaddood 0f6713f891 Add the timestamp option to the remote execution scripts 2019-12-18 08:17:41 -03:00
exploide 501c3d126f updated Python docs URL to modern version 2019-12-03 16:00:45 +01:00
exploide 6170e27a07 smbexec.py: added -codec parameter to deal with UnicodeDecodeErrors
fixes #708
2019-12-03 16:00:19 +01:00
asolino 553881b9da Merge branch 'master' into python36 2018-12-05 12:16:54 -03:00
asolino c328de8252 Changing Copyright notice 2018-12-05 12:14:55 -03:00
asolino ec77ea3d06 Code cleanup homework
- Optimizing imports
- Removing unused variables
- Still a lot to do.
- Test cases passing OK
2018-12-04 14:47:16 -03:00
asolino 19334ddf54 Merge branch 'master' into python36 2018-11-19 12:30:38 -03:00
Viktor Szakats 3f29d8dcdb fix/secure URLs
* also remove/fix some whitespace such as tabs
  and spaces at EOL
2018-11-18 19:47:09 +00:00
asolino a43ab5f5e0 Fix configparser Py2 error 2018-11-13 14:57:03 -03:00
asolino 61d4282b5d smbserver.py and smbexec.py Python3 port 2018-10-10 18:24:22 -03:00
asolino 9d8638cdf1 Print traceback info if running in DEBUG mode 2018-05-04 18:25:44 -03:00
luz.paz 0e96b60b92 Misc. typos
Found via `codespell -q 3 -I ../impacket-word-whitelist.txt` through downstream `curl`
2018-03-16 09:42:21 -04:00
asolino 1a3beb60f2 Changing Service Creation flags
* Following @ldionmarcil advise (https://github.com/byt3bl33d3r/CrackMapExec/pull/197) to avoid issues with multiple server's reboot in those cases where the service couldn't be deleted for some reason.
2017-08-07 11:07:33 -03:00
Martin Gallo 4152e128b8 Replaced shebang with a virtualenv friendly one
Replaced all instances of `#!/usr/bin/python` with `#!/usr/bin/env python` so impacket's examples and scripts can be run inside a virtualenv without having to call python.
2017-01-11 12:43:54 -03:00
asolino c049506e43 Minor cosmetic changes 2016-09-13 23:54:50 -03:00
dg 3c1959ceda added port 139 support and related options 2016-07-25 12:36:33 -07:00
asolino 1bdba48374 Adding -dc-ip option to examples
* Allows to specifying the IP address for the DC/kdcHost
* Collateral for https://github.com/CoreSecurity/impacket/issues/160
2016-05-31 21:22:54 -03:00
asolino 375b9972dc Changes the output filename based on the share specified.
* Addresses https://github.com/CoreSecurity/impacket/issues/156
* Debug message added
2016-05-07 16:54:43 -03:00
asolino 8c04d96979 Updating copyright notice. Welcome 2016 2016-01-06 14:08:30 -03:00
asolino 5851bd0cb9 Applying @0xsauby fix for password with '@' to the rest of the example scripts 2015-11-26 14:55:19 -03:00
asolino 4e32a0d498 Removing some pyCharm's erros/warnings
More scripts/libs changed. Hopefully doesn't break a thing. Test cases are passing
2015-05-25 20:40:17 -03:00
asolino 8b8f8a6947 Pyton imports fixups
1) Removed unnecesary imports, avoid import * whenever possible
2) Copyright updated
3) Minor typos fixed
4) File formats to Unix (LF)
2015-05-23 11:56:59 -03:00
asolino 9c85ee047a No need to encode the serviceName. It fails on some XP versions
This was left from the old RPC runtime where we had to manually encode things.
Now it's all handled by ndr.py
2015-05-01 13:31:32 -03:00
asolino 352816b37f Adding log level message format and adding try/catch to fail gracefully
Small fixes. Almost ready to tag new version
2015-04-30 18:05:37 -03:00
asolino 4c2e64ad3a Second round of logging change.
Now there should be a single logger called 'impacket' the library uses.
By default is has a NullHandler so nothing is printed, but messages are
forwarded to the upstream logger.

If you are a script using the library and want to set the root logger
with a custom formatter, you can import impacket.examples.logger.

After some testing I'll merge it into master
2015-04-25 14:40:42 -03:00
asolino 119e4438dd Changing logging mechanisms everywhere.
Full details coming soon
2015-04-25 14:40:41 -03:00